-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mehull-26
committed
Aug 20, 2024
1 parent
30cb048
commit f21706c
Showing
14 changed files
with
656,331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.10.35027.167 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ray Tracer", "Ray Tracer\Ray Tracer.vcxproj", "{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Debug|x64.ActiveCfg = Debug|x64 | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Debug|x64.Build.0 = Debug|x64 | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Debug|x86.Build.0 = Debug|Win32 | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Release|x64.ActiveCfg = Release|x64 | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Release|x64.Build.0 = Release|x64 | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Release|x86.ActiveCfg = Release|Win32 | ||
{E3C010E2-F07C-4E7B-B85A-CBF07934AB01}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A2D8F1C0-00E0-4537-AFDC-8F74CCADA57F} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>17.0</VCProjectVersion> | ||
<Keyword>Win32Proj</Keyword> | ||
<ProjectGuid>{e3c010e2-f07c-4e7b-b85a-cbf07934ab01}</ProjectGuid> | ||
<RootNamespace>RayTracer</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="image.ppm" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="camera.h" /> | ||
<ClInclude Include="color.h" /> | ||
<ClInclude Include="hittable.h" /> | ||
<ClInclude Include="hittable_list.h" /> | ||
<ClInclude Include="interval.h" /> | ||
<ClInclude Include="ray.h" /> | ||
<ClInclude Include="rtweekend.h" /> | ||
<ClInclude Include="sphere.h" /> | ||
<ClInclude Include="vec3.h" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="image.ppm" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="color.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="vec3.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="ray.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="hittable.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="sphere.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="hittable_list.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="rtweekend.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="interval.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="camera.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#ifndef CAMERA_H | ||
#define CAMERA_H | ||
|
||
#include "rtweekend.h" | ||
#include <chrono> | ||
#include "hittable.h" | ||
|
||
class camera { | ||
public: | ||
/* Public Camera Parameters Here */ | ||
|
||
double aspect_ratio = 1.0; // Ratio of image width over height | ||
int image_width = 100; // Rendered image width in pixel count | ||
int samples_per_pixel = 10; // Count of random samples for each pixel | ||
int max_depth = 10; // Maximum number of ray bounces into scene | ||
|
||
void render(const hittable& world) | ||
{ | ||
initialize(); | ||
std::ofstream fout; | ||
fout.open("image.ppm"); | ||
double avg_time = 0; | ||
fout << "P3\n" << image_width << ' ' << image_height << "\n255\n"; | ||
|
||
for (int j = 0; j < image_height; j++) | ||
{ | ||
//std::cout << "\rScanlines remaining: " << (image_height - j) << ' ' << std::flush; | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
for (int i = 0; i < image_width; i++) | ||
{ | ||
color pixel_color(0, 0, 0); | ||
for (int sample = 0; sample < samples_per_pixel; sample++) | ||
{ | ||
ray r = get_ray(i, j); | ||
pixel_color += ray_color(r, max_depth, world); | ||
} | ||
write_color(fout, pixel_samples_scale * pixel_color); | ||
} | ||
auto end = std::chrono::high_resolution_clock::now(); | ||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); | ||
avg_time += duration.count(); | ||
if (j % 10 == 0) | ||
{ | ||
avg_time = avg_time*1.0f / 10000; | ||
std::cout << "\rTime left: " << int((image_height - j) * avg_time / 3600) << " hours " << int((image_height - j) * avg_time) / 60 << " minutes " << int((image_height - j) * avg_time) % 60 << " seconds "; | ||
avg_time = 0; | ||
} | ||
} | ||
|
||
std::cout << "\rDone. \n"; | ||
} | ||
|
||
private: | ||
int image_height; // Rendered image height | ||
double pixel_samples_scale; // Color scale factor for a sum of pixel samples | ||
point3 center; // Camera center | ||
point3 pixel00_loc; // Location of pixel 0, 0 | ||
vec3 pixel_delta_u; // Offset to pixel to the right | ||
vec3 pixel_delta_v; // Offset to pixel below | ||
|
||
void initialize() { | ||
image_height = int(image_width / aspect_ratio); | ||
image_height = (image_height < 1) ? 1 : image_height; | ||
|
||
pixel_samples_scale = 1.0 / samples_per_pixel; | ||
|
||
center = point3(0, 0, 0); | ||
|
||
// Determine viewport dimensions. | ||
auto focal_length = 1.0; | ||
auto viewport_height = 2.0; | ||
auto viewport_width = viewport_height * (double(image_width) / image_height); | ||
|
||
// Calculate the vectors across the horizontal and down the vertical viewport edges. | ||
auto viewport_u = vec3(viewport_width, 0, 0); | ||
auto viewport_v = vec3(0, -viewport_height, 0); | ||
|
||
// Calculate the horizontal and vertical delta vectors from pixel to pixel. | ||
pixel_delta_u = viewport_u / image_width; | ||
pixel_delta_v = viewport_v / image_height; | ||
|
||
// Calculate the location of the upper left pixel. | ||
auto viewport_upper_left = | ||
center - vec3(0, 0, focal_length) - viewport_u / 2 - viewport_v / 2; | ||
pixel00_loc = viewport_upper_left + 0.5 * (pixel_delta_u + pixel_delta_v); | ||
} | ||
|
||
ray get_ray(int i, int j) const { | ||
// Construct a camera ray originating from the origin and directed at randomly sampled | ||
// point around the pixel location i, j. | ||
|
||
auto offset = sample_square(); | ||
auto pixel_sample = pixel00_loc | ||
+ ((i + offset.x()) * pixel_delta_u) | ||
+ ((j + offset.y()) * pixel_delta_v); | ||
|
||
auto ray_origin = center; | ||
auto ray_direction = pixel_sample - ray_origin; | ||
|
||
return ray(ray_origin, ray_direction); | ||
} | ||
|
||
vec3 sample_square() const { | ||
// Returns the vector to a random point in the [-.5,-.5]-[+.5,+.5] unit square. | ||
return vec3(random_double() - 0.5, random_double() - 0.5, 0); | ||
} | ||
|
||
color ray_color(const ray& r, int depth, const hittable& world) const | ||
{ | ||
// If we've exceeded the ray bounce limit, no more light is gathered. | ||
if (depth <= 0) | ||
return color(0, 0, 0); | ||
hit_record rec; | ||
|
||
if (world.hit(r, interval(0.001, infinity), rec)) | ||
{ | ||
vec3 direction = rec.normal + random_unit_vector(); | ||
return 0.5 * ray_color(ray(rec.p, direction), depth - 1, world); | ||
} | ||
|
||
vec3 unit_direction = unit_vector(r.direction()); | ||
auto a = 0.5 * (unit_direction.y() + 1.0); | ||
return (1.0 - a) * color(1.0, 1.0, 1.0) + a * color(0.5, 0.7, 1.0); | ||
} | ||
}; | ||
|
||
#endif |
Oops, something went wrong.