Update more shaders for receive shadow option

This commit is contained in:
Moritz Brückner 2020-07-13 23:28:43 +02:00
parent 9a47d77594
commit 3654d34997
3 changed files with 40 additions and 36 deletions

View file

@ -346,7 +346,7 @@ void main() {
fragColor.rgb += sampleLight( fragColor.rgb += sampleLight(
p, n, v, dotNV, pointPos, pointCol, albedo, roughness, occspec.y, f0 p, n, v, dotNV, pointPos, pointCol, albedo, roughness, occspec.y, f0
#ifdef _ShadowMap #ifdef _ShadowMap
, 0, pointBias , 0, pointBias, true
#endif #endif
#ifdef _Spot #ifdef _Spot
, true, spotData.x, spotData.y, spotDir , true, spotData.x, spotData.y, spotDir
@ -400,7 +400,7 @@ void main() {
occspec.y, occspec.y,
f0 f0
#ifdef _ShadowMap #ifdef _ShadowMap
, li, lightsArray[li * 2].w // bias , li, lightsArray[li * 2].w, true // bias
#endif #endif
#ifdef _Spot #ifdef _Spot
, li > numPoints - 1 , li > numPoints - 1

View file

@ -182,7 +182,7 @@ void main() {
fragColor.rgb += sampleLight( fragColor.rgb += sampleLight(
p, n, v, dotNV, pointPos, pointCol, albedo, roughness, occspec.y, f0 p, n, v, dotNV, pointPos, pointCol, albedo, roughness, occspec.y, f0
#ifdef _ShadowMap #ifdef _ShadowMap
, 0, pointBias , 0, pointBias, true
#endif #endif
#ifdef _Spot #ifdef _Spot
, true, spotData.x, spotData.y, spotDir , true, spotData.x, spotData.y, spotDir
@ -218,7 +218,7 @@ void main() {
occspec.y, occspec.y,
f0 f0
#ifdef _ShadowMap #ifdef _ShadowMap
, li, lightsArray[li * 2].w // bias , li, lightsArray[li * 2].w, true // bias
#endif #endif
#ifdef _Spot #ifdef _Spot
, li > numPoints - 1 , li > numPoints - 1

View file

@ -33,7 +33,7 @@
vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, const vec3 lp, const vec3 lightCol, vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, const vec3 lp, const vec3 lightCol,
const vec3 albedo, const float rough, const float spec, const vec3 f0 const vec3 albedo, const float rough, const float spec, const vec3 f0
#ifdef _ShadowMap #ifdef _ShadowMap
, int index, float bias , int index, float bias, bool receiveShadow
#endif #endif
#ifdef _Spot #ifdef _Spot
, bool isSpot, float spotA, float spotB, vec3 spotDir , bool isSpot, float spotA, float spotB, vec3 spotDir
@ -60,28 +60,30 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
direct *= smoothstep(spotB, spotA, spotEffect); direct *= smoothstep(spotB, spotA, spotEffect);
} }
#ifdef _ShadowMap #ifdef _ShadowMap
#ifdef _SinglePoint if (receiveShadow) {
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0); #ifdef _SinglePoint
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias); vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
#endif direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias);
#ifdef _Clusters #endif
if (index == 0) { #ifdef _Clusters
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0); if (index == 0) {
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias); vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
} direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias);
else if (index == 1) { }
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0); else if (index == 1) {
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias); vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
} direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias);
else if (index == 2) { }
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0); else if (index == 2) {
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias); vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
} direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias);
else if (index == 3) { }
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0); else if (index == 3) {
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias); vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
} direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias);
#endif }
#endif
}
#endif #endif
return direct; return direct;
} }
@ -89,15 +91,17 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
#ifdef _ShadowMap #ifdef _ShadowMap
#ifndef _Spot #ifndef _Spot
#ifdef _SinglePoint if (receiveShadow) {
direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n); #ifdef _SinglePoint
#endif direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
#ifdef _Clusters #endif
if (index == 0) direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n); #ifdef _Clusters
else if (index == 1) direct *= PCFCube(shadowMapPoint[1], ld, -l, bias, lightProj, n); if (index == 0) direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
else if (index == 2) direct *= PCFCube(shadowMapPoint[2], ld, -l, bias, lightProj, n); else if (index == 1) direct *= PCFCube(shadowMapPoint[1], ld, -l, bias, lightProj, n);
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n); else if (index == 2) direct *= PCFCube(shadowMapPoint[2], ld, -l, bias, lightProj, n);
#endif else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
#endif
}
#endif #endif
#endif #endif