diff --git a/src/main/java/me/cortex/vulkanite/client/rendering/Uniforms.java b/src/main/java/me/cortex/vulkanite/client/rendering/Uniforms.java new file mode 100644 index 0000000..14b2292 --- /dev/null +++ b/src/main/java/me/cortex/vulkanite/client/rendering/Uniforms.java @@ -0,0 +1,65 @@ +package me.cortex.vulkanite.client.rendering; + +import net.coderbot.iris.uniforms.CapturedRenderingState; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.CameraSubmersionType; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.RotationAxis; +import org.joml.Matrix4f; +import org.joml.Vector4f; + +import java.util.Objects; + +public class Uniforms { + + + //Copied from CommonUniforms + static int isEyeInWater() { + CameraSubmersionType var0 = MinecraftClient.getInstance().gameRenderer.getCamera().getSubmersionType(); + if (var0 == CameraSubmersionType.WATER) { + return 1; + } else if (var0 == CameraSubmersionType.LAVA) { + return 2; + } else { + return var0 == CameraSubmersionType.POWDER_SNOW ? 3 : 0; + } + } + + //Copied from CelestialUniforms + + static Vector4f getSunPosition() { + return getCelestialPosition(100.0F); + } + + static Vector4f getMoonPosition() { + return getCelestialPosition(-100.0F); + } + + + static Vector4f getCelestialPosition(float y) { + final float sunPathRotation = 0.0f; + + Vector4f position = new Vector4f(0.0F, y, 0.0F, 0.0F); + + Matrix4f celestial = new Matrix4f(CapturedRenderingState.INSTANCE.getGbufferModelView()); + + // This is the same transformation applied by renderSky, however, it's been moved to here. + // This is because we need the result of it before it's actually performed in vanilla. + celestial.rotate(RotationAxis.POSITIVE_Y.rotationDegrees(-90.0F)); + celestial.rotate(RotationAxis.POSITIVE_Z.rotationDegrees(sunPathRotation)); + celestial.rotate(RotationAxis.POSITIVE_X.rotationDegrees(getSkyAngle() * 360.0F)); + + position = celestial.transform(position); + + return position; + } + + private static ClientWorld getWorld() { + return MinecraftClient.getInstance().world; + } + + private static float getSkyAngle() { + return getWorld().getSkyAngleRadians(CapturedRenderingState.INSTANCE.getTickDelta()); + } +} diff --git a/src/main/java/me/cortex/vulkanite/client/rendering/VulkanPipeline.java b/src/main/java/me/cortex/vulkanite/client/rendering/VulkanPipeline.java index f4eb5cc..fa9fd8c 100644 --- a/src/main/java/me/cortex/vulkanite/client/rendering/VulkanPipeline.java +++ b/src/main/java/me/cortex/vulkanite/client/rendering/VulkanPipeline.java @@ -22,6 +22,7 @@ import net.coderbot.iris.texture.pbr.PBRTextureHolder; import net.coderbot.iris.texture.pbr.PBRTextureManager; import net.coderbot.iris.uniforms.CapturedRenderingState; +import net.coderbot.iris.uniforms.CelestialUniforms; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.Camera; import net.minecraft.client.render.CameraSubmersionType; @@ -204,28 +205,13 @@ public void renderPostShadows(VGImage outImg, Camera camera) { invProjMatrix.transformProject(+1, +1, 0, 1, tmpv3).get(12*Float.BYTES, bb); invViewMatrix.get(Float.BYTES * 16, bb); - Vector4f position = new Vector4f(0.0F, isDay() ? 100 : -100, 0.0F, 0.0F); + Uniforms.getSunPosition().get(Float.BYTES * 32, bb); + Uniforms.getMoonPosition().get(Float.BYTES * 36, bb); - // TODO: Deduplicate / remove this function. - Matrix4f celestial = new Matrix4f(); - celestial.identity(); + bb.putInt(Float.BYTES * 40, frameId++); - // This is the same transformation applied by renderSky, however, it's been moved to here. - // This is because we need the result of it before it's actually performed in vanilla. - celestial.rotate(RotationAxis.POSITIVE_Y.rotationDegrees(-90.0F)); - celestial.rotate(RotationAxis.POSITIVE_X.rotationDegrees(getSunAngle() * 360.0F)); - - celestial.transform(position); - - - Vector3f vec3 = new Vector3f(position.x(), position.y(), position.z()); - vec3.normalize(); - vec3.get(Float.BYTES * 32, bb); - - bb.putInt(Float.BYTES * 35, frameId++); - - int flags = isEyeInWater()&3; - bb.putInt(Float.BYTES * 36, flags); + int flags = Uniforms.isEyeInWater()&3; + bb.putInt(Float.BYTES * 41, flags); } uboBuffer.unmap(); uboBuffer.flush(); @@ -317,16 +303,4 @@ public void destory() { } - - //Copied from CommonUniforms - static int isEyeInWater() { - CameraSubmersionType var0 = MinecraftClient.getInstance().gameRenderer.getCamera().getSubmersionType(); - if (var0 == CameraSubmersionType.WATER) { - return 1; - } else if (var0 == CameraSubmersionType.LAVA) { - return 2; - } else { - return var0 == CameraSubmersionType.POWDER_SNOW ? 3 : 0; - } - } } diff --git a/src/main/java/me/cortex/vulkanite/compat/SodiumResultAdapter.java b/src/main/java/me/cortex/vulkanite/compat/SodiumResultAdapter.java index 4ce7983..4fba133 100644 --- a/src/main/java/me/cortex/vulkanite/compat/SodiumResultAdapter.java +++ b/src/main/java/me/cortex/vulkanite/compat/SodiumResultAdapter.java @@ -15,7 +15,6 @@ public class SodiumResultAdapter { public static void compute(ChunkBuildOutput buildResult) { var ebr = (IAccelerationBuildResult) buildResult; Map map = new HashMap<>(); - ebr.setAccelerationGeometryData(map); for (var pass : buildResult.meshes.entrySet()) { var vertData = pass.getValue().getVertexData(); @@ -47,6 +46,12 @@ public static void compute(ChunkBuildOutput buildResult) { } map.put(pass.getKey(), new GeometryData(vertices>>2, geometryBuffer)); } + + if (!map.isEmpty()) { + ebr.setAccelerationGeometryData(map); + } else { + ebr.setAccelerationGeometryData(null); + } } diff --git a/src/main/resources/vulkanite.mixins.json b/src/main/resources/vulkanite.mixins.json index 7849a2a..b982811 100644 --- a/src/main/resources/vulkanite.mixins.json +++ b/src/main/resources/vulkanite.mixins.json @@ -5,26 +5,26 @@ "compatibilityLevel": "JAVA_17", "client": [ "iris.MixinNewWorldRenderingPipeline", + "iris.MixinPackRenderTargetDirectives", "iris.MixinPBRAtlasTexture", "iris.MixinProgramSet", "iris.MixinRenderTarget", - "iris.MixinPackRenderTargetDirectives", - "iris.MixinStandardMacros", "iris.MixinShaderPackSourceNames", + "iris.MixinStandardMacros", "minecraft.MixinAbstractTexture", "minecraft.MixinMinecraftClient", "minecraft.MixinSpriteAtlasTexture", "sodium.MixinRenderRegionManager", "sodium.MixinRenderSection", "sodium.MixinRenderSectionManager", + "sodium.PendingSectionUploadAccessor", "sodium.chunk.MixinChunkBuildResult", "sodium.chunk.MixinChunkRenderRebuildTask", "sodium.chunk.VertexFormatAccessor", "sodium.gl.MixinCommandList", "sodium.gl.MixinGlBufferArena", "sodium.gl.MixinGLRenderDevice", - "sodium.gl.MixinMutableBuffer", - "sodium.PendingSectionUploadAccessor" + "sodium.gl.MixinMutableBuffer" ], "injectors": { "defaultRequire": 1