|
6 | 6 |
|
7 | 7 |
|
8 | 8 | def dict_sensor(direction=None, target=None, fwidth=1): |
9 | | - if direction is None: |
10 | | - dict_direction = {} |
11 | | - else: |
12 | | - dict_direction = {"direction": direction} |
| 9 | + result = {"type": "distant"} |
13 | 10 |
|
14 | | - if target is None: |
15 | | - dict_target = {} |
16 | | - else: |
17 | | - dict_target = {"target": target} |
| 11 | + if direction: |
| 12 | + result["direction"] = direction |
18 | 13 |
|
19 | | - dict_film = { |
| 14 | + if target: |
| 15 | + result["target"] = target |
| 16 | + |
| 17 | + result["film"] = { |
20 | 18 | "type": "hdrfilm", |
21 | 19 | "width": fwidth, |
22 | 20 | "height": 1, |
23 | 21 | "rfilter": {"type": "box"} |
24 | 22 | } |
25 | 23 |
|
26 | | - return { |
27 | | - "type": "distant", |
28 | | - **dict_direction, |
29 | | - **dict_target, |
30 | | - "film": dict_film, |
31 | | - } |
| 24 | + return result |
32 | 25 |
|
33 | 26 |
|
34 | 27 | def make_sensor(direction=None, target=None, fwidth=1): |
@@ -177,45 +170,56 @@ def test_intersection(variant_scalar_rgb, direction): |
177 | 170 | ek.dot(direction, [0, 0, -1]), atol=0.1) |
178 | 171 |
|
179 | 172 |
|
180 | | -@pytest.mark.parametrize("radiance", [10**x for x in range(-3, 4)]) |
181 | | -def test_render(variant_scalar_rgb, radiance): |
| 173 | +def test_render(variant_scalar_rgb): |
182 | 174 | # Test render results with a simple scene |
183 | 175 | from mitsuba.core.xml import load_dict |
184 | | - from mitsuba.core import Bitmap, Struct |
| 176 | + from mitsuba.core import Bitmap, Struct, ScalarTransform4f |
| 177 | + |
| 178 | + for w_e, w_o in zip(([0, 0, -1], [0, 1, -1]), ([0, 0, -1], [0, 1, -1])): |
| 179 | + l_e = 1.0 # Emitted radiance |
| 180 | + w_e = list(ek.normalize(w_e)) # Emitter direction |
| 181 | + w_o = list(ek.normalize(w_o)) # Sensor direction |
| 182 | + cos_theta_e = abs(ek.dot(w_e, [0, 0, 1])) |
| 183 | + cos_theta_o = abs(ek.dot(w_o, [0, 0, 1])) |
| 184 | + |
| 185 | + scale = 0.5 |
| 186 | + rho = 1.0 # Surface reflectance |
| 187 | + surface_area = 4. * scale ** 2 |
185 | 188 |
|
186 | | - def dict_scene(radiance=1.0, spp=1): |
187 | | - return { |
188 | | - "type": "scene", |
189 | | - "shape": { |
| 189 | + expected = l_e * cos_theta_e * surface_area * rho / np.pi * cos_theta_o |
| 190 | + |
| 191 | + dict_scene = { |
| 192 | + "type": "scene", |
| 193 | + "shape": { |
190 | 194 | "type": "rectangle", |
191 | | - "bsdf": {"type": "conductor"}, |
192 | | - }, |
193 | | - "integrator": {"type": "path"}, |
194 | | - "sensor": { |
195 | | - "type": "distant", |
196 | | - "film": { |
| 195 | + "to_world": ScalarTransform4f.scale(scale), |
| 196 | + "bsdf": {"type": "diffuse", "reflectance": rho}, |
| 197 | + }, |
| 198 | + "emitter": { |
| 199 | + "type": "directional", |
| 200 | + "irradiance": l_e, |
| 201 | + "direction": w_e |
| 202 | + }, |
| 203 | + "sensor": { |
| 204 | + "type": "distant", |
| 205 | + "direction": w_o, |
| 206 | + "film": { |
197 | 207 | "type": "hdrfilm", |
198 | | - "width": 1, |
199 | 208 | "height": 1, |
200 | | - "pixel_format": "rgb", |
| 209 | + "width": 1, |
| 210 | + "pixel_format": "luminance", |
201 | 211 | "rfilter": {"type": "box"}, |
202 | | - }, |
203 | | - "sampler": { |
204 | | - "type": "independent", |
205 | | - "sample_count": spp |
206 | | - }, |
207 | 212 | }, |
208 | | - "emitter": { |
209 | | - "type": "constant", |
210 | | - "radiance": { |
211 | | - "type": "spectrum", |
212 | | - "value": radiance |
213 | | - } |
214 | | - } |
215 | | - } |
216 | | - |
217 | | - scene = load_dict(dict_scene(spp=1, radiance=radiance)) |
| 213 | + "sampler": { |
| 214 | + "type": "independent", |
| 215 | + "sample_count": 512 |
| 216 | + }, |
| 217 | + }, |
| 218 | + "integrator": {"type": "path"} |
| 219 | + } |
| 220 | + |
| 221 | + scene = load_dict(dict_scene) |
218 | 222 | sensor = scene.sensors()[0] |
219 | 223 | scene.integrator().render(scene, sensor) |
220 | | - img = sensor.film().bitmap() |
221 | | - assert np.allclose(np.array(img), radiance) |
| 224 | + img = np.array(sensor.film().bitmap()).squeeze() |
| 225 | + assert np.allclose(np.array(img), expected) |
0 commit comments