Big UberShader update
-Added GRAPHICS_MAX_LIGHTPERPASS macro -Added glGetActiveUniform OpenGL function -Added (Uber)ShaderLibrary -Added (Uber)ShaderName parameter to models -Changed uniform system -Fixed Node copying -Moved Material class to Graphics module -Optimized lights -Remade Shader class -Renamed Node::Invalidate to Node::InvalidateNode -Renamed ShaderProgram to Shader Former-commit-id: 15f0cad52969e91a2442e7d750ba2dc412f3549d
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
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,
|
||||
@@ -2,20 +2,11 @@
|
||||
|
||||
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 vec4 LightColor;
|
||||
uniform vec2 LightFactors;
|
||||
uniform vec4 LightDirection;
|
||||
|
||||
uniform sampler2D GBuffer0;
|
||||
uniform sampler2D GBuffer1;
|
||||
@@ -56,15 +47,15 @@ void main()
|
||||
float depth = ColorToFloat(gVec2.xyz);
|
||||
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||
|
||||
vec3 lightDir = -Lights[0].parameters1.xyz;
|
||||
vec3 lightDir = -LightDirection.xyz;
|
||||
|
||||
// Ambient
|
||||
vec3 lightAmbient = Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||
vec3 lightAmbient = LightColor.rgb * LightFactors.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;
|
||||
vec3 lightDiffuse = lambert * LightColor.rgb * LightFactors.y;
|
||||
|
||||
// Specular
|
||||
vec3 lightSpecular;
|
||||
@@ -81,7 +72,7 @@ void main()
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, shininess);
|
||||
|
||||
lightSpecular = specularFactor * Lights[0].color.rgb * specularMultiplier;
|
||||
lightSpecular = specularFactor * LightColor.rgb * specularMultiplier;
|
||||
}
|
||||
else
|
||||
lightSpecular = vec3(0.0);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,21 +1,20 @@
|
||||
#version 140
|
||||
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
#define LIGHT_SPOT 2
|
||||
|
||||
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 int LightType;
|
||||
uniform vec4 LightColor;
|
||||
uniform vec2 LightFactors;
|
||||
uniform vec4 LightDirection;
|
||||
uniform vec4 LightParameters1;
|
||||
uniform vec4 LightParameters2;
|
||||
uniform vec2 LightParameters3;
|
||||
|
||||
uniform sampler2D GBuffer0;
|
||||
uniform sampler2D GBuffer1;
|
||||
@@ -26,7 +25,6 @@ uniform vec2 InvTargetSize;
|
||||
uniform vec4 SceneAmbient;
|
||||
|
||||
uniform bool Discard = false;
|
||||
uniform bool SpotLight;
|
||||
|
||||
float ColorToFloat(vec3 color)
|
||||
{
|
||||
@@ -67,28 +65,28 @@ void main()
|
||||
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||
worldPos.xyz /= worldPos.w;
|
||||
|
||||
vec3 lightDir = Lights[0].parameters1.xyz - worldPos.xyz;
|
||||
vec3 lightDir = LightParameters1.xyz - worldPos.xyz;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength;
|
||||
|
||||
float att = max(Lights[0].parameters1.w - Lights[0].parameters2.w*lightDirLength, 0.0);
|
||||
float att = max(LightParameters1.w - LightParameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
vec3 lightAmbient = att * Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||
vec3 lightAmbient = att * LightColor.rgb * LightFactors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||
|
||||
if (SpotLight)
|
||||
if (LightType == LIGHT_SPOT)
|
||||
{
|
||||
// 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;
|
||||
float curAngle = dot(LightParameters2.xyz, -lightDir);
|
||||
float outerAngle = LightParameters3.y;
|
||||
float innerMinusOuterAngle = LightParameters3.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;
|
||||
vec3 lightDiffuse = att * lambert * LightColor.rgb * LightFactors.y;
|
||||
|
||||
// Specular
|
||||
vec3 lightSpecular;
|
||||
@@ -99,7 +97,7 @@ void main()
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, shininess);
|
||||
|
||||
lightSpecular = att * specularFactor * Lights[0].color.rgb * specularMultiplier;
|
||||
lightSpecular = att * specularFactor * LightColor.rgb * specularMultiplier;
|
||||
}
|
||||
else
|
||||
lightSpecular = vec3(0.0);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,82 +0,0 @@
|
||||
#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
@@ -1,17 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
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,
|
||||
Reference in New Issue
Block a user