Skip to content

Commit 50ca1a9

Browse files
committed
Add two-sided rendering to the fragment shader.
1 parent 53bad4b commit 50ca1a9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

android/AndroidOpenGLESLessons/res/raw/per_pixel_fragment_shader_no_tex.glsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ void main()
1818

1919
// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
2020
// pointing in the same direction then it will get max illumination.
21-
float diffuse = max(dot(v_Normal, lightVector), 0.0);
21+
float diffuse;
22+
23+
if (gl_FrontFacing) {
24+
diffuse = max(dot(v_Normal, lightVector), 0.0);
25+
} else {
26+
diffuse = max(dot(-v_Normal, lightVector), 0.0);
27+
}
2228

2329
// Add attenuation.
2430
diffuse = diffuse * (1.0 / (1.0 + (0.10 * distance)));

0 commit comments

Comments
 (0)