Shadows stage 2 WIP
This commit is contained in:
@@ -22,6 +22,7 @@ in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace;
|
||||
}Input[];
|
||||
|
||||
out VertexData{
|
||||
@@ -32,6 +33,7 @@ out VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace;
|
||||
}Output;
|
||||
|
||||
layout(triangles) in;
|
||||
@@ -145,6 +147,7 @@ void main()
|
||||
Output.TextureCoordinate = Input[i].TextureCoordinate;
|
||||
Output.Tangent = Input[i].Tangent;
|
||||
Output.BiTangent = Input[i].BiTangent;
|
||||
Output.PositionLightSpace = Input[i].PositionLightSpace;
|
||||
|
||||
// convert to model space for the gravity to always be in -y
|
||||
vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0);
|
||||
@@ -186,6 +189,7 @@ void main()
|
||||
Output.TextureCoordinate = Input[i].TextureCoordinate;
|
||||
Output.Tangent = Input[i].Tangent;
|
||||
Output.BiTangent = Input[i].BiTangent;
|
||||
Output.PositionLightSpace = Input[i].PositionLightSpace;
|
||||
|
||||
// no change in position, pass through vertex
|
||||
gl_Position = gl_in[i].gl_Position;
|
||||
|
||||
@@ -13,6 +13,7 @@ layout (binding = 0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding = 1) uniform sampler2D NormalMapTexture;
|
||||
layout (binding = 2) uniform sampler2D SpecularMapTexture;
|
||||
layout (binding = 3) uniform sampler2D GlowMapTexture;
|
||||
layout (binding = 4) uniform sampler2D DepthMap;
|
||||
|
||||
#define TILE_SIZE 16
|
||||
|
||||
@@ -56,6 +57,7 @@ in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace;
|
||||
}Input;
|
||||
|
||||
out vec4 sceneColor;
|
||||
@@ -112,6 +114,45 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu
|
||||
return vec4(TBN * normalize(NormalMap), 0.0);
|
||||
}
|
||||
|
||||
//float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture)
|
||||
//{
|
||||
// // perform perspective divide
|
||||
// //vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w;
|
||||
// // Transform to [0,1] range
|
||||
// //projCoords = projCoords * 0.5 + 0.5;
|
||||
// // Get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
|
||||
// float closestDepth = texture(depthTexture, positionLightSpace.xy).r;
|
||||
// // Get depth of current fragment from light's perspective
|
||||
// float currentDepth = positionLightSpace.z;
|
||||
// // Check whether current frag pos is in shadow
|
||||
// float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
|
||||
//
|
||||
// return shadow;
|
||||
//
|
||||
//}
|
||||
|
||||
float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture)
|
||||
{
|
||||
|
||||
//float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005);
|
||||
// perform perspective divide
|
||||
vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w;
|
||||
// Transform to [0,1] range
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
// Get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
|
||||
//float lightDepth = texture(depthTexture, positionLightSpace.xy).r;
|
||||
float closestDepth = texture(depthTexture, projCoords.xy).r;
|
||||
// Get depth of current fragment from light's perspective
|
||||
//float currentDepth = positionLightSpace.z;
|
||||
float currentDepth = projCoords.z;
|
||||
// Check whether current frag pos is in shadow
|
||||
float shadow = currentDepth /*- bias*/ > closestDepth ? 1.0 : 0.0;
|
||||
// float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
|
||||
|
||||
return shadow;
|
||||
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate);
|
||||
@@ -134,24 +175,42 @@ void main()
|
||||
int start = int(LightGrids.Data[currentTile].Start);
|
||||
int amount = int(LightGrids.Data[currentTile].Amount);
|
||||
|
||||
float shadowFactor = 1.0;
|
||||
|
||||
for(int i = start; i < start + amount; i++) {
|
||||
|
||||
int l = int(LightIndex[i]);
|
||||
LightSource light = LightSources.List[l];
|
||||
|
||||
|
||||
LightResult light_result;
|
||||
//These if statements should be removed.
|
||||
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
|
||||
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||
shadowFactor = CalcShadowValue(Input.PositionLightSpace, normal, light.Direction, DepthMap);
|
||||
}
|
||||
|
||||
totalLighting.Diffuse += light_result.Diffuse;
|
||||
totalLighting.Specular += light_result.Specular;
|
||||
totalLighting.Specular += light_result.Specular;
|
||||
}
|
||||
|
||||
totalLighting.Diffuse += (1.0 - shadowFactor);
|
||||
totalLighting.Specular += (1.0 - shadowFactor);
|
||||
//LightResult getInformation;
|
||||
|
||||
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
|
||||
color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
|
||||
|
||||
//color_result = (totalLighting.Diffuse + (1.0 - shadowFactor) * (getInformation.Diffuse + (getInformation.Specular * specularTexel))) * color_result;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 lightSpaceMatrix; // Shadow map PV
|
||||
uniform mat4 LightV;
|
||||
uniform mat4 LightP;
|
||||
uniform mat4 Bones[100];
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
@@ -21,8 +24,17 @@ out VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace;
|
||||
}Output;
|
||||
|
||||
// N
|
||||
mat4 biasMatrix = mat4(
|
||||
vec4(0.5, 0.0, 0.0, 0.0),
|
||||
vec4(0.0, 0.5, 0.0, 0.0),
|
||||
vec4(0.0, 0.0, 0.5, 0.0),
|
||||
vec4(0.5, 0.5, 0.5, 1.0)
|
||||
);
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
@@ -34,9 +46,12 @@ void main()
|
||||
+ BoneWeights[2] * Bones[int(BoneIndices[2])]
|
||||
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
|
||||
}
|
||||
|
||||
gl_Position = P*V*M*boneTransform * vec4(Position, 1.0);
|
||||
|
||||
//vec4 lightPos = biasMatrix * LightP * LightV * M * vec4(Position, 1.0); // N
|
||||
|
||||
gl_Position = P*V*M*boneTransform * vec4(Position, 1.0);
|
||||
//gl_Position = lightPos; // N
|
||||
|
||||
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.TextureCoordinate = TextureCoords;
|
||||
Output.Normal = vec3(M * vec4(Normal, 0.0));
|
||||
@@ -44,4 +59,7 @@ void main()
|
||||
Output.BiTangent = vec3(M * vec4(BiTangent, 0.0));
|
||||
Output.ExplosionColor = vec4(1.0);
|
||||
Output.ExplosionPercentageElapsed = 0.0;
|
||||
|
||||
//Output.PositionLightSpace = lightPos; // N
|
||||
Output.PositionLightSpace = lightSpaceMatrix * (M * vec4(Position, 1.0));
|
||||
}
|
||||
Reference in New Issue
Block a user