From 83aaee5bc4613cc677378e85cc856dd5dfda9745 Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Sun, 16 Mar 2014 16:29:38 -0700 Subject: OpenGL2: Parallax corrected cubemap (cheaper trick) --- src/renderergl2/glsl/lightall_fp.glsl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/renderergl2/glsl') diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl index c74d6844..0f50a038 100644 --- a/src/renderergl2/glsl/lightall_fp.glsl +++ b/src/renderergl2/glsl/lightall_fp.glsl @@ -44,6 +44,12 @@ uniform vec4 u_NormalScale; uniform vec4 u_SpecularScale; #endif +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) +#if defined(USE_CUBEMAP) +uniform vec4 u_CubeMapInfo; +#endif +#endif + varying vec4 var_TexCoords; varying vec4 var_Color; @@ -323,19 +329,20 @@ mat3 cotangent_frame( vec3 N, vec3 p, vec2 uv ) void main() { + vec3 viewDir; vec3 L, N, E, H; float NL, NH, NE, EH; #if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_VERT_TANGENT_SPACE) mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz); - E = vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w); + viewDir = vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w); #else mat3 tangentToWorld = cotangent_frame(var_Normal, -var_ViewDir, var_TexCoords.xy); - E = var_ViewDir; + viewDir = var_ViewDir; #endif - E = normalize(E); + E = normalize(viewDir); L = var_LightDir.xyz; #if defined(USE_DELUXEMAP) @@ -497,6 +504,10 @@ void main() vec3 R = reflect(E, N); + // parallax corrected cubemap (cheaper trick) + // from http://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ + R += u_CubeMapInfo.xyz + u_CubeMapInfo.w * viewDir; + vec3 cubeLightColor = textureCubeLod(u_CubeMap, R, 7.0 - gloss * 7.0).rgb * u_EnableTextures.w; #if defined(USE_LIGHTMAP) -- cgit