Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
make iron independant of armory.
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002e committed Apr 1, 2024
1 parent 1e6710d commit a2ce522
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
56 changes: 41 additions & 15 deletions Sources/iron/RenderPath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -65,15 +66,39 @@ class RenderPath {
public var depthBuffers: Array<{name: String, format: String}> = [];
var additionalTargets: Array<kha.Canvas>;

#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<Clipmap>;

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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -583,7 +609,7 @@ class RenderPath {
}

#if (rp_voxels != "Off")
armory.renderpath.RenderPathCreator.res_pre_clear = true;
res_pre_clear = true;
#end
}

Expand Down
3 changes: 0 additions & 3 deletions Sources/iron/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions Sources/iron/object/Clipmap.hx
Original file line number Diff line number Diff line change
@@ -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() {};
}

0 comments on commit a2ce522

Please sign in to comment.