mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-20 17:05:32 +01:00
Add more player uniforms
This commit is contained in:
parent
0ea8a31103
commit
81d83e185b
6 changed files with 132 additions and 35 deletions
|
@ -18,11 +18,7 @@ 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 {
|
||||
|
@ -180,7 +176,8 @@ public class FrameUniforms implements UniformProvider {
|
|||
cleanProjection.scale(gra.flywheel$getZoom(), gra.flywheel$getZoom(), 1.0F);
|
||||
}
|
||||
|
||||
cleanProjection.mul(new Matrix4f().setPerspective(fov * ((float) Math.PI / 180F), (float) mc.getWindow().getWidth() / (float) mc.getWindow().getHeight(), 0.05F, gr.getDepthFar()));
|
||||
cleanProjection.mul(new Matrix4f().setPerspective(fov * ((float) Math.PI / 180F),
|
||||
(float) mc.getWindow().getWidth() / (float) mc.getWindow().getHeight(), 0.05F, gr.getDepthFar()));
|
||||
|
||||
cleanViewProjection.set(cleanProjection).mul(stack.last().pose());
|
||||
}
|
||||
|
@ -214,38 +211,12 @@ public class FrameUniforms implements UniformProvider {
|
|||
if (!camera.isInitialized()) {
|
||||
MemoryUtil.memPutInt(ptr, 0);
|
||||
MemoryUtil.memPutInt(ptr + 4, 0);
|
||||
return ptr + 8;
|
||||
}
|
||||
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;
|
||||
return Uniforms.writeInFluidAndBlock(ptr, level, blockPos, cameraPos);
|
||||
}
|
||||
|
||||
private static int getConstantAmbientLightFlag(RenderContext context) {
|
||||
|
|
|
@ -4,19 +4,24 @@ import org.jetbrains.annotations.Nullable;
|
|||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderContext;
|
||||
import com.jozufozu.flywheel.backend.mixin.AbstractClientPlayerAccessor;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.FastColor;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.scores.PlayerTeam;
|
||||
|
||||
public class PlayerUniforms implements UniformProvider {
|
||||
public static final int SIZE = 4 + 8 + 16;
|
||||
public static final int SIZE = 9 * 4 + 8 + 2 * 16;
|
||||
|
||||
@Nullable
|
||||
private RenderContext context;
|
||||
|
@ -63,5 +68,46 @@ public class PlayerUniforms implements UniformProvider {
|
|||
|
||||
ptr = Uniforms.writeVec2(ptr, (float) blockBrightness / (float) maxBrightness,
|
||||
(float) skyBrightness / (float) maxBrightness);
|
||||
|
||||
ptr = writeEyeIn(ptr, player);
|
||||
|
||||
MemoryUtil.memPutInt(ptr, player.isCrouching() ? 1 : 0);
|
||||
ptr += 4;
|
||||
MemoryUtil.memPutInt(ptr, player.isSleeping() ? 1 : 0);
|
||||
ptr += 4;
|
||||
MemoryUtil.memPutInt(ptr, player.isSwimming() ? 1 : 0);
|
||||
ptr += 4;
|
||||
MemoryUtil.memPutInt(ptr, player.isFallFlying() ? 1 : 0);
|
||||
ptr += 4;
|
||||
|
||||
MemoryUtil.memPutInt(ptr, player.isShiftKeyDown() ? 1 : 0);
|
||||
ptr += 4;
|
||||
|
||||
PlayerInfo info = ((AbstractClientPlayerAccessor) player).flywheel$getPlayerInfo();
|
||||
MemoryUtil.memPutInt(ptr, info.getGameMode().getId());
|
||||
ptr += 4;
|
||||
|
||||
int red = 0, green = 0, blue = 0, alpha = 0;
|
||||
PlayerTeam team = info.getTeam();
|
||||
if (team != null) {
|
||||
Integer color = team.getColor().getColor();
|
||||
if (color != null) {
|
||||
int icolor = color;
|
||||
red = FastColor.ARGB32.red(icolor);
|
||||
green = FastColor.ARGB32.green(icolor);
|
||||
blue = FastColor.ARGB32.blue(icolor);
|
||||
alpha = 255;
|
||||
}
|
||||
}
|
||||
|
||||
ptr = Uniforms.writeVec4(ptr, (float) red / 255f, (float) blue / 255f, (float) green / 255f,
|
||||
(float) alpha / 255f);
|
||||
}
|
||||
|
||||
private long writeEyeIn(long ptr, LocalPlayer player) {
|
||||
ClientLevel level = player.clientLevel;
|
||||
Vec3 eyePos = player.getEyePosition();
|
||||
BlockPos blockPos = BlockPos.containing(eyePos);
|
||||
return Uniforms.writeInFluidAndBlock(ptr, level, blockPos, eyePos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,14 @@ import com.jozufozu.flywheel.config.DebugMode;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
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 Uniforms {
|
||||
public static boolean frustumPaused = false;
|
||||
public static boolean frustumCapture = false;
|
||||
|
@ -119,6 +127,14 @@ public class Uniforms {
|
|||
}
|
||||
}
|
||||
|
||||
static long writeVec4(long ptr, float x, float y, float z, float w) {
|
||||
MemoryUtil.memPutFloat(ptr, x);
|
||||
MemoryUtil.memPutFloat(ptr + 4, y);
|
||||
MemoryUtil.memPutFloat(ptr + 8, z);
|
||||
MemoryUtil.memPutFloat(ptr + 12, w);
|
||||
return ptr + 16;
|
||||
}
|
||||
|
||||
static long writeVec3(long ptr, float camX, float camY, float camZ) {
|
||||
MemoryUtil.memPutFloat(ptr, camX);
|
||||
MemoryUtil.memPutFloat(ptr + 4, camY);
|
||||
|
@ -132,4 +148,36 @@ public class Uniforms {
|
|||
MemoryUtil.memPutFloat(ptr + 4, camY);
|
||||
return ptr + 8;
|
||||
}
|
||||
|
||||
static long writeInFluidAndBlock(long ptr, Level level, BlockPos blockPos, Vec3 pos) {
|
||||
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 (pos.y < blockPos.getY() + height) {
|
||||
// TODO: handle custom fluids via defines
|
||||
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 {
|
||||
// TODO: handle custom blocks via defines
|
||||
if (bState.is(Blocks.POWDER_SNOW)) {
|
||||
MemoryUtil.memPutInt(ptr + 4, 0);
|
||||
} else {
|
||||
MemoryUtil.memPutInt(ptr + 4, -1);
|
||||
}
|
||||
}
|
||||
|
||||
return ptr + 8;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.jozufozu.flywheel.backend.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
|
||||
@Mixin(AbstractClientPlayer.class)
|
||||
public interface AbstractClientPlayerAccessor {
|
||||
@Invoker("getPlayerInfo")
|
||||
PlayerInfo flywheel$getPlayerInfo();
|
||||
}
|
|
@ -1,10 +1,28 @@
|
|||
// player.glsl - Holds uniforms for player state.
|
||||
|
||||
layout (std140) uniform _FlwPlayerUniforms {
|
||||
/** Brightness of the brightest light that the player is holding, 0-1. */
|
||||
float flw_heldLight;
|
||||
vec4 _flw_eyePos;
|
||||
/** The brightness at the player's eye position. */
|
||||
vec2 flw_eyeBrightness;
|
||||
/** Contains 1 for water, 2 for lava, max-value for any other fluid, 0 for no fluid. */
|
||||
uint flw_playerEyeInFluid;
|
||||
/** Contains 1 for powder snow, max-value for any other block, 0 for no block. */
|
||||
uint flw_playerEyeInBlock;
|
||||
|
||||
uint flw_playerCrouching;
|
||||
uint flw_playerSleeping;
|
||||
uint flw_playerSwimming;
|
||||
uint flw_playerFallFlying;
|
||||
|
||||
uint flw_shiftKeyDown;
|
||||
|
||||
/** 0 = survival, 1 = creative, 2 = adventure, 3 = spectator. */
|
||||
uint flw_gameMode;
|
||||
|
||||
/** Alpha is 1 if any team color is present, 0 otherwise. */
|
||||
vec4 flw_teamColor;
|
||||
};
|
||||
|
||||
#define flw_eyePos _flw_eyePos.xyz
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"compatibilityLevel": "JAVA_17",
|
||||
"refmap": "flywheel.refmap.json",
|
||||
"client": [
|
||||
"AbstractClientPlayerAccessor",
|
||||
"GameRendererAccessor",
|
||||
"GlStateManagerMixin",
|
||||
"LightTextureAccessor",
|
||||
|
|
Loading…
Add table
Reference in a new issue