From 6bc132f8bf85516b4a89386c371fdd3e9937b4bf Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 23 Nov 2015 21:53:22 +0000 Subject: slideshow: Add back lighting in the SimpleTransition shaders Change-Id: Iec854a8369a7a9f845f261233e46aea8097db109 --- slideshow/opengl/basicFragmentShader.glsl | 8 ++++++-- slideshow/opengl/basicVertexShader.glsl | 2 ++ slideshow/opengl/reflectionFragmentShader.glsl | 6 ++++++ slideshow/opengl/reflectionVertexShader.glsl | 4 +++- 4 files changed, 17 insertions(+), 3 deletions(-) (limited to 'slideshow/opengl') diff --git a/slideshow/opengl/basicFragmentShader.glsl b/slideshow/opengl/basicFragmentShader.glsl index 7744432f0bcf..01d72a260ca0 100644 --- a/slideshow/opengl/basicFragmentShader.glsl +++ b/slideshow/opengl/basicFragmentShader.glsl @@ -30,10 +30,14 @@ uniform sampler2D slideTexture; varying vec2 v_texturePosition; +varying vec3 v_normal; void main() { - // TODO: handle lighting. - gl_FragColor = texture2D(slideTexture, v_texturePosition); + vec3 lightVector = vec3(0.0, 0.0, 1.0); + float light = max(dot(lightVector, v_normal), 0.0); + vec4 fragment = texture2D(slideTexture, v_texturePosition); + vec4 black = vec4(0.0, 0.0, 0.0, fragment.a); + gl_FragColor = mix(black, fragment, light); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/opengl/basicVertexShader.glsl b/slideshow/opengl/basicVertexShader.glsl index bd26c1b52115..020616fff872 100644 --- a/slideshow/opengl/basicVertexShader.glsl +++ b/slideshow/opengl/basicVertexShader.glsl @@ -29,11 +29,13 @@ #version 120 varying vec2 v_texturePosition; +varying vec3 v_normal; void main( void ) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; v_texturePosition = gl_MultiTexCoord0.xy; + v_normal = normalize(gl_NormalMatrix * gl_Normal); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/opengl/reflectionFragmentShader.glsl b/slideshow/opengl/reflectionFragmentShader.glsl index 9bf8ecb70c3d..b415279f2784 100644 --- a/slideshow/opengl/reflectionFragmentShader.glsl +++ b/slideshow/opengl/reflectionFragmentShader.glsl @@ -31,9 +31,15 @@ uniform sampler2D slideTexture; varying float v_isShadow; varying vec2 v_texturePosition; +varying vec3 v_normal; void main() { + vec3 lightVector = vec3(0.0, 0.0, 1.0); + float light = max(dot(lightVector, v_normal), 0.0); vec4 fragment = texture2D(slideTexture, v_texturePosition); + vec4 black = vec4(0.0, 0.0, 0.0, fragment.a); + fragment = mix(black, fragment, light); + if (v_isShadow > 0.5) { if (v_texturePosition.y > 1.0 - 0.3) gl_FragColor = mix(fragment, vec4(0.0, 0.0, 0.0, 0.0), (1.0 - v_texturePosition.y) / 0.3); diff --git a/slideshow/opengl/reflectionVertexShader.glsl b/slideshow/opengl/reflectionVertexShader.glsl index b08d0cc82f59..5087b98c57b0 100644 --- a/slideshow/opengl/reflectionVertexShader.glsl +++ b/slideshow/opengl/reflectionVertexShader.glsl @@ -28,13 +28,15 @@ #version 130 -varying float v_isShadow; varying vec2 v_texturePosition; +varying vec3 v_normal; +varying float v_isShadow; void main( void ) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; v_texturePosition = gl_MultiTexCoord0.xy; + v_normal = normalize(gl_NormalMatrix * gl_Normal); v_isShadow = float(gl_VertexID >= 6); } -- cgit v1.2.3