Full BSDF
This commit is contained in:
@ -304,10 +304,13 @@ class RenderPath {
|
||||
currentD = 1;
|
||||
currentFace = -1;
|
||||
meshesSorted = false;
|
||||
sun = null;
|
||||
|
||||
for (l in Scene.active.lights) {
|
||||
if (l.visible) l.buildMatrix(Scene.active.camera);
|
||||
if (l.data.raw.type == "sun") sun = l;
|
||||
if (l.data.raw.type == "sun") {
|
||||
if (sun == null || (!sun.data.raw.cast_shadow && l.data.raw.cast_shadow)) sun = l;
|
||||
}
|
||||
else point = l;
|
||||
}
|
||||
light = Scene.active.lights[0];
|
||||
@ -500,7 +503,7 @@ class RenderPath {
|
||||
}
|
||||
|
||||
public function drawMeshes(context: String) {
|
||||
var isShadows = context == "shadowmap";
|
||||
var isShadows = context == "shadowmap" || context == "shadowmap_transparent";
|
||||
if (isShadows) {
|
||||
// Disabled shadow casting for this light
|
||||
if (light == null || !light.data.raw.cast_shadow || !light.visible || light.data.raw.strength == 0) return;
|
||||
|
||||
@ -72,6 +72,8 @@ class Scene {
|
||||
public var embedded: Map<String, kha.Image>;
|
||||
|
||||
#if (rp_renderer == "Deferred")
|
||||
public static inline var MAX_MATERIALS = 16;
|
||||
public static inline var FLOATS_PER_MATERIAL_PARAM = 32; // 8 vec4s per material
|
||||
public var materialParamsBuffer: kha.arrays.Float32Array;
|
||||
public var materialParamsDirty: Bool = true;
|
||||
#end
|
||||
@ -113,7 +115,7 @@ class Scene {
|
||||
#end
|
||||
embedded = new Map();
|
||||
#if (rp_renderer == "Deferred")
|
||||
materialParamsBuffer = new kha.arrays.Float32Array(512);
|
||||
materialParamsBuffer = new kha.arrays.Float32Array(MAX_MATERIALS * FLOATS_PER_MATERIAL_PARAM);
|
||||
#end
|
||||
root = new Object();
|
||||
root.name = "Root";
|
||||
@ -213,11 +215,14 @@ class Scene {
|
||||
}
|
||||
|
||||
#if (rp_renderer == "Deferred")
|
||||
public function markMaterialParamsDirty() {
|
||||
materialParamsDirty = true;
|
||||
}
|
||||
|
||||
public function updateMaterialParams() {
|
||||
if (!materialParamsDirty) return;
|
||||
materialParamsDirty = false;
|
||||
var buf = materialParamsBuffer;
|
||||
for (i in 0...buf.length) buf[i] = 0.0;
|
||||
for (m in meshes) {
|
||||
if (m.materials == null) continue;
|
||||
for (mat in m.materials) {
|
||||
@ -237,12 +242,16 @@ class Scene {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (slot <= 0 || slot >= 16) continue;
|
||||
var base = slot * 32;
|
||||
if (base + 31 >= buf.length) continue;
|
||||
if (slot < 0 || slot >= MAX_MATERIALS) continue;
|
||||
var base = slot * FLOATS_PER_MATERIAL_PARAM;
|
||||
if (base + FLOATS_PER_MATERIAL_PARAM - 1 >= buf.length) continue;
|
||||
if (bc == null) continue;
|
||||
for (i in 0...FLOATS_PER_MATERIAL_PARAM) buf[base + i] = 0.0;
|
||||
buf[base + 6] = 1.5; // coatIOR
|
||||
buf[base + 12] = 1.45; // ior
|
||||
buf[base + 13] = 1.0; // thinWall
|
||||
for (c in bc) {
|
||||
if (c == null || c.name == null) continue;
|
||||
if (c == null || c.name == null || c.floatValue == null) continue;
|
||||
switch (c.name) {
|
||||
// matp0: vec4(anisotropy, anisoRot, sheen, sheenRough)
|
||||
case "anisotropy": buf[base + 0] = c.floatValue;
|
||||
@ -274,8 +283,13 @@ class Scene {
|
||||
case "subsurfaceColorB": buf[base + 21] = c.floatValue;
|
||||
case "sheenTintR": buf[base + 22] = c.floatValue;
|
||||
case "sheenTintG": buf[base + 23] = c.floatValue;
|
||||
// matp6: vec4(sheenTintB, 0, 0, 0)
|
||||
// matp6: vec4(sheenTintB, specularTintR, specularTintG, specularTintB)
|
||||
case "sheenTintB": buf[base + 24] = c.floatValue;
|
||||
case "specularTintR": buf[base + 25] = c.floatValue;
|
||||
case "specularTintG": buf[base + 26] = c.floatValue;
|
||||
case "specularTintB": buf[base + 27] = c.floatValue;
|
||||
// matp7: vec4(subsurfaceScale, 0, 0, 0)
|
||||
case "subsurfaceScale": buf[base + 28] = c.floatValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -431,7 +445,7 @@ class Scene {
|
||||
var object = new MeshObject(data, materials);
|
||||
parent != null ? object.setParent(parent) : object.setParent(root);
|
||||
#if (rp_renderer == "Deferred")
|
||||
materialParamsDirty = true;
|
||||
markMaterialParamsDirty();
|
||||
#end
|
||||
return object;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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": {
|
||||
|
||||
@ -39,7 +39,6 @@ class Inc {
|
||||
#if (rp_voxels == "Voxel GI")
|
||||
static var voxel_td1:kha.graphics4.TextureUnit;
|
||||
static var voxel_te1:kha.graphics4.TextureUnit;
|
||||
static var voxel_cc1:kha.graphics4.ConstantLocation;
|
||||
#else
|
||||
#if lnx_voxelgi_shadows
|
||||
static var voxel_te1:kha.graphics4.TextureUnit;
|
||||
@ -137,18 +136,22 @@ class Inc {
|
||||
break;
|
||||
if (LightObject.discardLightCulled(light)) continue;
|
||||
if (light.data.raw.type == "point") {
|
||||
if (!light.data.raw.cast_shadow) {
|
||||
if (light.data.raw.cast_shadow) {
|
||||
for(k in 0...6) {
|
||||
LightObject.pointLightsData[j ] = light.tileOffsetX[k]; // posx
|
||||
LightObject.pointLightsData[j + 1] = light.tileOffsetY[k]; // posy
|
||||
LightObject.pointLightsData[j + 2] = light.tileScale[k]; // tile scale factor relative to atlas
|
||||
LightObject.pointLightsData[j + 3] = 0; // padding
|
||||
j += 4;
|
||||
}
|
||||
}
|
||||
else {
|
||||
j += 4 * 6;
|
||||
continue;
|
||||
}
|
||||
for(k in 0...6) {
|
||||
LightObject.pointLightsData[j ] = light.tileOffsetX[k]; // posx
|
||||
LightObject.pointLightsData[j + 1] = light.tileOffsetY[k]; // posy
|
||||
LightObject.pointLightsData[j + 2] = light.tileScale[k]; // tile scale factor relative to atlas
|
||||
LightObject.pointLightsData[j + 3] = 0; // padding
|
||||
j += 4;
|
||||
}
|
||||
}
|
||||
else {
|
||||
j += 4 * 6; // Reserve slot for non-point lights to keep index aligned
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -214,11 +217,13 @@ class Inc {
|
||||
if (!light.lightInAtlas && !light.culledLight && light.visible && light.shadowMapScale > 0.0
|
||||
&& light.data.raw.strength > 0.0 && light.data.raw.cast_shadow) {
|
||||
ShadowMapAtlas.addLight(light, false);
|
||||
LightObject.tileBoundsDirty = true;
|
||||
}
|
||||
#if rp_shadowmap_transparent
|
||||
if (!light.lightInAtlasTransparent && !light.culledLight && light.visible && light.shadowMapScale > 0.0
|
||||
&& light.data.raw.strength > 0.0 && light.data.raw.cast_shadow) {
|
||||
ShadowMapAtlas.addLight(light, true);
|
||||
LightObject.tileBoundsDirty = true;
|
||||
}
|
||||
#end
|
||||
}
|
||||
@ -308,6 +313,7 @@ class Inc {
|
||||
var newTile = ShadowMapTile.assignTiles(tile.light, atlas, tile);
|
||||
if (newTile != null)
|
||||
atlas.activeTiles.push(newTile);
|
||||
LightObject.tileBoundsDirty = true;
|
||||
}
|
||||
updatePointLightAtlasData(false);
|
||||
#end
|
||||
@ -315,6 +321,7 @@ class Inc {
|
||||
for (tile in tilesToRemove) {
|
||||
atlas.activeTiles.remove(tile);
|
||||
tile.freeTile();
|
||||
LightObject.tileBoundsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,6 +412,7 @@ class Inc {
|
||||
var newTile = ShadowMapTile.assignTiles(tile.light, atlas, tile);
|
||||
if (newTile != null)
|
||||
atlas.activeTiles.push(newTile);
|
||||
LightObject.tileBoundsDirty = true;
|
||||
}
|
||||
updatePointLightAtlasData(true);
|
||||
#end
|
||||
@ -412,6 +420,7 @@ class Inc {
|
||||
for (tile in tilesToRemove) {
|
||||
atlas.activeTiles.remove(tile);
|
||||
tile.freeTile();
|
||||
LightObject.tileBoundsDirty = true;
|
||||
}
|
||||
}
|
||||
#end
|
||||
@ -419,25 +428,30 @@ class Inc {
|
||||
}
|
||||
#else
|
||||
public static function bindShadowMap() {
|
||||
for (l in iron.Scene.active.lights) {
|
||||
if (!l.visible || l.data.raw.type != "sun") continue;
|
||||
var sun = RenderPath.active.sun;
|
||||
if (sun != null && sun.visible && sun.data.raw.type == "sun") {
|
||||
var n = "shadowMap";
|
||||
path.bindTarget(n, n);
|
||||
#if rp_shadowmap_transparent
|
||||
var n = "shadowMapTransparent";
|
||||
path.bindTarget(n, n);
|
||||
break;
|
||||
#end
|
||||
}
|
||||
for (i in 0...pointIndex) {
|
||||
var n = "shadowMapPoint[" + i + "]";
|
||||
path.bindTarget(n, n);
|
||||
#if rp_shadowmap_transparent
|
||||
var n = "shadowMapPointTransparent[" + i + "]";
|
||||
path.bindTarget(n, n);
|
||||
#end
|
||||
}
|
||||
for (i in 0...spotIndex) {
|
||||
var n = "shadowMapSpot[" + i + "]";
|
||||
path.bindTarget(n, n);
|
||||
#if rp_shadowmap_transparent
|
||||
var n = "shadowMapSpotTransparent[" + i + "]";
|
||||
path.bindTarget(n, n);
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
@ -500,6 +514,7 @@ class Inc {
|
||||
spotIndex = 0;
|
||||
for (l in iron.Scene.active.lights) {
|
||||
if (!l.visible) continue;
|
||||
if (l.data.raw.type == "sun" && l != RenderPath.active.sun) continue;
|
||||
|
||||
path.light = l;
|
||||
var shadowmap = Inc.getShadowMap(l, false);
|
||||
@ -523,6 +538,7 @@ class Inc {
|
||||
spotIndex = 0;
|
||||
for (l in iron.Scene.active.lights) {
|
||||
if (!l.visible) continue;
|
||||
if (l.data.raw.type == "sun" && l != RenderPath.active.sun) continue;
|
||||
|
||||
path.light = l;
|
||||
var shadowmap_transparent = Inc.getShadowMap(l, true);
|
||||
@ -719,7 +735,7 @@ class Inc {
|
||||
#else
|
||||
t.format = "RGBA32";
|
||||
#end
|
||||
t.width = res * (6 + 16);
|
||||
t.width = res * (6 + Main.diffuseConeCount);
|
||||
t.height = res * Main.voxelgiClipmapCount;
|
||||
t.depth = res;
|
||||
}
|
||||
@ -840,12 +856,10 @@ class Inc {
|
||||
|
||||
voxel_ca1 = voxel_sh1.getConstantLocation("clipmaps");
|
||||
voxel_cb1 = voxel_sh1.getConstantLocation("clipmapLevel");
|
||||
voxel_cc1 = voxel_sh1.getConstantLocation("envmapStrength");
|
||||
|
||||
#if (rp_voxels == "Voxel GI")
|
||||
voxel_td1 = voxel_sh1.getTextureUnit("voxelsSampler");
|
||||
voxel_te1 = voxel_sh1.getTextureUnit("SDF");
|
||||
voxel_cc1 = voxel_sh1.getConstantLocation("envmapStrength");
|
||||
#else
|
||||
#if lnx_voxelgi_shadows
|
||||
voxel_te1 = voxel_sh1.getTextureUnit("SDF");
|
||||
@ -884,9 +898,11 @@ class Inc {
|
||||
#if lnx_brdf
|
||||
voxel_tg3 = voxel_sh3.getTextureUnit("senvmapBrdf");
|
||||
#end
|
||||
#if (rp_voxels == "Voxel AO")
|
||||
#if lnx_radiance
|
||||
voxel_th3 = voxel_sh3.getTextureUnit("senvmapRadiance");
|
||||
#end
|
||||
#end
|
||||
voxel_ca3 = voxel_sh3.getConstantLocation("clipmaps");
|
||||
voxel_cb3 = voxel_sh3.getConstantLocation("InvVP");
|
||||
voxel_cc3 = voxel_sh3.getConstantLocation("eye");
|
||||
@ -895,12 +911,14 @@ class Inc {
|
||||
#if lnx_irradiance
|
||||
voxel_cf3 = voxel_sh3.getConstantLocation("shirr");
|
||||
#end
|
||||
#if (rp_voxels == "Voxel AO")
|
||||
#if lnx_radiance
|
||||
voxel_cg3 = voxel_sh3.getConstantLocation("envmapNumMipmaps");
|
||||
#end
|
||||
#if lnx_envcol
|
||||
voxel_ch3 = voxel_sh3.getConstantLocation("backgroundCol");
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
#if (rp_voxels == "Voxel GI")
|
||||
if (voxel_sh4 == null)
|
||||
@ -988,7 +1006,6 @@ class Inc {
|
||||
#if (rp_voxels == "Voxel GI")
|
||||
g.setTexture(voxel_td1, rts.get("voxelsOutB").image);
|
||||
g.setImageTexture(voxel_te1, rts.get("voxelsSDF").image);
|
||||
g.setFloat(voxel_cc1, iron.Scene.active.world == null ? 0.0 : iron.Scene.active.world.probe.raw.strength);
|
||||
#else
|
||||
#if lnx_voxelgi_shadows
|
||||
g.setImageTexture(voxel_te1, rts.get("voxelsSDF").image);
|
||||
@ -1001,8 +1018,6 @@ class Inc {
|
||||
|
||||
g.setInt(voxel_cb1, iron.RenderPath.clipmapLevel);
|
||||
|
||||
g.setFloat(voxel_cc1, iron.Scene.active.world == null ? 0.0 : iron.Scene.active.world.probe.raw.strength);
|
||||
|
||||
g.compute(Std.int(res / 8), Std.int(res / 8), Std.int(res / 8));
|
||||
}
|
||||
|
||||
@ -1163,9 +1178,6 @@ class Inc {
|
||||
#if lnx_brdf
|
||||
g.setTexture(voxel_tg3, iron.Scene.active.embedded.get("brdf.png"));
|
||||
#end
|
||||
#if lnx_radiance
|
||||
g.setTexture(voxel_th3, iron.Scene.active.world.probe.radiance);
|
||||
#end
|
||||
|
||||
var fa = fillVoxelClipmapsArray(clipmaps);
|
||||
|
||||
@ -1205,28 +1217,12 @@ class Inc {
|
||||
iron.Scene.active.world.probe.irradiance;
|
||||
g.setFloats(voxel_cf3, irradiance);
|
||||
#end
|
||||
#if lnx_radiance
|
||||
g.setFloat(voxel_cg3, iron.Scene.active.world != null ? iron.Scene.active.world.probe.raw.radiance_mipmaps + 1 - 2 : 1);
|
||||
#end
|
||||
|
||||
#if lnx_envcol
|
||||
var x: kha.FastFloat = 0.0;
|
||||
var y: kha.FastFloat = 0.0;
|
||||
var z: kha.FastFloat = 0.0;
|
||||
|
||||
if (camera.data.raw.clear_color != null) {
|
||||
x = camera.data.raw.clear_color[0];
|
||||
y = camera.data.raw.clear_color[1];
|
||||
z = camera.data.raw.clear_color[2];
|
||||
}
|
||||
|
||||
g.setFloat3(voxel_ch3, x, y, z);
|
||||
#end
|
||||
|
||||
g.compute(Std.int((width + 7) / 8), Std.int((height + 7) / 8), 1);
|
||||
}
|
||||
#end
|
||||
|
||||
#if (rp_voxels == "Voxel GI")
|
||||
public static function resolveSpecular(g: kha.graphics4.Graphics) {
|
||||
var rts = path.renderTargets;
|
||||
var res = iron.RenderPath.getVoxelRes();
|
||||
@ -1278,6 +1274,7 @@ class Inc {
|
||||
|
||||
g.compute(Std.int((width + 7) / 8), Std.int((height + 7) / 8), 1);
|
||||
}
|
||||
#end
|
||||
|
||||
#if (rp_voxels == "Voxel GI")
|
||||
#end // GI
|
||||
|
||||
@ -27,7 +27,7 @@ class RenderPathDeferred {
|
||||
#if rp_gbuffer2 "gbuffer2", #end
|
||||
#if rp_gbuffer_emission "gbuffer_emission", #end
|
||||
#if (rp_ssrefr || lnx_voxelgi_refract) "gbuffer_refraction", #end
|
||||
#if lnx_anisotropy "gbuffer3" #end
|
||||
#if rp_clearcoat "gbuffer_coat_normal", #end
|
||||
]);
|
||||
}
|
||||
|
||||
@ -155,7 +155,11 @@ class RenderPathDeferred {
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = Inc.getDisplayp();
|
||||
#if rp_hdr
|
||||
t.format = "RGBA64";
|
||||
#else
|
||||
t.format = "RGBA32";
|
||||
#end
|
||||
t.scale = Inc.getSuperSampling();
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
@ -174,19 +178,6 @@ class RenderPathDeferred {
|
||||
}
|
||||
#end
|
||||
|
||||
#if lnx_anisotropy
|
||||
{
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "gbuffer3";
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = Inc.getDisplayp();
|
||||
t.format = "RGBA64";
|
||||
t.scale = Inc.getSuperSampling();
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
#end
|
||||
|
||||
#if rp_material_solid
|
||||
path.loadShader("shader_datas/deferred_light_solid/deferred_light");
|
||||
#elseif rp_material_mobile
|
||||
@ -295,7 +286,7 @@ class RenderPathDeferred {
|
||||
}
|
||||
#end
|
||||
|
||||
#if ((rp_antialiasing == "SMAA") || (rp_antialiasing == "TAA") || rp_fsr1)
|
||||
#if ((rp_antialiasing == "SMAA") || (rp_antialiasing == "TAA") || rp_fsr1 || (rp_ssr && !rp_ssr_half))
|
||||
{
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "bufa";
|
||||
@ -422,6 +413,19 @@ class RenderPathDeferred {
|
||||
}
|
||||
#end
|
||||
|
||||
#if rp_clearcoat
|
||||
{
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "gbuffer_coat_normal";
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = Inc.getDisplayp();
|
||||
t.format = "RGBA64";
|
||||
t.scale = Inc.getSuperSampling();
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
#end
|
||||
|
||||
#if (rp_ssrefr || lnx_voxelgi_refract)
|
||||
{
|
||||
var t = new RenderTargetRaw();
|
||||
@ -429,7 +433,7 @@ class RenderPathDeferred {
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = Inc.getDisplayp();
|
||||
t.format = "RGBA64";
|
||||
t.format = "RGBA32";
|
||||
t.scale = Inc.getSuperSampling();
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
@ -569,7 +573,14 @@ class RenderPathDeferred {
|
||||
#if (rp_ssrefr || lnx_voxelgi_refract)
|
||||
{
|
||||
path.setTarget("gbuffer_refraction");
|
||||
path.clearTarget(0xffff00ff);
|
||||
path.clearTarget(0x000000ff);
|
||||
}
|
||||
#end
|
||||
|
||||
#if rp_clearcoat
|
||||
{
|
||||
path.setTarget("gbuffer_coat_normal");
|
||||
path.clearTarget(0x00000000);
|
||||
}
|
||||
#end
|
||||
|
||||
@ -580,12 +591,6 @@ class RenderPathDeferred {
|
||||
}
|
||||
#end
|
||||
|
||||
#if lnx_anisotropy
|
||||
{
|
||||
path.setTarget("gbuffer3");
|
||||
path.clearTarget(0x00000000);
|
||||
}
|
||||
#end
|
||||
|
||||
RenderPathCreator.setTargetMeshes();
|
||||
|
||||
@ -782,8 +787,10 @@ class RenderPathDeferred {
|
||||
}
|
||||
#end
|
||||
|
||||
#if lnx_anisotropy
|
||||
path.bindTarget("gbuffer3", "gbuffer3");
|
||||
#if rp_clearcoat
|
||||
{
|
||||
path.bindTarget("gbuffer_coat_normal", "gbufferCoatNormal");
|
||||
}
|
||||
#end
|
||||
|
||||
#if rp_ssao
|
||||
@ -849,6 +856,7 @@ class RenderPathDeferred {
|
||||
#end
|
||||
|
||||
#if rp_material_solid
|
||||
Scene.active.updateMaterialParams();
|
||||
path.drawShader("shader_datas/deferred_light_solid/deferred_light");
|
||||
#elseif rp_material_mobile
|
||||
Scene.active.updateMaterialParams();
|
||||
@ -910,7 +918,10 @@ class RenderPathDeferred {
|
||||
|
||||
#if rp_water
|
||||
{
|
||||
#if (!kha_opengl)
|
||||
path.setDepthFrom("tex", "gbuffer1");
|
||||
#end
|
||||
|
||||
path.setTarget("buf");
|
||||
path.bindTarget("tex", "tex");
|
||||
path.drawShader("shader_datas/copy_pass/copy_pass");
|
||||
@ -918,7 +929,10 @@ class RenderPathDeferred {
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("buf", "tex");
|
||||
path.drawShader("shader_datas/water_pass/water_pass");
|
||||
|
||||
#if (!kha_opengl)
|
||||
path.setDepthFrom("tex", "gbuffer0");
|
||||
#end
|
||||
}
|
||||
#end
|
||||
|
||||
@ -934,7 +948,7 @@ class RenderPathDeferred {
|
||||
var targetb = "ssrb";
|
||||
#else
|
||||
var targeta = "buf";
|
||||
var targetb = "gbuffer1";
|
||||
var targetb = "bufa";
|
||||
#end
|
||||
|
||||
path.setTarget(targeta);
|
||||
@ -952,11 +966,21 @@ class RenderPathDeferred {
|
||||
path.setTarget(targetb);
|
||||
path.bindTarget(targeta, "tex");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
#if rp_ssr_half
|
||||
path.bindTarget("half", "gbufferD");
|
||||
#else
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
#end
|
||||
path.drawShader("shader_datas/blur_adaptive_pass/blur_adaptive_pass_x");
|
||||
|
||||
path.setTarget("tex");
|
||||
path.bindTarget(targetb, "tex");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
#if rp_ssr_half
|
||||
path.bindTarget("half", "gbufferD");
|
||||
#else
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
#end
|
||||
path.drawShader("shader_datas/blur_adaptive_pass/blur_adaptive_pass_y3_blend");
|
||||
|
||||
#if (!kha_opengl)
|
||||
@ -976,12 +1000,14 @@ class RenderPathDeferred {
|
||||
path.bindTarget("tex", "tex");
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("gbuffer1", "gbuffer1");
|
||||
path.drawShader("shader_datas/sss_pass/sss_pass_x");
|
||||
|
||||
path.setTarget("tex");
|
||||
path.bindTarget("buf", "tex");
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("gbuffer1", "gbuffer1");
|
||||
path.drawShader("shader_datas/sss_pass/sss_pass_y");
|
||||
|
||||
#if (!kha_opengl)
|
||||
@ -994,20 +1020,20 @@ class RenderPathDeferred {
|
||||
{
|
||||
if (leenkx.data.Config.raw.rp_ssrefr != false)
|
||||
{
|
||||
//#if (!kha_opengl)
|
||||
//path.setDepthFrom("gbuffer0", "gbuffer1"); // Unbind depth so we can read it
|
||||
//path.depthToRenderTarget.set("main", path.renderTargets.get("tex"));
|
||||
//#end
|
||||
#if (!kha_opengl)
|
||||
path.setDepthFrom("gbuffer0", "gbuffer1"); // Unbind depth so we can read it
|
||||
path.depthToRenderTarget.set("main", path.renderTargets.get("tex"));
|
||||
#end
|
||||
|
||||
//save depth
|
||||
path.setTarget("gbufferD1");
|
||||
path.bindTarget("_main", "tex");
|
||||
path.drawShader("shader_datas/copy_pass/copy_pass");
|
||||
|
||||
//#if (!kha_opengl)
|
||||
//path.setDepthFrom("gbuffer0", "tex"); // Re-bind depth
|
||||
//path.depthToRenderTarget.set("main", path.renderTargets.get("gbuffer0"));
|
||||
//#end
|
||||
#if (!kha_opengl)
|
||||
path.setDepthFrom("gbuffer0", "tex"); // Re-bind depth
|
||||
path.depthToRenderTarget.set("main", path.renderTargets.get("gbuffer0"));
|
||||
#end
|
||||
|
||||
//save background color
|
||||
path.setTarget("refr");
|
||||
@ -1043,6 +1069,7 @@ class RenderPathDeferred {
|
||||
path.bindTarget("tex", "tex");
|
||||
path.bindTarget("gbufferD1", "gbufferD1");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("gbuffer1", "gbuffer1");
|
||||
path.bindTarget("refr", "tex1");
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer_refraction", "gbuffer_refraction");
|
||||
|
||||
@ -130,7 +130,7 @@ class RenderPathForward {
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = Inc.getDisplayp();
|
||||
t.format = "RGBA64";
|
||||
t.format = "RGBA32";
|
||||
t.scale = Inc.getSuperSampling();
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
@ -489,7 +489,7 @@ class RenderPathForward {
|
||||
#if (rp_ssrefr || lnx_voxelgi_refract)
|
||||
{
|
||||
path.setTarget("gbuffer_refraction");
|
||||
path.clearTarget(0xffffff00);
|
||||
path.clearTarget(0x00000000);
|
||||
}
|
||||
#end
|
||||
|
||||
@ -645,11 +645,21 @@ class RenderPathForward {
|
||||
path.setTarget(targetb);
|
||||
path.bindTarget(targeta, "tex");
|
||||
path.bindTarget("lbuffer1", "gbuffer0");
|
||||
#if rp_ssr_half
|
||||
path.bindTarget("half", "gbufferD");
|
||||
#else
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
#end
|
||||
path.drawShader("shader_datas/blur_adaptive_pass/blur_adaptive_pass_x");
|
||||
|
||||
path.setTarget("lbuffer0");
|
||||
path.bindTarget(targetb, "tex");
|
||||
path.bindTarget("lbuffer1", "gbuffer0");
|
||||
#if rp_ssr_half
|
||||
path.bindTarget("half", "gbufferD");
|
||||
#else
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
#end
|
||||
path.drawShader("shader_datas/blur_adaptive_pass/blur_adaptive_pass_y3_blend");
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class UniformsManager extends Trait{
|
||||
static var texturesRegistered = false;
|
||||
static var texturesMap = new Map<Object, Map<MaterialData, Map<String, kha.Image>>>();
|
||||
|
||||
static var sceneRemoveInitalized = false;
|
||||
static var sceneRemoveInitialized = false;
|
||||
|
||||
public var uniformExists = false;
|
||||
|
||||
@ -32,7 +32,8 @@ class UniformsManager extends Trait{
|
||||
notifyOnAdd(init);
|
||||
notifyOnRemove(removeObject);
|
||||
|
||||
if (!sceneRemoveInitalized) {
|
||||
if (!sceneRemoveInitialized) {
|
||||
sceneRemoveInitialized = true;
|
||||
Scene.active.notifyOnRemove(removeScene);
|
||||
}
|
||||
}
|
||||
@ -166,7 +167,12 @@ class UniformsManager extends Trait{
|
||||
matMap.set(material, entry);
|
||||
}
|
||||
|
||||
entry.set(link, value); // parameter name, value
|
||||
if (entry.get(link) != value) {
|
||||
entry.set(link, value);
|
||||
#if (rp_renderer == "Deferred")
|
||||
if (Scene.active != null) Scene.active.markMaterialParamsDirty();
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
// Method to set map Object -> Material -> Link -> Vec3
|
||||
@ -188,7 +194,12 @@ class UniformsManager extends Trait{
|
||||
matMap.set(material, entry);
|
||||
}
|
||||
|
||||
entry.set(link, value); // parameter name, value
|
||||
if (entry.get(link) != value) {
|
||||
entry.set(link, value);
|
||||
#if (rp_renderer == "Deferred")
|
||||
if (Scene.active != null) Scene.active.markMaterialParamsDirty();
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
// Method to set map Object -> Material -> Link -> Texture
|
||||
@ -210,7 +221,12 @@ class UniformsManager extends Trait{
|
||||
matMap.set(material, entry);
|
||||
}
|
||||
|
||||
entry.set(link, value); // parameter name, value
|
||||
if (entry.get(link) != value) {
|
||||
entry.set(link, value);
|
||||
#if (rp_renderer == "Deferred")
|
||||
if (Scene.active != null) Scene.active.markMaterialParamsDirty();
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
// Method to get object specific material parameter float value
|
||||
@ -330,10 +346,15 @@ class UniformsManager extends Trait{
|
||||
var entry = material.get(mat);
|
||||
if (entry == null) return;
|
||||
|
||||
var existed = entry.exists(link);
|
||||
entry.remove(link);
|
||||
|
||||
if (!entry.keys().hasNext()) material.remove(mat);
|
||||
if (!material.keys().hasNext()) floatsMap.remove(object);
|
||||
|
||||
#if (rp_renderer == "Deferred")
|
||||
if (existed && Scene.active != null) Scene.active.markMaterialParamsDirty();
|
||||
#end
|
||||
}
|
||||
|
||||
public static function removeVectorValue(object: Object, mat:MaterialData, link: String) {
|
||||
@ -344,10 +365,15 @@ class UniformsManager extends Trait{
|
||||
var entry = material.get(mat);
|
||||
if (entry == null) return;
|
||||
|
||||
var existed = entry.exists(link);
|
||||
entry.remove(link);
|
||||
|
||||
if (!entry.keys().hasNext()) material.remove(mat);
|
||||
if (!material.keys().hasNext()) vectorsMap.remove(object);
|
||||
|
||||
#if (rp_renderer == "Deferred")
|
||||
if (existed && Scene.active != null) Scene.active.markMaterialParamsDirty();
|
||||
#end
|
||||
}
|
||||
|
||||
public static function removeTextureValue(object: Object, mat:MaterialData, link: String) {
|
||||
@ -358,10 +384,15 @@ class UniformsManager extends Trait{
|
||||
var entry = material.get(mat);
|
||||
if (entry == null) return;
|
||||
|
||||
var existed = entry.exists(link);
|
||||
entry.remove(link);
|
||||
|
||||
if (!entry.keys().hasNext()) material.remove(mat);
|
||||
if (!material.keys().hasNext()) texturesMap.remove(object);
|
||||
|
||||
#if (rp_renderer == "Deferred")
|
||||
if (existed && Scene.active != null) Scene.active.markMaterialParamsDirty();
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user