Factorize DecodeNormal from misc shaders.
This commit is contained in:
parent
77e5f413c7
commit
01b88fde9d
@ -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])
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
7
data/shaders/utils/decodeNormal.frag
Normal file
7
data/shaders/utils/decodeNormal.frag
Normal 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);
|
||||
}
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user