Skip to content

Commit

Permalink
Finished colored volume rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
Enigmatisms committed Jun 26, 2024
1 parent 2267944 commit 928c979
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
12 changes: 6 additions & 6 deletions bxdf/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ def setup_volume(self, path:str):

@staticmethod
def make_colorful_volume(density_grid: np.ndarray, xres: int, yres: int, zres: int):
z_coords = np.linspace(0, 0.9, zres, dtype = np.float32).reshape(-1, 1, 1, 1) + 0.1
y_coords = np.linspace(0, 0.9, yres, dtype = np.float32).reshape(1, -1, 1, 1) + 0.1
x_coords = np.linspace(0, 0.9, xres, dtype = np.float32).reshape(1, 1, -1, 1) + 0.1
z_coords = np.linspace(0, 4.0, zres, dtype = np.float32).reshape(-1, 1, 1, 1) + 0.1
y_coords = np.linspace(0, 0.5, yres, dtype = np.float32).reshape(1, -1, 1, 1) + 0.1
x_coords = np.linspace(0, 0.1, xres, dtype = np.float32).reshape(1, 1, -1, 1) + 0.01
density_grid = np.concatenate([
density_grid,
density_grid,
density_grid,
density_grid * z_coords,
density_grid * y_coords,
density_grid * x_coords,
], axis = -1)
return density_grid

Expand Down
7 changes: 4 additions & 3 deletions renderer/vanilla_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ def render(self, _t_start: int, _t_end: int, _s_start: int, _s_end: int, _a: int
color = vec3([0, 0, 0])
contribution = vec3([1, 1, 1])
emission_weight = 1.0
for _i in range(self.max_bounce):
for bounce in range(self.max_bounce):
if it.is_ray_not_hit(): break # nothing is hit, break
if ti.static(self.use_rr):
# Simple Russian Roullete ray termination
max_value = contribution.max()
if ti.random(float) > max_value: break
else: contribution *= 1. / (max_value + 1e-7) # unbiased calculation
if max_value < self.rr_threshold and bounce >= self.rr_bounce_th:
if ti.random(float) > max_value: break
else: contribution *= 1. / (max_value + 1e-7) # unbiased calculation
else:
if contribution.max() < 1e-4: break # contribution too small, break
hit_point = ray_d * it.min_depth + ray_o
Expand Down
5 changes: 3 additions & 2 deletions renderer/vpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ def render(self, _t_start: int, _t_end: int, _s_start: int, _s_end: int, _a: int
if ti.static(self.use_rr):
# Simple Russian Roullete ray termination
max_value = throughput.max()
if ti.random(float) > max_value: break
else: throughput *= 1. / (max_value + 1e-7) # unbiased calculation
if max_value < self.rr_threshold and bounce >= self.rr_bounce_th:
if ti.random(float) > max_value: break
else: throughput *= 1. / (max_value + 1e-7) # unbiased calculation
else:
if throughput.max() < 1e-5: break # contribution too small, break
# Step 2: ray intersection
Expand Down
19 changes: 10 additions & 9 deletions scenes/cbox/cbox-rgbvol.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
<float name="far_clip" value="2000"/>
<float name="fov" value="39.3077"/>
<integer name="sample_count" value="128"/>
<integer name="max_bounce" value="32"/>
<integer name="max_bounce" value="16"/>
<integer name="num_shadow_ray" value="1"/>

<integer name="start_t" value="1"/>
<integer name="end_t" value="100"/>
<integer name="start_s" value="0"/>
<integer name="end_s" value="100"/>

<integer name="rr_threshold" value="4"/>
<boolean name="use_rr" value="true"/> <!-- Whether to use Russian roulette ray termination -->
<float name="rr_threshold" value="0.1"/>
<integer name="rr_bounce_th" value="8"/>

<string name="accelerator" value="bvh"/>
<boolean name="use_rr" value="false"/> <!-- Whether to use Russian roulette ray termination -->
<boolean name="anti_alias" value="true"/>
<boolean name="stratified_sampling" value="true"/> <!-- TODO: stratified sampling only implemented for pixel sampling -->
<boolean name="use_mis" value="true"/> <!-- Whether to use multiple importance sampling -->
Expand Down Expand Up @@ -68,7 +69,7 @@

<emitter type="area" id="area">
<rgb name="emission" value="50.0, 50.0, 50.0"/>
<rgb name="scaler" value="0.3"/>
<rgb name="scaler" value="0.1"/>
</emitter>

<shape type="obj">
Expand Down Expand Up @@ -113,14 +114,14 @@
<volume name="janga" type="mono" phase_type="hg">
<string name="density_grid" path="./scenes/volume/janga-smoke-264-136-136.vol"/>
<rgb name="albedo" value="#F8F8F8"/>
<rgb name="density_scaling" value="10.0"/>
<rgb name="density_scaling" value="15.0"/>
<rgb name="par" value="0.7"/>
<bool name="mono2rgb" value="false"/>
<bool name="mono2rgb" value="true"/>

<transform name="toWorld">
<translate x="0.5" y="-0.6" z="2.4"/>
<rotate type="euler" r="20" p="0.0" y="90"/>
<scale x="0.01" y="0.035" z="0.02"/>
<translate x="0.6" y="0.0" z="1.3"/>
<rotate type="euler" r="0" p="0.0" y="0"/>
<scale x="0.03" y="0.03" z="0.03"/>
</transform>
</volume>

Expand Down
2 changes: 2 additions & 0 deletions tracer/path_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def __init__(self,
self.stratified_sample = prop['stratified_sampling'] # whether to use stratified sampling
self.use_mis = prop['use_mis'] # whether to use multiple importance sampling
self.num_shadow_ray = prop['num_shadow_ray'] # number of shadow samples to trace
self.rr_threshold = prop.get('rr_threshold', 0.1) # threshold of employing RR
self.rr_bounce_th = prop.get('rr_bounce_th', 4) # minimum number of bounces to start RR
self.brdf_two_sides = prop.get('brdf_two_sides', False)

if self.num_shadow_ray > 0:
Expand Down

0 comments on commit 928c979

Please sign in to comment.