owl-project / NVISII

Apache License 2.0
327 stars 28 forks source link

Numerical Precision Issues of Mesh lights with Small Scales #108

Open dgriffiths3 opened 3 years ago

dgriffiths3 commented 3 years ago

Hi, I am trying to render a simple scene similar to example 05_lights where a box is used as the walls for a room measuring only direct illumination. However, I keep getting a strange cracking like texture in the resulting image.

test

I achieve the direct illumination by setting nvisii.set_max_bounce_depth(diffuse_depth=0) then render with 1000 samples per-pixel. Here also sampling is at the pixel center.

For the material I have base_color=(1., 1., 1.), specular=0. and `roughness=1.0'. The effects seems worst when the base color is white, although its still present with other configuations.

I noticed the triangle_ids are also quite unusual (i.e. 0 only shown once and 23 triangle ids) and the box has a lot of vertices (i.e. more than 8):

# Triangle IDs
(0, 1, 2, 1, 3, 2, 6, 5, 4, 6, 7, 5, 10, 9, 8, 10, 11, 9, 12, 13, 14, 13, 15, 14, 16, 17, 18, 17, 19, 18, 22, 21, 20, 22, 23, 21)

# Vertices
((1.0, -1.0, -1.0), (1.0, 1.0, -1.0), (1.0, -1.0, 1.0), (1.0, 1.0, 1.0), (-1.0, -1.0, -1.0), (-1.0, 1.0, -1.0), (-1.0, -1.0, 1.0), (-1.0, 1.0, 1.0), (-1.0, 1.0, -1.0), (1.0, 1.0, -1.0), (-1.0, 1.0, 1.0), (1.0, 1.0, 1.0), (-1.0, -1.0, -1.0), (1.0, -1.0, -1.0), (-1.0, -1.0, 1.0), (1.0, -1.0, 1.0), (-1.0, -1.0, 1.0), (1.0, -1.0, 1.0), (-1.0, 1.0, 1.0), (1.0, 1.0, 1.0), (-1.0, -1.0, -1.0), (1.0, -1.0, -1.0), (-1.0, 1.0, -1.0), (1.0, 1.0, -1.0))

This was for the default create box but I also tried loaded in my own obj with 8 vertices and its the same. I can't work out why there are so many vertices, maybe this has something to do with the odd patterns?

Other sanity checks included visualising normals, depth and GPU ids and everything was as you'd expect it.

Any ideas on whats wrong here?

natevm commented 3 years ago

I actually have an intuition that this has to do with the mesh you’re using for your light source.

Does this use a point light? (Ie, an entity with a light and transform component attached, but no mesh) If not, what mesh are you using for your light source?

natevm commented 3 years ago

Also, your mesh data above indicates you have 23 vertices (triangle indices map into the vertex array). This is normal if you have multiple normals per vertex, ex for flat shading vs smooth shading.

dgriffiths3 commented 3 years ago

Okay, very interesting!

The light is a sphere light. The code I use for it is:

# Switch off ambiant light
nvisii.set_dome_light_intensity(0)
nvisii.disable_dome_light_sampling()

obj = nvisii.entity.create(
    name = 'light',
    mesh = nvisii.mesh.create_sphere('light'),
    transform = nvisii.transform.create('light'),
)
obj.set_light(nvisii.light.create('light'))
obj.get_light().set_intensity(250)
obj.get_light().set_temperature(8000)
obj.get_transform().set_scale(0.05, 0.05, 0.05)
obj.get_transform().set_position(0, 3, 0)

I guess this is not a point light? I was not aware I could make a point light by not assigning a mesh.

I just ran a quick test, and the artefacts are not there when using a point light.

natevm commented 3 years ago

To be clear, this is still a bug that I should fix. Some numerical precision issue it looks like. I think I have enough info to repro now though.

The point light feature is new! I added it to hopefully help with backwards compatibility with "video game-esque" FBX scenes containing point lights.

Unfortunately, point lights cast hard shadows, which are not physically realistic. Another workaround if you still want soft shadows is probably to increase the scale of the sphere light, then turn down the intensity from 250 down to something like 10. Another mesh type might also work better, like a plane light for example.

dgriffiths3 commented 3 years ago

Thanks for the advice. I still find artefacts even with a larger light (up until the point where its becomes to big for me), but point light will suffice for now!