From 69f538e1de1670c9441eeb9f7a8f15e1646327bc Mon Sep 17 00:00:00 2001 From: Qianyue He <984041003@qq.com> Date: Tue, 23 Apr 2024 23:20:25 +0800 Subject: [PATCH] Bug fix: sphere emitter cosine hemisphere sampling measure conversion. --- emitters/abtract_source.py | 19 +++++++++++++------ scenes/csphere/balls-multi.xml | 12 ++++++------ scenes/csphere/single-ball.xml | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/emitters/abtract_source.py b/emitters/abtract_source.py index ea7f972..761dda0 100644 --- a/emitters/abtract_source.py +++ b/emitters/abtract_source.py @@ -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 ================= @@ -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 diff --git a/scenes/csphere/balls-multi.xml b/scenes/csphere/balls-multi.xml index eb332ac..aae04ab 100644 --- a/scenes/csphere/balls-multi.xml +++ b/scenes/csphere/balls-multi.xml @@ -88,21 +88,21 @@ - + - + - + @@ -110,7 +110,7 @@ - + diff --git a/scenes/csphere/single-ball.xml b/scenes/csphere/single-ball.xml index 20b5da8..c6dc50b 100644 --- a/scenes/csphere/single-ball.xml +++ b/scenes/csphere/single-ball.xml @@ -10,7 +10,7 @@ - +