Skip to content

Commit 634c4ef

Browse files
committed
Fully working dynamic materials example
1 parent d0af094 commit 634c4ef

6 files changed

Lines changed: 37 additions & 18 deletions

File tree

examples/dynamic_geometry.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import os, sys, enum, copy, logging, collections
1+
import os, sys, enum, logging, collections
22

3-
import numpy as np
43
import cupy as cp
4+
import numpy as np
55
import optix as ox
6+
67
import glfw, imgui
78

89
from optix.sutil.gui import init_ui, display_stats
910
from optix.sutil.gl_display import GLDisplay
1011
from optix.sutil.trackball import Trackball, TrackballViewMode
1112
from optix.sutil.cuda_output_buffer import CudaOutputBuffer, CudaOutputBufferType, BufferImageFormat
1213

14+
script_dir = os.path.dirname(os.path.abspath(__file__))
15+
1316
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1417
log = logging.getLogger()
1518

16-
script_dir = os.path.dirname(os.path.abspath(__file__))
17-
1819
DEBUG=False
1920

2021
#------------------------------------------------------------------------------
@@ -83,11 +84,13 @@ def camera(self):
8384
def launch_dimensions(self):
8485
return (int(self.params.width), int(self.params.height))
8586

87+
8688
class AnimationMode(enum.Enum):
8789
NONE = 0
8890
DEFORM = 1
8991
EXPLODE = 2
9092

93+
9194
#------------------------------------------------------------------------------
9295
# Scene data
9396
#------------------------------------------------------------------------------

examples/dynamic_materials.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import os, sys, logging, collections
22

3-
import numpy as np
43
import cupy as cp
4+
import numpy as np
55
import optix as ox
6+
67
import glfw, imgui
78

89
from optix.sutil.gui import init_ui, display_text
910
from optix.sutil.camera import Camera
1011
from optix.sutil.gl_display import GLDisplay
1112
from optix.sutil.cuda_output_buffer import CudaOutputBuffer, CudaOutputBufferType, BufferImageFormat
1213

14+
script_dir = os.path.dirname(os.path.abspath(__file__))
15+
1316
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1417
log = logging.getLogger()
1518

16-
script_dir = os.path.dirname(os.path.abspath(__file__))
19+
DEBUG=False
1720

1821

1922
class Params:
@@ -174,13 +177,18 @@ def build_ias(state):
174177
state.params.trav_handle = state.ias.handle
175178

176179
def create_module(state):
180+
if DEBUG:
181+
exception_flags=ox.ExceptionFlags.DEBUG | ox.ExceptionFlags.TRACE_DEPTH | ox.ExceptionFlags.STACK_OVERFLOW,
182+
else:
183+
exception_flags=ox.ExceptionFlags.NONE
184+
177185
pipeline_opts = ox.PipelineCompileOptions(
178186
uses_motion_blur=False,
179187
traversable_graph_flags=ox.TraversableGraphFlags.ALLOW_SINGLE_LEVEL_INSTANCING,
180188
uses_primitive_type_flags=ox.PrimitiveTypeFlags.CUSTOM,
181189
num_payload_values=3,
182190
num_attribute_values=3,
183-
exception_flags=ox.ExceptionFlags.DEBUG | ox.ExceptionFlags.TRACE_DEPTH | ox.ExceptionFlags.STACK_OVERFLOW,
191+
exception_flags=exception_flags,
184192
pipeline_launch_params_variable_name="params")
185193

186194
compile_opts = ox.ModuleCompileOptions(
@@ -317,7 +325,7 @@ def update_sbt_header(state):
317325
# The right sphere will use the next compiled program group.
318326
material_index = state.material_index_2.nextval()
319327

320-
#state.hit_grps.update_program_group(3, state.hit_grps[3 + material_index])
328+
state.hit_sbts.update_program_group(3, state.hit_grps[3 + material_index])
321329

322330
state.sbt = ox.ShaderBindingTable(raygen_record=state.raygen_sbt, miss_records=state.miss_sbt,
323331
hitgroup_records=state.hit_sbts)

examples/hello.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
import os, sys, logging
2+
13
import optix as ox
24
import cupy as cp
35
import numpy as np
6+
47
from PIL import Image, ImageOps
5-
import logging
6-
import sys
8+
9+
script_dir = os.path.dirname(os.path.abspath(__file__))
10+
711
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
812
log = logging.getLogger()
913

1014
def create_module(ctx, pipeline_opts):
1115
compile_opts = ox.ModuleCompileOptions(debug_level=ox.CompileDebugLevel.LINEINFO)
12-
module = ox.Module(ctx, 'cuda/hello.cu', compile_opts, pipeline_opts)
16+
source = os.path.join(script_dir, 'cuda', 'hello.cu')
17+
module = ox.Module(ctx, source, compile_opts, pipeline_opts)
1318
return module
1419

1520

examples/spheres.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
from PIL import Image, ImageOps
88

9+
script_dir = os.path.dirname(os.path.abspath(__file__))
10+
911
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1012
log = logging.getLogger()
1113
img_size = (1024, 768)
1214

13-
script_dir = os.path.dirname(os.path.abspath(__file__))
14-
1515
def compute_spheres_bbox(centers, radii):
1616
out = cp.empty((centers.shape[0], 6), dtype='f4')
1717
out[:, :3] = centers - radii.reshape(-1, 1)

examples/triangle.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import optix as ox
1+
import os
2+
23
import cupy as cp
34
import numpy as np
5+
import optix as ox
6+
47
from PIL import Image, ImageOps
58

9+
script_dir = os.path.dirname(os.path.abspath(__file__))
10+
611
img_size = (1024, 768)
712

813
# use a regular function for logging
@@ -19,7 +24,8 @@ def create_acceleration_structure(ctx, vertices):
1924

2025
def create_module(ctx, pipeline_opts):
2126
compile_opts = ox.ModuleCompileOptions(debug_level=ox.CompileDebugLevel.LINEINFO)
22-
module = ox.Module(ctx, 'cuda/triangle.cu', compile_opts, pipeline_opts)
27+
source = os.path.join(script_dir, 'cuda', 'triangle.cu')
28+
module = ox.Module(ctx, source, compile_opts, pipeline_opts)
2329
return module
2430

2531

@@ -118,5 +124,3 @@ def launch_pipeline(pipeline : ox.Pipeline, sbt, gas):
118124
img = img.reshape(img_size[1], img_size[0], 4)
119125
img = ImageOps.flip(Image.fromarray(img, 'RGBA'))
120126
img.show()
121-
122-

optix/shader_binding_table.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,3 @@ cdef class ShaderBindingTable(OptixObject):
111111
return array_to_device_memory(record, stream=stream), record.shape[0], record.strides[0]
112112
else:
113113
raise ValueError(f"Unsupported record type '{type(record)}'")
114-

0 commit comments

Comments
 (0)