Implement image texture
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
{
|
{
|
||||||
"directoryIndex" : 0,
|
"directoryIndex" : 0,
|
||||||
"id" : "Raytracer::@6890427a1f51a3e7e1df",
|
"id" : "Raytracer::@6890427a1f51a3e7e1df",
|
||||||
"jsonFile" : "target-Raytracer-Debug-c20492cef9da68491c1d.json",
|
"jsonFile" : "target-Raytracer-Debug-28c14a284b376e6f3c5e.json",
|
||||||
"name" : "Raytracer",
|
"name" : "Raytracer",
|
||||||
"projectIndex" : 0
|
"projectIndex" : 0
|
||||||
}
|
}
|
@@ -26,7 +26,7 @@
|
|||||||
"objects" :
|
"objects" :
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"jsonFile" : "codemodel-v2-f6c7b9244f32065c2aec.json",
|
"jsonFile" : "codemodel-v2-d4a7d48a6b29f61122a4.json",
|
||||||
"kind" : "codemodel",
|
"kind" : "codemodel",
|
||||||
"version" :
|
"version" :
|
||||||
{
|
{
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"jsonFile" : "codemodel-v2-f6c7b9244f32065c2aec.json",
|
"jsonFile" : "codemodel-v2-d4a7d48a6b29f61122a4.json",
|
||||||
"kind" : "codemodel",
|
"kind" : "codemodel",
|
||||||
"version" :
|
"version" :
|
||||||
{
|
{
|
@@ -93,7 +93,8 @@
|
|||||||
10,
|
10,
|
||||||
11,
|
11,
|
||||||
12,
|
12,
|
||||||
13
|
13,
|
||||||
|
14
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -155,6 +156,11 @@
|
|||||||
"path" : "rayTracer.h",
|
"path" : "rayTracer.h",
|
||||||
"sourceGroupIndex" : 1
|
"sourceGroupIndex" : 1
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 1,
|
||||||
|
"path" : "rtw_stb_image.h",
|
||||||
|
"sourceGroupIndex" : 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"backtrace" : 1,
|
"backtrace" : 1,
|
||||||
"path" : "sphere.h",
|
"path" : "sphere.h",
|
@@ -7,18 +7,21 @@ CMakeFiles/Raytracer.dir/main.cpp.o
|
|||||||
/home/cjsatnarine/Code/Raytracer/bvh.h
|
/home/cjsatnarine/Code/Raytracer/bvh.h
|
||||||
/home/cjsatnarine/Code/Raytracer/camera.h
|
/home/cjsatnarine/Code/Raytracer/camera.h
|
||||||
/home/cjsatnarine/Code/Raytracer/colour.h
|
/home/cjsatnarine/Code/Raytracer/colour.h
|
||||||
|
/home/cjsatnarine/Code/Raytracer/external/stb_image.h
|
||||||
/home/cjsatnarine/Code/Raytracer/hittable.h
|
/home/cjsatnarine/Code/Raytracer/hittable.h
|
||||||
/home/cjsatnarine/Code/Raytracer/hittableList.h
|
/home/cjsatnarine/Code/Raytracer/hittableList.h
|
||||||
/home/cjsatnarine/Code/Raytracer/interval.h
|
/home/cjsatnarine/Code/Raytracer/interval.h
|
||||||
/home/cjsatnarine/Code/Raytracer/material.h
|
/home/cjsatnarine/Code/Raytracer/material.h
|
||||||
/home/cjsatnarine/Code/Raytracer/ray.h
|
/home/cjsatnarine/Code/Raytracer/ray.h
|
||||||
/home/cjsatnarine/Code/Raytracer/rayTracer.h
|
/home/cjsatnarine/Code/Raytracer/rayTracer.h
|
||||||
|
/home/cjsatnarine/Code/Raytracer/rtw_stb_image.h
|
||||||
/home/cjsatnarine/Code/Raytracer/sphere.h
|
/home/cjsatnarine/Code/Raytracer/sphere.h
|
||||||
/home/cjsatnarine/Code/Raytracer/texture.h
|
/home/cjsatnarine/Code/Raytracer/texture.h
|
||||||
/home/cjsatnarine/Code/Raytracer/vec3.h
|
/home/cjsatnarine/Code/Raytracer/vec3.h
|
||||||
/usr/include/alloca.h
|
/usr/include/alloca.h
|
||||||
/usr/include/asm-generic/errno-base.h
|
/usr/include/asm-generic/errno-base.h
|
||||||
/usr/include/asm-generic/errno.h
|
/usr/include/asm-generic/errno.h
|
||||||
|
/usr/include/assert.h
|
||||||
/usr/include/c++/13/algorithm
|
/usr/include/c++/13/algorithm
|
||||||
/usr/include/c++/13/backward/auto_ptr.h
|
/usr/include/c++/13/backward/auto_ptr.h
|
||||||
/usr/include/c++/13/backward/binders.h
|
/usr/include/c++/13/backward/binders.h
|
||||||
@@ -121,6 +124,7 @@ CMakeFiles/Raytracer.dir/main.cpp.o
|
|||||||
/usr/include/c++/13/iostream
|
/usr/include/c++/13/iostream
|
||||||
/usr/include/c++/13/istream
|
/usr/include/c++/13/istream
|
||||||
/usr/include/c++/13/limits
|
/usr/include/c++/13/limits
|
||||||
|
/usr/include/c++/13/math.h
|
||||||
/usr/include/c++/13/memory
|
/usr/include/c++/13/memory
|
||||||
/usr/include/c++/13/new
|
/usr/include/c++/13/new
|
||||||
/usr/include/c++/13/ostream
|
/usr/include/c++/13/ostream
|
||||||
@@ -129,6 +133,7 @@ CMakeFiles/Raytracer.dir/main.cpp.o
|
|||||||
/usr/include/c++/13/pstl/glue_memory_defs.h
|
/usr/include/c++/13/pstl/glue_memory_defs.h
|
||||||
/usr/include/c++/13/pstl/pstl_config.h
|
/usr/include/c++/13/pstl/pstl_config.h
|
||||||
/usr/include/c++/13/stdexcept
|
/usr/include/c++/13/stdexcept
|
||||||
|
/usr/include/c++/13/stdlib.h
|
||||||
/usr/include/c++/13/streambuf
|
/usr/include/c++/13/streambuf
|
||||||
/usr/include/c++/13/string
|
/usr/include/c++/13/string
|
||||||
/usr/include/c++/13/string_view
|
/usr/include/c++/13/string_view
|
||||||
@@ -163,6 +168,8 @@ CMakeFiles/Raytracer.dir/main.cpp.o
|
|||||||
/usr/include/stdint.h
|
/usr/include/stdint.h
|
||||||
/usr/include/stdio.h
|
/usr/include/stdio.h
|
||||||
/usr/include/stdlib.h
|
/usr/include/stdlib.h
|
||||||
|
/usr/include/string.h
|
||||||
|
/usr/include/strings.h
|
||||||
/usr/include/time.h
|
/usr/include/time.h
|
||||||
/usr/include/wchar.h
|
/usr/include/wchar.h
|
||||||
/usr/include/wctype.h
|
/usr/include/wctype.h
|
||||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -210,4 +210,8 @@ CMakeFiles/Raytracer.dir/main.cpp.o: \
|
|||||||
/home/cjsatnarine/Code/Raytracer/camera.h \
|
/home/cjsatnarine/Code/Raytracer/camera.h \
|
||||||
/home/cjsatnarine/Code/Raytracer/material.h \
|
/home/cjsatnarine/Code/Raytracer/material.h \
|
||||||
/home/cjsatnarine/Code/Raytracer/texture.h \
|
/home/cjsatnarine/Code/Raytracer/texture.h \
|
||||||
|
/home/cjsatnarine/Code/Raytracer/rtw_stb_image.h \
|
||||||
|
/home/cjsatnarine/Code/Raytracer/external/stb_image.h \
|
||||||
|
/usr/include/c++/13/stdlib.h /usr/include/string.h \
|
||||||
|
/usr/include/strings.h /usr/include/c++/13/math.h /usr/include/assert.h \
|
||||||
/home/cjsatnarine/Code/Raytracer/sphere.h
|
/home/cjsatnarine/Code/Raytracer/sphere.h
|
||||||
|
BIN
build/Raytracer
BIN
build/Raytracer
Binary file not shown.
BIN
earthmap.jpg
Normal file
BIN
earthmap.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 KiB |
27
main.cpp
27
main.cpp
@@ -99,8 +99,30 @@ void checkeredSpheres(void) {
|
|||||||
cam.render(world);
|
cam.render(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void earth(void) {
|
||||||
|
auto earthTexture = make_shared<imageTexture>("earthmap.jpg");
|
||||||
|
auto earthSurface = make_shared<lambertian>(earthTexture);
|
||||||
|
auto globe = make_shared<sphere>(point3(0, 0, 0), 2, earthSurface);
|
||||||
|
|
||||||
|
camera cam;
|
||||||
|
|
||||||
|
cam.aspectRatio = 16.0 / 9.0;
|
||||||
|
cam.imageWidth = 800;
|
||||||
|
cam.samplesPerPixel = 100;
|
||||||
|
cam.maxDepth = 50;
|
||||||
|
|
||||||
|
cam.vFieldOfView = 20;
|
||||||
|
cam.lookFrom = point3(0,0,12);
|
||||||
|
cam.lookAt = point3(0,0,0);
|
||||||
|
cam.vUp = vec3(0,1,0);
|
||||||
|
|
||||||
|
cam.defocusAngle = 0;
|
||||||
|
|
||||||
|
cam.render(hittableList(globe));
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
int sceneToShow = 2;
|
int sceneToShow = 3;
|
||||||
|
|
||||||
switch (sceneToShow) {
|
switch (sceneToShow) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -109,5 +131,8 @@ int main(void) {
|
|||||||
case 2:
|
case 2:
|
||||||
checkeredSpheres();
|
checkeredSpheres();
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
earth();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -55,7 +55,13 @@ class rtwImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool load(const std::string& filename) {
|
bool load(const std::string& filename) {
|
||||||
auto n = bytesPerPixel;
|
// Loads the linear (gamma=1) image data from the given file name. Returns true if the
|
||||||
|
// load succeeded. The resulting data buffer contains the three [0.0, 1.0]
|
||||||
|
// floating-point values for the first pixel (red, then green, then blue). Pixels are
|
||||||
|
// contiguous, going left to right for the width of the image, followed by the next row
|
||||||
|
// below, for the full height of the image.
|
||||||
|
|
||||||
|
auto n = bytesPerPixel; // Dummy out parameter: original components per pixel
|
||||||
fdata = stbi_loadf(filename.c_str(), &imageWidth, &imageHeight, &n, bytesPerPixel);
|
fdata = stbi_loadf(filename.c_str(), &imageWidth, &imageHeight, &n, bytesPerPixel);
|
||||||
if (fdata == nullptr) return false;
|
if (fdata == nullptr) return false;
|
||||||
|
|
||||||
@@ -96,7 +102,7 @@ class rtwImage {
|
|||||||
static int clamp(int x, int low, int high) {
|
static int clamp(int x, int low, int high) {
|
||||||
// Return the value clamped to the range [low, high].
|
// Return the value clamped to the range [low, high].
|
||||||
if (x < low) return low;
|
if (x < low) return low;
|
||||||
if (x < high) return high;
|
if (x < high) return x;
|
||||||
return high - 1;
|
return high - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user