wip for shadows

they work, but will be shit until we get cascaded.
This commit is contained in:
FakeShemp
2016-02-10 20:51:33 +01:00
parent cb77c1ff97
commit 36043010af
2 changed files with 42 additions and 7 deletions
+2 -2
View File
@@ -58,8 +58,8 @@ private:
glm::mat4 m_LightView;
glm::mat4 m_LightSpaceMatrix;
GLuint resolutionSizeWidth = 2048 * 2;
GLuint resolutionSizeHeigth = 2048 * 2;
GLuint resolutionSizeWidth = 1024 * 8;
GLuint resolutionSizeHeigth = 1024 * 8;
bool m_ShadowOn = true;
};
+40 -5
View File
@@ -114,18 +114,53 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu
return vec4(TBN * normalize(NormalMap), 0.0);
}
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 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);
}
float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampler2DShadow depthTexture)
{
float bias = 0.005;
//float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
//float bias = 0.005 * tan(acos(clamp(dot(normal, lightDir), 0,1))); bias = clamp(bias, 0,0.01);
//float bias = 0.005 * tan(acos(clamp(dot(normal, -lightDir), 0.0, 1.0)));
vec3 projCoords = vec3(positionLightSpace.xy, positionLightSpace.z + bias) / positionLightSpace.w;
projCoords = projCoords * 0.5 + 0.5;
//float shadowMapDepth = texture(depthTexture, projCoords.xy).r;
float shadowMapDepth = texture(depthTexture, projCoords);
float geometryDepth = projCoords.z;
float shadowMapDepth;
//for (int i = 0; i < 4; i++)
//{
// int index = i;
// //int index = int(16.0 * random(gl_FragCoord.xyy, i)) % 16;
// shadowMapDepth += 0.25 * texture(depthTexture, projCoords + vec3(poissonDisk[index], 0.0) / 700.0);
//}
shadowMapDepth = texture(depthTexture, projCoords);
//float geometryDepth = projCoords.z;
//float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0;
//float shadow = 1.0 - bias > shadowMapDepth ? 0.0 : 1.0;
@@ -193,8 +228,8 @@ void main()
totalLighting.Specular += light_result.Specular;
}
totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0);
totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0);
totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0);
totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0);
//LightResult getInformation;