<p>A fragment shader receives the <a href="https://www.khronos.org/opengl/wiki/Fragment_Shader#System_inputs" rel="nofollow noreferrer"><code>gl_FrontFacing</code> system-defined input value</a>. It will be <code>false</code> if the fragment was generated from a back-facing triangle, and <code>true</code> otherwise. So you can use that in your shader to determine how to generate a color value.</p>

CC BY-SA 4.0
2020-05-12T01:55:50.563Z
2020-05-12T01:55:50.563Z
Nicol Bolas
<p>I'm working on a simple 3d modeller and I would like to render the back facing triangles a bit darker, to easier differentiate between front and back faces. Like you can see in most modelling applications. How does one achieve is?</p>

<p>Should I enable back face culling and render the primitives and then enable front face culling, rotate the normals by 180 degrees and render the primitives again? Is this a practical approach?</p>

<opengl><shading><model>
OpenGL Render front and back faces with different shading for 3d modeller
Lenny White
# OpenGL Render front and back faces with different shading for 3d modeller

(Asked by: username_0 on 2020-05-11)

I'm working on a simple 3d modeller and I would like to render the back facing triangles a bit darker, to easier differentiate between front and back faces. Like you can see in most modelling applications. How does one achieve is?

Should I enable back face culling and render the primitives and then enable front face culling, rotate the normals by 180 degrees and render the primitives again? Is this a practical approach?

**Tags:** opengl, shading, model


---

## 1 answers

### Answer by username_1 on 2020-05-12. Score: 3 | Accepted answer

A fragment shader receives the [`gl_FrontFacing` system-defined input value](https://www.khronos.org/opengl/wiki/Fragment_Shader#System_inputs). It will be `false` if the fragment was generated from a back-facing triangle, and `true` otherwise. So you can use that in your shader to determine how to generate a color value.


---

