From 42e6da443a0fc8132bdfae99aff25a5c344e7e4b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 18 Jan 2014 03:24:55 +0100 Subject: [PATCH] Simplify Spheremap shader. --- data/shaders/objectpass_spheremap.frag | 15 +++++++-------- src/graphics/shaders.cpp | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index 7db065066..7c907f629 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -1,8 +1,7 @@ #version 130 uniform sampler2D tex; -noperspective in vec3 eyenor; -noperspective in vec3 viewpos; +in vec4 color; noperspective in vec3 nor; void main() { @@ -10,16 +9,16 @@ void main() { const vec3 forward = vec3(0.0, 0.0, 1.0); // get the angle between the forward vector and the horizontal portion of the normal - vec3 normal_x = normalize(vec3(eyenor.x, 0.0, eyenor.z)); - float sin_theta_x = length(cross( forward, normal_x )) * eyenor.x/abs(eyenor.x); + vec3 normal_x = normalize(vec3(nor.x, 0.0, nor.z)); + float sin_theta_x = length(cross( forward, normal_x )) * nor.x/abs(nor.x); // get the angle between the forward vector and the vertical portion of the normal - vec3 normal_y = normalize(vec3(0.0, eyenor.y, eyenor.z)); - float sin_theta_y = length(cross( forward, normal_y )) * eyenor.y/abs(eyenor.y); + vec3 normal_y = normalize(vec3(0.0, nor.y, nor.z)); + float sin_theta_y = length(cross( forward, normal_y )) * nor.y/abs(nor.y); - vec4 detail0 = texture2D(tex, vec2(0.5 + sin_theta_x*0.5, 0.5 + sin_theta_y*0.5)); + vec4 detail0 = texture2D(tex, 0.5 * vec2(sin_theta_x, sin_theta_y) + 0.5); - gl_FragData[0] = detail0 * gl_Color; + gl_FragData[0] = detail0 * color; gl_FragData[1] = vec4(nor, gl_FragCoord.z); gl_FragData[2] = vec4(0.); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 46935d8e1..56354515e 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -97,7 +97,7 @@ void Shaders::loadShaders() m_shaders[ES_WATER_SURFACE] = glsl(dir + "water.vert", dir + "pass.frag", m_callbacks[ES_WATER]); - m_shaders[ES_SPHERE_MAP] = glslmat(dir + "objectpass_rimlit.vert", dir + "objectpass_spheremap.frag", + m_shaders[ES_SPHERE_MAP] = glslmat(dir + "objectpass.vert", dir + "objectpass_spheremap.frag", m_callbacks[ES_OBJECTPASS], EMT_SOLID); m_shaders[ES_GRASS] = glslmat(dir + "grass.vert", dir + "grass.frag",