Factorize DecodeNormal from misc shaders.

This commit is contained in:
Vincent Lejeune 2014-03-21 18:17:21 +01:00
parent 77e5f413c7
commit 01b88fde9d
7 changed files with 17 additions and 30 deletions

View File

@ -14,12 +14,7 @@ varying vec2 uv;
#define Spec gl_FragData[1]
#endif
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
vec3 DecodeNormal(vec2 n);
mat4 getMatrix(float L[9])
{

View File

@ -12,12 +12,7 @@ flat in vec3 col;
out vec4 Diffuse;
out vec4 Specular;
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
vec3 DecodeNormal(vec2 n);
void main() {
vec2 texc = gl_FragCoord.xy / screen;

View File

@ -25,12 +25,7 @@ vec3 rand(vec2 co)
return texture(noise_texture, co*20.16).xyz;
}
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
vec3 DecodeNormal(vec2 n);
void main(void)
{

View File

@ -19,12 +19,7 @@ varying vec2 uv;
#endif
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
vec3 DecodeNormal(vec2 n);
void main() {
float z = texture(dtex, uv).x;

View File

@ -23,12 +23,7 @@ varying vec2 uv;
#endif
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
vec3 DecodeNormal(vec2 n);
float getShadowFactor(vec3 pos, float bias, int index)
{

View File

@ -0,0 +1,7 @@
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}

View File

@ -1231,6 +1231,7 @@ namespace LightShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlight.frag").c_str());
attrib_Position = glGetAttribLocation(Program, "Position");
attrib_Color = glGetAttribLocation(Program, "Color");
@ -1553,6 +1554,7 @@ namespace FullScreenShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlight.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
@ -1583,6 +1585,7 @@ namespace FullScreenShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/diffuseenvmap.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_blueLmn = glGetUniformLocation(Program, "blueLmn[0]");
@ -1615,6 +1618,7 @@ namespace FullScreenShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlightshadow.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
@ -1801,6 +1805,7 @@ namespace FullScreenShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/ssao.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");