Refactor scene, disable shadows, disable exceptions
This commit is contained in:
@@ -60,8 +60,8 @@ uniform SpotLight u_spotLight;*/
|
||||
|
||||
uniform mat3 u_normalMatrix;
|
||||
|
||||
uniform sampler2D u_texture_directionalShadowMap;
|
||||
uniform samplerCube u_texture_pointShadowMap0;
|
||||
// uniform sampler2D u_texture_directionalShadowMap;
|
||||
// uniform samplerCube u_texture_pointShadowMap0;
|
||||
//uniform samplerCube u_texture_pointShadowMap1;
|
||||
//uniform samplerCube u_texture_pointShadowMap2;
|
||||
//uniform samplerCube u_texture_pointShadowMap3;
|
||||
@@ -74,9 +74,9 @@ vec3 sampleOffsetDirections[20] = vec3[] (
|
||||
vec3( 0, 1, 1), vec3( 0, -1, 1), vec3( 0, -1, -1), vec3( 0, 1, -1)
|
||||
);
|
||||
|
||||
uniform bool b_drawShadows;
|
||||
// uniform bool b_drawShadows;
|
||||
|
||||
uniform float pointShadowDepthMapFarPlane;
|
||||
// uniform float pointShadowDepthMapFarPlane;
|
||||
|
||||
vec3 directionalLightContribution(DirectionalLight light, vec3 normal, vec3 viewDir);
|
||||
vec3 pointLightContribution(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||
@@ -90,8 +90,8 @@ void computeShading(
|
||||
|
||||
float computeAttenuation(vec3 lightPos, vec3 fragPos, float K_q);
|
||||
|
||||
float computeDirectionalShadows(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir);
|
||||
float computePointShadows(vec3 fragPos, vec3 lightPos);
|
||||
// float computeDirectionalShadows(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir);
|
||||
// float computePointShadows(vec3 fragPos, vec3 lightPos);
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -131,8 +131,8 @@ vec3 directionalLightContribution(DirectionalLight light, vec3 normal, vec3 view
|
||||
computeShading(ambientColor, diffuseColor, specularColor, lightDir, viewDir, normal, ambient, diffuse, specular);
|
||||
|
||||
float shadows = 0.0f;
|
||||
if(b_drawShadows)
|
||||
shadows = computeDirectionalShadows(v_fragmentPositionDirectionalLightSpace, normal, lightDir);
|
||||
// if(b_drawShadows)
|
||||
// shadows = computeDirectionalShadows(v_fragmentPositionDirectionalLightSpace, normal, lightDir);
|
||||
|
||||
return (ambient + (1.0f - shadows) * (diffuse + specular));
|
||||
}
|
||||
@@ -158,8 +158,8 @@ vec3 pointLightContribution(PointLight light, vec3 normal, vec3 fragPos, vec3 vi
|
||||
//specular *= attenuation;
|
||||
|
||||
float shadows = 0.0f;
|
||||
if(b_drawShadows)
|
||||
shadows = computePointShadows(v_fragmentPosition, light.position);
|
||||
// if(b_drawShadows)
|
||||
// shadows = computePointShadows(v_fragmentPosition, light.position);
|
||||
|
||||
return (ambient + (1.0f - shadows) * (diffuse + specular));
|
||||
}
|
||||
@@ -219,57 +219,57 @@ float computeAttenuation(vec3 lightPos, vec3 fragPos, float K_q) {
|
||||
|
||||
}
|
||||
|
||||
float computeDirectionalShadows(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir) {
|
||||
// float computeDirectionalShadows(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir) {
|
||||
|
||||
// Perspective divide
|
||||
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||
// // Perspective divide
|
||||
// vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||
|
||||
// Transform from [-1,1] to [0,1]
|
||||
projCoords *= 0.5f;
|
||||
projCoords += 0.5f;
|
||||
// // Transform from [-1,1] to [0,1]
|
||||
// projCoords *= 0.5f;
|
||||
// projCoords += 0.5f;
|
||||
|
||||
if(projCoords.z > 1.0f) return 0.0f;
|
||||
// if(projCoords.z > 1.0f) return 0.0f;
|
||||
|
||||
float closestDepth = texture(u_texture_directionalShadowMap, projCoords.xy).r;
|
||||
float currentDepth = projCoords.z;
|
||||
// float closestDepth = texture(u_texture_directionalShadowMap, projCoords.xy).r;
|
||||
// float currentDepth = projCoords.z;
|
||||
|
||||
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
|
||||
bias *= 0.25f;
|
||||
// float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
|
||||
// bias *= 0.25f;
|
||||
|
||||
float shadow = 0.0;
|
||||
vec2 texelSize = 1.0 / textureSize(u_texture_directionalShadowMap, 0);
|
||||
for(int x = -1; x <= 1; x++) {
|
||||
for(int y = -1; y <= 1; y++) {
|
||||
float pcfDepth = texture(u_texture_directionalShadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
|
||||
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= 9.0f;
|
||||
// float shadow = 0.0;
|
||||
// vec2 texelSize = 1.0 / textureSize(u_texture_directionalShadowMap, 0);
|
||||
// for(int x = -1; x <= 1; x++) {
|
||||
// for(int y = -1; y <= 1; y++) {
|
||||
// float pcfDepth = texture(u_texture_directionalShadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
|
||||
// shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
|
||||
// }
|
||||
// }
|
||||
// shadow /= 9.0f;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
// return shadow;
|
||||
// }
|
||||
|
||||
float computePointShadows(vec3 fragPos, vec3 lightPos) {
|
||||
// float computePointShadows(vec3 fragPos, vec3 lightPos) {
|
||||
|
||||
// get vector between fragment position and light position
|
||||
vec3 fragToLight = fragPos - lightPos;
|
||||
// // get vector between fragment position and light position
|
||||
// vec3 fragToLight = fragPos - lightPos;
|
||||
|
||||
// now get current linear depth as the length between the fragment and light position
|
||||
float currentDepth = length(fragToLight);
|
||||
// // now get current linear depth as the length between the fragment and light position
|
||||
// float currentDepth = length(fragToLight);
|
||||
|
||||
float shadow = 0.0;
|
||||
float bias = 0.05;
|
||||
int samples = 20;
|
||||
float viewDistance = length(v_viewPositionTangent - fragPos);
|
||||
float diskRadius = 0.05;
|
||||
// float shadow = 0.0;
|
||||
// float bias = 0.05;
|
||||
// int samples = 20;
|
||||
// float viewDistance = length(v_viewPositionTangent - fragPos);
|
||||
// float diskRadius = 0.05;
|
||||
|
||||
for(int i = 0; i < samples; ++i) {
|
||||
float closestDepth = texture(u_texture_pointShadowMap0, fragToLight + sampleOffsetDirections[i] * diskRadius).r;
|
||||
closestDepth *= pointShadowDepthMapFarPlane;
|
||||
if(currentDepth - bias > closestDepth)
|
||||
shadow += 1.0;
|
||||
}
|
||||
// for(int i = 0; i < samples; ++i) {
|
||||
// float closestDepth = texture(u_texture_pointShadowMap0, fragToLight + sampleOffsetDirections[i] * diskRadius).r;
|
||||
// closestDepth *= pointShadowDepthMapFarPlane;
|
||||
// if(currentDepth - bias > closestDepth)
|
||||
// shadow += 1.0;
|
||||
// }
|
||||
|
||||
shadow /= float(samples);
|
||||
return shadow;
|
||||
}
|
||||
// shadow /= float(samples);
|
||||
// return shadow;
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user