2

As a follow-up question to this question I have the following scenario:

I have a 2D object (let's say a plane for simplicity) that I want to render from both sides in Qt3D. The mentioned question provided an amazing answer to disable the culling and this indeed makes the object visible from both sides. However, I noticed that the light only reflects on one side of the entity, which makes a pure diffuse color look black on the non-illuminated side.

Here is the top view (as expected): topview

From below, however, the mesh just swallows all light and color and looks black: bottomview

So, how can I have light reflections on both sides?

It should work for more complex 3D shapes done with 2D meshes, so I cannot e.g. create a mirrored mesh of the object.

Note: Adding an Ambient component to the material makes the color a bit visible on the bottom view, but it is still very dark due to the lack of light reflection.

Mariam
  • 342
  • 3
  • 18
  • Do you provide a material for back faces (or have enabled material for both sides)? There _might_ also be a parameter for lighting to enable back face lighting. (I believe I mentioned this already but I know rather nothing about Qt3D but have some experiences concerning this in OpenGL.) – Scheff's Cat Sep 03 '18 at 08:23
  • 1
    It looks like you have to write your own shader to achieve this. Apparently there is some `glLightMode` which tells OpenGL to light both sides of a triangle but it doesn't seem to be available in Qt3D. You can check whether a fragment is back- or front-facing in a fragment shader using `gl_FrontFacing`. – Florian Blume Sep 03 '18 at 09:06
  • If you are using the phong shader provided by Qt3D have a look at how it is implemented [here](https://github.com/qt/qt3d/tree/5.11/src/extras/defaults). The corresponding shader code can be found [here](https://github.com/qt/qt3d/tree/5.11/src/extras/shaders/gl3). – Florian Blume Sep 03 '18 at 09:08
  • Maybe a bit of an incomplete comment, oops. What you could do then is to invert the normal before computing the lightning in the shader. The reflected light is calculated using the normal and the vector from the vertices to the light source. If you invert the normal you should obtain the same results on both sides. – Florian Blume Sep 03 '18 at 09:11
  • 2
    @FlorianBlume thanks. I will see what I can do and keep you updated! – Mariam Sep 03 '18 at 09:55
  • @FlorianBlume unfortunately I realized this is a complex question in relation to the time I have for this project, so for now I will be content with the ambient component and try to look into this deeper another time in the future. – Mariam Sep 04 '18 at 12:37
  • Maybe I can try to work something out tomorrow, right now I have to prepare my defense. – Florian Blume Sep 04 '18 at 12:51
  • @FlorianBlume no, no, this wasn't what I meant. I just have to read a bit more in shaders etc. and I will just postpone this question a bit. And good luck with your defense! – Mariam Sep 04 '18 at 13:02
  • Sorry, I couldn't wait :D https://github.com/Sonnentierchen/Qt3D-TwiceReflectingMaterial Have a look at the frag.test shader to see how it works. If you remove these lines `if (!gl_FrontFacing) { _worldNormal = -worldNormal; }` you'll notice that the reflection on one side vanishes. You have to adapt the shader a bit, it's not the nicest but I only found this one usable on the internet. – Florian Blume Sep 05 '18 at 16:02
  • The shininess is not optimal, so you probably have to investigate a proper Phong shader. You can rotate the plane with your mouse to see how the reflection changes. – Florian Blume Sep 05 '18 at 16:03

0 Answers0