Improved Deferred Shading performances

Former-commit-id: 7251e9f552230c31409f7780929fcc30f2b85bed
This commit is contained in:
Lynix
2014-01-11 19:16:36 +01:00
parent 9bf66e7e16
commit b9dca8966d
10 changed files with 95 additions and 46 deletions

View File

@@ -7,7 +7,7 @@ out vec4 RenderTarget2;
void main()
{
RenderTarget0 = vec4(0.0, 0.0, 0.0, 0.0);
RenderTarget1 = vec4(0.0, 0.0, 0.0, 1.0);
RenderTarget2 = vec4(0.0, 0.0, 0.0, 0.0);
RenderTarget1 = vec4(0.0, 0.0, 0.0, 0.0);
RenderTarget2 = vec4(1.0, 0.0, 0.0, 0.0);
gl_FragDepth = 1.0;
}

View File

@@ -1 +1 @@
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,49,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,50,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,49,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,49,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,50,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,103,108,95,70,114,97,103,68,101,112,116,104,32,61,32,49,46,48,59,13,10,125,13,10,
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,49,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,50,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,49,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,50,32,61,32,118,101,99,52,40,49,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,103,108,95,70,114,97,103,68,101,112,116,104,32,61,32,49,46,48,59,13,10,125,13,10,

View File

@@ -25,23 +25,35 @@ uniform mat4 InvViewProjMatrix;
uniform vec2 InvTargetSize;
uniform vec4 SceneAmbient;
float ColorToFloat(vec3 color)
{
const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256));
return dot(color, byte_to_float);
}
#define kPI 3.1415926536
vec3 DecodeNormal(in vec4 encodedNormal)
{
//return encodedNormal.xyz*2.0 - 1.0;
float a = encodedNormal.x * kPI;
vec2 scth = vec2(sin(a), cos(a));
vec2 scphi = vec2(sqrt(1.0 - encodedNormal.y*encodedNormal.y), encodedNormal.y);
return vec3(scth.y*scphi.x, scth.x*scphi.x, scphi.y);
}
void main()
{
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0);
if (gVec0.w == 0.0)
{
RenderTarget0 = vec4(gVec0.xyz, 1.0);
return;
}
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);
vec3 diffuseColor = gVec0.xyz;
vec3 normal = gVec1.xyz*2.0 - 1.0;
vec3 specularColor = gVec2.xyz;
float depth = gVec1.w*2.0 - 1.0;
vec3 normal = DecodeNormal(gVec1);
vec3 specularColor = vec3(gVec0.w);
float depth = ColorToFloat(gVec2.xyz);
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
vec3 lightDir = -Lights[0].parameters1.xyz;
@@ -58,7 +70,7 @@ void main()
vec3 lightSpecular = vec3(0.0);
if (shininess > 0.0)
{
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth*2.0 - 1.0);
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
worldPos.xyz /= worldPos.w;

File diff suppressed because one or more lines are too long

View File

@@ -28,6 +28,24 @@ uniform vec4 SceneAmbient;
uniform bool Discard = false;
uniform bool SpotLight;
float ColorToFloat(vec3 color)
{
const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256));
return dot(color, byte_to_float);
}
#define kPI 3.1415926536
vec3 DecodeNormal(in vec4 encodedNormal)
{
//return encodedNormal.xyz*2.0 - 1.0;
float a = encodedNormal.x * kPI;
vec2 scth = vec2(sin(a), cos(a));
vec2 scphi = vec2(sqrt(1.0 - encodedNormal.y*encodedNormal.y), encodedNormal.y);
return vec3(scth.y*scphi.x, scth.x*scphi.x, scphi.y);
}
void main()
{
if (Discard)
@@ -35,22 +53,16 @@ void main()
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0);
if (gVec0.w == 0.0)
{
RenderTarget0 = vec4(gVec0.xyz, 1.0);
return;
}
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);
vec3 diffuseColor = gVec0.xyz;
vec3 normal = gVec1.xyz*2.0 - 1.0;
vec3 specularColor = gVec2.xyz;
float depth = gVec1.w*2.0 - 1.0;
vec3 normal = DecodeNormal(gVec1);
vec3 specularColor = vec3(gVec0.w);
float depth = ColorToFloat(gVec2.xyz);
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth*2.0 - 1.0);
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
worldPos.xyz /= worldPos.w;

File diff suppressed because one or more lines are too long