|
|
|
|
@ -2,6 +2,7 @@ package leenkx.renderpath;
|
|
|
|
|
|
|
|
|
|
import iron.RenderPath;
|
|
|
|
|
import iron.object.LightObject;
|
|
|
|
|
import iron.object.Clipmap;
|
|
|
|
|
|
|
|
|
|
import leenkx.math.Helper;
|
|
|
|
|
import kha.arrays.Float32Array;
|
|
|
|
|
@ -22,6 +23,7 @@ class Inc {
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
#if (rp_voxels != "Off")
|
|
|
|
|
static var voxelClipmapsArray:Float32Array = null;
|
|
|
|
|
static var voxel_sh0:kha.graphics4.ComputeShader = null;
|
|
|
|
|
static var voxel_sh1:kha.graphics4.ComputeShader = null;
|
|
|
|
|
static var voxel_ta0:kha.graphics4.TextureUnit;
|
|
|
|
|
@ -37,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_tf1:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_cc1:kha.graphics4.ConstantLocation;
|
|
|
|
|
#else
|
|
|
|
|
#if lnx_voxelgi_shadows
|
|
|
|
|
@ -92,31 +93,6 @@ class Inc {
|
|
|
|
|
static var voxel_cc4:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cd4:kha.graphics4.ConstantLocation;
|
|
|
|
|
|
|
|
|
|
static var voxel_sh5:kha.graphics4.ComputeShader = null;
|
|
|
|
|
static var voxel_ta5:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_te5:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_tf5:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_tg5:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_ca5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cb5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cc5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cd5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_ce5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cf5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cg5:kha.graphics4.ConstantLocation;
|
|
|
|
|
#if rp_shadowmap
|
|
|
|
|
static var voxel_tb5:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_tc5:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_td5:kha.graphics4.TextureUnit;
|
|
|
|
|
static var voxel_ch5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_ci5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cj5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_ck5:kha.graphics4.ConstantLocation;
|
|
|
|
|
#if lnx_shadowmap_atlas
|
|
|
|
|
static var voxel_cl5:kha.graphics4.ConstantLocation;
|
|
|
|
|
static var voxel_cm5:kha.graphics4.ConstantLocation;
|
|
|
|
|
#end
|
|
|
|
|
#end
|
|
|
|
|
#end //rp_voxels == "Voxel GI"
|
|
|
|
|
#end //rp_voxels != "Off"
|
|
|
|
|
|
|
|
|
|
@ -617,9 +593,6 @@ class Inc {
|
|
|
|
|
// Init voxels
|
|
|
|
|
#if (rp_voxels != 'Off')
|
|
|
|
|
initGI();
|
|
|
|
|
#if (rp_voxels == "Voxel GI")
|
|
|
|
|
initGI("voxelsLight");
|
|
|
|
|
#end
|
|
|
|
|
#end
|
|
|
|
|
#end // lnx_config
|
|
|
|
|
}
|
|
|
|
|
@ -740,12 +713,6 @@ class Inc {
|
|
|
|
|
t.height = res * Main.voxelgiClipmapCount;
|
|
|
|
|
t.depth = res;
|
|
|
|
|
}
|
|
|
|
|
else if (t.name == "voxelsLight") {
|
|
|
|
|
t.format = "R32UI";
|
|
|
|
|
t.width = res;
|
|
|
|
|
t.height = res * Main.voxelgiClipmapCount;
|
|
|
|
|
t.depth = res * 3; // Store R, G, B in separate z-slices
|
|
|
|
|
}
|
|
|
|
|
else if (t.name == "voxelsOut" || t.name == "voxelsOutB") {
|
|
|
|
|
#if (rp_voxels == "Voxel AO")
|
|
|
|
|
t.format = "R8";
|
|
|
|
|
@ -877,8 +844,7 @@ class Inc {
|
|
|
|
|
|
|
|
|
|
#if (rp_voxels == "Voxel GI")
|
|
|
|
|
voxel_td1 = voxel_sh1.getTextureUnit("voxelsSampler");
|
|
|
|
|
voxel_te1 = voxel_sh1.getTextureUnit("voxelsLight");
|
|
|
|
|
voxel_tf1 = voxel_sh1.getTextureUnit("SDF");
|
|
|
|
|
voxel_te1 = voxel_sh1.getTextureUnit("SDF");
|
|
|
|
|
voxel_cc1 = voxel_sh1.getConstantLocation("envmapStrength");
|
|
|
|
|
#else
|
|
|
|
|
#if lnx_voxelgi_shadows
|
|
|
|
|
@ -951,38 +917,27 @@ class Inc {
|
|
|
|
|
voxel_cc4 = voxel_sh4.getConstantLocation("eye");
|
|
|
|
|
voxel_cd4 = voxel_sh4.getConstantLocation("postprocess_resolution");
|
|
|
|
|
}
|
|
|
|
|
if (voxel_sh5 == null)
|
|
|
|
|
{
|
|
|
|
|
voxel_sh5 = path.getComputeShader("voxel_light");
|
|
|
|
|
voxel_ta5 = voxel_sh5.getTextureUnit("voxelsLight");
|
|
|
|
|
voxel_te5 = voxel_sh5.getTextureUnit("voxels");
|
|
|
|
|
voxel_tf5 = voxel_sh5.getTextureUnit("voxelsSampler");
|
|
|
|
|
voxel_tg5 = voxel_sh5.getTextureUnit("voxelsSDFSampler");
|
|
|
|
|
#end
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
voxel_ca5 = voxel_sh5.getConstantLocation("clipmaps");
|
|
|
|
|
voxel_cb5 = voxel_sh5.getConstantLocation("clipmapLevel");
|
|
|
|
|
|
|
|
|
|
voxel_cc5 = voxel_sh5.getConstantLocation("lightPos");
|
|
|
|
|
voxel_cd5 = voxel_sh5.getConstantLocation("lightColor");
|
|
|
|
|
voxel_ce5 = voxel_sh5.getConstantLocation("lightType");
|
|
|
|
|
voxel_cf5 = voxel_sh5.getConstantLocation("lightDir");
|
|
|
|
|
voxel_cg5 = voxel_sh5.getConstantLocation("spotData");
|
|
|
|
|
#if rp_shadowmap
|
|
|
|
|
voxel_tb5 = voxel_sh5.getTextureUnit("shadowMap");
|
|
|
|
|
voxel_tc5 = voxel_sh5.getTextureUnit("shadowMapSpot");
|
|
|
|
|
voxel_td5 = voxel_sh5.getTextureUnit("shadowMapPoint");
|
|
|
|
|
|
|
|
|
|
voxel_ch5 = voxel_sh5.getConstantLocation("lightShadow");
|
|
|
|
|
voxel_ci5 = voxel_sh5.getConstantLocation("lightProj");
|
|
|
|
|
voxel_cj5 = voxel_sh5.getConstantLocation("LVP");
|
|
|
|
|
voxel_ck5 = voxel_sh5.getConstantLocation("shadowsBias");
|
|
|
|
|
#if lnx_shadowmap_atlas
|
|
|
|
|
voxel_cl5 = voxel_sh5.getConstantLocation("index");
|
|
|
|
|
voxel_cm5 = voxel_sh5.getConstantLocation("pointLightDataArray");
|
|
|
|
|
#end
|
|
|
|
|
#end
|
|
|
|
|
public static function fillVoxelClipmapsArray(clipmaps: Array<Clipmap>): Float32Array {
|
|
|
|
|
if (voxelClipmapsArray == null || voxelClipmapsArray.length != Main.voxelgiClipmapCount * 10) {
|
|
|
|
|
voxelClipmapsArray = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
var fa = voxelClipmapsArray;
|
|
|
|
|
for (i in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[i * 10] = clipmaps[i].voxelSize;
|
|
|
|
|
fa[i * 10 + 1] = clipmaps[i].extents.x;
|
|
|
|
|
fa[i * 10 + 2] = clipmaps[i].extents.y;
|
|
|
|
|
fa[i * 10 + 3] = clipmaps[i].extents.z;
|
|
|
|
|
fa[i * 10 + 4] = clipmaps[i].center.x;
|
|
|
|
|
fa[i * 10 + 5] = clipmaps[i].center.y;
|
|
|
|
|
fa[i * 10 + 6] = clipmaps[i].center.z;
|
|
|
|
|
fa[i * 10 + 7] = clipmaps[i].offset_prev.x;
|
|
|
|
|
fa[i * 10 + 8] = clipmaps[i].offset_prev.y;
|
|
|
|
|
fa[i * 10 + 9] = clipmaps[i].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
return fa;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function computeVoxelsOffsetPrev(g: kha.graphics4.Graphics) {
|
|
|
|
|
@ -996,19 +951,7 @@ class Inc {
|
|
|
|
|
g.setImageTexture(voxel_ta0, rts.get("voxelsOut").image);
|
|
|
|
|
g.setImageTexture(voxel_tb0, rts.get("voxelsOutB").image);
|
|
|
|
|
|
|
|
|
|
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
for (i in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[i * 10] = clipmaps[i].voxelSize;
|
|
|
|
|
fa[i * 10 + 1] = clipmaps[i].extents.x;
|
|
|
|
|
fa[i * 10 + 2] = clipmaps[i].extents.y;
|
|
|
|
|
fa[i * 10 + 3] = clipmaps[i].extents.z;
|
|
|
|
|
fa[i * 10 + 4] = clipmaps[i].center.x;
|
|
|
|
|
fa[i * 10 + 5] = clipmaps[i].center.y;
|
|
|
|
|
fa[i * 10 + 6] = clipmaps[i].center.z;
|
|
|
|
|
fa[i * 10 + 7] = clipmaps[i].offset_prev.x;
|
|
|
|
|
fa[i * 10 + 8] = clipmaps[i].offset_prev.y;
|
|
|
|
|
fa[i * 10 + 9] = clipmaps[i].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
var fa = fillVoxelClipmapsArray(clipmaps);
|
|
|
|
|
|
|
|
|
|
g.setFloats(voxel_ca0, fa);
|
|
|
|
|
|
|
|
|
|
@ -1029,7 +972,6 @@ class Inc {
|
|
|
|
|
if (rts.get("voxelsOut") == null) initGI("voxelsOut");
|
|
|
|
|
if (rts.get("voxelsOutB") == null) initGI("voxelsOutB");
|
|
|
|
|
#if (rp_voxels == "Voxel GI")
|
|
|
|
|
if (rts.get("voxelsLight") == null) initGI("voxelsLight");
|
|
|
|
|
if (rts.get("voxelsSDF") == null) initGI("voxelsSDF");
|
|
|
|
|
#elseif lnx_voxelgi_shadows
|
|
|
|
|
if (rts.get("voxelsSDF") == null) initGI("voxelsSDF");
|
|
|
|
|
@ -1045,8 +987,7 @@ class Inc {
|
|
|
|
|
g.setImageTexture(voxel_tc1, rts.get("voxelsOut").image);
|
|
|
|
|
#if (rp_voxels == "Voxel GI")
|
|
|
|
|
g.setTexture(voxel_td1, rts.get("voxelsOutB").image);
|
|
|
|
|
g.setImageTexture(voxel_te1, rts.get("voxelsLight").image);
|
|
|
|
|
g.setImageTexture(voxel_tf1, rts.get("voxelsSDF").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
|
|
|
|
|
@ -1054,19 +995,7 @@ class Inc {
|
|
|
|
|
#end
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
for (i in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[i * 10] = clipmaps[i].voxelSize;
|
|
|
|
|
fa[i * 10 + 1] = clipmaps[i].extents.x;
|
|
|
|
|
fa[i * 10 + 2] = clipmaps[i].extents.y;
|
|
|
|
|
fa[i * 10 + 3] = clipmaps[i].extents.z;
|
|
|
|
|
fa[i * 10 + 4] = clipmaps[i].center.x;
|
|
|
|
|
fa[i * 10 + 5] = clipmaps[i].center.y;
|
|
|
|
|
fa[i * 10 + 6] = clipmaps[i].center.z;
|
|
|
|
|
fa[i * 10 + 7] = clipmaps[i].offset_prev.x;
|
|
|
|
|
fa[i * 10 + 8] = clipmaps[i].offset_prev.y;
|
|
|
|
|
fa[i * 10 + 9] = clipmaps[i].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
var fa = fillVoxelClipmapsArray(clipmaps);
|
|
|
|
|
|
|
|
|
|
g.setFloats(voxel_ca1, fa);
|
|
|
|
|
|
|
|
|
|
@ -1084,6 +1013,8 @@ class Inc {
|
|
|
|
|
var clipmaps = iron.RenderPath.clipmaps;
|
|
|
|
|
var clipmap = clipmaps[iron.RenderPath.clipmapLevel];
|
|
|
|
|
|
|
|
|
|
if (rts.get("voxelsSDF") == null || rts.get("voxelsSDFtmp") == null) return;
|
|
|
|
|
|
|
|
|
|
var read_sdf = "voxelsSDF";
|
|
|
|
|
var write_sdf = "voxelsSDFtmp";
|
|
|
|
|
|
|
|
|
|
@ -1095,19 +1026,7 @@ class Inc {
|
|
|
|
|
g.setImageTexture(voxel_ta2, rts.get(read_sdf).image);
|
|
|
|
|
g.setImageTexture(voxel_tb2, rts.get(write_sdf).image);
|
|
|
|
|
|
|
|
|
|
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
for (j in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[j * 10] = clipmaps[j].voxelSize;
|
|
|
|
|
fa[j * 10 + 1] = clipmaps[j].extents.x;
|
|
|
|
|
fa[j * 10 + 2] = clipmaps[j].extents.y;
|
|
|
|
|
fa[j * 10 + 3] = clipmaps[j].extents.z;
|
|
|
|
|
fa[j * 10 + 4] = clipmaps[j].center.x;
|
|
|
|
|
fa[j * 10 + 5] = clipmaps[j].center.y;
|
|
|
|
|
fa[j * 10 + 6] = clipmaps[j].center.z;
|
|
|
|
|
fa[j * 10 + 7] = clipmaps[j].offset_prev.x;
|
|
|
|
|
fa[j * 10 + 8] = clipmaps[j].offset_prev.y;
|
|
|
|
|
fa[j * 10 + 9] = clipmaps[j].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
var fa = fillVoxelClipmapsArray(clipmaps);
|
|
|
|
|
|
|
|
|
|
g.setFloats(voxel_ca2, fa);
|
|
|
|
|
|
|
|
|
|
@ -1124,6 +1043,18 @@ class Inc {
|
|
|
|
|
write_sdf = write_sdf == "voxelsSDF" ? "voxelsSDFtmp" : "voxelsSDF";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If passcount is odd, result is in voxelsSDFtmp but consumers read voxelsSDF
|
|
|
|
|
if (passcount % 2 != 0) {
|
|
|
|
|
g.setComputeShader(voxel_sh2);
|
|
|
|
|
g.setImageTexture(voxel_ta2, rts.get("voxelsSDFtmp").image);
|
|
|
|
|
g.setImageTexture(voxel_tb2, rts.get("voxelsSDF").image);
|
|
|
|
|
fillVoxelClipmapsArray(clipmaps);
|
|
|
|
|
g.setFloats(voxel_ca2, voxelClipmapsArray);
|
|
|
|
|
g.setInt(voxel_cb2, iron.RenderPath.clipmapLevel);
|
|
|
|
|
g.setFloat(voxel_cc2, 1.0);
|
|
|
|
|
g.compute(Std.int(res / 8), Std.int(res / 8), Std.int(res / 8));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
@ -1153,19 +1084,7 @@ class Inc {
|
|
|
|
|
g.setTexture(voxel_th3, iron.Scene.active.world.probe.radiance);
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
for (i in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[i * 10] = clipmaps[i].voxelSize;
|
|
|
|
|
fa[i * 10 + 1] = clipmaps[i].extents.x;
|
|
|
|
|
fa[i * 10 + 2] = clipmaps[i].extents.y;
|
|
|
|
|
fa[i * 10 + 3] = clipmaps[i].extents.z;
|
|
|
|
|
fa[i * 10 + 4] = clipmaps[i].center.x;
|
|
|
|
|
fa[i * 10 + 5] = clipmaps[i].center.y;
|
|
|
|
|
fa[i * 10 + 6] = clipmaps[i].center.z;
|
|
|
|
|
fa[i * 10 + 7] = clipmaps[i].offset_prev.x;
|
|
|
|
|
fa[i * 10 + 8] = clipmaps[i].offset_prev.y;
|
|
|
|
|
fa[i * 10 + 9] = clipmaps[i].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
var fa = fillVoxelClipmapsArray(clipmaps);
|
|
|
|
|
|
|
|
|
|
g.setFloats(voxel_ca3, fa);
|
|
|
|
|
|
|
|
|
|
@ -1248,19 +1167,7 @@ class Inc {
|
|
|
|
|
g.setTexture(voxel_th3, iron.Scene.active.world.probe.radiance);
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
for (i in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[i * 10] = clipmaps[i].voxelSize;
|
|
|
|
|
fa[i * 10 + 1] = clipmaps[i].extents.x;
|
|
|
|
|
fa[i * 10 + 2] = clipmaps[i].extents.y;
|
|
|
|
|
fa[i * 10 + 3] = clipmaps[i].extents.z;
|
|
|
|
|
fa[i * 10 + 4] = clipmaps[i].center.x;
|
|
|
|
|
fa[i * 10 + 5] = clipmaps[i].center.y;
|
|
|
|
|
fa[i * 10 + 6] = clipmaps[i].center.z;
|
|
|
|
|
fa[i * 10 + 7] = clipmaps[i].offset_prev.x;
|
|
|
|
|
fa[i * 10 + 8] = clipmaps[i].offset_prev.y;
|
|
|
|
|
fa[i * 10 + 9] = clipmaps[i].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
var fa = fillVoxelClipmapsArray(clipmaps);
|
|
|
|
|
|
|
|
|
|
g.setFloats(voxel_ca3, fa);
|
|
|
|
|
|
|
|
|
|
@ -1338,19 +1245,7 @@ class Inc {
|
|
|
|
|
g.setTexture(voxel_tf4, rts.get("gbuffer2").image);
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
for (i in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[i * 10] = clipmaps[i].voxelSize;
|
|
|
|
|
fa[i * 10 + 1] = clipmaps[i].extents.x;
|
|
|
|
|
fa[i * 10 + 2] = clipmaps[i].extents.y;
|
|
|
|
|
fa[i * 10 + 3] = clipmaps[i].extents.z;
|
|
|
|
|
fa[i * 10 + 4] = clipmaps[i].center.x;
|
|
|
|
|
fa[i * 10 + 5] = clipmaps[i].center.y;
|
|
|
|
|
fa[i * 10 + 6] = clipmaps[i].center.z;
|
|
|
|
|
fa[i * 10 + 7] = clipmaps[i].offset_prev.x;
|
|
|
|
|
fa[i * 10 + 8] = clipmaps[i].offset_prev.y;
|
|
|
|
|
fa[i * 10 + 9] = clipmaps[i].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
var fa = fillVoxelClipmapsArray(clipmaps);
|
|
|
|
|
|
|
|
|
|
g.setFloats(voxel_ca4, fa);
|
|
|
|
|
|
|
|
|
|
@ -1385,147 +1280,6 @@ class Inc {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if (rp_voxels == "Voxel GI")
|
|
|
|
|
public static function computeVoxelsLight(g: kha.graphics4.Graphics) {
|
|
|
|
|
var rts = path.renderTargets;
|
|
|
|
|
var res = iron.RenderPath.getVoxelRes();
|
|
|
|
|
var camera = iron.Scene.active.camera;
|
|
|
|
|
var clipmaps = iron.RenderPath.clipmaps;
|
|
|
|
|
var clipmap = clipmaps[iron.RenderPath.clipmapLevel];
|
|
|
|
|
var lights = iron.Scene.active.lights;
|
|
|
|
|
|
|
|
|
|
var lightIndex = 0;
|
|
|
|
|
for (i in 0...lights.length) {
|
|
|
|
|
var l = lights[i];
|
|
|
|
|
if (!l.visible) continue;
|
|
|
|
|
path.light = l;
|
|
|
|
|
|
|
|
|
|
g.setComputeShader(voxel_sh5);
|
|
|
|
|
|
|
|
|
|
g.setImageTexture(voxel_ta5, rts.get("voxelsLight").image);
|
|
|
|
|
g.setImageTexture(voxel_te5, rts.get("voxels").image);
|
|
|
|
|
g.setTexture(voxel_tf5, rts.get("voxelsOut").image);
|
|
|
|
|
g.setTexture(voxel_tg5, rts.get("voxelsSDF").image);
|
|
|
|
|
|
|
|
|
|
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
|
|
|
|
|
for (j in 0...Main.voxelgiClipmapCount) {
|
|
|
|
|
fa[j * 10] = clipmaps[j].voxelSize;
|
|
|
|
|
fa[j * 10 + 1] = clipmaps[j].extents.x;
|
|
|
|
|
fa[j * 10 + 2] = clipmaps[j].extents.y;
|
|
|
|
|
fa[j * 10 + 3] = clipmaps[j].extents.z;
|
|
|
|
|
fa[j * 10 + 4] = clipmaps[j].center.x;
|
|
|
|
|
fa[j * 10 + 5] = clipmaps[j].center.y;
|
|
|
|
|
fa[j * 10 + 6] = clipmaps[j].center.z;
|
|
|
|
|
fa[j * 10 + 7] = clipmaps[j].offset_prev.x;
|
|
|
|
|
fa[j * 10 + 8] = clipmaps[j].offset_prev.y;
|
|
|
|
|
fa[j * 10 + 9] = clipmaps[j].offset_prev.z;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g.setFloats(voxel_ca5, fa);
|
|
|
|
|
|
|
|
|
|
g.setInt(voxel_cb5, iron.RenderPath.clipmapLevel);
|
|
|
|
|
|
|
|
|
|
#if rp_shadowmap
|
|
|
|
|
if (l.data.raw.type == "sun") {
|
|
|
|
|
#if lnx_shadowmap_atlas
|
|
|
|
|
#if lnx_shadowmap_atlas_single_map
|
|
|
|
|
g.setTexture(voxel_tb5, rts.get("shadowMapAtlas").image);
|
|
|
|
|
#else
|
|
|
|
|
g.setTexture(voxel_tb5, rts.get("shadowMapAtlasSun").image);
|
|
|
|
|
#end
|
|
|
|
|
#else
|
|
|
|
|
g.setTexture(voxel_tb5, rts.get("shadowMap").image);
|
|
|
|
|
#end
|
|
|
|
|
g.setInt(voxel_ch5, 1); // lightShadow
|
|
|
|
|
}
|
|
|
|
|
else if (l.data.raw.type == "spot" || l.data.raw.type == "area") {
|
|
|
|
|
#if lnx_shadowmap_atlas
|
|
|
|
|
#if lnx_shadowmap_atlas_single_map
|
|
|
|
|
g.setTexture(voxel_tc5, rts.get("shadowMapAtlas").image);
|
|
|
|
|
#else
|
|
|
|
|
g.setTexture(voxel_tc5, rts.get("shadowMapAtlasSpot").image);
|
|
|
|
|
#end
|
|
|
|
|
#else
|
|
|
|
|
g.setTexture(voxel_tc5, rts.get("shadowMapSpot[" + lightIndex + "]").image);
|
|
|
|
|
#end
|
|
|
|
|
g.setInt(voxel_ch5, 2);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#if lnx_shadowmap_atlas
|
|
|
|
|
#if lnx_shadowmap_atlas_single_map
|
|
|
|
|
g.setTexture(voxel_td5, rts.get("shadowMapAtlas").image);
|
|
|
|
|
#else
|
|
|
|
|
g.setTexture(voxel_td5, rts.get("shadowMapAtlasPoint").image);
|
|
|
|
|
g.setInt(voxel_cl5, i);
|
|
|
|
|
g.setFloats(voxel_cm5, iron.object.LightObject.pointLightsData);
|
|
|
|
|
#end
|
|
|
|
|
#else
|
|
|
|
|
g.setCubeMap(voxel_td5, rts.get("shadowMapPoint[" + lightIndex + "]").cubeMap);
|
|
|
|
|
#end
|
|
|
|
|
g.setInt(voxel_ch5, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// lightProj
|
|
|
|
|
var near = l.data.raw.near_plane;
|
|
|
|
|
var far = l.data.raw.far_plane;
|
|
|
|
|
var a:kha.FastFloat = far + near;
|
|
|
|
|
var b:kha.FastFloat = far - near;
|
|
|
|
|
var f2:kha.FastFloat = 2.0;
|
|
|
|
|
var c:kha.FastFloat = f2 * far * near;
|
|
|
|
|
var vx:kha.FastFloat = a / b;
|
|
|
|
|
var vy:kha.FastFloat = c / b;
|
|
|
|
|
g.setFloat2(voxel_ci5, vx, vy);
|
|
|
|
|
// LVP
|
|
|
|
|
m.setFrom(l.VP);
|
|
|
|
|
m.multmat(iron.object.Uniforms.biasMat);
|
|
|
|
|
#if lnx_shadowmap_atlas
|
|
|
|
|
if (l.data.raw.type == "sun")
|
|
|
|
|
{
|
|
|
|
|
// tile matrix
|
|
|
|
|
m.setIdentity();
|
|
|
|
|
// scale [0-1] coords to [0-tilescale]
|
|
|
|
|
m._00 = l.tileScale[0];
|
|
|
|
|
m._11 = l.tileScale[0];
|
|
|
|
|
// offset coordinate start from [0, 0] to [tile-start-x, tile-start-y]
|
|
|
|
|
m._30 = l.tileOffsetX[0];
|
|
|
|
|
m._31 = l.tileOffsetY[0];
|
|
|
|
|
m.multmat(m);
|
|
|
|
|
#if (!kha_opengl)
|
|
|
|
|
m.setIdentity();
|
|
|
|
|
m._11 = -1.0;
|
|
|
|
|
m._31 = 1.0;
|
|
|
|
|
m.multmat(m);
|
|
|
|
|
#end
|
|
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
g.setMatrix(voxel_cj5, m.self);
|
|
|
|
|
// shadowsBias
|
|
|
|
|
g.setFloat(voxel_ck5, l.data.raw.shadows_bias);
|
|
|
|
|
#end // rp_shadowmap
|
|
|
|
|
|
|
|
|
|
// lightPos
|
|
|
|
|
g.setFloat3(voxel_cc5, l.transform.worldx(), l.transform.worldy(), l.transform.worldz());
|
|
|
|
|
// lightCol
|
|
|
|
|
var f = l.data.raw.strength;
|
|
|
|
|
g.setFloat3(voxel_cd5, l.data.raw.color[0] * f, l.data.raw.color[1] * f, l.data.raw.color[2] * f);
|
|
|
|
|
// lightType
|
|
|
|
|
g.setInt(voxel_ce5, iron.data.LightData.typeToInt(l.data.raw.type));
|
|
|
|
|
// lightDir
|
|
|
|
|
var v = l.look();
|
|
|
|
|
g.setFloat3(voxel_cf5, v.x, v.y, v.z);
|
|
|
|
|
// spotData
|
|
|
|
|
if (l.data.raw.type == "spot") {
|
|
|
|
|
var vx = l.data.raw.spot_size;
|
|
|
|
|
var vy = vx - l.data.raw.spot_blend;
|
|
|
|
|
g.setFloat2(voxel_cg5, vx, vy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g.compute(Std.int(res / 8), Std.int(res / 8), Std.int(res / 8));
|
|
|
|
|
|
|
|
|
|
if (!iron.object.LightObject.discardLightCulled(l)) {
|
|
|
|
|
lightIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#end // GI
|
|
|
|
|
#end // Voxels
|
|
|
|
|
}
|
|
|
|
|
@ -1881,7 +1635,8 @@ class ShadowMapTile {
|
|
|
|
|
if (size < oldTile.size) {
|
|
|
|
|
oldTile.forEachTileLinked(function(lTile) {
|
|
|
|
|
var childTile = findFreeChildTile(lTile, size);
|
|
|
|
|
tilesFound.push(childTile);
|
|
|
|
|
if (childTile != null)
|
|
|
|
|
tilesFound.push(childTile);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// reuse parent tiles
|
|
|
|
|
@ -1910,6 +1665,7 @@ class ShadowMapTile {
|
|
|
|
|
while (size < childrenTile.size) {
|
|
|
|
|
childrenTile = childrenTile.tiles[0];
|
|
|
|
|
}
|
|
|
|
|
if (childrenTile.light != null) return null;
|
|
|
|
|
return childrenTile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|