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

Gi clipmaps #208

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions Sources/iron/RenderPath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RenderPath {
var lastFrameTime = 0.0;
var loading = 0;
var cachedShaderContexts: Map<String, CachedShaderContext> = new Map();
var depthBuffers: Array<{name: String, format: String}> = [];
public var depthBuffers: Array<{name: String, format: String}> = [];
var additionalTargets: Array<kha.Canvas>;

#if rp_voxels
Expand Down Expand Up @@ -112,6 +112,34 @@ class RenderPath {
numTrisShadow = 0;
#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];

clipmap.voxelSize = armory.renderpath.RenderPathCreator.clipmaps[0].voxelSize * Math.pow(2.0, armory.renderpath.RenderPathCreator.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 = armory.renderpath.Inc.getVoxelRes();
var extents = new iron.math.Vec3(clipmap.voxelSize * res, clipmap.voxelSize * res, clipmap.voxelSize * res);
if (clipmap.extents.x != extents.x || clipmap.extents.y != extents.y || clipmap.extents.z != extents.z)
{
armory.renderpath.RenderPathCreator.pre_clear = true;
}
clipmap.extents = extents;
#end

// Render to screen or probe
var cam = Scene.active.camera;
isProbePlanar = cam != null && cam.renderTarget != null;
Expand Down Expand Up @@ -539,7 +567,7 @@ class RenderPath {
}
}

// Resize textures
// Resize textures FIXME: this doesn't seem to resize 2D images
for (rt in renderTargets) {
if (rt != null && rt.raw.width == 0) {
App.notifyOnInit(rt.image.unload);
Expand All @@ -553,6 +581,16 @@ class RenderPath {
rt.image.setDepthStencilFrom(depthToRenderTarget.get(rt.depthStencilFrom).image);
}
}

#if (rp_voxels != "Off")
#if (rp_voxels == "Voxel GI")
armory.renderpath.Inc.initGI("voxels_diffuse");
armory.renderpath.Inc.initGI("voxels_specular");
#else
armory.renderpath.Inc.initGI("voxels_ao");
#end
armory.renderpath.RenderPathCreator.res_pre_clear = true;
#end
}

public function createRenderTarget(t: RenderTargetRaw): RenderTarget {
Expand Down
4 changes: 2 additions & 2 deletions Sources/iron/object/MeshObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class MeshObject extends Object {
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);
//if (context == "voxel" && raw != null && raw.mobile == true) return setCulled(isShadow, true);
#end

return setCulled(isShadow, false);
Expand All @@ -185,7 +185,7 @@ class MeshObject extends Object {
// particleSystems for update, particleOwner for render
if (particleSystems != null || particleOwner != null) radiusScale *= 1000;
#end
if (context == "voxel") radiusScale *= 100;
//if (context == "voxel") radiusScale *= 100;
if (data.geom.instanced) radiusScale *= 100;
var isShadow = context == "shadowmap";
var frustumPlanes = isShadow ? light.frustumPlanes : camera.frustumPlanes;
Expand Down
9 changes: 7 additions & 2 deletions Sources/iron/object/Uniforms.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.Clamp, TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.LinearFilter, MipMapFilter.LinearMipFilter);
}
paramsSet = true;
}
else if (rt.isCubeMap) {
Expand Down