Skip to content

Commit

Permalink
Bug fix: sphere emitter cosine hemisphere sampling measure conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Enigmatisms committed Apr 23, 2024
1 parent 635c75a commit 69f538e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
19 changes: 13 additions & 6 deletions emitters/abtract_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from rich.console import Console
CONSOLE = Console(width = 128)

HEMISPHERE_SAMPLE_SPHERE = True

# point-0: PointSource, area-1: AreaSource, spot-2: SpotSource, collimated-4: CollimatedSource

# =============== Emitter Type =================
Expand Down Expand Up @@ -102,13 +104,18 @@ def sample_hit(
tri_id = prim_info[self.obj_ref_id, 0]
center = dvs[tri_id, 0]
radius = dvs[tri_id, 1][0]
to_hit = (hit_pos - center).normalized()
# the pdf here can be viewed as being both both sa & area measure
# since for a unit sphere, different unit solid angle extends to the same amount of area
local_dir, pdf = cosine_hemisphere()
normal, _ = delocalize_rotate(to_hit, local_dir)

if ti.static(HEMISPHERE_SAMPLE_SPHERE):
to_hit = (hit_pos - center).normalized()
# the pdf here can be viewed as being both both sa & area measure
# since for a unit sphere, different unit solid angle extends to the same amount of area
local_dir, pdf = uniform_sphere()
normal, _ = delocalize_rotate(to_hit, local_dir)
ret_pos = center + normal * radius
ret_pdf = pdf / (radius * radius)
else:
normal, _pdf = uniform_sphere()
ret_pos = center + normal * radius
ret_pdf = pdf
else:
mesh_num = prim_info[self.obj_ref_id, 1]
tri_id = (ti.random(int) % mesh_num) + prim_info[self.obj_ref_id, 0] # ASSUME that triangles are similar in terms of area
Expand Down
12 changes: 6 additions & 6 deletions scenes/csphere/balls-multi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,29 @@
</medium>
</bsdf>

<emitter type="area" id="area">
<!-- <emitter type="area" id="area">
<rgb name="emission" value="70.0, 63.2, 60.3"/>
<rgb name="scaler" value="0.15"/>
</emitter>
</emitter> -->

<emitter type="area" id="ball_emit">
<rgb name="emission" value="2.0, 1.5, 1.3"/>
<rgb name="scaler" value="0.15"/>
<rgb name="scaler" value="2"/>
</emitter>

<emitter type="point" id="point">
<!-- <emitter type="point" id="point">
<rgb name="emission" value="60.0, 60., 60.0"/>
<rgb name="scaler" value="0.15"/>
<point name="center" x="2.779" y="3.0" z="-1.0"/>
</emitter>
</emitter> -->

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

<shape type="obj">
Expand Down
2 changes: 1 addition & 1 deletion scenes/csphere/single-ball.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<float name="fov" value="39.3077"/>
<integer name="sample_count" value="128"/>
<integer name="max_bounce" value="12"/>
<integer name="num_shadow_ray" value="0"/>
<integer name="num_shadow_ray" value="1"/>

<integer name="start_t" value="1"/>
<integer name="end_t" value="100"/>
Expand Down

0 comments on commit 69f538e

Please sign in to comment.