From c9c4666390cd26af0a6240f33255def203232d15 Mon Sep 17 00:00:00 2001 From: yvain Date: Wed, 17 Jul 2024 19:07:57 +0200 Subject: [PATCH 1/6] fix crashes with voxels --- Sources/iron/RenderPath.hx | 12 ++++++++---- Sources/iron/object/LightObject.hx | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/iron/RenderPath.hx b/Sources/iron/RenderPath.hx index 05167a8f..abdbde48 100644 --- a/Sources/iron/RenderPath.hx +++ b/Sources/iron/RenderPath.hx @@ -83,6 +83,8 @@ class RenderPath { return 64; #elseif (rp_voxelgi_resolution == 32) return 32; + #elseif (rp_voxelgi_resolution == 16) + return 16; #else return 0; #end @@ -689,15 +691,17 @@ 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 - return img; + if (t.mipmaps) + img.generateMipmaps(1); // Allocate mipmaps + return img; } else { // 2D texture if (t.is_image != null && t.is_image) { // Image var img = Image.create(width, height, t.format != null ? getTextureFormat(t.format) : TextureFormat.RGBA32); - if (t.mipmaps) img.generateMipmaps(1000); // Allocate mipmaps - return img; + if (t.mipmaps) + img.generateMipmaps(16); // Allocate mipmaps + return img; } else { // Render target return Image.createRenderTarget(width, height, diff --git a/Sources/iron/object/LightObject.hx b/Sources/iron/object/LightObject.hx index b9c3a8b1..bbd4d7f3 100644 --- a/Sources/iron/object/LightObject.hx +++ b/Sources/iron/object/LightObject.hx @@ -18,7 +18,7 @@ class LightObject extends Object { public var lightInAtlas = false; public var culledLight = false; public static var pointLightsData: kha.arrays.Float32Array = null; - public var shadowMapScale = 0.0; + public var shadowMapScale = 1.0;//when in forward, we drawMeshes() which will set this only after drawing shadowmap. This locks the drawing of the atlases so it's better to initialize it at 1.0 // Data used in uniforms public var tileOffsetX: Array = [0.0]; public var tileOffsetY: Array = [0.0]; From 4f2694cba61fc2dd43059541c5bba66fe4d77867 Mon Sep 17 00:00:00 2001 From: yvain Date: Fri, 26 Jul 2024 16:17:30 +0200 Subject: [PATCH 2/6] don't use mimpmaps for voxels images. --- Sources/iron/RenderPath.hx | 6 +----- Sources/iron/object/LightObject.hx | 2 +- Sources/iron/object/Uniforms.hx | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Sources/iron/RenderPath.hx b/Sources/iron/RenderPath.hx index abdbde48..47c82564 100644 --- a/Sources/iron/RenderPath.hx +++ b/Sources/iron/RenderPath.hx @@ -689,11 +689,7 @@ class RenderPath { if (height < 1) height = 1; if (t.depth != null && t.depth > 1) { // 3D texture // Image only - var img = Image.create3D(width, height, depth, - t.format != null ? getTextureFormat(t.format) : TextureFormat.RGBA32); - if (t.mipmaps) - img.generateMipmaps(1); // Allocate mipmaps - return img; + return Image.create3D(width, height, depth, t.format != null ? getTextureFormat(t.format) : TextureFormat.RGBA32); } else { // 2D texture if (t.is_image != null && t.is_image) { // Image diff --git a/Sources/iron/object/LightObject.hx b/Sources/iron/object/LightObject.hx index bbd4d7f3..30152456 100644 --- a/Sources/iron/object/LightObject.hx +++ b/Sources/iron/object/LightObject.hx @@ -18,7 +18,7 @@ class LightObject extends Object { public var lightInAtlas = false; public var culledLight = false; public static var pointLightsData: kha.arrays.Float32Array = null; - public var shadowMapScale = 1.0;//when in forward, we drawMeshes() which will set this only after drawing shadowmap. This locks the drawing of the atlases so it's better to initialize it at 1.0 + public var shadowMapScale = 1.0;//when in forward, we drawMeshes() which will set this only after drawing shadowmap. This blocks the drawing of the atlases so it's better to initialize it at 1.0 // Data used in uniforms public var tileOffsetX: Array = [0.0]; public var tileOffsetY: Array = [0.0]; diff --git a/Sources/iron/object/Uniforms.hx b/Sources/iron/object/Uniforms.hx index d59c77f1..f6df2e19 100644 --- a/Sources/iron/object/Uniforms.hx +++ b/Sources/iron/object/Uniforms.hx @@ -181,11 +181,11 @@ class Uniforms { // Multiple voxel volumes, always set params g.setImageTexture(context.textureUnits[j], rt.image); // image2D/3D if (rt.raw.name.startsWith("voxels_")) { - g.setTextureParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.LinearFilter, MipMapFilter.LinearMipFilter); + g.setTextureParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.LinearFilter, MipMapFilter.NoMipFilter); } else if (rt.raw.name.startsWith("voxels")) { - g.setTexture3DParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.LinearFilter, MipMapFilter.LinearMipFilter); + g.setTexture3DParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.PointFilter, MipMapFilter.NoMipFilter); } else { From 0d73a896f8f4dd26f3d205b9981cf340e057c195 Mon Sep 17 00:00:00 2001 From: yvain Date: Sat, 27 Jul 2024 07:14:45 +0200 Subject: [PATCH 3/6] use linear filter and no mipmap filter for 3D voxels images --- Sources/iron/object/Uniforms.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/iron/object/Uniforms.hx b/Sources/iron/object/Uniforms.hx index f6df2e19..26349699 100644 --- a/Sources/iron/object/Uniforms.hx +++ b/Sources/iron/object/Uniforms.hx @@ -185,7 +185,7 @@ class Uniforms { } else if (rt.raw.name.startsWith("voxels")) { - g.setTexture3DParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.PointFilter, MipMapFilter.NoMipFilter); + g.setTexture3DParameters(context.textureUnits[j], TextureAddressing.Clamp, TextureAddressing.Clamp, TextureAddressing.Clamp, TextureFilter.LinearFilter, TextureFilter.LinearFilter, MipMapFilter.NoMipFilter); } else { From 8d7402a6c4f6f05097f5c1d52f7a8e6e7b2f8d74 Mon Sep 17 00:00:00 2001 From: yvain Date: Wed, 31 Jul 2024 13:30:41 +0200 Subject: [PATCH 4/6] rollback --- Sources/iron/object/LightObject.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/iron/object/LightObject.hx b/Sources/iron/object/LightObject.hx index 30152456..b9c3a8b1 100644 --- a/Sources/iron/object/LightObject.hx +++ b/Sources/iron/object/LightObject.hx @@ -18,7 +18,7 @@ class LightObject extends Object { public var lightInAtlas = false; public var culledLight = false; public static var pointLightsData: kha.arrays.Float32Array = null; - public var shadowMapScale = 1.0;//when in forward, we drawMeshes() which will set this only after drawing shadowmap. This blocks the drawing of the atlases so it's better to initialize it at 1.0 + public var shadowMapScale = 0.0; // Data used in uniforms public var tileOffsetX: Array = [0.0]; public var tileOffsetY: Array = [0.0]; From c93aa27b472f01d2bb54a9775c463dda68bc13d7 Mon Sep 17 00:00:00 2001 From: yvain Date: Mon, 5 Aug 2024 20:03:29 +0200 Subject: [PATCH 5/6] set default shadowMapScale value to 1.0 --- Sources/iron/object/LightObject.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/iron/object/LightObject.hx b/Sources/iron/object/LightObject.hx index b9c3a8b1..10866bc1 100644 --- a/Sources/iron/object/LightObject.hx +++ b/Sources/iron/object/LightObject.hx @@ -18,7 +18,7 @@ class LightObject extends Object { public var lightInAtlas = false; public var culledLight = false; public static var pointLightsData: kha.arrays.Float32Array = null; - public var shadowMapScale = 0.0; + public var shadowMapScale = 1.0; // When in forward if this defaults to 0.0, the atlas are not drawn before being bound. // Data used in uniforms public var tileOffsetX: Array = [0.0]; public var tileOffsetY: Array = [0.0]; From 3debc8635a69e8611893f0ba8ea973ec512c5a41 Mon Sep 17 00:00:00 2001 From: yvain Date: Thu, 8 Aug 2024 11:59:22 +0200 Subject: [PATCH 6/6] Check if 3D images are mipmaps for images creation. --- Sources/iron/RenderPath.hx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/iron/RenderPath.hx b/Sources/iron/RenderPath.hx index 47c82564..adee8214 100644 --- a/Sources/iron/RenderPath.hx +++ b/Sources/iron/RenderPath.hx @@ -689,14 +689,18 @@ class RenderPath { if (height < 1) height = 1; if (t.depth != null && t.depth > 1) { // 3D texture // Image only - return Image.create3D(width, height, depth, t.format != null ? getTextureFormat(t.format) : TextureFormat.RGBA32); + var img = Image.create3D(width, height, depth, + t.format != null ? getTextureFormat(t.format) : TextureFormat.RGBA32); + if (t.mipmaps) + img.generateMipmaps(1000); // Allocate mipmaps + return img; } else { // 2D texture if (t.is_image != null && t.is_image) { // Image var img = Image.create(width, height, t.format != null ? getTextureFormat(t.format) : TextureFormat.RGBA32); if (t.mipmaps) - img.generateMipmaps(16); // Allocate mipmaps + img.generateMipmaps(1000); // Allocate mipmaps return img; } else { // Render target