diff --git a/data/shaders/normalmap.frag b/data/shaders/normalmap.frag index 5e921c439..f977e5e46 100644 --- a/data/shaders/normalmap.frag +++ b/data/shaders/normalmap.frag @@ -4,7 +4,13 @@ uniform sampler2D normalMap; noperspective in vec3 tangent; noperspective in vec3 bitangent; 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() { @@ -16,5 +22,5 @@ void main() 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; - Normal = 0.5 * FragmentNormal + 0.5; + EncodedNormal = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5; } diff --git a/data/shaders/object_pass1.frag b/data/shaders/object_pass1.frag index 9c794eaf2..5c47fafc7 100644 --- a/data/shaders/object_pass1.frag +++ b/data/shaders/object_pass1.frag @@ -1,8 +1,14 @@ #version 130 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) { - Normal = 0.5 * nor + 0.5; + EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5; } diff --git a/data/shaders/objectref_pass1.frag b/data/shaders/objectref_pass1.frag index 3c6a9f857..8c5500dbd 100644 --- a/data/shaders/objectref_pass1.frag +++ b/data/shaders/objectref_pass1.frag @@ -3,12 +3,18 @@ uniform sampler2D tex; noperspective in vec3 nor; 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() { vec4 col = texture(tex, uv); if (col.a < 0.5) discard; - Normal = 0.5 * nor + 0.5; + EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5; } diff --git a/data/shaders/pointlight.frag b/data/shaders/pointlight.frag index eab9678c0..06a2552f3 100644 --- a/data/shaders/pointlight.frag +++ b/data/shaders/pointlight.frag @@ -13,10 +13,17 @@ in vec2 uv; 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); +} + void main() { vec2 texc = uv; 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; xpos = invproj * xpos; diff --git a/data/shaders/ssao.frag b/data/shaders/ssao.frag index c692d9c3a..5af8b3819 100644 --- a/data/shaders/ssao.frag +++ b/data/shaders/ssao.frag @@ -21,6 +21,13 @@ 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); +} + void main(void) { vec4 cur = texture(ntex, uv); @@ -29,7 +36,7 @@ void main(void) FragPos /= FragPos.w; // 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 float len = dot(vec3(1.0), abs(cur.xyz)); if (len < 0.2 || curdepth > 0.999) discard; diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index c2f7d08ad..faedb9d61 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -14,6 +14,13 @@ out vec4 Diff; out vec4 Spec; 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() { float z = texture(dtex, uv).x; vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0; @@ -28,7 +35,7 @@ void main() { return; } - vec3 norm = normalize(2. * texture(ntex, uv).xyz - 1.); + vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.)); // Normalized on the cpu vec3 L = direction; diff --git a/lib/irrlicht/include/SColor.h b/lib/irrlicht/include/SColor.h index 93654333c..8b6c2afa1 100644 --- a/lib/irrlicht/include/SColor.h +++ b/lib/irrlicht/include/SColor.h @@ -34,7 +34,6 @@ namespace video //! The normalized non-float formats from the _rg extension ECF_R8, ECF_R8G8, - ECF_R11G11B10F, ECF_R16, ECF_R16G16, diff --git a/lib/irrlicht/source/Irrlicht/COpenGLTexture.cpp b/lib/irrlicht/source/Irrlicht/COpenGLTexture.cpp index c0b3bd7a3..0bc4b612a 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLTexture.cpp +++ b/lib/irrlicht/source/Irrlicht/COpenGLTexture.cpp @@ -238,12 +238,6 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT #endif } break; - case ECF_R11G11B10F: - filtering = GL_NEAREST; - colorformat = GL_RGB; - type = GL_FLOAT; - internalformat = GL_R11F_G11F_B10F; - break; case ECF_G32R32F: { #ifdef GL_ARB_texture_rg diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index be514c91b..2696bebb7 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -67,7 +67,7 @@ RTT::RTT() rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", 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_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_SPECULARMAP] = drv->addRenderTargetTexture(res, "rtt.specularmap", ECF_R8, stencil);