From 9ef9f5a6378696dfeb26dd7f52b40c8ab28f91d0 Mon Sep 17 00:00:00 2001 From: Onek8 Date: Wed, 21 May 2025 16:15:50 +0000 Subject: [PATCH] Update leenkx/Sources/leenkx/renderpath/Inc.hx --- leenkx/Sources/leenkx/renderpath/Inc.hx | 424 ++++++++---------------- 1 file changed, 139 insertions(+), 285 deletions(-) diff --git a/leenkx/Sources/leenkx/renderpath/Inc.hx b/leenkx/Sources/leenkx/renderpath/Inc.hx index 69087f3..3f084a4 100644 --- a/leenkx/Sources/leenkx/renderpath/Inc.hx +++ b/leenkx/Sources/leenkx/renderpath/Inc.hx @@ -31,13 +31,13 @@ class Inc { static var m = iron.math.Mat4.identity(); static var voxel_ca1:kha.compute.ConstantLocation; static var voxel_cb1:kha.compute.ConstantLocation; + static var voxel_cc1:kha.compute.ConstantLocation; #if (rp_voxels == "Voxel GI") static var voxel_td1:kha.compute.TextureUnit; static var voxel_te1:kha.compute.TextureUnit; - static var voxel_tf1:kha.compute.TextureUnit; #else #if lnx_voxelgi_shadows - static var voxel_tf1:kha.compute.TextureUnit; + static var voxel_te1:kha.compute.TextureUnit; #end #end #if (lnx_voxelgi_shadows || rp_voxels == "Voxel GI") @@ -53,12 +53,28 @@ class Inc { static var voxel_tb3:kha.compute.TextureUnit; static var voxel_tc3:kha.compute.TextureUnit; static var voxel_td3:kha.compute.TextureUnit; + static var voxel_te3:kha.compute.TextureUnit; + static var voxel_tf3:kha.compute.TextureUnit; + #if lnx_brdf + static var voxel_tg3:kha.compute.TextureUnit; + #end + #if lnx_radiance + static var voxel_th3:kha.compute.TextureUnit; + #end static var voxel_ca3:kha.compute.ConstantLocation; static var voxel_cb3:kha.compute.ConstantLocation; static var voxel_cc3:kha.compute.ConstantLocation; static var voxel_cd3:kha.compute.ConstantLocation; static var voxel_ce3:kha.compute.ConstantLocation; + #if lnx_irradiance static var voxel_cf3:kha.compute.ConstantLocation; + #end + #if lnx_radiance + static var voxel_cg3:kha.compute.ConstantLocation; + #end + #if lnx_envcol + static var voxel_ch3:kha.compute.ConstantLocation; + #end #if (rp_voxels == "Voxel GI") static var voxel_sh4:kha.compute.Shader = null; static var voxel_ta4:kha.compute.TextureUnit; @@ -71,36 +87,6 @@ class Inc { static var voxel_cb4:kha.compute.ConstantLocation; static var voxel_cc4:kha.compute.ConstantLocation; static var voxel_cd4:kha.compute.ConstantLocation; - static var voxel_ce4:kha.compute.ConstantLocation; - static var voxel_cf4:kha.compute.ConstantLocation; - #end - #if (rp_voxels == "Voxel GI") - static var voxel_sh5:kha.compute.Shader = null; - static var voxel_ta5:kha.compute.TextureUnit; - static var voxel_te5:kha.compute.TextureUnit; - static var voxel_tf5:kha.compute.TextureUnit; - static var voxel_tg5:kha.compute.TextureUnit; - static var voxel_ca5:kha.compute.ConstantLocation; - static var voxel_cb5:kha.compute.ConstantLocation; - static var voxel_cc5:kha.compute.ConstantLocation; - static var voxel_cd5:kha.compute.ConstantLocation; - static var voxel_ce5:kha.compute.ConstantLocation; - static var voxel_cf5:kha.compute.ConstantLocation; - static var voxel_cg5:kha.compute.ConstantLocation; - #if rp_shadowmap - static var voxel_tb5:kha.compute.TextureUnit; - static var voxel_tc5:kha.compute.TextureUnit; - static var voxel_td5:kha.compute.TextureUnit; - static var voxel_ch5:kha.compute.ConstantLocation; - static var voxel_ci5:kha.compute.ConstantLocation; - static var voxel_cj5:kha.compute.ConstantLocation; - static var voxel_ck5:kha.compute.ConstantLocation; - static var voxel_cl5:kha.compute.ConstantLocation; - static var voxel_cm5:kha.compute.ConstantLocation; - #if lnx_shadowmap_atlas - static var m2 = iron.math.Mat4.identity(); - #end - #end #end #end //rp_voxels @@ -401,7 +387,7 @@ class Inc { #if lnx_debug endShadowsLogicProfile(); #end - #end // rp_shadowmap + #end } #else public static function bindShadowMap() { @@ -585,7 +571,7 @@ class Inc { t.width = 0; t.height = 0; t.displayp = getDisplayp(); - t.format = "R32"; + t.format = "R16"; t.scale = getSuperSampling(); t.depth_buffer = "main"; path.createRenderTarget(t); @@ -675,12 +661,11 @@ class Inc { t.width = 0; t.height = 0; t.displayp = getDisplayp(); - //t.scale = Inc.getSuperSampling(); - t.format = t.name == "voxels_ao" ? "R8" : "RGBA32"; + t.format = "RGBA32"; } else { if (t.name == "voxelsSDF" || t.name == "voxelsSDFtmp") { - t.format = "R8"; + t.format = "R16"; t.width = res; t.height = res * Main.voxelgiClipmapCount; t.depth = res; @@ -689,37 +674,31 @@ class Inc { #if (rp_voxels == "Voxel AO") { if (t.name == "voxelsOut" || t.name == "voxelsOutB") { - t.format = "R8"; + t.format = "R16"; t.width = res * (6 + 16); t.height = res * Main.voxelgiClipmapCount; t.depth = res; } else { - t.format = "R32"; + t.format = "R32UI"; t.width = res * 6; t.height = res; - t.depth = res; + t.depth = res * 2; } } #else { if (t.name == "voxelsOut" || t.name == "voxelsOutB") { - t.format = "RGBA32"; + t.format = "RGBA64"; t.width = res * (6 + 16); t.height = res * Main.voxelgiClipmapCount; t.depth = res; } - else if (t.name == "voxelsLight") { - t.format = "R32"; - t.width = res; - t.height = res; - t.depth = res * 3; - } else { - t.format = "R32"; + t.format = "R32UI"; t.width = res * 6; t.height = res; - t.depth = res * 12; + t.depth = res * 16; } } #end @@ -827,14 +806,14 @@ 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("voxelsLight"); - voxel_tf1 = voxel_sh1.getTextureUnit("SDF"); + voxel_te1 = voxel_sh1.getTextureUnit("SDF"); #else #if lnx_voxelgi_shadows - voxel_tf1 = voxel_sh1.getTextureUnit("SDF"); + voxel_te1 = voxel_sh1.getTextureUnit("SDF"); #end #end } @@ -865,12 +844,28 @@ class Inc { #else voxel_td3 = voxel_sh3.getTextureUnit("voxels_diffuse"); #end - voxel_ca3 = voxel_sh3.getConstantLocation("clipmaps"); + voxel_te3 = voxel_sh3.getTextureUnit("gbuffer1"); + voxel_tf3 = voxel_sh3.getTextureUnit("gbuffer2"); + #if lnx_brdf + voxel_tg3 = voxel_sh3.getTextureUnit("senvmapBrdf"); + #end + #if lnx_radiance + voxel_th3 = voxel_sh3.getTextureUnit("senvmapRadiance"); + #end + voxel_ca3 = voxel_sh3.getConstantLocation("clipmaps"); voxel_cb3 = voxel_sh3.getConstantLocation("InvVP"); - voxel_cc3 = voxel_sh3.getConstantLocation("cameraProj"); - voxel_cd3 = voxel_sh3.getConstantLocation("eye"); - voxel_ce3 = voxel_sh3.getConstantLocation("eyeLook"); - voxel_cf3 = voxel_sh3.getConstantLocation("postprocess_resolution"); + voxel_cc3 = voxel_sh3.getConstantLocation("eye"); + voxel_cd3 = voxel_sh3.getConstantLocation("postprocess_resolution"); + voxel_ce3 = voxel_sh3.getConstantLocation("envmapStrength"); + #if lnx_irradiance + voxel_cf3 = voxel_sh3.getConstantLocation("shirr"); + #end + #if lnx_radiance + voxel_cg3 = voxel_sh3.getConstantLocation("envmapNumMipmaps"); + #end + #if lnx_envcol + voxel_ch3 = voxel_sh3.getConstantLocation("backgroundCol"); + #end } #if (rp_voxels == "Voxel GI") if (voxel_sh4 == null) @@ -884,42 +879,8 @@ class Inc { voxel_tf4 = voxel_sh4.getTextureUnit("sveloc"); voxel_ca4 = voxel_sh4.getConstantLocation("clipmaps"); voxel_cb4 = voxel_sh4.getConstantLocation("InvVP"); - voxel_cc4 = voxel_sh4.getConstantLocation("cameraProj"); - voxel_cd4 = voxel_sh4.getConstantLocation("eye"); - voxel_ce4 = voxel_sh4.getConstantLocation("eyeLook"); - voxel_cf4 = voxel_sh4.getConstantLocation("postprocess_resolution"); - } - #end - #if (rp_voxels == "Voxel GI") - 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"); - 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 + voxel_cc4 = voxel_sh4.getConstantLocation("eye"); + voxel_cd4 = voxel_sh4.getConstantLocation("postprocess_resolution"); } #end } @@ -970,11 +931,10 @@ class Inc { kha.compute.Compute.setTexture(voxel_tc1, rts.get("voxelsOut").image, kha.compute.Access.Write); #if (rp_voxels == "Voxel GI") kha.compute.Compute.setSampledTexture(voxel_td1, rts.get("voxelsOutB").image); - kha.compute.Compute.setTexture(voxel_te1, rts.get("voxelsLight").image, kha.compute.Access.Read); - kha.compute.Compute.setTexture(voxel_tf1, rts.get("voxelsSDF").image, kha.compute.Access.Write); + kha.compute.Compute.setTexture(voxel_te1, rts.get("voxelsSDF").image, kha.compute.Access.Write); #else #if lnx_voxelgi_shadows - kha.compute.Compute.setTexture(voxel_tf1, rts.get("voxelsSDF").image, kha.compute.Access.Write); + kha.compute.Compute.setTexture(voxel_te1, rts.get("voxelsSDF").image, kha.compute.Access.Write); #end #end @@ -996,6 +956,8 @@ class Inc { kha.compute.Compute.setInt(voxel_cb1, iron.RenderPath.clipmapLevel); + kha.compute.Compute.setFloat(voxel_cc1, iron.Scene.active.world == null ? 0.0 : iron.Scene.active.world.probe.raw.strength); + kha.compute.Compute.compute(Std.int(res / 8), Std.int(res / 8), Std.int(res / 8)); } @@ -1048,6 +1010,7 @@ class Inc { } } #end + #if (rp_voxels == "Voxel AO") public static function resolveAO() { var rts = path.renderTargets; @@ -1060,13 +1023,20 @@ class Inc { kha.compute.Compute.setSampledTexture(voxel_ta3, rts.get("voxelsOut").image); kha.compute.Compute.setSampledTexture(voxel_tb3, rts.get("half").image); - #if lnx_deferred kha.compute.Compute.setSampledTexture(voxel_tc3, rts.get("gbuffer0").image); - #else - kha.compute.Compute.setSampledTexture(voxel_tc3, rts.get("lbuffer1").image); - #end kha.compute.Compute.setTexture(voxel_td3, rts.get("voxels_ao").image, kha.compute.Access.Write); + kha.compute.Compute.setSampledTexture(voxel_te3, rts.get("gbuffer1").image); + #if rp_gbuffer2 + kha.compute.Compute.setSampledTexture(voxel_tf3, rts.get("gbuffer2").image); + #end + #if lnx_brdf + kha.compute.Compute.setSampledTexture(voxel_tg3, iron.Scene.active.embedded.get("brdf.png")); + #end + #if lnx_radiance + kha.compute.Compute.setSampledTexture(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; @@ -1093,18 +1063,7 @@ class Inc { kha.compute.Compute.setMatrix(voxel_cb3, m.self); - var near = camera.data.raw.near_plane; - var far = camera.data.raw.far_plane; - var v = new iron.math.Vec2(); - v.x = far / (far - near); - v.y = (-far * near) / (far - near); - - kha.compute.Compute.setFloat2(voxel_cc3, v.x, v.y); - - - kha.compute.Compute.setFloat3(voxel_cd3, camera.transform.worldx(), camera.transform.worldy(), camera.transform.worldz()); - var eyeLook = camera.lookWorld().normalize(); - kha.compute.Compute.setFloat3(voxel_ce3, eyeLook.x, eyeLook.y, eyeLook.z); + kha.compute.Compute.setFloat3(voxel_cc3, camera.transform.worldx(), camera.transform.worldy(), camera.transform.worldz()); var width = iron.App.w(); var height = iron.App.h(); @@ -1119,7 +1078,32 @@ class Inc { width = Std.int(dp * Inc.getSuperSampling()); } } - kha.compute.Compute.setFloat2(voxel_cf3, width, height); + kha.compute.Compute.setFloat2(voxel_cd3, width, height); + + kha.compute.Compute.setFloat(voxel_ce3, iron.Scene.active.world == null ? 0.0 : iron.Scene.active.world.probe.raw.strength); + #if lnx_irradiance + var irradiance = iron.Scene.active.world == null ? + iron.data.WorldData.getEmptyIrradiance() : + iron.Scene.active.world.probe.irradiance; + kha.compute.Compute.setFloats(voxel_cf3, irradiance); + #end + #if lnx_radiance + kha.compute.Compute.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]; + } + + kha.compute.Compute.setFloat3(voxel_ch3, x, y, z); + #end kha.compute.Compute.compute(Std.int((width + 7) / 8), Std.int((height + 7) / 8), 1); } @@ -1135,12 +1119,18 @@ class Inc { kha.compute.Compute.setSampledTexture(voxel_ta3, rts.get("voxelsOut").image); kha.compute.Compute.setSampledTexture(voxel_tb3, rts.get("half").image); - #if lnx_deferred kha.compute.Compute.setSampledTexture(voxel_tc3, rts.get("gbuffer0").image); - #else - kha.compute.Compute.setSampledTexture(voxel_tc3, rts.get("lbuffer1").image); - #end kha.compute.Compute.setTexture(voxel_td3, rts.get("voxels_diffuse").image, kha.compute.Access.Write); + kha.compute.Compute.setSampledTexture(voxel_te3, rts.get("gbuffer1").image); + #if rp_gbuffer2 + kha.compute.Compute.setSampledTexture(voxel_tf3, rts.get("gbuffer2").image); + #end + #if lnx_brdf + kha.compute.Compute.setSampledTexture(voxel_tg3, iron.Scene.active.embedded.get("brdf.png")); + #end + #if lnx_radiance + kha.compute.Compute.setSampledTexture(voxel_th3, iron.Scene.active.world.probe.radiance); + #end var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10); for (i in 0...Main.voxelgiClipmapCount) { @@ -1168,18 +1158,7 @@ class Inc { kha.compute.Compute.setMatrix(voxel_cb3, m.self); - var near = camera.data.raw.near_plane; - var far = camera.data.raw.far_plane; - var v = new iron.math.Vec2(); - v.x = far / (far - near); - v.y = (-far * near) / (far - near); - - kha.compute.Compute.setFloat2(voxel_cc3, v.x, v.y); - - - kha.compute.Compute.setFloat3(voxel_cd3, camera.transform.worldx(), camera.transform.worldy(), camera.transform.worldz()); - var eyeLook = camera.lookWorld().normalize(); - kha.compute.Compute.setFloat3(voxel_ce3, eyeLook.x, eyeLook.y, eyeLook.z); + kha.compute.Compute.setFloat3(voxel_cc3, camera.transform.worldx(), camera.transform.worldy(), camera.transform.worldz()); var width = iron.App.w(); var height = iron.App.h(); @@ -1194,7 +1173,32 @@ class Inc { width = Std.int(dp * Inc.getSuperSampling()); } } - kha.compute.Compute.setFloat2(voxel_cf3, width, height); + kha.compute.Compute.setFloat2(voxel_cd3, width, height); + + kha.compute.Compute.setFloat(voxel_ce3, iron.Scene.active.world == null ? 0.0 : iron.Scene.active.world.probe.raw.strength); + #if lnx_irradiance + var irradiance = iron.Scene.active.world == null ? + iron.data.WorldData.getEmptyIrradiance() : + iron.Scene.active.world.probe.irradiance; + kha.compute.Compute.setFloats(voxel_cf3, irradiance); + #end + #if lnx_radiance + kha.compute.Compute.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]; + } + + kha.compute.Compute.setFloat3(voxel_ch3, x, y, z); + #end kha.compute.Compute.compute(Std.int((width + 7) / 8), Std.int((height + 7) / 8), 1); } @@ -1210,13 +1214,12 @@ class Inc { kha.compute.Compute.setSampledTexture(voxel_ta4, rts.get("voxelsOut").image); kha.compute.Compute.setSampledTexture(voxel_tb4, rts.get("half").image); - #if lnx_deferred kha.compute.Compute.setSampledTexture(voxel_tc4, rts.get("gbuffer0").image); - #else - kha.compute.Compute.setSampledTexture(voxel_tc4, rts.get("lbuffer1").image); - #end kha.compute.Compute.setSampledTexture(voxel_td4, rts.get("voxelsSDF").image); kha.compute.Compute.setTexture(voxel_te4, rts.get("voxels_specular").image, kha.compute.Access.Write); + #if rp_gbuffer2 + kha.compute.Compute.setSampledTexture(voxel_tf4, rts.get("gbuffer2").image); + #end kha.compute.Compute.setSampledTexture(voxel_tf4, rts.get("gbuffer2").image); @@ -1246,18 +1249,7 @@ class Inc { kha.compute.Compute.setMatrix(voxel_cb4, m.self); - var near = camera.data.raw.near_plane; - var far = camera.data.raw.far_plane; - var v = new iron.math.Vec2(); - v.x = far / (far - near); - v.y = (-far * near) / (far - near); - - kha.compute.Compute.setFloat2(voxel_cc4, v.x, v.y); - - - kha.compute.Compute.setFloat3(voxel_cd4, camera.transform.worldx(), camera.transform.worldy(), camera.transform.worldz()); - var eyeLook = camera.lookWorld().normalize(); - kha.compute.Compute.setFloat3(voxel_ce4, eyeLook.x, eyeLook.y, eyeLook.z); + kha.compute.Compute.setFloat3(voxel_cc4, camera.transform.worldx(), camera.transform.worldy(), camera.transform.worldz()); var width = iron.App.w(); var height = iron.App.h(); @@ -1272,148 +1264,10 @@ class Inc { width = Std.int(dp * Inc.getSuperSampling()); } } - kha.compute.Compute.setFloat2(voxel_cf4, width, height); + kha.compute.Compute.setFloat2(voxel_cd4, width, height); kha.compute.Compute.compute(Std.int((width + 7) / 8), Std.int((height + 7) / 8), 1); } - public static function computeVoxelsLight() { - 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; - - pointIndex = spotIndex = 0; - for (i in 0...lights.length) { - var l = lights[i]; - if (!l.visible) continue; - path.light = l; - - kha.compute.Compute.setShader(voxel_sh5); - - kha.compute.Compute.setTexture(voxel_ta5, rts.get("voxelsLight").image, kha.compute.Access.Write); - kha.compute.Compute.setTexture(voxel_te5, rts.get("voxels").image, kha.compute.Access.Read); - kha.compute.Compute.setSampledTexture(voxel_tf5, rts.get("voxelsOut").image); - kha.compute.Compute.setSampledTexture(voxel_tg5, rts.get("voxelsSDF").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; - } - - kha.compute.Compute.setFloats(voxel_ca5, fa); - - kha.compute.Compute.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 - kha.compute.Compute.setSampledTexture(voxel_tb5, rts.get("shadowMapAtlas").image); - #else - kha.compute.Compute.setSampledTexture(voxel_tb5, rts.get("shadowMapAtlasSun").image); - #end - #else - kha.compute.Compute.setSampledTexture(voxel_tb5, rts.get("shadowMap").image); - #end - kha.compute.Compute.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 - kha.compute.Compute.setSampledTexture(voxel_tc5, rts.get("shadowMapAtlas").image); - #else - kha.compute.Compute.setSampledTexture(voxel_tc5, rts.get("shadowMapAtlasSpot").image); - #end - #else - kha.compute.Compute.setSampledTexture(voxel_tc5, rts.get("shadowMapSpot[" + spotIndex + "]").image); - spotIndex++; - #end - kha.compute.Compute.setInt(voxel_ch5, 2); - } - else { - #if lnx_shadowmap_atlas - #if lnx_shadowmap_atlas_single_map - kha.compute.Compute.setSampledTexture(voxel_td5, rts.get("shadowMapAtlas").image); - #else - kha.compute.Compute.setSampledTexture(voxel_td5, rts.get("shadowMapAtlasPoint").image); - kha.compute.Compute.setInt(voxel_cl5, i); - kha.compute.Compute.setFloats(voxel_cm5, iron.object.LightObject.pointLightsData); - #end - #else - kha.compute.Compute.setSampledCubeMap(voxel_td5, rts.get("shadowMapPoint[" + pointIndex + "]").cubeMap); - pointIndex++; - #end - kha.compute.Compute.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; - kha.compute.Compute.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] - m2._00 = l.tileScale[0]; - m2._11 = l.tileScale[0]; - // offset coordinate start from [0, 0] to [tile-start-x, tile-start-y] - m2._30 = l.tileOffsetX[0]; - m2._31 = l.tileOffsetY[0]; - m.multmat(m2); - #if (!kha_opengl) - m2.setIdentity(); - m2._11 = -1.0; - m2._31 = 1.0; - m.multmat(m2); - #end - } - #end - kha.compute.Compute.setMatrix(voxel_cj5, m.self); - // shadowsBias - kha.compute.Compute.setFloat(voxel_ck5, l.data.raw.shadows_bias); - #end // rp_shadowmap - - // lightPos - kha.compute.Compute.setFloat3(voxel_cc5, l.transform.worldx(), l.transform.worldy(), l.transform.worldz()); - // lightCol - var f = l.data.raw.strength; - kha.compute.Compute.setFloat3(voxel_cd5, l.data.raw.color[0] * f, l.data.raw.color[1] * f, l.data.raw.color[2] * f); - // lightType - kha.compute.Compute.setInt(voxel_ce5, iron.data.LightData.typeToInt(l.data.raw.type)); - // lightDir - var v = l.look(); - kha.compute.Compute.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; - kha.compute.Compute.setFloat2(voxel_cg5, vx, vy); - } - - kha.compute.Compute.compute(Std.int(res / 8), Std.int(res / 8), Std.int(res / 8)); - } - } #end // GI #end // Voxels }