Merge remote-tracking branch 'origin/master' into ExplosionEffectV2

# Conflicts:
#	resources/Schema/Components/ExplosionEffect.xml
#	resources/Shaders/ExplosionEffect.geom.glsl
#	src/Game/Systems/ExplosionEffectSystem.cpp
This commit is contained in:
FakeShemp
2016-03-10 11:49:51 +01:00
184 changed files with 36165 additions and 12717 deletions
@@ -0,0 +1,31 @@
#version 430
layout (binding = 0) uniform sampler2D Texture0;
layout (binding = 1)uniform sampler2D Texture1;
in VertexData{
vec2 TextureCoordinate;
}Input;
out vec4 sceneColor;
out vec4 bloomColor;
void main()
{
vec4 texel0 = texture(Texture0, Input.TextureCoordinate);
vec4 texel1 = texture(Texture1, Input.TextureCoordinate);
float texel1_total = (texel1.r + texel1.g + texel1.b) * texel1.a;
texel1_total = ceil(clamp(texel1_total, 0, 1));
vec4 result0 = texel0 * (1.0 - texel1_total);
vec4 result1 = texel1 * texel1_total;
//vec4 final = texel1 * texel1_total + texel0 * (1.0 - texel1_total);
//float res = 1.0 - texel1_total;
//vec4 final = vec4(texel1_total, texel1_total, texel1_total, 1.0);
sceneColor = result1;
bloomColor = vec4(0.0, 0.0, 0.0, 0.0);
}
@@ -0,0 +1,13 @@
#version 430
layout (location = 0) in vec3 Position;
out VertexData{
vec2 TextureCoordinate;
}Output;
void main()
{
gl_Position = vec4(Position, 1.0);
Output.TextureCoordinate = (vec2(Position) + 1) / 2;
}
@@ -1,5 +1,7 @@
#version 430
#define MAX_SPLITS 4
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -27,6 +29,7 @@ in VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Input[];
out VertexData{
@@ -37,6 +40,7 @@ out VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Output;
layout(triangles) in;
@@ -161,6 +165,14 @@ void main()
// pass through vertex data
PassThingsThrough(i);
for (int j = 0; j < MAX_SPLITS; j++)
{
Output.PositionLightSpace[j] = Input[i].PositionLightSpace[j];
}
for (int j = 0; j < MAX_SPLITS; j++)
{
Output.PositionLightSpace[j] = Input[i].PositionLightSpace[j];
}
// convert to window space
gl_Position = P * V * M * vec4(ExplodedPosition, 1.0);
+2 -4
View File
@@ -1,8 +1,6 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 PVM;
layout(location = 0) in vec3 Position;
layout(location = 5) in vec4 BoneIndices;
@@ -15,7 +13,7 @@ out VertexData{
void main()
{
gl_Position = P * V * M * vec4(Position, 1.0);
gl_Position = PVM * vec4(Position, 1.0);
Output.Position = Position;
}
@@ -1,8 +1,6 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 PVM;
uniform mat4 Bones[100];
@@ -27,7 +25,7 @@ void main()
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
}
gl_Position = P*V*M*boneTransform * vec4(Position, 1.0);
gl_Position = PVM*boneTransform * vec4(Position, 1.0);
Output.Position = vec3(0.0);
}
+183 -4
View File
@@ -1,7 +1,9 @@
#version 430
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -11,9 +13,10 @@ uniform vec2 ScreenDimensions;
uniform vec4 FillColor;
uniform vec4 AmbientColor;
uniform float FillPercentage;
uniform float GlowIntensity = 10;
uniform float GlowIntensity;
uniform vec3 CameraPosition;
uniform int SSAOQuality;
uniform float FarDistance[MAX_SPLITS];
uniform vec2 DiffuseUVRepeat;
uniform vec2 NormalUVRepeat;
@@ -25,6 +28,7 @@ layout (binding = 2) uniform sampler2D NormalMapTexture;
layout (binding = 3) uniform sampler2D SpecularMapTexture;
layout (binding = 4) uniform sampler2D GlowMapTexture;
layout (binding = 5) uniform samplerCube CubeMap;
layout (binding = 30) uniform sampler2DArrayShadow DepthMap;
#define TILE_SIZE 16
@@ -59,7 +63,6 @@ layout (std430, binding = 4) buffer LightIndexBuffer
float LightIndex[];
};
in VertexData{
vec3 Position;
vec3 Normal;
@@ -68,6 +71,7 @@ in VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Input;
out vec4 sceneColor;
@@ -78,6 +82,25 @@ struct LightResult {
vec4 Specular;
};
vec2 poissonDisk[16] = vec2[](
vec2( -0.94201624, -0.39906216 ),
vec2( 0.94558609, -0.76890725 ),
vec2( -0.094184101, -0.92938870 ),
vec2( 0.34495938, 0.29387760 ),
vec2( -0.91588581, 0.45771432 ),
vec2( -0.81544232, -0.87912464 ),
vec2( -0.38277543, 0.27676845 ),
vec2( 0.97484398, 0.75648379 ),
vec2( 0.44323325, -0.97511554 ),
vec2( 0.53742981, -0.47373420 ),
vec2( -0.26496911, -0.41893023 ),
vec2( 0.79197514, 0.19090188 ),
vec2( -0.24188840, 0.99706507 ),
vec2( -0.81409955, 0.91437590 ),
vec2( 0.19984126, 0.78641367 ),
vec2( 0.14383161, -0.14100790 )
);
float CalcAttenuation(float radius, float dist, float falloff) {
return 1.0 - smoothstep(radius * falloff, radius, dist);
}
@@ -124,6 +147,154 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu
return vec4(TBN * normalize(NormalMap), 0.0);
}
// Returns a "random" value.
float Random(vec3 seed, int i)
{
vec4 seed4 = vec4(seed, i);
float dot_product = dot(seed4, vec4(12.9898, 78.233, 45.164, 94.673));
return fract(sin(dot_product) * 43758.5453);
}
int getShadowIndex(float far_distance[1])
{
return 0;
}
int getShadowIndex(float far_distance[2])
{
float depth = gl_FragCoord.z / gl_FragCoord.w;
int index = 1;
if ( depth < far_distance[0] )
{
index = 0;
}
return index;
}
int getShadowIndex(float far_distance[3])
{
float depth = gl_FragCoord.z / gl_FragCoord.w;
int index = 2;
if ( depth < far_distance[0] )
{
index = 0;
}
else if ( depth < far_distance[1] && depth > far_distance[0] )
{
index = 1;
}
return index;
}
int getShadowIndex(float far_distance[4])
{
float depth = gl_FragCoord.z / gl_FragCoord.w;
int index = 3;
if ( depth < far_distance[0] )
{
index = 0;
}
else if ( depth < far_distance[1] && depth > far_distance[0] )
{
index = 1;
}
else if ( depth < far_distance[2] && depth > far_distance[1] )
{
index = 2;
}
return index;
}
// Standard hardware-calculated PCF method
float PCFShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index)
{
return texture(depth_texture_array, vec4(projection_coords.xy, layer_index, projection_coords.z));
}
// PCF + Poisson model method
float PoissonShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread)
{
int loop;
float multiplier = 1.0 / float(taps);
float shadowMapDepth;
for (int i = 0; i < taps; i++)
{
loop = i;
vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index));
shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z));
}
return shadowMapDepth;
}
// PCF + Poisson + RandomSample model method
float PoissonDotShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread)
{
int loop;
float multiplier = 1.0 / float(taps);
float shadowMapDepth;
for (int i = 0; i < taps; i++)
{
loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16;
vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index));
shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z));
}
return shadowMapDepth;
}
// Hardware PCF + Additional software PCF method
float SoftwarePCF(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, float bias)
{
float shadow = 0.0;
vec3 texelSize = 1.0 / textureSize(depth_texture_array, 0);
for(int x = -1; x <= 1; x++)
{
for(int y = -1; y <= 1; y++)
{
shadow += texture(depth_texture_array, vec4(projection_coords.xy + vec2(x, y) * texelSize.xy / (1.0 + layer_index), layer_index, projection_coords.z));
}
}
return shadow / 9.0;
}
float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler2DArrayShadow depth_texture_array, int layer_index)
{
float shadowMapDepth;
float bias = 0.005;
// Various bias methods.
//bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias);
//bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
bias = bias + bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
// Calculate coordinates in projection space.
vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w;
projCoords = projCoords * 0.5 + 0.5;
//projCoords = (floor(projCoords * 255.0)) / 255.0;
// Various methods for shadow calculation in fastest to slowest order.
//shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index);
//shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
//shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias);
return shadowMapDepth;
}
void main()
{
float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r;
@@ -131,7 +302,7 @@ void main()
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat);
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
vec4 position = V * M * vec4(Input.Position, 1.0);
vec4 position = VM * vec4(Input.Position, 1.0);
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
@@ -151,6 +322,8 @@ void main()
int start = int(LightGrids.Data[currentTile].Start);
int amount = int(LightGrids.Data[currentTile].Amount);
float shadowFactor = 0.0;
for(int i = start; i < start + amount; i++) {
@@ -162,16 +335,21 @@ void main()
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
int DepthMapIndex = getShadowIndex(FarDistance);
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap, DepthMapIndex);
}
totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a);
totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a);
}
totalLighting.Diffuse *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0);
totalLighting.Specular *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0);
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
float specularResult = (specularTexel.r + specularTexel.g + specularTexel.b)/3.0;
vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a;
vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
color_result = color_result * clamp(1/specularTexel.a, 0, 1) + reflectionTotal;
//vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
@@ -182,6 +360,7 @@ void main()
color_result += FillColor;
}
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
//sceneColor = CommonUniforms.testColour;
//sceneColor = vec4(reflectionColor.xyz, 1);
color_result.xyz += glowTexel.xyz*GlowIntensity;
+13 -2
View File
@@ -1,8 +1,13 @@
#version 430
uniform mat4 PVM;
#define MAX_SPLITS 4
uniform mat4 TIM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 LightV[MAX_SPLITS];
uniform mat4 LightP[MAX_SPLITS];
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
@@ -18,12 +23,13 @@ out VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Output;
void main()
{
gl_Position = P*V*M * vec4(Position, 1.0);
mat4 TIM = transpose(inverse(M));
gl_Position = PVM * vec4(Position, 1.0);
//mat4 TIM = transpose(inverse(M));
Output.Position = Position;
Output.TextureCoordinate = TextureCoords;
Output.Normal = vec3(TIM * vec4(Normal, 0.0));
@@ -31,4 +37,9 @@ void main()
Output.BiTangent = vec3(TIM * vec4(BiTangent, 0.0));
Output.ExplosionColor = vec4(1.0);
Output.ExplosionPercentageElapsed = 0.0;
for(int i = 0; i < MAX_SPLITS; i++)
{
Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * vec4(Position, 1.0);
}
}
@@ -1,7 +1,9 @@
#version 430
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -11,7 +13,7 @@ uniform vec2 ScreenDimensions;
uniform vec4 FillColor;
uniform vec4 AmbientColor;
uniform float FillPercentage;
uniform float GlowIntensity = 10;
uniform float GlowIntensity;
uniform vec3 CameraPosition;
uniform int SSAOQuality;
@@ -69,6 +71,7 @@ in VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Input;
out vec4 sceneColor;
@@ -138,7 +141,7 @@ void main()
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat);
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
vec4 position = V * M * vec4(Input.Position, 1.0);
vec4 position = VM * vec4(Input.Position, 1.0);
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
@@ -178,7 +181,7 @@ void main()
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
float specularResult = (specularTexel.r + specularTexel.g + specularTexel.b)/3.0;
vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a;
vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
color_result = color_result * clamp(1/specularTexel.a, 0, 1) + reflectionTotal;
//vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
+13 -1
View File
@@ -1,9 +1,15 @@
#version 430
#define MAX_SPLITS 4
uniform mat4 PVM;
uniform mat4 TIM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 Bones[100];
uniform mat4 LightV[MAX_SPLITS];
uniform mat4 LightP[MAX_SPLITS];
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
@@ -21,6 +27,7 @@ out VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Output;
void main()
@@ -34,7 +41,7 @@ void main()
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
}
gl_Position = P*V*M*boneTransform * vec4(Position, 1.0);
gl_Position = PVM*boneTransform * vec4(Position, 1.0);
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
Output.TextureCoordinate = TextureCoords;
@@ -43,4 +50,9 @@ void main()
Output.BiTangent = vec3(M * vec4(BiTangent, 0.0));
Output.ExplosionColor = vec4(1.0);
Output.ExplosionPercentageElapsed = 0.0;
for(int i = 0; i < MAX_SPLITS; i++)
{
Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * boneTransform * vec4(Position, 1.0);
}
}
@@ -1,5 +1,7 @@
#version 430
#define MAX_SPLITS 4
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -95,6 +97,7 @@ in VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Input;
out vec4 sceneColor;
@@ -1,7 +1,9 @@
#version 430
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -12,6 +14,10 @@ uniform vec4 FillColor;
uniform vec4 Color;
uniform vec4 AmbientColor;
uniform int SSAOQuality;
uniform float FarDistance[MAX_SPLITS];
layout (binding = 0) uniform sampler2D AOTexture;
layout (binding = 30) uniform sampler2DArrayShadow DepthMap;
//Get bineded at the same time as the textures
uniform vec2 DiffuseUVRepeat1;
@@ -26,7 +32,6 @@ uniform vec2 SpecularUVRepeat3;
uniform vec2 GlowUVRepeat1;
uniform vec2 GlowUVRepeat2;
uniform vec2 GlowUVRepeat3;
layout (binding = 0) uniform sampler2D AOTexture;
layout (binding = 1) uniform sampler2D SplatMapTexture;
layout (binding = 2) uniform sampler2D DiffuseTexture1;
layout (binding = 3) uniform sampler2D DiffuseTexture2;
@@ -83,6 +88,7 @@ in VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Input;
out vec4 sceneColor;
@@ -93,6 +99,25 @@ struct LightResult {
vec4 Specular;
};
vec2 poissonDisk[16] = vec2[](
vec2( -0.94201624, -0.39906216 ),
vec2( 0.94558609, -0.76890725 ),
vec2( -0.094184101, -0.92938870 ),
vec2( 0.34495938, 0.29387760 ),
vec2( -0.91588581, 0.45771432 ),
vec2( -0.81544232, -0.87912464 ),
vec2( -0.38277543, 0.27676845 ),
vec2( 0.97484398, 0.75648379 ),
vec2( 0.44323325, -0.97511554 ),
vec2( 0.53742981, -0.47373420 ),
vec2( -0.26496911, -0.41893023 ),
vec2( 0.79197514, 0.19090188 ),
vec2( -0.24188840, 0.99706507 ),
vec2( -0.81409955, 0.91437590 ),
vec2( 0.19984126, 0.78641367 ),
vec2( 0.14383161, -0.14100790 )
);
float CalcAttenuation(float radius, float dist, float falloff) {
return 1.0 - smoothstep(radius * 0.3, radius, dist);
}
@@ -176,6 +201,154 @@ vec4 CalcBlendedNormal(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B,
return vec4(TBN * normalize(Normal_result), 0.0);
}
// Returns a "random" value.
float Random(vec3 seed, int i)
{
vec4 seed4 = vec4(seed, i);
float dot_product = dot(seed4, vec4(12.9898, 78.233, 45.164, 94.673));
return fract(sin(dot_product) * 43758.5453);
}
int getShadowIndex(float far_distance[1])
{
return 0;
}
int getShadowIndex(float far_distance[2])
{
float depth = gl_FragCoord.z / gl_FragCoord.w;
int index = 1;
if ( depth < far_distance[0] )
{
index = 0;
}
return index;
}
int getShadowIndex(float far_distance[3])
{
float depth = gl_FragCoord.z / gl_FragCoord.w;
int index = 2;
if ( depth < far_distance[0] )
{
index = 0;
}
else if ( depth < far_distance[1] && depth > far_distance[0] )
{
index = 1;
}
return index;
}
int getShadowIndex(float far_distance[4])
{
float depth = gl_FragCoord.z / gl_FragCoord.w;
int index = 3;
if ( depth < far_distance[0] )
{
index = 0;
}
else if ( depth < far_distance[1] && depth > far_distance[0] )
{
index = 1;
}
else if ( depth < far_distance[2] && depth > far_distance[1] )
{
index = 2;
}
return index;
}
// Standard hardware-calculated PCF method
float PCFShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index)
{
return texture(depth_texture_array, vec4(projection_coords.xy, layer_index, projection_coords.z));
}
// PCF + Poisson model method
float PoissonShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread)
{
int loop;
float multiplier = 1.0 / float(taps);
float shadowMapDepth;
for (int i = 0; i < taps; i++)
{
loop = i;
vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index));
shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z));
}
return shadowMapDepth;
}
// PCF + Poisson + RandomSample model method
float PoissonDotShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread)
{
int loop;
float multiplier = 1.0 / float(taps);
float shadowMapDepth;
for (int i = 0; i < taps; i++)
{
loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16;
vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index));
shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z));
}
return shadowMapDepth;
}
// Hardware PCF + Additional software PCF method
float SoftwarePCF(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, float bias)
{
float shadow = 0.0;
vec3 texelSize = 1.0 / textureSize(depth_texture_array, 0);
for(int x = -1; x <= 1; x++)
{
for(int y = -1; y <= 1; y++)
{
shadow += texture(depth_texture_array, vec4(projection_coords.xy + vec2(x, y) * texelSize.xy / (1.0 + layer_index), layer_index, projection_coords.z));
}
}
return shadow / 9.0;
}
float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler2DArrayShadow depth_texture_array, int layer_index)
{
float shadowMapDepth;
float bias = 0.005;
// Various bias methods.
//bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias);
//bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
bias = bias + bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
// Calculate coordinates in projection space.
vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w;
projCoords = projCoords * 0.5 + 0.5;
//projCoords = (floor(projCoords * 255.0)) / 255.0;
// Various methods for shadow calculation in fastest to slowest order.
//shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index);
//shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
//shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias);
return shadowMapDepth;
}
void main()
{
float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r;
@@ -189,7 +362,7 @@ void main()
GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3);
vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3,
SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3);
vec4 position = V * M * vec4(Input.Position, 1.0);
vec4 position = VM * vec4(Input.Position, 1.0);
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3,
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3);
@@ -208,6 +381,8 @@ void main()
int start = int(LightGrids.Data[currentTile].Start);
int amount = int(LightGrids.Data[currentTile].Amount);
float shadowFactor = 0.0;
for(int i = start; i < start + amount; i++) {
int l = int(LightIndex[i]);
@@ -218,12 +393,17 @@ void main()
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
int DepthMapIndex = getShadowIndex(FarDistance);
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap, DepthMapIndex);
}
totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a);
totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a);
}
totalLighting.Diffuse *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0);
totalLighting.Specular *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0);
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
//vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
@@ -1,7 +1,9 @@
#version 430
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -84,6 +86,7 @@ in VertexData{
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Input;
out vec4 sceneColor;
@@ -190,7 +193,7 @@ void main()
GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3);
vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3,
SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3);
vec4 position = V * M * vec4(Input.Position, 1.0);
vec4 position = VM * vec4(Input.Position, 1.0);
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3,
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3);
+8 -4
View File
@@ -14,11 +14,15 @@ uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.01
void main()
{
vec2 tex_offset = 1.0 / textureSize2D(Texture, 0);
vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0];
vec3 center = texture(Texture, Input.TextureCoordinate).rgb;
vec3 result = center * weight[0];
for(int i = 1; i < 5; ++i) {
result += texture(Texture, Input.TextureCoordinate + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
result += texture(Texture, Input.TextureCoordinate - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
vec4 eastFragments = texture(Texture, Input.TextureCoordinate + vec2(tex_offset.x * i, 0.0));
vec4 westFragments = texture(Texture, Input.TextureCoordinate - vec2(tex_offset.x * i, 0.0));
result += eastFragments.rgb * weight[i] * eastFragments.a;
result += westFragments.rgb * weight[i] * westFragments.a;
result += center * weight[i] * (1.0 - westFragments.a);
result += center * weight[i] * (1.0 - eastFragments.a);
}
fragmentColor = vec4(result, 1.0);
}
+8 -4
View File
@@ -14,11 +14,15 @@ uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.01
void main()
{
vec2 tex_offset = 1.0 / textureSize2D(Texture, 0);
vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0];
vec3 center = texture(Texture, Input.TextureCoordinate).rgb;
vec3 result = center * weight[0];
for(int i = 1; i < 5; ++i) {
result += texture(Texture, Input.TextureCoordinate + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
result += texture(Texture, Input.TextureCoordinate - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
vec4 northFragments = texture(Texture, Input.TextureCoordinate + vec2(0.0, tex_offset.y * i));
vec4 southFragments = texture(Texture, Input.TextureCoordinate - vec2(0.0, tex_offset.y * i));
result += northFragments.rgb * weight[i] * northFragments.a;
result += southFragments.rgb * weight[i] * southFragments.a;
result += center * weight[i] * (1.0 - northFragments.a);
result += center * weight[i] * (1.0 - southFragments.a);
}
fragmentColor = vec4(result, 1.0);
}
+2 -5
View File
@@ -1,8 +1,5 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 PVM;
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
@@ -16,6 +13,6 @@ out VertexData{
void main()
{
gl_Position = P*V*M * vec4(Position, 1.0);
gl_Position = PVM * vec4(Position, 1.0);
Output.Position = Position, 1.0;
}
+2 -5
View File
@@ -1,8 +1,5 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 PVM;
uniform mat4 Bones[100];
layout(location = 0) in vec3 Position;
@@ -27,6 +24,6 @@ void main()
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
}
gl_Position = P*V*M*boneTransform * vec4(Position, 1.0);
gl_Position = PVM*boneTransform * vec4(Position, 1.0);
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
}
+22
View File
@@ -0,0 +1,22 @@
#version 430
#define ALPHA_CUTOFF 0.3
layout (binding = 24) uniform sampler2D DiffuseTexture;
uniform float Alpha;
in VertexData{
vec2 TextureCoordinate;
}Input;
layout (location = 0) out float ShadowMap;
void main()
{
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoordinate) * Alpha;
if (diffuseTexel.a < ALPHA_CUTOFF)
{
discard;
}
}
+18
View File
@@ -0,0 +1,18 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
layout (location = 0) in vec3 Position;
layout (location = 4) in vec2 TextureCoords;
out VertexData{
vec2 TextureCoordinate;
}Output;
void main()
{
gl_Position = P * V * M * vec4(Position, 1.0);
Output.TextureCoordinate = TextureCoords;
}
+29
View File
@@ -0,0 +1,29 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 Bones[100];
layout (location = 0) in vec3 Position;
layout (location = 4) in vec2 TextureCoords;
layout(location = 5) in vec4 BoneIndices;
layout(location = 6) in vec4 BoneWeights;
out VertexData{
vec2 TextureCoordinate;
}Output;
void main()
{
mat4 boneTransform = mat4(1);
if(BoneWeights[0] > 0.0f){
boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])]
+ BoneWeights[1] * Bones[int(BoneIndices[1])]
+ BoneWeights[2] * Bones[int(BoneIndices[2])]
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
}
gl_Position = P * V * M * boneTransform * vec4(Position, 1.0);
Output.TextureCoordinate = TextureCoords;
}
+2 -3
View File
@@ -3,8 +3,6 @@
uniform vec4 Color;
uniform vec4 FillColor;
uniform float FillPercentage;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
layout (binding = 1) uniform sampler2D DiffuseTexture;
@@ -35,7 +33,8 @@ void main()
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
//bloomColor = vec4(clamp((glowTexel.xyz*3) - 1.0, 0, 100), 1.0);
bloomColor = vec4(1.0, 1.0, 1.0, 0.0);
bloomColor = vec4(max(color_result.xyz - 1.0, 0.0), clamp(color_result.a, 0, 1));
//bloomColor = vec4(1.0, 1.0, 1.0, 0.0);
}
+2 -4
View File
@@ -1,8 +1,6 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 PVM;
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
@@ -17,7 +15,7 @@ out VertexData{
void main()
{
gl_Position = P * V * M * vec4(Position, 1.0);
gl_Position = PVM* vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoordinate = TextureCoords;
@@ -0,0 +1,6 @@
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
{
mat3 TBN = mat3(tangent, bitangent, normal);
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
return vec4(TBN * normalize(NormalMap), 0.0);
}