Use another normal encoding method from a crytek slide.
This commit is contained in:
parent
1c98cf0b61
commit
f50e6f817d
@ -4,7 +4,13 @@ uniform sampler2D normalMap;
|
|||||||
noperspective in vec3 tangent;
|
noperspective in vec3 tangent;
|
||||||
noperspective in vec3 bitangent;
|
noperspective in vec3 bitangent;
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
out vec3 Normal;
|
out vec2 EncodedNormal;
|
||||||
|
|
||||||
|
// from Crytek "a bit more deferred CryEngine"
|
||||||
|
vec2 EncodeNormal(vec3 n)
|
||||||
|
{
|
||||||
|
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@ -16,5 +22,5 @@ void main()
|
|||||||
vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent);
|
vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent);
|
||||||
|
|
||||||
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
|
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
|
||||||
Normal = 0.5 * FragmentNormal + 0.5;
|
EncodedNormal = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
#version 130
|
#version 130
|
||||||
noperspective in vec3 nor;
|
noperspective in vec3 nor;
|
||||||
out vec3 Normal;
|
out vec2 EncodedNormal;
|
||||||
|
|
||||||
|
// from Crytek "a bit more deferred CryEngine"
|
||||||
|
vec2 EncodeNormal(vec3 n)
|
||||||
|
{
|
||||||
|
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
Normal = 0.5 * nor + 0.5;
|
EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,18 @@ uniform sampler2D tex;
|
|||||||
|
|
||||||
noperspective in vec3 nor;
|
noperspective in vec3 nor;
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
out vec3 Normal;
|
out vec2 EncodedNormal;
|
||||||
|
|
||||||
|
// from Crytek "a bit more deferred CryEngine"
|
||||||
|
vec2 EncodeNormal(vec3 n)
|
||||||
|
{
|
||||||
|
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 col = texture(tex, uv);
|
vec4 col = texture(tex, uv);
|
||||||
if (col.a < 0.5)
|
if (col.a < 0.5)
|
||||||
discard;
|
discard;
|
||||||
Normal = 0.5 * nor + 0.5;
|
EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,17 @@ in vec2 uv;
|
|||||||
out vec4 Diffuse;
|
out vec4 Diffuse;
|
||||||
out vec4 Specular;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 texc = uv;
|
vec2 texc = uv;
|
||||||
float z = texture(dtex, texc).x;
|
float z = texture(dtex, texc).x;
|
||||||
vec3 norm = normalize(2. * texture(ntex, texc).xyz - 1.);
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
|
||||||
|
|
||||||
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
|
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
|
||||||
xpos = invproj * xpos;
|
xpos = invproj * xpos;
|
||||||
|
@ -21,6 +21,13 @@ vec3 rand(vec2 co)
|
|||||||
return texture(noise_texture, co*20.16).xyz;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
vec4 cur = texture(ntex, uv);
|
vec4 cur = texture(ntex, uv);
|
||||||
@ -29,7 +36,7 @@ void main(void)
|
|||||||
FragPos /= FragPos.w;
|
FragPos /= FragPos.w;
|
||||||
|
|
||||||
// get the normal of current fragment
|
// get the normal of current fragment
|
||||||
vec3 norm = normalize(cur.xyz * vec3(2.0) - vec3(1.0));
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
||||||
// Workaround for nvidia and skyboxes
|
// Workaround for nvidia and skyboxes
|
||||||
float len = dot(vec3(1.0), abs(cur.xyz));
|
float len = dot(vec3(1.0), abs(cur.xyz));
|
||||||
if (len < 0.2 || curdepth > 0.999) discard;
|
if (len < 0.2 || curdepth > 0.999) discard;
|
||||||
|
@ -14,6 +14,13 @@ out vec4 Diff;
|
|||||||
out vec4 Spec;
|
out vec4 Spec;
|
||||||
out vec4 SpecularMap;
|
out vec4 SpecularMap;
|
||||||
|
|
||||||
|
vec3 DecodeNormal(vec2 n)
|
||||||
|
{
|
||||||
|
float z = dot(n, n) * 2. - 1.;
|
||||||
|
vec2 xy = normalize(n) * sqrt(1. - z * z);
|
||||||
|
return vec3(xy,z);
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float z = texture(dtex, uv).x;
|
float z = texture(dtex, uv).x;
|
||||||
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
|
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
|
||||||
@ -28,7 +35,7 @@ void main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 norm = normalize(2. * texture(ntex, uv).xyz - 1.);
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
||||||
|
|
||||||
// Normalized on the cpu
|
// Normalized on the cpu
|
||||||
vec3 L = direction;
|
vec3 L = direction;
|
||||||
|
@ -34,7 +34,6 @@ namespace video
|
|||||||
//! The normalized non-float formats from the _rg extension
|
//! The normalized non-float formats from the _rg extension
|
||||||
ECF_R8,
|
ECF_R8,
|
||||||
ECF_R8G8,
|
ECF_R8G8,
|
||||||
ECF_R11G11B10F,
|
|
||||||
ECF_R16,
|
ECF_R16,
|
||||||
ECF_R16G16,
|
ECF_R16G16,
|
||||||
|
|
||||||
|
@ -238,12 +238,6 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ECF_R11G11B10F:
|
|
||||||
filtering = GL_NEAREST;
|
|
||||||
colorformat = GL_RGB;
|
|
||||||
type = GL_FLOAT;
|
|
||||||
internalformat = GL_R11F_G11F_B10F;
|
|
||||||
break;
|
|
||||||
case ECF_G32R32F:
|
case ECF_G32R32F:
|
||||||
{
|
{
|
||||||
#ifdef GL_ARB_texture_rg
|
#ifdef GL_ARB_texture_rg
|
||||||
|
@ -67,7 +67,7 @@ RTT::RTT()
|
|||||||
rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", ECF_A8R8G8B8, stencil);
|
rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", ECF_A8R8G8B8, stencil);
|
||||||
rtts[RTT_TMP3] = drv->addRenderTargetTexture(res, "rtt.tmp3", ECF_A8R8G8B8, stencil);
|
rtts[RTT_TMP3] = drv->addRenderTargetTexture(res, "rtt.tmp3", ECF_A8R8G8B8, stencil);
|
||||||
rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_R8, stencil);
|
rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_R8, stencil);
|
||||||
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_R11G11B10F, stencil);
|
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_G16R16F, stencil);
|
||||||
rtts[RTT_COLOR] = drv->addRenderTargetTexture(res, "rtt.color", ECF_A16B16G16R16F, stencil);
|
rtts[RTT_COLOR] = drv->addRenderTargetTexture(res, "rtt.color", ECF_A16B16G16R16F, stencil);
|
||||||
rtts[RTT_SPECULARMAP] = drv->addRenderTargetTexture(res, "rtt.specularmap", ECF_R8, stencil);
|
rtts[RTT_SPECULARMAP] = drv->addRenderTargetTexture(res, "rtt.specularmap", ECF_R8, stencil);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user