Finish adding most view.h things to frame.glsl

This commit is contained in:
Kneelawk 2024-03-02 01:06:42 -08:00
parent 9f1c722474
commit 87c914100e
No known key found for this signature in database
GPG Key ID: DB4E28870D6D260A
2 changed files with 59 additions and 1 deletions

View File

@ -16,11 +16,17 @@ import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.Vec3;
public class FrameUniforms implements UniformProvider {
public static final int SIZE = 304;
public static final int SIZE = 1188;
public int debugMode;
@Nullable
@ -123,11 +129,19 @@ public class FrameUniforms implements UniformProvider {
MemoryUtil.memPutFloat(ptr, Math.max(2.5F, (float) window.getWidth() / 1920.0F * 2.5F));
ptr += 4;
MemoryUtil.memPutFloat(ptr, (float) window.getWidth() / (float) window.getHeight());
ptr += 4;
MemoryUtil.memPutFloat(ptr, Minecraft.getInstance().gameRenderer.getDepthFar());
ptr += 4;
MemoryUtil.memPutInt(ptr, getConstantAmbientLightFlag(context));
ptr += 4;
ptr = writeTime(ptr);
ptr = writeCameraIn(ptr);
MemoryUtil.memPutInt(ptr, debugMode);
lastInit = true;
@ -195,6 +209,45 @@ public class FrameUniforms implements UniformProvider {
return ptr + 16;
}
private long writeCameraIn(long ptr) {
Camera camera = context.camera();
if (!camera.isInitialized()) {
MemoryUtil.memPutInt(ptr, 0);
MemoryUtil.memPutInt(ptr + 4, 0);
return ptr + 8;
}
Level level = camera.getEntity().level();
BlockPos blockPos = camera.getBlockPosition();
Vec3 cameraPos = camera.getPosition();
FluidState fState = level.getFluidState(blockPos);
BlockState bState = level.getBlockState(blockPos);
float height = fState.getHeight(level, blockPos);
if (fState.isEmpty()) {
MemoryUtil.memPutInt(ptr, 0);
} else if (cameraPos.y < blockPos.getY() + height) {
if (fState.is(FluidTags.WATER)) {
MemoryUtil.memPutInt(ptr, 1);
} else if (fState.is(FluidTags.LAVA)) {
MemoryUtil.memPutInt(ptr, 2);
} else {
MemoryUtil.memPutInt(ptr, -1);
}
}
if (bState.isAir()) {
MemoryUtil.memPutInt(ptr + 4, 0);
} else {
if (bState.is(Blocks.POWDER_SNOW)) {
MemoryUtil.memPutInt(ptr + 4, 0);
} else {
MemoryUtil.memPutInt(ptr + 4, -1);
}
}
return ptr + 8;
}
private static long writeVec3(long ptr, float camX, float camY, float camZ) {
MemoryUtil.memPutFloat(ptr, camX);
MemoryUtil.memPutFloat(ptr + 4, camY);

View File

@ -38,6 +38,8 @@ layout(std140) uniform _FlwFrameUniforms {
vec2 flw_viewportSize;
float flw_defaultLineWidth;
float flw_aspectRatio;
float flw_viewDistance;
uint flw_constantAmbientLight;
@ -47,6 +49,9 @@ layout(std140) uniform _FlwFrameUniforms {
float flw_renderTicks;
float flw_renderSeconds;
uint flw_cameraInFluid;
uint flw_cameraInBlock;
uint _flw_debugMode;
};