Shadow fixes
This commit is contained in:
parent
1e39f73eb4
commit
2eab2c1adb
|
@ -147,7 +147,9 @@ uniform vec3 sunCol;
|
||||||
#ifdef _SinglePoint // Fast path for single light
|
#ifdef _SinglePoint // Fast path for single light
|
||||||
uniform vec3 pointPos;
|
uniform vec3 pointPos;
|
||||||
uniform vec3 pointCol;
|
uniform vec3 pointCol;
|
||||||
uniform float pointBias;
|
#ifdef _ShadowMap
|
||||||
|
uniform float pointBias;
|
||||||
|
#endif
|
||||||
#ifdef _Spot
|
#ifdef _Spot
|
||||||
uniform vec3 spotDir;
|
uniform vec3 spotDir;
|
||||||
uniform vec2 spotData;
|
uniform vec2 spotData;
|
||||||
|
|
|
@ -186,7 +186,7 @@
|
||||||
{
|
{
|
||||||
"name": "pointBias",
|
"name": "pointBias",
|
||||||
"link": "_pointShadowsBias",
|
"link": "_pointShadowsBias",
|
||||||
"ifdef": ["_SinglePoint"]
|
"ifdef": ["_SinglePoint", "_ShadowMap"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "spotDir",
|
"name": "spotDir",
|
||||||
|
|
|
@ -62,24 +62,24 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
|
||||||
#ifdef _ShadowMap
|
#ifdef _ShadowMap
|
||||||
#ifdef _SinglePoint
|
#ifdef _SinglePoint
|
||||||
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
|
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
|
||||||
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias, shadowmapSize);
|
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _Clusters
|
#ifdef _Clusters
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
|
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
|
||||||
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias, shadowmapSize);
|
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias);
|
||||||
}
|
}
|
||||||
else if (index == 1) {
|
else if (index == 1) {
|
||||||
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
|
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
|
||||||
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias, shadowmapSize);
|
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias);
|
||||||
}
|
}
|
||||||
else if (index == 2) {
|
else if (index == 2) {
|
||||||
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
|
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
|
||||||
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias, shadowmapSize);
|
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias);
|
||||||
}
|
}
|
||||||
else if (index == 3) {
|
else if (index == 3) {
|
||||||
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
|
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
|
||||||
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias, shadowmapSize);
|
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,6 +88,7 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _ShadowMap
|
#ifdef _ShadowMap
|
||||||
|
#ifndef _Spot
|
||||||
#ifdef _SinglePoint
|
#ifdef _SinglePoint
|
||||||
direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
|
direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
|
||||||
#endif
|
#endif
|
||||||
|
@ -98,6 +99,7 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
|
||||||
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
|
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
return direct;
|
return direct;
|
||||||
}
|
}
|
||||||
|
|
|
@ -352,7 +352,7 @@ def make_forward_mobile(con_mesh):
|
||||||
frag.add_include('std/shadows.glsl')
|
frag.add_include('std/shadows.glsl')
|
||||||
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
|
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
|
||||||
frag.add_uniform('vec3 eye', '_cameraPosition')
|
frag.add_uniform('vec3 eye', '_cameraPosition')
|
||||||
frag.write('svisibility = shadowTestCascade(shadowMap, eye, wposition + n * shadowsBias * 10, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0));')
|
frag.write('svisibility = shadowTestCascade(shadowMap, eye, wposition + n * shadowsBias * 10, shadowsBias);')
|
||||||
else:
|
else:
|
||||||
frag.write('if (lightPosition.w > 0.0) {')
|
frag.write('if (lightPosition.w > 0.0) {')
|
||||||
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||||
|
@ -363,28 +363,28 @@ def make_forward_mobile(con_mesh):
|
||||||
if '_SinglePoint' in wrd.world_defs:
|
if '_SinglePoint' in wrd.world_defs:
|
||||||
frag.add_uniform('vec3 pointPos', '_pointPosition')
|
frag.add_uniform('vec3 pointPos', '_pointPosition')
|
||||||
frag.add_uniform('vec3 pointCol', '_pointColor')
|
frag.add_uniform('vec3 pointCol', '_pointColor')
|
||||||
|
if '_Spot' in wrd.world_defs:
|
||||||
|
frag.add_uniform('vec3 spotDir', link='_spotDirection')
|
||||||
|
frag.add_uniform('vec2 spotData', link='_spotData')
|
||||||
frag.write('float visibility = 1.0;')
|
frag.write('float visibility = 1.0;')
|
||||||
frag.write('vec3 ld = pointPos - wposition;')
|
frag.write('vec3 ld = pointPos - wposition;')
|
||||||
frag.write('vec3 l = normalize(ld);')
|
frag.write('vec3 l = normalize(ld);')
|
||||||
frag.write('float dotNL = max(dot(n, l), 0.0);')
|
frag.write('float dotNL = max(dot(n, l), 0.0);')
|
||||||
if '_Spot' in wrd.world_defs:
|
|
||||||
frag.add_uniform('vec3 spotDir', link='_spotDirection')
|
|
||||||
frag.add_uniform('vec2 spotData', link='_spotData')
|
|
||||||
if is_shadows:
|
if is_shadows:
|
||||||
vert.add_out('vec4 spotPosition')
|
|
||||||
vert.add_uniform('mat4 LWVPSpot0', '_biasLightWorldViewProjectionMatrixSpot0')
|
|
||||||
vert.write('spotPosition = LWVPSpot0 * spos;')
|
|
||||||
frag.add_uniform('float pointBias', link='_pointShadowsBias')
|
frag.add_uniform('float pointBias', link='_pointShadowsBias')
|
||||||
|
frag.add_include('std/shadows.glsl')
|
||||||
|
if '_Spot' in wrd.world_defs:
|
||||||
|
vert.add_out('vec4 spotPosition')
|
||||||
|
vert.add_uniform('mat4 LWVPSpot0', link='_biasLightWorldViewProjectionMatrixSpot0')
|
||||||
|
vert.write('spotPosition = LWVPSpot0 * spos;')
|
||||||
frag.add_uniform('sampler2DShadow shadowMapSpot[1]')
|
frag.add_uniform('sampler2DShadow shadowMapSpot[1]')
|
||||||
frag.write('if (spotPosition.w > 0.0) {')
|
frag.write('if (spotPosition.w > 0.0) {')
|
||||||
frag.write(' vec3 lPos = spotPosition.xyz / spotPosition.w;')
|
frag.write(' vec3 lPos = spotPosition.xyz / spotPosition.w;')
|
||||||
frag.write(' visibility = texture(shadowMap, vec3(lPos.xy, lPos.z - pointBias).r;')
|
frag.write(' visibility = texture(shadowMapSpot[0], vec3(lPos.xy, lPos.z - pointBias)).r;')
|
||||||
frag.write('}')
|
frag.write('}')
|
||||||
elif is_shadows:
|
else:
|
||||||
frag.add_include('std/shadows.glsl')
|
|
||||||
frag.add_uniform('vec2 lightProj', link='_lightPlaneProj')
|
frag.add_uniform('vec2 lightProj', link='_lightPlaneProj')
|
||||||
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]')
|
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]')
|
||||||
frag.add_uniform('float pointBias', link='_pointShadowsBias')
|
|
||||||
frag.write('const float s = shadowmapCubePcfSize;') # TODO: incorrect...
|
frag.write('const float s = shadowmapCubePcfSize;') # TODO: incorrect...
|
||||||
frag.write('float compare = lpToDepth(ld - n * pointBias * 80, lightProj);')
|
frag.write('float compare = lpToDepth(ld - n * pointBias * 80, lightProj);')
|
||||||
frag.write('visibility = texture(shadowMapPoint[0], vec4(-l + n * pointBias * 80, compare)).r;')
|
frag.write('visibility = texture(shadowMapPoint[0], vec4(-l + n * pointBias * 80, compare)).r;')
|
||||||
|
@ -554,7 +554,7 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
||||||
frag.add_include('std/shadows.glsl')
|
frag.add_include('std/shadows.glsl')
|
||||||
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
|
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
|
||||||
frag.add_uniform('vec3 eye', '_cameraPosition')
|
frag.add_uniform('vec3 eye', '_cameraPosition')
|
||||||
frag.write('svisibility = shadowTestCascade(shadowMap, eye, wposition + n * shadowsBias * 10, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0));')
|
frag.write('svisibility = shadowTestCascade(shadowMap, eye, wposition + n * shadowsBias * 10, shadowsBias);')
|
||||||
else:
|
else:
|
||||||
if tese != None:
|
if tese != None:
|
||||||
tese.add_out('vec4 lightPosition')
|
tese.add_out('vec4 lightPosition')
|
||||||
|
@ -580,16 +580,18 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
||||||
if '_SinglePoint' in wrd.world_defs:
|
if '_SinglePoint' in wrd.world_defs:
|
||||||
frag.add_uniform('vec3 pointPos', link='_pointPosition')
|
frag.add_uniform('vec3 pointPos', link='_pointPosition')
|
||||||
frag.add_uniform('vec3 pointCol', link='_pointColor')
|
frag.add_uniform('vec3 pointCol', link='_pointColor')
|
||||||
if is_shadows:
|
|
||||||
frag.add_uniform('vec2 lightProj', link='_lightPlaneProj', included=True)
|
|
||||||
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]', included=True)
|
|
||||||
frag.add_uniform('float pointBias', link='_pointShadowsBias')
|
|
||||||
if '_Spot' in wrd.world_defs:
|
if '_Spot' in wrd.world_defs:
|
||||||
frag.add_uniform('vec3 spotDir', link='_spotDirection')
|
frag.add_uniform('vec3 spotDir', link='_spotDirection')
|
||||||
frag.add_uniform('vec2 spotData', link='_spotData')
|
frag.add_uniform('vec2 spotData', link='_spotData')
|
||||||
if is_shadows:
|
if is_shadows:
|
||||||
frag.add_uniform('mat4 LWVPSpot0', '_biasLightWorldViewProjectionMatrixSpot0', included=True)
|
frag.add_uniform('float pointBias', link='_pointShadowsBias')
|
||||||
|
if '_Spot' in wrd.world_defs:
|
||||||
|
# Skip world matrix, already in world-space
|
||||||
|
frag.add_uniform('mat4 LWVPSpot0', link='_biasLightViewProjectionMatrixSpot0', included=True)
|
||||||
frag.add_uniform('sampler2DShadow shadowMapSpot[1]', included=True)
|
frag.add_uniform('sampler2DShadow shadowMapSpot[1]', included=True)
|
||||||
|
else:
|
||||||
|
frag.add_uniform('vec2 lightProj', link='_lightPlaneProj', included=True)
|
||||||
|
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]', included=True)
|
||||||
frag.write('direct += sampleLight(')
|
frag.write('direct += sampleLight(')
|
||||||
frag.write(' wposition, n, vVec, dotNV, pointPos, pointCol, albedo, roughness, specular, f0')
|
frag.write(' wposition, n, vVec, dotNV, pointPos, pointCol, albedo, roughness, specular, f0')
|
||||||
if is_shadows:
|
if is_shadows:
|
||||||
|
|
|
@ -685,6 +685,8 @@ class ArmRenderPathRendererPanel(bpy.types.Panel):
|
||||||
layout.use_property_split = True
|
layout.use_property_split = True
|
||||||
layout.use_property_decorate = False
|
layout.use_property_decorate = False
|
||||||
wrd = bpy.data.worlds['Arm']
|
wrd = bpy.data.worlds['Arm']
|
||||||
|
if len(wrd.arm_rplist) <= wrd.arm_rplist_index:
|
||||||
|
return
|
||||||
rpdat = wrd.arm_rplist[wrd.arm_rplist_index]
|
rpdat = wrd.arm_rplist[wrd.arm_rplist_index]
|
||||||
|
|
||||||
layout.prop(rpdat, 'rp_renderer')
|
layout.prop(rpdat, 'rp_renderer')
|
||||||
|
|
Loading…
Reference in a new issue