From 1d88efafb10c4b614e394a80a5325a62e3999d02 Mon Sep 17 00:00:00 2001 From: e2002e Date: Mon, 8 Apr 2024 15:26:45 +0200 Subject: [PATCH] bump; --- Sources/iron/RenderPath.hx | 83 ++++++++++++++++++++++++++---- Sources/iron/Scene.hx | 3 -- Sources/iron/object/Clipmap.hx | 10 ++++ Sources/iron/object/LightObject.hx | 4 ++ Sources/iron/object/MeshObject.hx | 4 -- Sources/iron/object/Uniforms.hx | 9 +++- 6 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 Sources/iron/object/Clipmap.hx diff --git a/Sources/iron/RenderPath.hx b/Sources/iron/RenderPath.hx index 3d3132c7..2da972b1 100644 --- a/Sources/iron/RenderPath.hx +++ b/Sources/iron/RenderPath.hx @@ -17,6 +17,7 @@ import iron.object.Object; import iron.object.LightObject; import iron.object.MeshObject; import iron.object.Uniforms; +import iron.object.Clipmap; class RenderPath { @@ -65,15 +66,39 @@ class RenderPath { var depthBuffers: Array<{name: String, format: String}> = []; var additionalTargets: Array; - #if rp_voxels - public var voxelized = 0; - public var onVoxelize: Void->Bool = null; - public function voxelize() { // Returns true if scene should be voxelized - if (onVoxelize != null) return onVoxelize(); - #if arm_voxelgi_revox - return true; + #if (rp_voxels != "Off") + public static var pre_clear = true; + public static var res_pre_clear = true; + public static var clipmapLevel = 0; + public static var clipmaps:Array; + + public static inline function getVoxelRes(): Int { + #if (rp_voxelgi_resolution == 512) + return 512; + #elseif (rp_voxelgi_resolution == 256) + return 256; + #elseif (rp_voxelgi_resolution == 128) + return 128; + #elseif (rp_voxelgi_resolution == 64) + return 64; + #elseif (rp_voxelgi_resolution == 32) + return 32; #else - return ++voxelized > 2 ? false : true; + return 0; + #end + } + + public static inline function getVoxelResZ(): Float { + #if (rp_voxelgi_resolution_z == 1.0) + return 1.0; + #elseif (rp_voxelgi_resolution_z == 0.5) + return 0.5; + #elseif (rp_voxelgi_resolution_z == 0.25) + return 0.25; + #elseif (rp_voxelgi_resolution_z == 0.125) + return 0.125; + #else + return 0.0; #end } #end @@ -112,6 +137,35 @@ class RenderPath { numTrisShadow = 0; #end + #if (rp_voxels != "Off") + clipmapLevel = (clipmapLevel + 1) % Main.voxelgiClipmapCount; + var clipmap = clipmaps[clipmapLevel]; + + clipmap.voxelSize = clipmaps[0].voxelSize * Math.pow(2.0, clipmapLevel); + + var texelSize = 2.0 * clipmap.voxelSize; + var camera = iron.Scene.active.camera; + var center = new iron.math.Vec3( + Math.floor(camera.transform.worldx() / texelSize) * texelSize, + Math.floor(camera.transform.worldy() / texelSize) * texelSize, + Math.floor(camera.transform.worldz() / texelSize) * texelSize + ); + + clipmap.offset_prev.x = Std.int((clipmap.center.x - center.x) / texelSize); + clipmap.offset_prev.y = Std.int((clipmap.center.y - center.y) / texelSize); + clipmap.offset_prev.z = Std.int((clipmap.center.z - center.z) / texelSize); + clipmap.center = center; + + var res = getVoxelRes(); + var resZ = getVoxelResZ(); + var extents = new iron.math.Vec3(clipmap.voxelSize * res, clipmap.voxelSize * res, clipmap.voxelSize * resZ); + if (clipmap.extents.x != extents.x || clipmap.extents.y != extents.y || clipmap.extents.z != extents.z) + { + pre_clear = true; + } + clipmap.extents = extents; + #end + // Render to screen or probe var cam = Scene.active.camera; isProbePlanar = cam != null && cam.renderTarget != null; @@ -517,7 +571,8 @@ class RenderPath { if (rt == null || rt.raw.width > 0 || rt.depthStencilFrom == "" || - rt == depthToRenderTarget.get(rt.depthStencilFrom)) { + rt == depthToRenderTarget.get(rt.depthStencilFrom) || + rt.raw.is_image == true) { continue; } @@ -526,7 +581,8 @@ class RenderPath { if (rt2 == null || rt2.raw.width > 0 || rt2.depthStencilFrom != "" || - depthToRenderTarget.get(rt2.raw.depth_buffer) != null) { + depthToRenderTarget.get(rt2.raw.depth_buffer) != null || + rt2.raw.is_image == true) { continue; } @@ -553,6 +609,10 @@ class RenderPath { rt.image.setDepthStencilFrom(depthToRenderTarget.get(rt.depthStencilFrom).image); } } + + #if (rp_voxels != "Off") + res_pre_clear = true; + #end } public function createRenderTarget(t: RenderTargetRaw): RenderTarget { @@ -630,7 +690,8 @@ class RenderPath { // Image only var img = Image.create3D(width, height, depth, t.format != null ? getTextureFormat(t.format) : TextureFormat.RGBA32); - if (t.mipmaps) img.generateMipmaps(1000); // Allocate mipmaps + if (t.mipmaps) + img.generateMipmaps(1000); // Allocate mipmaps return img; } else { // 2D texture diff --git a/Sources/iron/Scene.hx b/Sources/iron/Scene.hx index 462de368..bd779f7f 100644 --- a/Sources/iron/Scene.hx +++ b/Sources/iron/Scene.hx @@ -213,9 +213,6 @@ class Scene { Data.getSceneRaw(sceneName, function(format: TSceneFormat) { Scene.create(format, function(o: Object) { if (done != null) done(o); - #if rp_voxels // Revoxelize - RenderPath.active.voxelized = 0; - #end #if (rp_background == "World") if (removeWorldShader != null) { diff --git a/Sources/iron/object/Clipmap.hx b/Sources/iron/object/Clipmap.hx new file mode 100644 index 00000000..9632f39c --- /dev/null +++ b/Sources/iron/object/Clipmap.hx @@ -0,0 +1,10 @@ +package iron.object; + +class Clipmap { + public var voxelSize = 0.125; + public var extents:iron.math.Vec3; + public var center:iron.math.Vec3; + public var offset_prev:iron.math.Vec3; + + public function new() {}; +} diff --git a/Sources/iron/object/LightObject.hx b/Sources/iron/object/LightObject.hx index 5323ceef..b9c3a8b1 100644 --- a/Sources/iron/object/LightObject.hx +++ b/Sources/iron/object/LightObject.hx @@ -634,6 +634,8 @@ class LightObject extends Object { 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) @@ -648,6 +650,8 @@ class LightObject extends Object { return 8; #elseif (rp_max_lights_cluster == 16) return 16; + #elseif (rp_max_lights_cluster == 24) + return 24; #elseif (rp_max_lights_cluster == 32) return 32; #elseif (rp_max_lights_cluster == 64) diff --git a/Sources/iron/object/MeshObject.hx b/Sources/iron/object/MeshObject.hx index 089144fa..15f1ed26 100644 --- a/Sources/iron/object/MeshObject.hx +++ b/Sources/iron/object/MeshObject.hx @@ -167,10 +167,6 @@ class MeshObject extends Object { if (skip_context == context) return setCulled(isShadow, true); if (force_context != null && force_context != context) return setCulled(isShadow, true); - #if (!arm_voxelgi_revox) // No revox - do not voxelize moving objects - if (context == "voxel" && raw != null && raw.mobile == true) return setCulled(isShadow, true); - #end - return setCulled(isShadow, false); } diff --git a/Sources/iron/object/Uniforms.hx b/Sources/iron/object/Uniforms.hx index 5eabdeba..8c1c3dee 100644 --- a/Sources/iron/object/Uniforms.hx +++ b/Sources/iron/object/Uniforms.hx @@ -178,9 +178,14 @@ class Uniforms { } if (isImage) { - g.setImageTexture(context.textureUnits[j], rt.image); // image2D/3D // Multiple voxel volumes, always set params - g.setTexture3DParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.PointFilter, MipMapFilter.LinearMipFilter); + g.setImageTexture(context.textureUnits[j], rt.image); // image2D/3D + if (rt.raw.depth <= 1) { + g.setTextureParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.LinearFilter, MipMapFilter.NoMipFilter); + } + else { + g.setTexture3DParameters(context.textureUnits[j], TextureAddressing.Mirror, TextureAddressing.Mirror, TextureAddressing.Mirror, TextureFilter.LinearFilter, TextureFilter.LinearFilter, MipMapFilter.LinearMipFilter); + } paramsSet = true; } else if (rt.isCubeMap) {