Skip to content

Commit

Permalink
changed uniforms, fixed no geometry jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
MCRcortex committed Sep 14, 2023
1 parent 5a18eeb commit 84ac9d3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 37 deletions.
65 changes: 65 additions & 0 deletions src/main/java/me/cortex/vulkanite/client/rendering/Uniforms.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class SodiumResultAdapter {
public static void compute(ChunkBuildOutput buildResult) {
var ebr = (IAccelerationBuildResult) buildResult;
Map<TerrainRenderPass, GeometryData> map = new HashMap<>();
ebr.setAccelerationGeometryData(map);
for (var pass : buildResult.meshes.entrySet()) {
var vertData = pass.getValue().getVertexData();

Expand Down Expand Up @@ -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);
}
}


Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/vulkanite.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 84ac9d3

Please sign in to comment.