Full BSDF

This commit is contained in:
2026-08-07 02:04:01 -07:00
parent 7aeebf2008
commit fe017dd874
55 changed files with 2306 additions and 1215 deletions

View File

@ -245,7 +245,12 @@ class LightObject extends Object {
// Snap to texel coords - fix translation swim
var smsize = data.raw.shadowmap_size;
#if lnx_csm // Cascades
smsize = Std.int(smsize / 4);
#if lnx_shadowmap_atlas
var ts = cascade < tileScale.length ? tileScale[cascade] : 1.0;
smsize = Std.int(Math.max(ts * data.raw.shadowmap_size, 1.0));
#else
smsize = Std.int(smsize / cascadeCount);
#end
#end
var worldPerTexelX = (maxx - minx) / smsize;
var worldPerTexelY = (maxy - miny) / smsize;
@ -685,22 +690,6 @@ class LightObject extends Object {
return LWVPMatrixArray;
}
public static inline function getMaxLights(): Int {
#if (rp_max_lights == 8)
return 8;
#elseif (rp_max_lights == 16)
return 16;
#elseif (rp_max_lights == 24)
return 24;
#elseif (rp_max_lights == 32)
return 32;
#elseif (rp_max_lights == 64)
return 64;
#else
return 4;
#end
}
public static inline function getMaxLightsCluster(): Int {
#if (rp_max_lights_cluster == 8)
return 8;
@ -718,6 +707,90 @@ class LightObject extends Object {
}
#end // lnx_clusters
public static inline function getMaxLights(): Int {
#if (rp_max_lights == 8)
return 8;
#elseif (rp_max_lights == 16)
return 16;
#elseif (rp_max_lights == 24)
return 24;
#elseif (rp_max_lights == 32)
return 32;
#elseif (rp_max_lights == 64)
return 64;
#else
return 4;
#end
}
#if (rp_shadowmap && lnx_shadowmap_atlas)
public static var sunTileBoundsArray: Float32Array = null;
public static var tileBoundsDirty: Bool = true;
public static function updateSunTileBoundsArray(): Float32Array {
if (!tileBoundsDirty && sunTileBoundsArray != null) return sunTileBoundsArray;
tileBoundsDirty = false;
var maxLights = getMaxLights();
var numTiles = maxLights * cascadeCount;
if (sunTileBoundsArray == null) {
sunTileBoundsArray = new Float32Array(numTiles * 4);
}
for (k in 0...sunTileBoundsArray.length) sunTileBoundsArray[k] = 0;
var i = 0;
for (light in Scene.active.lights) {
if (i >= maxLights) break;
if (!light.visible || light.data.raw.type != "sun") continue;
if (!light.data.raw.cast_shadow || light.data.raw.strength == 0.0) continue;
for (c in 0...cascadeCount) {
var idx = (i * cascadeCount + c) * 4;
sunTileBoundsArray[idx ] = light.tileOffsetX[c];
sunTileBoundsArray[idx + 2] = light.tileOffsetX[c] + light.tileScale[c];
#if (!kha_opengl)
// flip bounds to match
sunTileBoundsArray[idx + 1] = 1.0 - (light.tileOffsetY[c] + light.tileScale[c]);
sunTileBoundsArray[idx + 3] = 1.0 - light.tileOffsetY[c];
#else
sunTileBoundsArray[idx + 1] = light.tileOffsetY[c];
sunTileBoundsArray[idx + 3] = light.tileOffsetY[c] + light.tileScale[c];
#end
}
i++;
}
return sunTileBoundsArray;
}
#end
#if (rp_shadowmap && lnx_shadowmap_atlas)
public static var spotTileBoundsArray: Float32Array = null;
public static function updateSpotTileBoundsArray(): Float32Array {
var maxLights = getMaxLights();
if (spotTileBoundsArray == null) {
spotTileBoundsArray = new Float32Array(maxLights * 4);
}
for (k in 0...spotTileBoundsArray.length) spotTileBoundsArray[k] = 0;
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
i++;
}
return spotTileBoundsArray;
}
#end
public inline function right(): Vec4 {
return new Vec4(V._00, V._10, V._20);
}

View File

@ -90,7 +90,7 @@ class MeshObject extends Object {
if (tilesheet != null) tilesheet.remove();
if (Scene.active != null) Scene.active.meshes.remove(this);
#if (rp_renderer == "Deferred")
if (Scene.active != null) Scene.active.materialParamsDirty = true;
if (Scene.active != null) Scene.active.markMaterialParamsDirty();
#end
data.refcount--;
super.remove();

View File

@ -827,9 +827,20 @@ class Uniforms {
}
}
case "_shadowMapSize": {
if (light != null && light.data.raw.cast_shadow) {
var shadowLight = light;
if (shadowLight == null || !shadowLight.data.raw.cast_shadow) {
shadowLight = RenderPath.active.sun;
}
if (shadowLight != null && shadowLight.data.raw.cast_shadow) {
v = helpVec;
v.x = v.y = light.data.raw.shadowmap_size;
v.x = v.y = shadowLight.data.raw.shadowmap_size;
#if lnx_csm
#if (!lnx_shadowmap_atlas)
if (shadowLight.data.raw.type == "sun") {
v.x = shadowLight.data.raw.shadowmap_size * LightObject.cascadeCount;
}
#end
#end
}
}
default:
@ -887,9 +898,11 @@ class Uniforms {
case "_envmapIrradiance": {
fa = Scene.active.world == null ? WorldData.getEmptyIrradiance() : Scene.active.world.probe.irradiance;
}
case "_materialParams": {
#if (rp_renderer == "Deferred")
case "_materialParams": {
fa = Scene.active.materialParamsBuffer;
}
#end
#if lnx_clusters
case "_lightsArray": {
fa = LightObject.lightsArray;
@ -906,15 +919,18 @@ class Uniforms {
#end
#end // lnx_clusters
#if lnx_csm
case "_cascadeData": {
for (l in Scene.active.lights) {
if (l.data.raw.type == "sun") {
fa = l.getCascadeData();
break;
}
}
case "_cascadeData": {
var sun = RenderPath.active.sun;
if (sun != null && sun.data.raw.type == "sun") {
fa = sun.getCascadeData();
}
#end
}
#end
#if lnx_shadowmap_atlas
case "_tileBoundsSunArray": {
fa = LightObject.updateSunTileBoundsArray();
}
#end
}
if (fa != null) {
@ -1067,32 +1083,30 @@ class Uniforms {
}
}
case "_biasLightWorldViewProjectionMatrixSun": {
for (l in iron.Scene.active.lights) {
if (l.data.raw.type == "sun") {
// object is null for DrawQuad
object == null ? helpMat.setIdentity() : helpMat.setFrom(object.transform.worldUnpack);
helpMat.multmat(l.VP);
helpMat.multmat(biasMat);
#if lnx_shadowmap_atlas
// tile matrix
helpMat2.setIdentity();
// scale [0-1] coords to [0-tilescale]
helpMat2._00 = l.tileScale[0];
helpMat2._11 = l.tileScale[0];
// offset coordinate start from [0, 0] to [tile-start-x, tile-start-y]
helpMat2._30 = l.tileOffsetX[0];
helpMat2._31 = l.tileOffsetY[0];
helpMat.multmat(helpMat2);
#if (!kha_opengl)
helpMat2.setIdentity();
helpMat2._11 = -1.0;
helpMat2._31 = 1.0;
helpMat.multmat(helpMat2);
#end
#end
m = helpMat;
break;
}
var sun = RenderPath.active.sun;
if (sun != null && sun.data.raw.type == "sun") {
// object is null for DrawQuad
object == null ? helpMat.setIdentity() : helpMat.setFrom(object.transform.worldUnpack);
helpMat.multmat(sun.VP);
helpMat.multmat(biasMat);
#if lnx_shadowmap_atlas
// tile matrix
helpMat2.setIdentity();
// scale [0-1] coords to [0-tilescale]
helpMat2._00 = sun.tileScale[0];
helpMat2._11 = sun.tileScale[0];
// offset coordinate start from [0, 0] to [tile-start-x, tile-start-y]
helpMat2._30 = sun.tileOffsetX[0];
helpMat2._31 = sun.tileOffsetY[0];
helpMat.multmat(helpMat2);
#if (!kha_opengl)
helpMat2.setIdentity();
helpMat2._11 = -1.0;
helpMat2._31 = 1.0;
helpMat.multmat(helpMat2);
#end
#end
m = helpMat;
}
}
#if rp_probes
@ -1376,7 +1390,7 @@ class Uniforms {
if (fa == null) return;
g.setFloats(location, fa);
}
else if (c.type == "int") {
else if (c.type == "int" || c.type == "uint") {
var i: Null<Int> = null;
switch (c.link) {
case "_uid": {