Added Deferred Shading

Former-commit-id: 926022d6306144e2f87cd293291928bda44c7a87
This commit is contained in:
Lynix
2013-10-22 12:54:05 +02:00
parent d363e29e15
commit b7b65d7119
28 changed files with 2355 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
#version 140
out vec4 RenderTarget0;
uniform sampler2D ColorTexture;
uniform vec2 InvTargetSize;
void main()
{
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
RenderTarget0 = textureLod(ColorTexture, texCoord, 0.0);
}

View File

@@ -0,0 +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,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,125,13,10,

View File

@@ -0,0 +1,24 @@
#version 140
out vec4 RenderTarget0;
uniform float BrightLuminance = 0.8;
uniform float BrightMiddleGrey = 0.5;
uniform float BrightThreshold = 0.8;
uniform sampler2D ColorTexture;
uniform sampler2D BloomTexture;
uniform vec2 InvTargetSize;
void main()
{
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb;
color *= BrightMiddleGrey/BrightLuminance;
color *= 1.0 + (color / (BrightThreshold*BrightThreshold));
color -= 0.5;
color /= (1.0 + color);
RenderTarget0 = vec4(color, 1.0);
};

View File

@@ -0,0 +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,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,76,117,109,105,110,97,110,99,101,32,61,32,48,46,56,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,77,105,100,100,108,101,71,114,101,121,32,61,32,48,46,53,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,32,61,32,48,46,56,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,66,108,111,111,109,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,13,10,9,99,111,108,111,114,32,42,61,32,66,114,105,103,104,116,77,105,100,100,108,101,71,114,101,121,47,66,114,105,103,104,116,76,117,109,105,110,97,110,99,101,59,13,10,9,99,111,108,111,114,32,42,61,32,49,46,48,32,43,32,40,99,111,108,111,114,32,47,32,40,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,42,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,41,41,59,13,10,9,99,111,108,111,114,32,45,61,32,48,46,53,59,13,10,9,99,111,108,111,114,32,47,61,32,40,49,46,48,32,43,32,99,111,108,111,114,41,59,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,44,32,49,46,48,41,59,13,10,125,59,13,10,

View File

@@ -0,0 +1,17 @@
#version 140
out vec4 RenderTarget0;
uniform sampler2D BloomTexture;
uniform sampler2D ColorTexture;
uniform vec2 InvTargetSize;
void main()
{
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec3 bloomColor = textureLod(BloomTexture, texCoord, 0.0).rgb;
vec3 originalColor = textureLod(ColorTexture, texCoord, 0.0).rgb;
RenderTarget0 = vec4(originalColor + bloomColor, 1.0);
}

View File

@@ -0,0 +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,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,66,108,111,111,109,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,9,118,101,99,51,32,98,108,111,111,109,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,66,108,111,111,109,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,9,118,101,99,51,32,111,114,105,103,105,110,97,108,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,111,114,105,103,105,110,97,108,67,111,108,111,114,32,43,32,98,108,111,111,109,67,111,108,111,114,44,32,49,46,48,41,59,13,10,125,13,10,

View File

@@ -0,0 +1,13 @@
#version 140
out vec4 RenderTarget0;
out vec4 RenderTarget1;
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);
gl_FragDepth = 1.0;
}

View File

@@ -0,0 +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,

View File

@@ -0,0 +1,81 @@
#version 140
out vec4 RenderTarget0;
struct Light
{
int type;
vec4 ambient;
vec4 color;
vec2 factors;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
};
uniform vec3 EyePosition;
uniform Light Lights[1];
uniform sampler2D GBuffer0;
uniform sampler2D GBuffer1;
uniform sampler2D GBuffer2;
uniform mat4 InvViewProjMatrix;
uniform vec2 InvTargetSize;
uniform vec4 SceneAmbient;
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;
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
vec3 lightDir = -Lights[0].parameters1.xyz;
// Ambient
vec3 lightAmbient = Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
vec3 lightDiffuse = lambert * Lights[0].color.rgb * Lights[0].factors.y;
// Specular
vec3 lightSpecular = vec3(0.0);
if (shininess > 0.0)
{
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
worldPos.xyz /= worldPos.w;
vec3 eyeVec = normalize(EyePosition - worldPos.xyz);
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, shininess);
lightSpecular = specularFactor * Lights[0].color.rgb;
}
lightSpecular *= specularColor;
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
vec4 fragmentColor = vec4(lightColor * diffuseColor, 1.0);
RenderTarget0 = fragmentColor;
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,47 @@
#version 140
out vec4 RenderTarget0;
uniform float FXAAReduceMul = 0.0; // 1.0/8.0
uniform float FXAASpanMax = 8.0;
uniform sampler2D ColorTexture;
uniform vec2 InvTargetSize;
void main()
{
#define FXAA_REDUCE_MIN (1.0/128.0)
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec3 rgbNW = textureLod(ColorTexture, texCoord, 0.0).rgb;
vec3 rgbNE = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(1,0)).rgb;
vec3 rgbSW = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(0,1)).rgb;
vec3 rgbSE = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(1,1)).rgb;
vec3 rgbM = textureLod(ColorTexture, texCoord, 0.0).rgb;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAAReduceMul), FXAA_REDUCE_MIN);
float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
dir = min(vec2(FXAASpanMax, FXAASpanMax), max(vec2(-FXAASpanMax, -FXAASpanMax), dir * rcpDirMin)) * InvTargetSize;
vec3 rgbA = (1.0/2.0) * (textureLod(ColorTexture, texCoord + dir * (1.0/3.0 - 0.5), 0.0).rgb + textureLod(ColorTexture, texCoord + dir * (2.0/3.0 - 0.5), 0.0).rgb);
vec3 rgbB = rgbA * 1.0/2.0 + 1.0/4.0 * (textureLod(ColorTexture, texCoord + dir * (0.0/3.0 - 0.5), 0.0).rgb + textureLod(ColorTexture, texCoord + dir * (3.0/3.0 - 0.5), 0.0).rgb);
float lumaB = dot(rgbB, luma);
vec3 fragmentColor = (lumaB < lumaMin || lumaB > lumaMax) ? rgbA : rgbB;
RenderTarget0 = vec4(fragmentColor, 1.0);
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,25 @@
// http://www.geeks3d.com/20100909/shader-library-gaussian-blur-post-processing-filter-in-glsl/
#version 140
out vec4 RenderTarget0;
uniform sampler2D ColorTexture;
uniform vec2 Filter;
uniform vec2 InvTargetSize;
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
void main()
{
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb * weight[0];
for (int i = 1; i < 3; i++)
{
color += textureLod(ColorTexture, texCoord + Filter*vec2(offset[i])*InvTargetSize, 0.0).rgb * weight[i];
color += textureLod(ColorTexture, texCoord - Filter*vec2(offset[i])*InvTargetSize, 0.0).rgb * weight[i];
}
RenderTarget0 = vec4(color, 1.0);
}

View File

@@ -0,0 +1 @@
47,47,32,104,116,116,112,58,47,47,119,119,119,46,103,101,101,107,115,51,100,46,99,111,109,47,50,48,49,48,48,57,48,57,47,115,104,97,100,101,114,45,108,105,98,114,97,114,121,45,103,97,117,115,115,105,97,110,45,98,108,117,114,45,112,111,115,116,45,112,114,111,99,101,115,115,105,110,103,45,102,105,108,116,101,114,45,105,110,45,103,108,115,108,47,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,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,70,105,108,116,101,114,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,102,108,111,97,116,32,111,102,102,115,101,116,91,51,93,32,61,32,102,108,111,97,116,91,93,40,48,46,48,44,32,49,46,51,56,52,54,49,53,51,56,52,54,44,32,51,46,50,51,48,55,54,57,50,51,48,56,41,59,13,10,102,108,111,97,116,32,119,101,105,103,104,116,91,51,93,32,61,32,102,108,111,97,116,91,93,40,48,46,50,50,55,48,50,55,48,50,55,48,44,32,48,46,51,49,54,50,49,54,50,49,54,50,44,32,48,46,48,55,48,50,55,48,50,55,48,51,41,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,48,93,59,13,10,13,10,9,102,111,114,32,40,105,110,116,32,105,32,61,32,49,59,32,105,32,60,32,51,59,32,105,43,43,41,13,10,9,123,13,10,9,9,99,111,108,111,114,32,43,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,43,32,70,105,108,116,101,114,42,118,101,99,50,40,111,102,102,115,101,116,91,105,93,41,42,73,110,118,84,97,114,103,101,116,83,105,122,101,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,105,93,59,13,10,9,9,99,111,108,111,114,32,43,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,45,32,70,105,108,116,101,114,42,118,101,99,50,40,111,102,102,115,101,116,91,105,93,41,42,73,110,118,84,97,114,103,101,116,83,105,122,101,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,105,93,59,13,10,9,125,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,44,32,49,46,48,41,59,13,10,125,13,10,

View File

@@ -0,0 +1,84 @@
#version 140
out vec4 RenderTarget0;
struct Light
{
int type;
vec4 ambient;
vec4 color;
vec2 factors;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
};
uniform vec3 EyePosition;
uniform Light Lights[1];
uniform sampler2D GBuffer0;
uniform sampler2D GBuffer1;
uniform sampler2D GBuffer2;
uniform mat4 InvViewProjMatrix;
uniform vec2 InvTargetSize;
uniform vec4 SceneAmbient;
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;
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
worldPos.xyz /= worldPos.w;
vec3 lightDir = Lights[0].parameters1.xyz - worldPos.xyz;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength;
float att = max(Lights[0].parameters1.w - Lights[0].parameters2.x*lightDirLength, 0.0);
// Ambient
vec3 lightAmbient = att * Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
vec3 lightDiffuse = att * lambert * Lights[0].color.rgb * Lights[0].factors.y;
// Specular
vec3 lightSpecular = vec3(0.0);
if (shininess > 0.0)
{
vec3 eyeVec = normalize(EyePosition - worldPos.xyz);
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, shininess);
lightSpecular = att * specularFactor * Lights[0].color.rgb;
}
lightSpecular *= specularColor;
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
vec4 fragmentColor = vec4(lightColor * diffuseColor, 1.0);
RenderTarget0 = fragmentColor;
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,82 @@
#version 140
out vec4 RenderTarget0;
uniform float SSAOBias = 0.0;
uniform float SSAOIntensity = 3.0;
uniform float SSAOSampleScale = 0.1;
uniform float SSAOScale = 1.0;
uniform int NoiseTextureSize;
uniform mat4 InvViewProjMatrix;
uniform sampler2D GBuffer1;
uniform sampler2D NoiseTexture;
uniform vec2 TargetSize;
uniform vec2 InvTargetSize;
vec3 extractPosition(in float depth, in vec2 texCoord)
{
depth = depth*2.0 - 1.0;
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
worldPos.xyz /= worldPos.w;
return worldPos.xyz;
}
float doAmbientOcclusion(in vec2 texCoord, in vec3 original, in vec3 normal)
{
vec3 newp = extractPosition(textureLod(GBuffer1, texCoord, 0.0).w, texCoord);
vec3 diff = newp - original;
float d = length(diff);
vec3 v = diff * 1.0/d;
d *= SSAOScale;
return max(0.0, dot(normal, v) - SSAOBias) * (SSAOIntensity / (1.0 + d));
}
void main(void)
{
const vec2 Kernel[16] = vec2[](
vec2(0.53812504, 0.18565957),
vec2(0.13790712, 0.24864247),
vec2(0.33715037, 0.56794053),
vec2(-0.6999805, -0.04511441),
vec2(0.06896307, -0.15983082),
vec2(0.056099437, 0.006954967),
vec2(-0.014653638, 0.14027752),
vec2(0.010019933, -0.1924225),
vec2(-0.35775623, -0.5301969),
vec2(-0.3169221, 0.106360726),
vec2(0.010350345, -0.58698344),
vec2(-0.08972908, -0.49408212),
vec2(0.7119986, -0.0154690035),
vec2(-0.053382345, 0.059675813),
vec2(0.035267662, -0.063188605),
vec2(-0.47761092, 0.2847911));
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
if (gVec1.w == 1.0)
{
RenderTarget0 = vec4(1.0, 0.0, 0.0, 0.0);
return;
}
vec3 normal = gVec1.xyz*2.0 - 1.0;
vec3 viewPos = extractPosition(gVec1.w, texCoord);
vec2 randVec = normalize(textureLod(NoiseTexture, texCoord * (TargetSize/NoiseTextureSize), 0.0).xy * 2.0 - 1.0);
float ao = 0.0;
const int ITERATIONS = 16;
for (int i = 0; i < ITERATIONS; ++i)
{
vec2 coord = reflect(Kernel[i], randVec) * SSAOSampleScale;
ao += doAmbientOcclusion(texCoord + coord, viewPos, normal);
}
RenderTarget0 = vec4(1.0 - ao/ITERATIONS, 0.0, 0.0, 0.0);
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,17 @@
#version 140
out vec4 RenderTarget0;
uniform sampler2D ColorTexture;
uniform sampler2D SSAOTexture;
uniform vec2 InvTargetSize;
void main()
{
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb;
float ssao = textureLod(SSAOTexture, texCoord, 0.0).r;
RenderTarget0 = vec4(color*ssao, 1.0);
}

View File

@@ -0,0 +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,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,83,83,65,79,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,9,102,108,111,97,116,32,115,115,97,111,32,61,32,116,101,120,116,117,114,101,76,111,100,40,83,83,65,79,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,59,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,42,115,115,97,111,44,32,49,46,48,41,59,13,10,125,13,10,

View File

@@ -0,0 +1,90 @@
#version 140
out vec4 RenderTarget0;
struct Light
{
int type;
vec4 ambient;
vec4 color;
vec2 factors;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
};
uniform vec3 EyePosition;
uniform Light Lights[1];
uniform sampler2D GBuffer0;
uniform sampler2D GBuffer1;
uniform sampler2D GBuffer2;
uniform mat4 InvViewProjMatrix;
uniform vec2 InvTargetSize;
uniform vec4 SceneAmbient;
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;
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
worldPos.xyz /= worldPos.w;
vec3 lightDir = Lights[0].parameters1.xyz - worldPos.xyz;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength;
float att = max(Lights[0].parameters1.w - Lights[0].parameters2.w*lightDirLength, 0.0);
// Ambient
vec3 lightAmbient = att * Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
// Modification de l'atténuation pour gérer le spot
float curAngle = dot(Lights[0].parameters2.xyz, -lightDir);
float outerAngle = Lights[0].parameters3.y;
float innerMinusOuterAngle = Lights[0].parameters3.x - outerAngle;
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
vec3 lightDiffuse = att * lambert * Lights[0].color.rgb * Lights[0].factors.y;
// Specular
vec3 lightSpecular = vec3(0.0);
if (shininess > 0.0)
{
vec3 eyeVec = normalize(EyePosition - worldPos.xyz);
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, shininess);
lightSpecular = att * specularFactor * Lights[0].color.rgb;
}
lightSpecular *= specularColor;
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
vec4 fragmentColor = vec4(lightColor * diffuseColor, 1.0);
RenderTarget0 = fragmentColor;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long