From a2ce52258696fb995a31af1eef7bffbef99f01e6 Mon Sep 17 00:00:00 2001 From: e2002e Date: Mon, 1 Apr 2024 14:46:06 +0200 Subject: [PATCH] make iron independant of armory. --- Sources/iron/RenderPath.hx | 56 +++++++++++++++++++++++++--------- Sources/iron/Scene.hx | 3 -- Sources/iron/object/Clipmap.hx | 10 ++++++ 3 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 Sources/iron/object/Clipmap.hx diff --git a/Sources/iron/RenderPath.hx b/Sources/iron/RenderPath.hx index 76e08321..17c41810 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 { public 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 @@ -113,10 +138,10 @@ class RenderPath { #end #if (rp_voxels != "Off") - armory.renderpath.RenderPathCreator.clipmapLevel = (armory.renderpath.RenderPathCreator.clipmapLevel + 1) % Main.voxelgiClipmapCount; - var clipmap = armory.renderpath.RenderPathCreator.clipmaps[armory.renderpath.RenderPathCreator.clipmapLevel]; + clipmapLevel = (clipmapLevel + 1) % Main.voxelgiClipmapCount; + var clipmap = clipmaps[clipmapLevel]; - clipmap.voxelSize = armory.renderpath.RenderPathCreator.clipmaps[0].voxelSize * Math.pow(2.0, armory.renderpath.RenderPathCreator.clipmapLevel); + clipmap.voxelSize = clipmaps[0].voxelSize * Math.pow(2.0, clipmapLevel); var texelSize = 2.0 * clipmap.voxelSize; var camera = iron.Scene.active.camera; @@ -131,11 +156,12 @@ class RenderPath { clipmap.offset_prev.z = Std.int((clipmap.center.z - center.z) / texelSize); clipmap.center = center; - var res = armory.renderpath.Inc.getVoxelRes(); - var extents = new iron.math.Vec3(clipmap.voxelSize * res, clipmap.voxelSize * res, clipmap.voxelSize * res); + 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) { - armory.renderpath.RenderPathCreator.pre_clear = true; + pre_clear = true; } clipmap.extents = extents; #end @@ -583,7 +609,7 @@ class RenderPath { } #if (rp_voxels != "Off") - armory.renderpath.RenderPathCreator.res_pre_clear = true; + res_pre_clear = true; #end } 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() {}; +}