Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Opacity problem on stl file when backface culling is enabled #3069

Open
TimDeBauwReLu opened this issue May 13, 2024 · 11 comments
Open
Labels
module: rendering General rendering issues type: bug 🐞 Errors in functionality

Comments

@TimDeBauwReLu
Copy link

Bug description

I have a problem where the opacity of stl objects behaves inconsistently when backface culling is enabled. I have two meshes of a mandible, which both are rendered correctly when opacity=1 (see pictures below). I also checked that the backfaces of both meshes are on the inside.
Screenshot 2024-05-13 at 12 58 00
Screenshot 2024-05-13 at 12 58 11

When changing the opacity to be less than 1, you can see that the color of the bone is different on both objects (see pictures below). When zooming out far, both objects are again rendered correctly. Do you know what can cause this?

Screenshot 2024-05-13 at 12 57 22 Screenshot 2024-05-13 at 12 57 41

Steps to reproduce

const reader = vtkSTLReader.newInstance()
reader.setUrl('Mandible_broken.stl', { binary: true })

const mapper = vtkMapper.newInstance();
mapper.setInputConnection(reader.getOutputPort());

const actor = vtkActor.newInstance();
actor.getProperty().setBackfaceCulling(true);
actor.getProperty().setOpacity(0.5);
actor.setMapper(mapper);

const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();
renderer.addActor(actor);
 renderWindow.render();

Detailed Behavior

No response

Expected Behavior

Both objects are rendered correctly when opacity is less than 1 and backface culling is enabled

Environment

  • vtk.js version:
  • Browsers:
  • OS:
@TimDeBauwReLu TimDeBauwReLu added the type: bug 🐞 Errors in functionality label May 13, 2024
@finetjul finetjul added the module: rendering General rendering issues label May 13, 2024
@finetjul
Copy link
Member

What picture is incorrect ? do you have backface culling enabled on the incorrect picture ?

@TimDeBauwReLu
Copy link
Author

Backface culling is enabled on all pictures, the last picture (larger mandible with the full jawbone) is the incorrect one

@TimDeBauwReLu
Copy link
Author

I forgot to mention that this problem does not appear when using camera.setParallelProjection(true);

@finetjul
Copy link
Member

What's the difference between the 3rd picture and the last picture ? Only the mesh is different ?

@TimDeBauwReLu
Copy link
Author

The color of the bone is too dark, and you can see a big contrast between the bone and the teeth sockets (dark red vs bright red). It is supposed to be like this I believe:
Screenshot 2024-05-13 at 14 15 38

@finetjul
Copy link
Member

Gotcha.

It would be great if you could attach that STL file to the issue.
The shader code should be investigated...

@TimDeBauwReLu
Copy link
Author

Here are the files used to reproduce it:

Archive.zip

@finetjul
Copy link
Member

You might want to check the magnitude of your normals (maybe it is different between the teeth triangles and the jaw triangles).
Alternatively, you might also want to test without diffuse light coefficient, only ambient, and see if the problem is light related.
Finally, you might want to consider the OrderIndependentTranslucentPass code...

@TimDeBauwReLu
Copy link
Author

@finetjul It looks like it has something to do with the diffuse light coefficient. When I put it to zero, it looks like this.

Screenshot 2024-05-15 at 17 04 18

I guess that depending on the distance from the camera to the object, the intensity of the diffuse component changes? Do you have an idea where to investigate this issue?

@finetjul
Copy link
Member

And this blackness does not happen if it is opaque? Do you have ambient lighting?

@TimDeBauwReLu
Copy link
Author

TimDeBauwReLu commented May 16, 2024

Yes, it is caused because I do not have ambient lighting I believe. The blackness also occurs when the mesh is opaque

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: rendering General rendering issues type: bug 🐞 Errors in functionality
Projects
None yet
Development

No branches or pull requests

2 participants