Change normal encoding method to get rid of RG16 textures and buffers
This commit is contained in:
parent
c27a4cfebe
commit
c05b12a6ab
16 changed files with 73 additions and 40 deletions
|
@ -34,6 +34,7 @@
|
|||
<program>
|
||||
<vertex-shader>Shaders/fog.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/fog.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>depth_tex</name>
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
<program>
|
||||
<vertex-shader>Shaders/light-spot.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/light-point.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>attenuation</name>
|
||||
<index>12</index>
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
<program>
|
||||
<vertex-shader>Shaders/light-spot.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/light-spot.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>attenuation</name>
|
||||
<index>12</index>
|
||||
|
|
|
@ -26,7 +26,6 @@ the objects that use it, and replaces it with the default shader.
|
|||
</and>
|
||||
</or>
|
||||
<extension-supported>GL_EXT_gpu_shader4</extension-supported>
|
||||
<extension-supported>GL_ARB_texture_rg</extension-supported>
|
||||
</and>
|
||||
</predicate>
|
||||
<pass>
|
||||
|
@ -51,8 +50,9 @@ the objects that use it, and replaces it with the default shader.
|
|||
</material>
|
||||
<cull-face>back</cull-face>
|
||||
<program>
|
||||
<vertex-shader n="1">Shaders/ubershader.vert</vertex-shader>
|
||||
<fragment-shader n="1">Shaders/ubershader-gbuffer.frag</fragment-shader>
|
||||
<vertex-shader>Shaders/ubershader.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/ubershader-gbuffer.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
<!-- <vertex-shader n="1">Shaders/deferred-gbuffer.vert</vertex-shader>
|
||||
<fragment-shader n="1">Shaders/deferred-gbuffer.frag</fragment-shader>-->
|
||||
</program>
|
||||
|
|
|
@ -149,7 +149,6 @@
|
|||
</and>
|
||||
</or>
|
||||
<extension-supported>GL_EXT_gpu_shader4</extension-supported>
|
||||
<extension-supported>GL_ARB_texture_rg</extension-supported>
|
||||
</and>
|
||||
</predicate>
|
||||
<pass>
|
||||
|
@ -189,6 +188,7 @@
|
|||
<program>
|
||||
<vertex-shader>Shaders/deferred-gbuffer.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/deferred-gbuffer.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>texture</name>
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<program>
|
||||
<vertex-shader>Shaders/sunlight.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/sunlight.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>depth_tex</name>
|
||||
|
|
|
@ -212,7 +212,6 @@
|
|||
</and>
|
||||
</or>
|
||||
<extension-supported>GL_EXT_gpu_shader4</extension-supported>
|
||||
<extension-supported>GL_ARB_texture_rg</extension-supported>
|
||||
</and>
|
||||
</predicate>
|
||||
<pass>
|
||||
|
@ -249,6 +248,7 @@
|
|||
<program>
|
||||
<vertex-shader>Shaders/deferred-gbuffer.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/deferred-gbuffer.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>texture</name>
|
||||
|
|
|
@ -152,8 +152,9 @@
|
|||
<type>noise</type>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader n="1">Shaders/urban-gbuffer.vert</vertex-shader>
|
||||
<fragment-shader n="1">Shaders/urban-gbuffer.frag</fragment-shader>
|
||||
<vertex-shader>Shaders/urban-gbuffer.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/urban-gbuffer.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
|
@ -313,6 +314,7 @@
|
|||
<program>
|
||||
<vertex-shader>Shaders/urban-gbuffer.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/urban-gbuffer.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
|
|
|
@ -8,6 +8,9 @@ varying vec3 ecNormal;
|
|||
varying float alpha;
|
||||
uniform int materialID;
|
||||
uniform sampler2D texture;
|
||||
|
||||
vec2 normal_encode(vec3 n);
|
||||
|
||||
void main() {
|
||||
vec4 texel = texture2D(texture, gl_TexCoord[0].st);
|
||||
if (texel.a * alpha < 0.1)
|
||||
|
@ -17,7 +20,7 @@ void main() {
|
|||
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb, vec3( 0.3, 0.59, 0.11 ) );
|
||||
|
||||
vec3 normal2 = normalize( (2.0 * gl_Color.a - 1.0) * ecNormal );
|
||||
gl_FragData[0] = vec4( (normal2.xy + vec2(1.0,1.0)) * 0.5, 0.0, 1.0 );
|
||||
gl_FragData[0] = vec4( normal_encode(normal2), 0.0, 1.0 );
|
||||
gl_FragData[1] = vec4( gl_Color.rgb * texel.rgb, float( materialID ) / 255.0 );
|
||||
gl_FragData[2] = vec4( specular, shininess / 255.0, emission, 1.0 );
|
||||
gl_FragData[2] = vec4( specular, shininess / 128.0, emission, 1.0 );
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@ uniform vec4 fg_FogColor;
|
|||
uniform float fg_FogDensity;
|
||||
uniform vec3 fg_Planes;
|
||||
varying vec3 ray;
|
||||
|
||||
vec3 position( vec3 viewdir, float depth );
|
||||
|
||||
void main() {
|
||||
vec2 coords = gl_TexCoord[0].xy;
|
||||
float initialized = texture2D( spec_emis_tex, coords ).a;
|
||||
|
@ -16,11 +19,7 @@ void main() {
|
|||
normal.z = sqrt( 1.0 - dot( normal.xy, normal.xy ) );
|
||||
float len = length(normal);
|
||||
normal /= len;
|
||||
vec3 viewDir = normalize(ray);
|
||||
float depth = texture2D( depth_tex, coords ).r;
|
||||
vec3 pos;
|
||||
pos.z = - fg_Planes.y / (fg_Planes.x + depth * fg_Planes.z);
|
||||
pos.xy = viewDir.xy / viewDir.z * pos.z;
|
||||
vec3 pos = position( normalize(ray), texture2D( depth_tex, coords ).r );
|
||||
|
||||
float fogFactor = 0.0;
|
||||
const float LOG2 = 1.442695;
|
||||
|
|
28
Shaders/gbuffer-functions.frag
Normal file
28
Shaders/gbuffer-functions.frag
Normal file
|
@ -0,0 +1,28 @@
|
|||
uniform vec3 fg_Planes;
|
||||
|
||||
// normal compression functions from
|
||||
// http://aras-p.info/texts/CompactNormalStorage.html#method04spheremap
|
||||
vec2 normal_encode(vec3 n)
|
||||
{
|
||||
float p = sqrt(n.z * 8.0 + 8.0);
|
||||
return n.xy / p + 0.5;
|
||||
}
|
||||
|
||||
vec3 normal_decode(vec2 enc)
|
||||
{
|
||||
vec2 fenc = enc * 4.0 - 2.0;
|
||||
float f = dot(fenc,fenc);
|
||||
float g = sqrt(1.0 - f / 4.0);
|
||||
vec3 n;
|
||||
n.xy = fenc * g;
|
||||
n.z = 1.0 - f / 2.0;
|
||||
return n;
|
||||
}
|
||||
|
||||
vec3 position( vec3 viewDir, float depth )
|
||||
{
|
||||
vec3 pos;
|
||||
pos.z = - fg_Planes.y / (fg_Planes.x + depth * fg_Planes.z);
|
||||
pos.xy = viewDir.xy / viewDir.z * pos.z;
|
||||
return pos;
|
||||
}
|
|
@ -15,21 +15,19 @@ uniform float Far;
|
|||
|
||||
varying vec4 ecPosition;
|
||||
|
||||
vec3 position( vec3 viewdir, float depth );
|
||||
vec3 normal_decode(vec2 enc);
|
||||
|
||||
void main() {
|
||||
vec3 ray = ecPosition.xyz / ecPosition.w;
|
||||
vec3 ecPos3 = ray;
|
||||
vec3 viewDir = normalize(ray);
|
||||
vec2 coords = gl_FragCoord.xy / fg_BufferSize;
|
||||
|
||||
float depth = texture2D( depth_tex, coords ).r;
|
||||
vec3 normal;
|
||||
normal.xy = texture2D( normal_tex, coords ).rg * 2.0 - vec2(1.0,1.0);
|
||||
normal.z = sqrt( 1.0 - dot( normal.xy, normal.xy ) );
|
||||
vec3 normal = normal_decode(texture2D( normal_tex, coords ).rg);
|
||||
vec4 spec_emis = texture2D( spec_emis_tex, coords );
|
||||
|
||||
vec3 pos;
|
||||
pos.z = - fg_Planes.y / (fg_Planes.x + depth * fg_Planes.z);
|
||||
pos.xy = viewDir.xy * pos.z / viewDir.z;
|
||||
vec3 pos = position(viewDir, texture2D( depth_tex, coords ).r);
|
||||
|
||||
if ( pos.z < ecPos3.z ) // Negative direction in z
|
||||
discard; // Don't light surface outside the light volume
|
||||
|
|
|
@ -19,21 +19,19 @@ uniform float Far;
|
|||
|
||||
varying vec4 ecPosition;
|
||||
|
||||
vec3 position( vec3 viewdir, float depth );
|
||||
vec3 normal_decode(vec2 enc);
|
||||
|
||||
void main() {
|
||||
vec3 ray = ecPosition.xyz / ecPosition.w;
|
||||
vec3 ecPos3 = ray;
|
||||
vec3 viewDir = normalize(ray);
|
||||
vec2 coords = gl_FragCoord.xy / fg_BufferSize;
|
||||
|
||||
float depth = texture2D( depth_tex, coords ).r;
|
||||
vec3 normal;
|
||||
normal.xy = texture2D( normal_tex, coords ).rg * 2.0 - vec2(1.0,1.0);
|
||||
normal.z = sqrt( 1.0 - dot( normal.xy, normal.xy ) );
|
||||
vec3 normal = normal_decode(texture2D( normal_tex, coords ).rg);
|
||||
vec4 spec_emis = texture2D( spec_emis_tex, coords );
|
||||
|
||||
vec3 pos;
|
||||
pos.z = - fg_Planes.y / (fg_Planes.x + depth * fg_Planes.z);
|
||||
pos.xy = viewDir.xy * pos.z / viewDir.z;
|
||||
vec3 pos = position(viewDir, texture2D( depth_tex, coords ).r);
|
||||
|
||||
if ( pos.z < ecPos3.z ) // Negative direction in z
|
||||
discard; // Don't light surface outside the light volume
|
||||
|
|
|
@ -9,6 +9,10 @@ uniform vec4 fg_SunSpecularColor;
|
|||
uniform vec3 fg_SunDirection;
|
||||
uniform vec3 fg_Planes;
|
||||
varying vec3 ray;
|
||||
|
||||
vec3 position( vec3 viewdir, float depth );
|
||||
vec3 normal_decode(vec2 enc);
|
||||
|
||||
vec4 DynamicShadow( in vec4 ecPosition, out vec4 tint )
|
||||
{
|
||||
vec4 coords;
|
||||
|
@ -44,16 +48,11 @@ void main() {
|
|||
vec4 spec_emis = texture2D( spec_emis_tex, coords );
|
||||
if ( spec_emis.a < 0.1 )
|
||||
discard;
|
||||
vec3 normal;
|
||||
normal.xy = texture2D( normal_tex, coords ).rg * 2.0 - vec2(1.0,1.0);
|
||||
normal.z = sqrt( 1.0 - dot( normal.xy, normal.xy ) );
|
||||
vec3 normal = normal_decode(texture2D( normal_tex, coords ).rg);
|
||||
float len = length(normal);
|
||||
normal /= len;
|
||||
vec3 viewDir = normalize(ray);
|
||||
float depth = texture2D( depth_tex, coords ).r;
|
||||
vec3 pos;
|
||||
pos.z = - fg_Planes.y / (fg_Planes.x + depth * fg_Planes.z);
|
||||
pos.xy = viewDir.xy / viewDir.z * pos.z;
|
||||
vec3 pos = position( viewDir, texture2D( depth_tex, coords ).r );
|
||||
|
||||
vec4 tint;
|
||||
#if 0
|
||||
|
@ -86,7 +85,7 @@ void main() {
|
|||
vec3 Iemis = spec_emis.z * color;
|
||||
if (len > 0.0001) {
|
||||
halfDir /= len;
|
||||
Ispec = pow( clamp( dot( halfDir, normal ), 0.0, 1.0 ), spec_emis.y * 255.0 ) * spec_emis.x * fg_SunSpecularColor.rgb;
|
||||
Ispec = pow( clamp( dot( halfDir, normal ), 0.0, 1.0 ), spec_emis.y * 128.0 ) * spec_emis.x * fg_SunSpecularColor.rgb;
|
||||
}
|
||||
gl_FragColor = vec4(mix(vec3(0.0), Idiff + Ispec, shadow) + Iemis, 1.0);
|
||||
// gl_FragColor = mix(tint, vec4(mix(vec3(0.0), Idiff + Ispec, shadow) + Iemis, 1.0), 0.92);
|
||||
|
|
|
@ -56,6 +56,7 @@ uniform vec3 dirt_g_color;
|
|||
uniform vec3 dirt_b_color;
|
||||
|
||||
//uniform vec4 fg_SunAmbientColor;
|
||||
vec2 normal_encode(vec3 n);
|
||||
|
||||
///fog include//////////////////////
|
||||
uniform int fogType;
|
||||
|
@ -87,7 +88,6 @@ void main (void)
|
|||
} else {
|
||||
N = normalize(VNormal);
|
||||
}
|
||||
vec2 eyeN = (N.xy + vec2(1.0,1.0))*0.5;
|
||||
///END bump
|
||||
vec4 reflection = textureCube(Environment, reflVec * N);
|
||||
vec3 viewVec = normalize(vViewVec);
|
||||
|
@ -180,7 +180,7 @@ void main (void)
|
|||
// END lightmap
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
gl_FragData[0]=vec4(eyeN, 0.0, 1.0);
|
||||
gl_FragData[0]=vec4(normal_encode(N), 0.0, 1.0);
|
||||
gl_FragData[1]=vec4(fragColor.rgb,1.0/255.0);
|
||||
gl_FragData[2]=vec4(specular, gl_FrontMaterial.shininess/255.0, emission, 1.0);
|
||||
gl_FragData[2]=vec4(specular, gl_FrontMaterial.shininess/128.0, emission, 1.0);
|
||||
}
|
|
@ -37,6 +37,8 @@ int linear_search_steps = 10;
|
|||
int GlobalIterationCount = 0;
|
||||
int gIterationCap = 64;
|
||||
|
||||
vec2 normal_encode(vec3 n);
|
||||
|
||||
void QDM(inout vec3 p, inout vec3 v)
|
||||
{
|
||||
const int MAX_LEVEL = TEXTURE_MIP_LEVELS;
|
||||
|
@ -184,7 +186,7 @@ void main (void)
|
|||
N.z = sqrt(1.0 - min(1.0,dot(N.xy, N.xy)));
|
||||
float Nz = N.z;
|
||||
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
|
||||
gl_FragData[0] = vec4( (N.xy + vec2(1.0,1.0)) * 0.5, 0.0, 1.0 );
|
||||
gl_FragData[0] = vec4( normal_encode(N), 0.0, 1.0 );
|
||||
|
||||
vec4 ambient_light = constantColor + vec4(gl_Color.rgb, 1.0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue