Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 1644444

Browse files
committed
added checkered textures
1 parent 67e158c commit 1644444

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

OptiX-Path-Tracer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ cuda_compile_and_embed( embedded_dielectric_programs programs/materials/dielectr
2626
cuda_compile_and_embed( embedded_lambertian_programs programs/materials/lambertian.cu )
2727
cuda_compile_and_embed( embedded_constant_texture_programs programs/textures/constant_texture.cu )
2828
cuda_compile_and_embed( embedded_aarect_programs programs/hitables/aarect.cu )
29+
cuda_compile_and_embed( embedded_checker_texture_programs programs/textures/checkered_texture.cu )
2930

3031
# this is doing the same using OptiX
3132
add_executable(OptiX-Path-Tracer
@@ -50,6 +51,7 @@ add_executable(OptiX-Path-Tracer
5051
${embedded_dielectric_programs}
5152
${embedded_constant_texture_programs}
5253
${embedded_aarect_programs}
54+
${embedded_checker_texture_programs}
5355
)
5456

5557
target_link_libraries(OptiX-Path-Tracer

OptiX-Path-Tracer/host_includes/scenes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ optix::GeometryGroup InOneWeekend(optix::Context &g_context, Camera &camera, int
2525
// reference C++ and CUDA codes.
2626
std::vector<optix::GeometryInstance> d_list;
2727

28-
d_list.push_back(createSphere(vec3f(0.f, -1000.0f, -1.f), 1000.f, Lambertian(new Constant_Texture(vec3f(0.5f, 0.5f, 0.5f))), g_context));
28+
Texture *checker = new Checker_Texture(new Constant_Texture(vec3f(0.2, 0.3, 0.1)), new Constant_Texture(vec3f(0.9, 0.9, 0.9)));
29+
30+
d_list.push_back(createSphere(vec3f(0.f, -1000.0f, -1.f), 1000.f, Lambertian(checker), g_context));
2931

3032
for (int a = -11; a < 11; a++) {
3133
for (int b = -11; b < 11; b++) {
@@ -45,7 +47,7 @@ optix::GeometryGroup InOneWeekend(optix::Context &g_context, Camera &camera, int
4547
d_list.push_back(createSphere(vec3f(0.f, 1.f, 0.f), 1.f, Dielectric(1.5f), g_context));
4648
d_list.push_back(createSphere(vec3f(-4.f, 1.f, 0.f), 1.f, Lambertian(new Constant_Texture(vec3f(0.4f, 0.2f, 0.1f))), g_context));
4749
d_list.push_back(createSphere(vec3f(4.f, 1.f, 0.f), 1.f, Metal(new Constant_Texture(vec3f(0.7f, 0.6f, 0.5f)), 0.0f), g_context));
48-
//createBox(vec3f(2.3f, 0.5f, 1.6f), vec3f(3.55f, 3.f, 3.2f), Lambertian(vec3f(rnd()*rnd(), rnd()*rnd(), rnd()*rnd())), g_context, d_list);
50+
//createBox(vec3f(0.3f, 0.5f, 0.6f), vec3f(3.55f, 3.f, 3.2f), Lambertian(new Constant_Texture(vec3f(rnd()*rnd(), rnd()*rnd(), rnd()*rnd()))), g_context, d_list);
4951

5052
// now, create the optix world that contains all these GIs
5153
optix::GeometryGroup d_world = g_context->createGeometryGroup();

OptiX-Path-Tracer/host_includes/textures.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,50 @@
1111
executable (ie, we can simply declare and use this here as
1212
'extern'. */
1313
extern "C" const char embedded_constant_texture_programs[];
14+
extern "C" const char embedded_checker_texture_programs[];
1415

1516
struct Texture {
16-
virtual void assignTo(optix::GeometryInstance gi, optix::Context &g_context) const = 0;
17+
virtual optix::Program assignTo(optix::GeometryInstance gi, optix::Context &g_context) const = 0;
1718
};
1819

1920
struct Constant_Texture : public Texture{
2021
Constant_Texture(const vec3f &c) : color(c) {}
2122

22-
virtual void assignTo(optix::GeometryInstance gi, optix::Context &g_context) const override {
23+
virtual optix::Program assignTo(optix::GeometryInstance gi, optix::Context &g_context) const override {
2324
optix::Program textProg = g_context->createProgramFromPTXString(embedded_constant_texture_programs, "sample_texture");
2425

2526
textProg["color"]->set3fv(&color.x);
2627
gi["sample_texture"]->setProgramId(textProg);
28+
29+
return textProg;
2730
}
2831

2932
const vec3f color;
3033
};
3134

35+
struct Checker_Texture : public Texture{
36+
Checker_Texture(const Texture *o, const Texture *e) : odd(o), even(e) {}
37+
38+
virtual optix::Program assignTo(optix::GeometryInstance gi, optix::Context &g_context) const override {
39+
optix::Program textProg = g_context->createProgramFromPTXString(embedded_checker_texture_programs, "sample_texture");
40+
41+
// this defines how the secondary texture programs will be named
42+
// in thecheckered program context. They might be named "sample_texture"
43+
// in their own source code and context, but will be invoked by the names
44+
// defined here.
45+
textProg["odd"]->setProgramId(odd->assignTo(gi, g_context));
46+
textProg["even"]->setProgramId(even->assignTo(gi, g_context));
47+
48+
// this "replaces" the previous gi->setProgramId assgined to the geometry
49+
// by the "odd" and "even" assignTo() calls. In practice, this assigns the
50+
// actual checkered_program sample_texture to the material.
51+
gi["sample_texture"]->setProgramId(textProg);
52+
53+
return textProg;
54+
}
55+
56+
const Texture* odd;
57+
const Texture* even;
58+
};
59+
3260
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "texture.h"
2+
3+
rtDeclareVariable(rtCallableProgramId<float3(float, float, float3)>, odd, , );
4+
rtDeclareVariable(rtCallableProgramId<float3(float, float, float3)>, even, , );
5+
6+
RT_CALLABLE_PROGRAM float3 sample_texture(float u, float v, float3 p) {
7+
float sines = sin(10 * p.x) * sin(10 - p.y) * sin(10 * p.z);
8+
9+
if (sines < 0)
10+
return odd(u, v, p);
11+
else
12+
return even(u, v, p);
13+
}

0 commit comments

Comments
 (0)