Scaled slope bias and transparent shadows fixes

This commit is contained in:
2026-10-31 01:10:21 -07:00
parent 29f0765864
commit f45ad72056
15 changed files with 126 additions and 48 deletions

View File

@ -674,7 +674,7 @@ class LightObject extends Object {
break;
}
if (discardLightCulled(light)) continue;
if (light.data.raw.type == type) {
if (light.data.raw.type == type || (type == "spot" && light.data.raw.type == "area")) {
m.setFrom(light.VP);
m.multmat(Uniforms.biasMat);
#if lnx_shadowmap_atlas
@ -711,8 +711,8 @@ class LightObject extends Object {
LWVPMatrixArray[i * 16 + 13] = m._31;
LWVPMatrixArray[i * 16 + 14] = m._32;
LWVPMatrixArray[i * 16 + 15] = m._33;
i++; // only increment in light type
}
}
i++;
}
return LWVPMatrixArray;
}
@ -791,7 +791,7 @@ class LightObject extends Object {
public static var spotTileBoundsArray: Float32Array = null;
public static function updateSpotTileBoundsArray(): Float32Array {
var maxLights = getMaxLights();
var maxLights = maxLightsCluster;
if (spotTileBoundsArray == null) {
spotTileBoundsArray = new Float32Array(maxLights * 4);
}
@ -799,19 +799,20 @@ class LightObject extends Object {
var i = 0;
for (light in Scene.active.lights) {
if (i >= maxLights) break;
if (!light.visible || light.data.raw.type != "spot") continue;
if (!light.data.raw.cast_shadow || light.data.raw.strength == 0.0) continue;
var idx = i * 4;
spotTileBoundsArray[idx ] = light.tileOffsetX[0];
spotTileBoundsArray[idx + 2] = light.tileOffsetX[0] + light.tileScale[0];
#if (!kha_opengl)
// flip bounds
spotTileBoundsArray[idx + 1] = 1.0 - (light.tileOffsetY[0] + light.tileScale[0]);
spotTileBoundsArray[idx + 3] = 1.0 - light.tileOffsetY[0];
#else
spotTileBoundsArray[idx + 1] = light.tileOffsetY[0];
spotTileBoundsArray[idx + 3] = light.tileOffsetY[0] + light.tileScale[0];
#end
if (discardLightCulled(light)) continue;
if ((light.data.raw.type == "spot" || light.data.raw.type == "area") && light.data.raw.cast_shadow) {
var idx = i * 4;
spotTileBoundsArray[idx ] = light.tileOffsetX[0];
spotTileBoundsArray[idx + 2] = light.tileOffsetX[0] + light.tileScale[0];
#if (!kha_opengl)
// flip bounds
spotTileBoundsArray[idx + 1] = 1.0 - (light.tileOffsetY[0] + light.tileScale[0]);
spotTileBoundsArray[idx + 3] = 1.0 - light.tileOffsetY[0];
#else
spotTileBoundsArray[idx + 1] = light.tileOffsetY[0];
spotTileBoundsArray[idx + 3] = light.tileOffsetY[0] + light.tileScale[0];
#end
}
i++;
}
return spotTileBoundsArray;

View File

@ -928,6 +928,14 @@ class Uniforms {
case "_tileBoundsSunArray": {
fa = LightObject.updateSunTileBoundsArray();
}
case "_tileBoundsSpotArray": {
fa = LightObject.updateSpotTileBoundsArray();
}
#end
#if (!lnx_clusters && lnx_spot)
case "_biasLightWorldViewProjectionMatrixSpotArray": {
fa = updateSpotMatrixFloats();
}
#end
}
@ -1387,6 +1395,11 @@ class Uniforms {
fa = LightObject.updateLWVPMatrixArray(object, "spot");
}
#end // lnx_clusters
#if (!lnx_clusters && lnx_spot)
case "_biasLightWorldViewProjectionMatrixSpotArray": {
fa = updateSpotMatrixFloats();
}
#end
#if lnx_morph_target
case "_morphWeights": {
fa = cast(object, MeshObject).morphTarget.morphWeights;
@ -1473,6 +1486,32 @@ class Uniforms {
}
return null;
}
static var spotMatrixFloats: Float32Array = null;
static function updateSpotMatrixFloats(): Float32Array {
var light = getSpot(0);
if (light == null) return null;
if (spotMatrixFloats == null) spotMatrixFloats = new Float32Array(16);
helpMat.setFrom(light.VP);
helpMat.multmat(biasMat);
spotMatrixFloats[0 ] = helpMat._00;
spotMatrixFloats[1 ] = helpMat._01;
spotMatrixFloats[2 ] = helpMat._02;
spotMatrixFloats[3 ] = helpMat._03;
spotMatrixFloats[4 ] = helpMat._10;
spotMatrixFloats[5 ] = helpMat._11;
spotMatrixFloats[6 ] = helpMat._12;
spotMatrixFloats[7 ] = helpMat._13;
spotMatrixFloats[8 ] = helpMat._20;
spotMatrixFloats[9 ] = helpMat._21;
spotMatrixFloats[10] = helpMat._22;
spotMatrixFloats[11] = helpMat._23;
spotMatrixFloats[12] = helpMat._30;
spotMatrixFloats[13] = helpMat._31;
spotMatrixFloats[14] = helpMat._32;
spotMatrixFloats[15] = helpMat._33;
return spotMatrixFloats;
}
#end
static function currentMat(object: Object): MaterialData {

View File

@ -171,7 +171,7 @@ class Inc {
var t = new RenderTargetRaw();
t.name = name;
t.width = t.height = size;
t.format = transparent ? "RGBA64" : "DEPTH16";
t.format = transparent ? "RGBA128" : "DEPTH16";
return path.createRenderTarget(t);
}
@ -498,7 +498,7 @@ class Inc {
t.name = target;
t.width = sizew;
t.height = sizeh;
t.format = transparent ? "RGBA64" : "DEPTH16";
t.format = transparent ? "RGBA128" : "DEPTH16";
rt = path.createRenderTarget(t);
}
}

View File

@ -540,7 +540,7 @@ class RenderPathDeferred {
t2.name = "empty_shadowmap_transparent";
t2.width = 1;
t2.height = 1;
t2.format = "RGBA64";
t2.format = "RGBA128";
path.createRenderTarget(t2);
path.setTarget("empty_shadowmap_transparent");
path.currentG.clear(0xffffffff, null);