From 50ca1a91f9c24e7772020ecde1dc262a50f48761 Mon Sep 17 00:00:00 2001 From: Learn OpenGL ES Date: Thu, 10 May 2012 18:12:05 -0400 Subject: [PATCH] Add two-sided rendering to the fragment shader. --- .../res/raw/per_pixel_fragment_shader_no_tex.glsl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/AndroidOpenGLESLessons/res/raw/per_pixel_fragment_shader_no_tex.glsl b/android/AndroidOpenGLESLessons/res/raw/per_pixel_fragment_shader_no_tex.glsl index 4655f41..c13eca8 100644 --- a/android/AndroidOpenGLESLessons/res/raw/per_pixel_fragment_shader_no_tex.glsl +++ b/android/AndroidOpenGLESLessons/res/raw/per_pixel_fragment_shader_no_tex.glsl @@ -18,7 +18,13 @@ void main() // Calculate the dot product of the light vector and vertex normal. If the normal and light vector are // pointing in the same direction then it will get max illumination. - float diffuse = max(dot(v_Normal, lightVector), 0.0); + float diffuse; + + if (gl_FrontFacing) { + diffuse = max(dot(v_Normal, lightVector), 0.0); + } else { + diffuse = max(dot(-v_Normal, lightVector), 0.0); + } // Add attenuation. diffuse = diffuse * (1.0 / (1.0 + (0.10 * distance)));