Skip to content

Commit

Permalink
Volume rendering no MIS completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Enigmatisms committed Jun 29, 2024
1 parent b25daab commit 9f0bfed
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
24 changes: 10 additions & 14 deletions bxdf/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,20 @@ def make_colorful_volume(density_grid: np.ndarray, xres: int, yres: int, zres: i
density_grid
], axis = -1)

# 创建一个从0到1的渐变数组,表示x轴从左到右
half_x = zres // 3
grad_l = np.linspace(1, 0, half_x, dtype = np.float32) ** 0.25
grad_r = np.linspace(0, 1, zres - half_x, dtype = np.float32) ** 0.1
grad_l = np.linspace(1, 0, half_x, dtype = np.float32) ** 0.65
grad_r = np.linspace(0, 1, zres - half_x, dtype = np.float32) ** 0.6

# 前半部分,从红色(1, 0, 0)到白色(1, 1, 1)
left_half = np.zeros((half_x, 3), dtype = np.float32)
left_half[:, 0] = 1 # 红色通道保持1
left_half[:, 1] = 1 - grad_l # 绿色通道从0到1
left_half[:, 2] = 1 - grad_l # 蓝色通道从0到1
left_half[:, 0] = 1 - grad_l
left_half[:, 1] = 1
left_half[:, 2] = 1

# 后半部分,从白色(1, 1, 1)到蓝色(0, 0, 1)
right_half = np.zeros((zres - half_x, 3), dtype = np.float32)
right_half[:, 0] = 1 - grad_r # 红色通道从1到0
right_half[:, 1] = 1 - grad_r # 绿色通道从1到0
right_half[:, 2] = 1 # 蓝色通道保持1
right_half[:, 0] = 1
right_half[:, 1] = 1
right_half[:, 2] = 1 - grad_r

# 将两个部分组合在一起
color_gradient = np.vstack((left_half, right_half))

return density_grid * color_gradient[:, None, None, :]
Expand Down Expand Up @@ -383,7 +379,7 @@ def sample_distance_delta_tracking_3d(self,

t = near_far[0] - ti.log(1.0 - ti.random(float)) * inv_maj
while t < near_far[1]:
d = self.density_lookup_lerp_3d(grid, ray_ol + t * ray_dl, vec3([
d = self.density_lookup_3d(grid, ray_ol + t * ray_dl, vec3([
ti.random(float), ti.random(float), ti.random(float)
]))
# Scatter upon real collision
Expand Down Expand Up @@ -442,7 +438,7 @@ def eval_tr_ratio_tracking_3d(self,

if t >= near_far[1]: break
# for mono-chromatic medium, this is 1
d = self.density_lookup_lerp_3d(grid, ray_ol + t * ray_dl, vec3([
d = self.density_lookup_3d(grid, ray_ol + t * ray_dl, vec3([
ti.random(float), ti.random(float), ti.random(float)
]))

Expand Down
55 changes: 37 additions & 18 deletions scenes/cbox/cbox-rgbvol.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<float name="far_clip" value="2000"/>
<float name="fov" value="39.3077"/>
<integer name="sample_count" value="128"/>
<integer name="max_bounce" value="16"/>
<integer name="max_bounce" value="32"/>
<integer name="num_shadow_ray" value="1"/>

<integer name="start_t" value="1"/>
Expand All @@ -18,8 +18,8 @@
<integer name="end_s" value="100"/>

<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"/>
<float name="rr_threshold" value="0.05"/>
<integer name="rr_bounce_th" value="24"/>

<string name="accelerator" value="bvh"/>
<boolean name="anti_alias" value="true"/>
Expand Down Expand Up @@ -50,13 +50,13 @@
</brdf>

<brdf type="phong" id="left_wall">
<rgb name="k_d" value="#BDBDBD"/>
<rgb name="k_d" value="#DD2525"/>
<rgb name="k_g" value="10.0"/>
<rgb name="k_s" value="#221313"/>
</brdf>

<brdf type="phong" id="right_wall">
<rgb name="k_d" value="#BDBDBD"/>
<rgb name="k_d" value="#25DD25"/>
<rgb name="k_g" value="10.0"/>
<rgb name="k_s" value="#132213"/>
</brdf>
Expand All @@ -67,18 +67,37 @@
<rgb name="k_s" value="0.0"/>
</brdf>

<emitter type="area" id="area">
<rgb name="emission" value="50.0, 50.0, 50.0"/>
<rgb name="scaler" value="0.12"/>
<emitter type="area" id="area_red">
<rgb name="emission" value="50.0, 5.0, 5.0"/>
<rgb name="scaler" value="0.08"/>
</emitter>

<emitter type="area" id="area_green">
<rgb name="emission" value="5.0, 50.0, 5.0"/>
<rgb name="scaler" value="0.08"/>
</emitter>

<emitter type="area" id="area_blue">
<rgb name="emission" value="5.0, 5.0, 50.0"/>
<rgb name="scaler" value="0.15"/>
</emitter>

<shape type="obj">
<string name="filename" value="../meshes/cornell/cbox_luminaire.obj"/>
<string name="filename" value="../meshes/cornell/cbox_red_light.obj"/>
<ref type="material" id="light"/>
<ref type="emitter" id="area"/>
<transform name="toWorld">
<translate x="0" y="-0.001" z="0"/>
</transform>
<ref type="emitter" id="area_red"/>
</shape>

<shape type="obj">
<string name="filename" value="../meshes/cornell/cbox_green_light.obj"/>
<ref type="material" id="light"/>
<ref type="emitter" id="area_green"/>
</shape>

<shape type="obj">
<string name="filename" value="../meshes/cornell/cbox_blue_light.obj"/>
<ref type="material" id="light"/>
<ref type="emitter" id="area_blue"/>
</shape>

<shape type="obj">
Expand Down Expand Up @@ -112,16 +131,16 @@

<!-- Definition of grid volume -->
<volume name="janga" type="mono" phase_type="hg">
<string name="density_grid" path="./scenes/volume/janga-smoke-264-136-136.vol"/>
<string name="density_grid" path="./scenes/volume/embergen_dust_devil_tornado_a_50-256-256-256.vol"/>
<rgb name="albedo" value="#F8F8F8"/>
<rgb name="density_scaling" value="25.0"/>
<rgb name="par" value="0.7"/>
<rgb name="density_scaling" value="15.0"/>
<rgb name="par" value="0.9"/>
<bool name="mono2rgb" value="true"/>

<transform name="toWorld">
<translate x="0.35" y="-0.6" z="2.8"/>
<translate x="0.35" y="-0.6" z="4.0"/>
<rotate type="euler" r="10" p="0.0" y="90"/>
<scale x="0.01" y="0.035" z="0.02"/>
<scale x="0.02" y="0.025" z="0.02"/>
</transform>
</volume>

Expand Down

0 comments on commit 9f0bfed

Please sign in to comment.