Fix LTC shadow
This commit is contained in:
parent
da84a870f1
commit
4172e0a2c6
|
@ -83,6 +83,19 @@ uniform mat4 invVP;
|
|||
//!uniform vec3 lightArea3;
|
||||
//!uniform sampler2D sltcMat;
|
||||
//!uniform sampler2D sltcMag;
|
||||
#ifdef _ShadowMap
|
||||
#ifdef _SinglePoint
|
||||
//!uniform sampler2DShadow shadowMapSpot[1];
|
||||
//!uniform mat4 LWVPSpot0;
|
||||
#endif
|
||||
#ifdef _Clusters
|
||||
//!uniform sampler2DShadow shadowMapSpot[4];
|
||||
//!uniform mat4 LWVPSpot0;
|
||||
//!uniform mat4 LWVPSpot1;
|
||||
//!uniform mat4 LWVPSpot2;
|
||||
//!uniform mat4 LWVPSpot3;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform vec2 cameraProj;
|
||||
|
|
|
@ -217,6 +217,26 @@
|
|||
"name": "LWVPSpot3",
|
||||
"link": "_biasLightWorldViewProjectionMatrixSpot3",
|
||||
"ifdef": ["_Spot", "_ShadowMap"]
|
||||
},
|
||||
{
|
||||
"name": "LWVPSpot0",
|
||||
"link": "_biasLightWorldViewProjectionMatrixSpot0",
|
||||
"ifdef": ["_LTC", "_ShadowMap"]
|
||||
},
|
||||
{
|
||||
"name": "LWVPSpot1",
|
||||
"link": "_biasLightWorldViewProjectionMatrixSpot1",
|
||||
"ifdef": ["_LTC", "_ShadowMap"]
|
||||
},
|
||||
{
|
||||
"name": "LWVPSpot2",
|
||||
"link": "_biasLightWorldViewProjectionMatrixSpot2",
|
||||
"ifdef": ["_LTC", "_ShadowMap"]
|
||||
},
|
||||
{
|
||||
"name": "LWVPSpot3",
|
||||
"link": "_biasLightWorldViewProjectionMatrixSpot3",
|
||||
"ifdef": ["_LTC", "_ShadowMap"]
|
||||
}
|
||||
],
|
||||
"vertex_shader": "../include/pass_viewray.vert.glsl",
|
||||
|
|
|
@ -47,6 +47,19 @@ uniform vec3 lightArea2;
|
|||
uniform vec3 lightArea3;
|
||||
uniform sampler2D sltcMat;
|
||||
uniform sampler2D sltcMag;
|
||||
#ifdef _ShadowMap
|
||||
#ifdef _SinglePoint
|
||||
uniform sampler2DShadow shadowMapSpot[1];
|
||||
uniform mat4 LWVPSpot0;
|
||||
#endif
|
||||
#ifdef _Clusters
|
||||
uniform sampler2DShadow shadowMapSpot[4];
|
||||
uniform mat4 LWVPSpot0;
|
||||
uniform mat4 LWVPSpot1;
|
||||
uniform mat4 LWVPSpot2;
|
||||
uniform mat4 LWVPSpot3;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, const vec3 lp, const vec3 lightCol,
|
||||
|
@ -97,6 +110,34 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _LTC
|
||||
#ifdef _ShadowMap
|
||||
#ifdef _SinglePoint
|
||||
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
|
||||
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias);
|
||||
#endif
|
||||
#ifdef _Clusters
|
||||
if (index == 0) {
|
||||
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);
|
||||
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias);
|
||||
}
|
||||
else if (index == 2) {
|
||||
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);
|
||||
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return direct;
|
||||
#endif
|
||||
|
||||
#ifdef _Spot
|
||||
if (isSpot) {
|
||||
float spotEffect = dot(spotDir, l); // lightDir
|
||||
|
|
|
@ -134,7 +134,7 @@ class Inc {
|
|||
path.currentFace = -1;
|
||||
|
||||
if (l.data.raw.type == "point") pointIndex++;
|
||||
else if (l.data.raw.type == "spot") spotIndex++;
|
||||
else if (l.data.raw.type == "spot" || l.data.raw.type == "area") spotIndex++;
|
||||
}
|
||||
|
||||
// One light at a time for now, precompute all lights for tiled
|
||||
|
|
|
@ -1486,8 +1486,6 @@ class ArmoryExporter:
|
|||
o['type'] = 'area'
|
||||
o['size'] = objref.size
|
||||
o['size_y'] = objref.size_y
|
||||
else: # Hemi
|
||||
o['type'] = 'sun'
|
||||
|
||||
o['cast_shadow'] = objref.use_shadow
|
||||
o['near_plane'] = objref.arm_clip_start
|
||||
|
|
|
@ -507,6 +507,16 @@ def make_forward(con_mesh):
|
|||
frag.add_uniform('vec3 lightArea3', '_lightArea3', included=True)
|
||||
frag.add_uniform('sampler2D sltcMat', '_ltcMat', included=True)
|
||||
frag.add_uniform('sampler2D sltcMag', '_ltcMag', included=True)
|
||||
if '_ShadowMap' in wrd.world_defs:
|
||||
if '_SinglePoint' in wrd.world_defs:
|
||||
frag.add_uniform('mat4 LWVPSpot0', link='_biasLightViewProjectionMatrixSpot0', included=True)
|
||||
frag.add_uniform('sampler2DShadow shadowMapSpot[1]', included=True)
|
||||
if '_Clusters' in wrd.world_defs:
|
||||
frag.add_uniform('mat4 LWVPSpot0', link='_biasLightWorldViewProjectionMatrixSpot0', included=True)
|
||||
frag.add_uniform('mat4 LWVPSpot1', link='_biasLightWorldViewProjectionMatrixSpot1', included=True)
|
||||
frag.add_uniform('mat4 LWVPSpot2', link='_biasLightWorldViewProjectionMatrixSpot2', included=True)
|
||||
frag.add_uniform('mat4 LWVPSpot3', link='_biasLightWorldViewProjectionMatrixSpot3', included=True)
|
||||
frag.add_uniform('sampler2DShadow shadowMapSpot[4]', included=True)
|
||||
|
||||
if not blend:
|
||||
mrt = rpdat.rp_ssr
|
||||
|
@ -664,7 +674,7 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
|||
frag.write('const vec2 smSize = shadowmapSize;')
|
||||
frag.write('svisibility = PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize);')
|
||||
frag.write('}') # receiveShadow
|
||||
if '_VoxelShadow' and '_VoxelAOvar':
|
||||
if '_VoxelShadow' in wrd.world_defs and '_VoxelAOvar' in wrd.world_defs:
|
||||
frag.write('svisibility *= 1.0 - traceShadow(voxels, voxpos, sunDir, 0.14, 5.0);')
|
||||
frag.write('direct += (lambertDiffuseBRDF(albedo, sdotNL) + specularBRDF(f0, roughness, sdotNL, sdotNH, dotNV, sdotVH) * specular) * sunCol * svisibility;')
|
||||
# sun
|
||||
|
@ -690,7 +700,7 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
|||
frag.write(' , 0, pointBias')
|
||||
if '_Spot' in wrd.world_defs:
|
||||
frag.write(' , true, spotData.x, spotData.y, spotDir')
|
||||
if '_VoxelShadow' and '_VoxelAOvar':
|
||||
if '_VoxelShadow' in wrd.world_defs and '_VoxelAOvar' in wrd.world_defs:
|
||||
frag.write(' , voxels, voxpos')
|
||||
frag.write(');')
|
||||
|
||||
|
|
Loading…
Reference in a new issue