Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Adjusting Polygon offset factor #63

Open
ManishJu opened this issue Jan 21, 2020 · 4 comments
Open

Adjusting Polygon offset factor #63

ManishJu opened this issue Jan 21, 2020 · 4 comments

Comments

@ManishJu
Copy link

ManishJu commented Jan 21, 2020

Is there a way to adjust the polygon offset factor of the material in this ray-tracer as geometries that are really close to each other are z-fighting. The three.js real-time version works fine , the ray tracer doesn't seem to pick up the value put in the material properties.

Edit: I have tried to reduce the range of the camera near and far plane but with no success in the ray-tracer.
I also changed the precision of the depth buffer to 16 bits by setting depth to true [ in cavas context] in your RayTracingRenderer.js file but with no success.

Thanks !

@jaxry
Copy link
Contributor

jaxry commented Jan 21, 2020

Is there a way to adjust the polygon offset factor of the material

I can't think of a way. Three's polygonOffset uses glPolygonOffset which transposes depth values of the rasterized image. RayTracingRenderer doesn't use a depth buffer at all, since ray tracing traverses a BVH instead. Do you have some ideas how we could prevent z-fighting in other ways?

@ManishJu
Copy link
Author

Sorting of objects from back to front is already done with threejs by default.

But the the nvidia guy gave multiple options:
https://devtalk.nvidia.com/default/topic/913414/optix/how-can-optix-solve-the-problem-of-z-fighting-/

  1. Increase BVH precision,
  2. Offset the ray origin a little from the primitive surface (not good for transparent objects)
  3. Unique primitive IDS, but a lot complicated when using instancing, which has now started heavily being used in webgl rendering .

What do you think ?

@jaxry
Copy link
Contributor

jaxry commented Jan 23, 2020

Wonderful resource, thanks for finding this. Correct me if I'm mistaken, but this forum post addresses how to avoid self-intersection with the same triangle? What you're describing involves z-fighting between two triangles that are close together? I can see how 1. would fix that, but what about 2. and 3.?

  1. The BVH precision is using the max built-in texture storage of 32-bit float. I'm not sure how easy it would be to increase this.
  2. I think we're doing this already! We offset the ray origin, from the surface, by a fixed small amount of 0.0005. It avoids the self-intersection problem described in the post.
    https://github.com/hoverinc/ray-tracing-renderer/blob/master/src/renderer/glsl/chunks/sampleShadowCatcher.glsl#L117
  3. This solution is interesting and sounds like something we could explore. We'd need to allocate extra memory in the BVH for primitive IDs, but that's doable. But would it offer an advantage over ray origin offsetting?

@ManishJu
Copy link
Author

ManishJu commented Mar 3, 2020

  1. Yes you cannot go beyond 32 bit float precision in WebGL2 :(
  2. Oh that's great, but we are having self intersection problems with thin planes, currently managing with tricks.
  3. Yes when geometry is quite thin and almost overlapping, this should be really useful :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants