diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/postProcessing/BlazeDhFogRenderer.java b/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/postProcessing/BlazeDhFogRenderer.java index 14735f383..b022c84e1 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/postProcessing/BlazeDhFogRenderer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/postProcessing/BlazeDhFogRenderer.java @@ -24,9 +24,8 @@ public class BlazeDhFogRenderer {} #else -import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogColorMode; -import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection; import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiFogRenderParam; import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer; import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer; import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper; @@ -50,8 +49,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhFo import java.awt.*; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.OptionalDouble; -import java.util.OptionalInt; import com.mojang.blaze3d.buffers.GpuBuffer; import com.mojang.blaze3d.buffers.GpuBufferSlice; @@ -61,7 +58,6 @@ import com.mojang.blaze3d.pipeline.BlendFunction; import com.mojang.blaze3d.pipeline.RenderPipeline; import com.mojang.blaze3d.systems.CommandEncoder; import com.mojang.blaze3d.systems.GpuDevice; -import com.mojang.blaze3d.systems.RenderPass; import com.mojang.blaze3d.systems.RenderSystem; #if MC_VER <= MC_26_1_2 @@ -168,7 +164,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer //region @Override - public void render(RenderParams renderParams) + public void render(RenderParams renderParams, DhApiFogRenderParam fogRenderParams) { this.tryInit(); @@ -229,48 +225,19 @@ public class BlazeDhFogRenderer implements IDhFogRenderer // create data // - int lodDrawDistance = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH; - Mat4f inverseMvmProjMatrix = new Mat4f(renderParams.dhMvmProjMatrix); inverseMvmProjMatrix.invert(); - if (renderParams.dhMvmProjMatrix == null) - { - return; - } - - - Color fogColor = this.getFogColor(renderParams.partialTicks); - - // fog config - float farFogStart = Config.Client.Advanced.Graphics.Fog.farFogStart.get(); - float farFogEnd = Config.Client.Advanced.Graphics.Fog.farFogEnd.get(); - float farFogMin = Config.Client.Advanced.Graphics.Fog.farFogMin.get(); - float farFogMax = Config.Client.Advanced.Graphics.Fog.farFogMax.get(); - float farFogDensity = Config.Client.Advanced.Graphics.Fog.farFogDensity.get(); - - // override fog if underwater - if (MC_RENDER.isFogStateSpecial()) - { - // hide everything behind fog - farFogStart = 0.0f; - farFogEnd = 0.0f; - } - - - // height config - EDhApiHeightFogMixMode heightFogMixingMode = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMixMode.get(); - boolean heightFogEnabled = heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL && heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL; + EDhApiHeightFogMixMode heightFogMixingMode = fogRenderParams.getHeightFogMixingMode(); + boolean heightFogEnabled = + heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL + && heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL; boolean useSphericalFog = heightFogMixingMode == EDhApiHeightFogMixMode.SPHERICAL; - EDhApiHeightFogDirection heightFogCameraDirection = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDirection.get(); - float heightFogStart = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogStart.get(); - float heightFogEnd = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogEnd.get(); - float heightFogMin = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMin.get(); - float heightFogMax = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMax.get(); - float heightFogDensity = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDensity.get(); + Color fogColor = fogRenderParams.getFogColor(); + // upload data // @@ -287,31 +254,30 @@ public class BlazeDhFogRenderer implements IDhFogRenderer fogColor.getAlpha() / 255.0f) // uFogColor .putFloat(1.f / lodDrawDistance) //uFogScale .putFloat(1.f / MC.getWrappedClientLevel().getMaxHeight()) //uFogVerticalScale - // only used for debugging - .putInt(0) //uFogDebugMode // 1 = render everything with fog color // 7 = use debug rendering - .putInt(Config.Client.Advanced.Graphics.Fog.farFogFalloff.get().value) //uFogFalloffType + .putInt(0) //uFogDebugMode // 0 = normal // 1 = render everything with fog color // 7 = use debug rendering + .putInt(fogRenderParams.getFarFogFalloff().value) //uFogFalloffType // fog config - .putFloat(farFogStart) // uFarFogStart - .putFloat(farFogEnd - farFogStart) // uFarFogLength - .putFloat(farFogMin) // uFarFogMin - .putFloat(farFogMax - farFogMin) // uFarFogRange - .putFloat(farFogDensity) // uFarFogDensity + .putFloat(fogRenderParams.getFarFogStartPercent()) // uFarFogStart + .putFloat(fogRenderParams.getFarFogEndPercent() - fogRenderParams.getFarFogStartPercent()) // uFarFogLength + .putFloat(fogRenderParams.getFarFogMinThickness()) // uFarFogMin + .putFloat(fogRenderParams.getFarFogMaxThickness() - fogRenderParams.getFarFogMinThickness()) // uFarFogRange + .putFloat(fogRenderParams.getFarFogDensity()) // uFarFogDensity // height fog config - .putFloat(heightFogStart) // uHeightFogStart - .putFloat(heightFogEnd - heightFogStart) // uHeightFogLength - .putFloat(heightFogMin) // uHeightFogMin - .putFloat(heightFogMax - heightFogMin) // uHeightFogRange - .putFloat(heightFogDensity) // uHeightFogDensity + .putFloat(fogRenderParams.getHeightFogStartPercent()) // uHeightFogStart + .putFloat(fogRenderParams.getHeightFogEndPercent() - fogRenderParams.getHeightFogStartPercent()) // uHeightFogLength + .putFloat(fogRenderParams.getHeightFogMinThickness()) // uHeightFogMin + .putFloat(fogRenderParams.getHeightFogMaxThickness() - fogRenderParams.getHeightFogMinThickness()) // uHeightFogRange + .putFloat(fogRenderParams.getHeightFogDensity()) // uHeightFogDensity // ?? .putInt(heightFogEnabled ? 1 : 0) // uHeightFogEnabled - .putInt(Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogFalloff.get().value) // uHeightFogFalloffType - .putInt(heightFogCameraDirection.basedOnCamera ? 1 : 0) // uHeightBasedOnCamera - .putFloat(Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogBaseHeight.get()) // uHeightFogBaseHeight - .putInt(heightFogCameraDirection.fogAppliesUp ? 1 : 0) // uHeightFogAppliesUp - .putInt(heightFogCameraDirection.fogAppliesDown ? 1 : 0) // uHeightFogAppliesDown + .putInt(fogRenderParams.getHeightFogFalloff().value) // uHeightFogFalloffType + .putInt(fogRenderParams.getHeightFogDirection().basedOnCamera ? 1 : 0) // uHeightBasedOnCamera + .putFloat(fogRenderParams.getHeightFogBaseHeight()) // uHeightFogBaseHeight + .putInt(fogRenderParams.getHeightFogDirection().fogAppliesUp ? 1 : 0) // uHeightFogAppliesUp + .putInt(fogRenderParams.getHeightFogDirection().fogAppliesDown ? 1 : 0) // uHeightFogAppliesDown .putInt(useSphericalFog ? 1 : 0) // uUseSphericalFog .putInt(heightFogMixingMode.value) // uHeightFogMixingMode .putFloat((float)MC_RENDER.getCameraExactPosition().y) // uCameraBlockYPos @@ -335,21 +301,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer } - private Color getFogColor(float partialTicks) - { - Color fogColor; - - if (Config.Client.Advanced.Graphics.Fog.colorMode.get() == EDhApiFogColorMode.USE_SKY_COLOR) - { - fogColor = MC_RENDER.getSkyColor(); - } - else - { - fogColor = MC_RENDER.getFogColor(partialTicks); - } - - return fogColor; - } + private void renderFogToTexture() { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogRenderer.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogRenderer.java index dd54a20f0..fca615396 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogRenderer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogRenderer.java @@ -19,6 +19,7 @@ package com.seibel.distanthorizons.common.render.openGl.postProcessing.fog; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiFogRenderParam; import com.seibel.distanthorizons.common.render.openGl.glObject.GLState; import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; @@ -108,7 +109,7 @@ public class GlDhFogRenderer implements IDhFogRenderer //region @Override - public void render(RenderParams renderParams) + public void render(RenderParams renderParams, DhApiFogRenderParam fogRenderParams) { // GLState needed in MC 1.16.5 probably due to MC not manually setting each GL state they need before the next rendering step try (GLState state = new GLState()) @@ -126,7 +127,7 @@ public class GlDhFogRenderer implements IDhFogRenderer } GlDhFogShader.INSTANCE.frameBuffer = this.fogFramebuffer; - GlDhFogShader.INSTANCE.setProjectionMatrix(renderParams.dhMvmProjMatrix); + GlDhFogShader.INSTANCE.prepUniformObjects(renderParams.dhMvmProjMatrix, fogRenderParams); GlDhFogShader.INSTANCE.render(renderParams); GlDhFogApplyShader.INSTANCE.fogTexture = this.fogTexture; diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogShader.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogShader.java index ec9af37e4..9c561d040 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogShader.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fog/GlDhFogShader.java @@ -19,9 +19,9 @@ package com.seibel.distanthorizons.common.render.openGl.postProcessing.fog; -import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogColorMode; import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection; import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiFogRenderParam; import com.seibel.distanthorizons.api.objects.math.DhApiMat4f; import com.seibel.distanthorizons.common.render.openGl.GlDhMetaRenderer; import com.seibel.distanthorizons.common.render.openGl.glObject.shader.GlShaderProgram; @@ -37,8 +37,6 @@ import com.seibel.distanthorizons.core.util.math.Mat4f; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper; import org.lwjgl.opengl.GL32; -import java.awt.*; - public class GlDhFogShader extends GlAbstractShaderRenderer { public static final GlDhFogShader INSTANCE = new GlDhFogShader(); @@ -51,6 +49,7 @@ public class GlDhFogShader extends GlAbstractShaderRenderer public int frameBuffer; private Mat4f inverseMvmProjMatrix; + private DhApiFogRenderParam fogRenderParams; @@ -167,95 +166,58 @@ public class GlDhFogShader extends GlAbstractShaderRenderer { int lodDrawDistance = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH; - - - if (this.inverseMvmProjMatrix != null) - { - this.shader.setUniform(this.uInvMvmProj, this.inverseMvmProjMatrix); - } + this.shader.setUniform(this.uInvMvmProj, this.inverseMvmProjMatrix); // Fog uniforms - this.shader.setUniform(this.uFogColor, this.getFogColor(renderParams.partialTicks)); + this.shader.setUniform(this.uFogColor, this.fogRenderParams.getFogColor()); this.shader.setUniform(this.uFogScale, 1.f / lodDrawDistance); this.shader.setUniform(this.uFogVerticalScale, 1.f / MC.getWrappedClientLevel().getMaxHeight()); - // only used for debugging - this.shader.setUniform(this.uFogDebugMode, 0); // 1 = render everything with fog color // 7 = use debug rendering - this.shader.setUniform(this.uFogFalloffType, Config.Client.Advanced.Graphics.Fog.farFogFalloff.get().value); + this.shader.setUniform(this.uFogDebugMode, 0); // 0 = normal // 1 = render everything with fog color // 7 = use debug rendering + this.shader.setUniform(this.uFogFalloffType, this.fogRenderParams.getFarFogFalloff().value); // fog config - float farFogStart = Config.Client.Advanced.Graphics.Fog.farFogStart.get(); - float farFogEnd = Config.Client.Advanced.Graphics.Fog.farFogEnd.get(); - float farFogMin = Config.Client.Advanced.Graphics.Fog.farFogMin.get(); - float farFogMax = Config.Client.Advanced.Graphics.Fog.farFogMax.get(); - float farFogDensity = Config.Client.Advanced.Graphics.Fog.farFogDensity.get(); - - // override fog if underwater - if (MC_RENDER.isFogStateSpecial()) - { - // hide everything behind fog - farFogStart = 0.0f; - farFogEnd = 0.0f; - } - - this.shader.setUniform(this.uFarFogStart, farFogStart); - this.shader.setUniform(this.uFarFogLength, farFogEnd - farFogStart); - this.shader.setUniform(this.uFarFogMin, farFogMin); - this.shader.setUniform(this.uFarFogRange, farFogMax - farFogMin); - this.shader.setUniform(this.uFarFogDensity, farFogDensity); + this.shader.setUniform(this.uFarFogStart, this.fogRenderParams.getFarFogStartPercent()); + this.shader.setUniform(this.uFarFogLength, this.fogRenderParams.getFarFogEndPercent() - this.fogRenderParams.getFarFogStartPercent()); + this.shader.setUniform(this.uFarFogMin, this.fogRenderParams.getFarFogMinThickness()); + this.shader.setUniform(this.uFarFogRange, this.fogRenderParams.getFarFogMaxThickness() - this.fogRenderParams.getFarFogMinThickness()); + this.shader.setUniform(this.uFarFogDensity, this.fogRenderParams.getFarFogDensity()); // height config - EDhApiHeightFogMixMode heightFogMixingMode = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMixMode.get(); - boolean heightFogEnabled = heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL && heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL; + EDhApiHeightFogMixMode heightFogMixingMode = this.fogRenderParams.getHeightFogMixingMode(); + boolean heightFogEnabled = + heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL + && heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL; boolean useSphericalFog = heightFogMixingMode == EDhApiHeightFogMixMode.SPHERICAL; - EDhApiHeightFogDirection heightFogCameraDirection = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDirection.get(); + EDhApiHeightFogDirection heightFogDirection = this.fogRenderParams.getHeightFogDirection(); - float heightFogStart = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogStart.get(); - float heightFogEnd = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogEnd.get(); - float heightFogMin = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMin.get(); - float heightFogMax = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMax.get(); - float heightFogDensity = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDensity.get(); - - this.shader.setUniform(this.uHeightFogStart, heightFogStart); - this.shader.setUniform(this.uHeightFogLength, heightFogEnd - heightFogStart); - this.shader.setUniform(this.uHeightFogMin, heightFogMin); - this.shader.setUniform(this.uHeightFogRange, heightFogMax - heightFogMin); - this.shader.setUniform(this.uHeightFogDensity, heightFogDensity); + this.shader.setUniform(this.uHeightFogStart, this.fogRenderParams.getHeightFogStartPercent()); + this.shader.setUniform(this.uHeightFogLength, this.fogRenderParams.getHeightFogEndPercent() - this.fogRenderParams.getHeightFogStartPercent()); + this.shader.setUniform(this.uHeightFogMin, this.fogRenderParams.getFarFogMinThickness()); + this.shader.setUniform(this.uHeightFogRange, this.fogRenderParams.getFarFogMaxThickness() - this.fogRenderParams.getFarFogMinThickness()); + this.shader.setUniform(this.uHeightFogDensity, this.fogRenderParams.getFarFogDensity()); this.shader.setUniform(this.uHeightFogEnabled, heightFogEnabled); - this.shader.setUniform(this.uHeightFogFalloffType, Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogFalloff.get().value); - this.shader.setUniform(this.uHeightFogBaseHeight, Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogBaseHeight.get()); - this.shader.setUniform(this.uHeightBasedOnCamera, heightFogCameraDirection.basedOnCamera); - this.shader.setUniform(this.uHeightFogAppliesUp, heightFogCameraDirection.fogAppliesUp); - this.shader.setUniform(this.uHeightFogAppliesDown, heightFogCameraDirection.fogAppliesDown); + this.shader.setUniform(this.uHeightFogFalloffType, this.fogRenderParams.getHeightFogFalloff().value); + this.shader.setUniform(this.uHeightFogBaseHeight, this.fogRenderParams.getHeightFogBaseHeight()); + this.shader.setUniform(this.uHeightBasedOnCamera, heightFogDirection.basedOnCamera); + this.shader.setUniform(this.uHeightFogAppliesUp, heightFogDirection.fogAppliesUp); + this.shader.setUniform(this.uHeightFogAppliesDown, heightFogDirection.fogAppliesDown); this.shader.setUniform(this.uUseSphericalFog, useSphericalFog); this.shader.setUniform(this.uHeightFogMixingMode, heightFogMixingMode.value); this.shader.setUniform(this.uCameraBlockYPos, (float)MC_RENDER.getCameraExactPosition().y); } - private Color getFogColor(float partialTicks) - { - Color fogColor; - - if (Config.Client.Advanced.Graphics.Fog.colorMode.get() == EDhApiFogColorMode.USE_SKY_COLOR) - { - fogColor = MC_RENDER.getSkyColor(); - } - else - { - fogColor = MC_RENDER.getFogColor(partialTicks); - } - - return fogColor; - } - public void setProjectionMatrix(DhApiMat4f modelViewProjectionMatrix) + public void prepUniformObjects(DhApiMat4f modelViewProjectionMatrix, DhApiFogRenderParam fogRenderParams) { this.inverseMvmProjMatrix = new Mat4f(modelViewProjectionMatrix); this.inverseMvmProjMatrix.invert(); + + this.fogRenderParams = fogRenderParams; } //endregion diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java index 3781fd8c8..403cbfe17 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java @@ -1,11 +1,8 @@ package com.seibel.distanthorizons.fabric; import com.seibel.distanthorizons.api.DhApi; -import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBlockColorOverrideEvent; -import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBlockStateWrapperCreatedEvent; -import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiChunkProcessingEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.*; import com.seibel.distanthorizons.api.methods.events.DhApiEventRegister; -import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelLoadEvent; import com.seibel.distanthorizons.common.AbstractModInitializer; import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper; @@ -18,10 +15,7 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; -import com.seibel.distanthorizons.fabric.testing.TestBlockWrapperCreatedEvent; -import com.seibel.distanthorizons.fabric.testing.TestChunkInputReplacerEvent; -import com.seibel.distanthorizons.fabric.testing.TestCustomColorEvent; -import com.seibel.distanthorizons.fabric.testing.TestWorldGenBindingEvent; +import com.seibel.distanthorizons.fabric.testing.*; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; @@ -106,6 +100,12 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy DhApi.events.bind(DhApiBlockColorOverrideEvent.class, new TestCustomColorEvent()); DhApi.events.bind(DhApiBlockStateWrapperCreatedEvent.class, new TestBlockWrapperCreatedEvent()); } + + // test fog override + if (false) + { + DhApi.events.bind(DhApiBeforeFogRenderEvent.class, new TestFogRenderEvent()); + } } diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestFogRenderEvent.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestFogRenderEvent.java new file mode 100644 index 000000000..cef972f9c --- /dev/null +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestFogRenderEvent.java @@ -0,0 +1,45 @@ +package com.seibel.distanthorizons.fabric.testing; + +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeFogRenderEvent; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiCancelableEventParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiFogRenderParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiMutableFogRenderParam; +import com.seibel.distanthorizons.core.logging.DhLogger; +import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; + +public class TestFogRenderEvent extends DhApiBeforeFogRenderEvent +{ + private static final DhLogger LOGGER = new DhLoggerBuilder().build(); + + private static final float INCREMENT_PER_SECOND = 0.25f; + + + private float lastFar = 1; + private long lastUpdateTime = System.nanoTime(); + + + + @Override + public void beforeRender(DhApiCancelableEventParam event) + { + EventParam eventParam = event.value; + DhApiFogRenderParam originalParms = eventParam.getOriginalFogRenderParam(); + DhApiMutableFogRenderParam mutableParms = eventParam.getFogRenderParam(); + + long currentTime = System.nanoTime(); + float deltaSeconds = (currentTime - this.lastUpdateTime) / 1_000_000_000f; + this.lastUpdateTime = currentTime; + + this.lastFar += INCREMENT_PER_SECOND * deltaSeconds; + if (this.lastFar >= originalParms.getFarFogMaxThickness()) + { + this.lastFar = 0.0f; + } + + mutableParms.setFarFogStartPercent(this.lastFar); + mutableParms.setFarFogEndPercent(this.lastFar + 0.5f); + } + + + +}