Compare commits
38
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37db94649f | ||
|
|
896f4cccc0 | ||
|
|
de3c554e63 | ||
|
|
8417427059 | ||
|
|
ba5a32fb34 | ||
|
|
8b1c94151a | ||
|
|
3623024cce | ||
|
|
2dcbe0302e | ||
|
|
502bddd720 | ||
|
|
0c22fee8c0 | ||
|
|
f69f6eb883 | ||
|
|
cebd9aec96 | ||
|
|
2554a84950 | ||
|
|
49bbdff418 | ||
|
|
8995de9067 | ||
|
|
18b74212ca | ||
|
|
06190d0ef9 | ||
|
|
254a37d757 | ||
|
|
2b5bcf4098 | ||
|
|
4e00934353 | ||
|
|
c524451704 | ||
|
|
e26ce6d076 | ||
|
|
da3dfaee66 | ||
|
|
463335856f | ||
|
|
3315926f7c | ||
|
|
68d3fb6062 | ||
|
|
b108cc1f4a | ||
|
|
167010380e | ||
|
|
dd91f3844a | ||
|
|
b7cf3092da | ||
|
|
60afc12893 | ||
|
|
8677837a8f | ||
|
|
02f6cf7d71 | ||
|
|
85a46c0bba | ||
|
|
30f65bd914 | ||
|
|
bedb45c8aa | ||
|
|
1602520624 | ||
|
|
f69c379ae1 |
+1
-1
Submodule common updated: 15fa973553...b0d75af8c4
+2
-2
@@ -6,10 +6,10 @@ org.gradle.caching=true
|
||||
# IntelliJ IDEA is not yet fully compatible with configuration cache, see: https://github.com/FabricMC/fabric-loom/issues/1349
|
||||
org.gradle.configuration-cache=false
|
||||
|
||||
mod_version=0.1.1-beta
|
||||
mod_version=0.1.4-beta
|
||||
|
||||
# Saturn's emote library (git.selimaj.dev/saturnclientmc/emotes)
|
||||
emotes_version=0.1.0
|
||||
emotes_version=0.1.1
|
||||
|
||||
# Loom, for every Minecraft version (read in settings.gradle.kts).
|
||||
loom_version=1.17.21
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 591 KiB |
@@ -1,18 +1,28 @@
|
||||
package org.saturnclient.impl.cosmetics;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
import org.saturnclient.client.player.SaturnPlayer;
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.cosmetics.Cloaks;
|
||||
import org.saturnclient.emotes.core.Animation;
|
||||
import org.saturnclient.emotes.core.Bone;
|
||||
import org.saturnclient.emotes.core.bend.LimbBend;
|
||||
import org.saturnclient.emotes.core.bend.Vec3;
|
||||
import org.saturnclient.emotes.fabric.access.BendablePart;
|
||||
import org.saturnclient.impl.cosmetics.utils.ShaderUtils;
|
||||
import org.saturnclient.saturnclient.SaturnRenderState;
|
||||
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
//? if >=1.21.9 {
|
||||
@@ -33,7 +43,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.equipment.EquipmentAsset;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
@@ -383,6 +392,50 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
||||
}
|
||||
}
|
||||
|
||||
/** A torso bend past this curves the back more than a flat cloak can follow. */
|
||||
private static final float MAX_CLOAK_BEND = (float) Math.toRadians(10);
|
||||
/** Whether each animation bends the torso past that at any point. */
|
||||
private static final Map<Animation, Boolean> BENDS_TORSO = Collections.synchronizedMap(new WeakHashMap<>());
|
||||
|
||||
/**
|
||||
* Whether the player is playing an emote that curves the torso (a twerk, the griddy). The cloak
|
||||
* would cut through the arched back, so it's hidden for the whole emote rather than only while
|
||||
* the back is curved, which would flicker.
|
||||
*/
|
||||
private static boolean playingTorsoBend(SaturnPlayer player) {
|
||||
return org.saturnclient.emotes.fabric.Emotes.playing(player.uuid)
|
||||
.map(playing -> BENDS_TORSO.computeIfAbsent(playing.animation(), CloakFeatureRenderer::bendsTorso))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private static boolean bendsTorso(Animation animation) {
|
||||
for (float tick = 0; tick <= animation.length(); tick += 0.5f) {
|
||||
if (animation.sample(tick).get(Bone.BODY).filter(body -> Math.abs(body.bend()) > MAX_CLOAK_BEND).isPresent()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* An emote that bends the torso a little leans the chest from the hips, so the cloak hangs from
|
||||
* where the top of the back ends up, turned as much as the torso is there.
|
||||
*/
|
||||
private static void followBend(MatrixStack matrices, ModelPart body) {
|
||||
LimbBend bend = ((BendablePart) (Object) body).saturnEmotes$getBend();
|
||||
if (bend == null || bend.isStraight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The top of the torso, in the body's own pixels
|
||||
float[] top = new float[3];
|
||||
bend.bendPoint(0, 0, 0, top);
|
||||
matrices.translate(top[0] / 16.0f, top[1] / 16.0f, top[2] / 16.0f);
|
||||
|
||||
Vec3 axis = bend.axis();
|
||||
matrices.multiply(new Quaternionf().rotationAxis(bend.angleAt(0), axis.x(), axis.y(), axis.z()));
|
||||
}
|
||||
|
||||
// Shift array left and insert new value at the start
|
||||
private void updateSegmentValues(float value) {
|
||||
// Shift all elements one position to the right (from end to start)
|
||||
@@ -416,7 +469,7 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
||||
//?} else
|
||||
//SaturnPlayer player = SaturnPlayer.get(state.name);
|
||||
|
||||
if (player == null) {
|
||||
if (player == null || playingTorsoBend(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -436,17 +489,24 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
||||
|
||||
matrices.push();
|
||||
|
||||
// On the back: the whole player (which emotes like the backflip turn), then the body's position
|
||||
// and turn (which crouching and emotes move), then the chest's lean when an emote bends the torso
|
||||
PlayerEntityModel model = this.getContextModel();
|
||||
//? if >=1.21.5 {
|
||||
model.getRootPart().applyTransform(matrices);
|
||||
model.body.applyTransform(matrices);
|
||||
//?} else {
|
||||
/*model.getRootPart().rotate(matrices);
|
||||
model.body.rotate(matrices);
|
||||
*///?}
|
||||
followBend(matrices, model.body);
|
||||
|
||||
matrices.translate(0.0f, 0.0f, 0.12f);
|
||||
|
||||
if (this.hasCustomModelForLayer(state.equippedChestStack, LayerType.HUMANOID)) {
|
||||
matrices.translate(0.0F, -0.053125F, 0.06875F);
|
||||
}
|
||||
|
||||
if (state.isInSneakingPose) {
|
||||
matrices.translate(0, 0.16f, 0.0f);
|
||||
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(29.0f));
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastUpdate >= 20) {
|
||||
float velX = Math.min(0.8f, state.field_53537 / 108.0f);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.saturnclient.impl.cosmetics;
|
||||
|
||||
import org.joml.Quaternionf;
|
||||
import org.saturnclient.client.player.SaturnPlayer;
|
||||
import org.saturnclient.impl.cosmetics.obj.MtlLoader;
|
||||
import org.saturnclient.impl.cosmetics.obj.ObjModel;
|
||||
@@ -16,7 +15,6 @@ import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.PlayerEntityModel;
|
||||
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
|
||||
public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
||||
public HatFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context) {
|
||||
@@ -41,11 +39,16 @@ public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState,
|
||||
|
||||
matrices.push();
|
||||
|
||||
// On the head, as vanilla places head items: the whole player (which emotes like the backflip
|
||||
// turn), then the head's position, turn and scale (which crouching and emotes move)
|
||||
PlayerEntityModel model = this.getContextModel();
|
||||
//? if >=1.21.5 {
|
||||
ModelPart head = this.getContextModel().head;
|
||||
matrices.multiply(new Quaternionf().rotationZYX(head.roll, head.yaw, head.pitch));
|
||||
//?} else
|
||||
//this.getContextModel().head.rotate(matrices);
|
||||
model.getRootPart().applyTransform(matrices);
|
||||
model.head.applyTransform(matrices);
|
||||
//?} else {
|
||||
/*model.getRootPart().rotate(matrices);
|
||||
model.head.rotate(matrices);
|
||||
*///?}
|
||||
|
||||
ObjModel.cosmetic("hat", player.hat).render(MtlLoader.cosmetic(player.hat),
|
||||
matrices, output, light,
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
//? if >=1.21.6
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
//? if >=1.21.6
|
||||
import net.minecraft.client.option.GameOptions;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
|
||||
//? if >=1.21.6
|
||||
import org.saturnclient.impl.ui.SaturnScreenFabric;
|
||||
import org.saturnclient.mod.mods.FreelookMod;
|
||||
import org.saturnclient.mod.mods.ZoomMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
//? if >=1.21.6
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
/**
|
||||
@@ -38,4 +46,18 @@ public class GameRendererMixin {
|
||||
cir.setReturnValue(zoomedFov);
|
||||
}
|
||||
}
|
||||
|
||||
//? if >=1.21.6 {
|
||||
// From 1.21.6 the menu blur's strength is the vanilla setting, read here every frame. While a
|
||||
// Saturn screen is open, it's Saturn's background blur instead, faded in with the screen.
|
||||
@Redirect(method = "render", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/option/GameOptions;getMenuBackgroundBlurrinessValue()I"))
|
||||
private int useSaturnBlur(GameOptions options) {
|
||||
if (MinecraftClient.getInstance().currentScreen instanceof SaturnScreenFabric saturnScreen) {
|
||||
return saturnScreen.screen.getBackgroundBlur();
|
||||
}
|
||||
|
||||
return options.getMenuBackgroundBlurrinessValue();
|
||||
}
|
||||
//?}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,17 @@ package org.saturnclient.impl.provider;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.toast.SystemToast;
|
||||
//? if >=1.21.9 {
|
||||
import net.minecraft.entity.player.SkinTextures;
|
||||
//?} else
|
||||
//import net.minecraft.client.util.SkinTextures;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import org.saturnclient.common.provider.SaturnProvider;
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
@@ -16,6 +22,9 @@ import org.saturnclient.impl.cosmetics.utils.IdentifierUtils;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
public class SaturnProviderImpl implements SaturnProvider {
|
||||
/** Looks up the signed-in player's skin; made once, since the skin provider caches it */
|
||||
private Supplier<Identifier> playerSkin;
|
||||
|
||||
@Override
|
||||
public MinecraftClientRef getClient() {
|
||||
return (MinecraftClientRef) SaturnClient.client;
|
||||
@@ -50,6 +59,23 @@ public class SaturnProviderImpl implements SaturnProvider {
|
||||
/** Shown longer than the vanilla default, since these ask the player to act. */
|
||||
private static final SystemToast.Type WARNING_TOAST = new SystemToast.Type(15_000L);
|
||||
|
||||
@Override
|
||||
public IdentifierRef getPlayerSkin() {
|
||||
if (playerSkin == null) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
// 1.21.9 moved SkinTextures and renamed the skin provider's lookup.
|
||||
//? if >=1.21.9 {
|
||||
Supplier<SkinTextures> textures = client.getSkinProvider().supplySkinTextures(client.getGameProfile(), false);
|
||||
playerSkin = () -> textures.get().body().texturePath();
|
||||
//?} else {
|
||||
/*Supplier<SkinTextures> textures = client.getSkinProvider().getSkinTexturesSupplier(client.getGameProfile());
|
||||
playerSkin = () -> textures.get().texture();
|
||||
*///?}
|
||||
}
|
||||
|
||||
return (IdentifierRef) (Object) playerSkin.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModVersion() {
|
||||
return FabricLoader.getInstance().getModContainer(SaturnClient.MOD_ID)
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.components.SkinPreview.EntityDrawer;
|
||||
|
||||
@@ -21,33 +20,32 @@ import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class EntityDrawerImpl implements EntityDrawer {
|
||||
@Override
|
||||
public void render(RenderScope renderScope, boolean negativeAngle, float angle, float scale, ElementContext ctx) {
|
||||
public boolean render(RenderScope renderScope, int width, int height, float yaw) {
|
||||
LivingEntity entity = SaturnClient.client.player;
|
||||
|
||||
if (entity != null) {
|
||||
drawEntity(renderScope, 0, 0, 75, 78, 30, 0.0625F, ctx.mouseX / scale, ctx.mouseY / scale,
|
||||
SaturnClient.client.player);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The player is about 1.8 blocks tall; leave some room above and below.
|
||||
drawEntity(renderScope, 0, 0, width, height, (int) (height / 2.2F), 0.0625F, yaw, entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Draws the entity in the box, turned by yaw degrees (0 faces the viewer) with its head straight.
|
||||
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, int size, float scale,
|
||||
float mouseX, float mouseY, LivingEntity entity) {
|
||||
float f = (float) (x1 + x2) / 2.0F;
|
||||
float g = (float) (y1 + y2) / 2.0F;
|
||||
float yaw, LivingEntity entity) {
|
||||
renderScope.enableScissor(x1, y1, x2, y2);
|
||||
float h = (float) Math.atan((double) ((f - mouseX) / 40.0F));
|
||||
float i = (float) Math.atan((double) ((g - mouseY) / 40.0F));
|
||||
Quaternionf quaternionf = (new Quaternionf()).rotateZ((float) Math.PI);
|
||||
Quaternionf quaternionf2 = (new Quaternionf()).rotateX(i * 20.0F * ((float) Math.PI / 180F));
|
||||
quaternionf.mul(quaternionf2);
|
||||
Quaternionf quaternionf2 = new Quaternionf();
|
||||
float j = entity.bodyYaw;
|
||||
float k = entity.getYaw();
|
||||
float l = entity.getPitch();
|
||||
float m = entity.lastHeadYaw;
|
||||
float n = entity.headYaw;
|
||||
entity.bodyYaw = 180.0F + h * 20.0F;
|
||||
entity.setYaw(180.0F + h * 40.0F);
|
||||
entity.setPitch(-i * 20.0F);
|
||||
entity.bodyYaw = 180.0F + yaw;
|
||||
entity.setYaw(180.0F + yaw);
|
||||
entity.setPitch(0.0F);
|
||||
entity.headYaw = entity.getYaw();
|
||||
entity.lastHeadYaw = entity.getYaw();
|
||||
float o = entity.getScale();
|
||||
@@ -83,7 +81,6 @@ public class EntityDrawerImpl implements EntityDrawer {
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.components.SkinPreview.EntityDrawer;
|
||||
|
||||
@@ -92,14 +89,12 @@ import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class EntityDrawerImpl implements EntityDrawer {
|
||||
// Draws the entity in the box, turned by yaw degrees (0 faces the viewer) with its head straight.
|
||||
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, int size, float f,
|
||||
float mouseX,
|
||||
float mouseY, LivingEntity entity, float angle, boolean negativeAngle) {
|
||||
float yaw, LivingEntity entity) {
|
||||
float g = (float) (x1 + x2) / 2.0F;
|
||||
float h = (float) (y1 + y2) / 2.0F;
|
||||
renderScope.enableScissor(0, 6, x2, y2);
|
||||
float i = (float) Math.atan((double) ((g - mouseX) / 40.0F));
|
||||
float j = (float) Math.atan((double) ((h - mouseY) / 40.0F));
|
||||
renderScope.enableScissor(x1, y1, x2, y2);
|
||||
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
|
||||
float k = entity.bodyYaw;
|
||||
float l = entity.getYaw();
|
||||
@@ -109,10 +104,10 @@ public class EntityDrawerImpl implements EntityDrawer {
|
||||
//? if <1.21.5
|
||||
//float n = entity.prevHeadYaw;
|
||||
float o = entity.headYaw;
|
||||
entity.setYaw(angle);
|
||||
entity.bodyYaw = angle;
|
||||
entity.setPitch(-(j * 20.0F));
|
||||
entity.headYaw = negativeAngle ? (i * 40.0F) + 180f : -(i * 40.0F);
|
||||
entity.setYaw(180.0F + yaw);
|
||||
entity.bodyYaw = 180.0F + yaw;
|
||||
entity.setPitch(0.0F);
|
||||
entity.headYaw = entity.getYaw();
|
||||
//? if >=1.21.5
|
||||
entity.lastHeadYaw = entity.getHeadYaw();
|
||||
//? if <1.21.5
|
||||
@@ -166,12 +161,15 @@ public class EntityDrawerImpl implements EntityDrawer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, boolean negativeAngle, float angle, float scale, ElementContext ctx) {
|
||||
public boolean render(RenderScope renderScope, int width, int height, float yaw) {
|
||||
LivingEntity entity = SaturnClient.client.player;
|
||||
if (entity != null) {
|
||||
drawEntity(renderScope, 0, 0, 75, 78, 30, 0.0625F, ctx.mouseX / scale, ctx.mouseY / scale, entity, angle,
|
||||
negativeAngle);
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The player is about 1.8 blocks tall; leave some room above and below.
|
||||
drawEntity(renderScope, 0, 0, width, height, (int) (height / 2.2F), 0.0625F, yaw, entity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
|
||||
@@ -0,0 +1,380 @@
|
||||
package org.saturnclient.impl.ui;
|
||||
|
||||
// Glass: a copy of the game behind the screen, blurred, drawn through each panel's rounded rectangle
|
||||
// texture as a mask. There's a copy for each blur strength in use (menus and widgets have their own),
|
||||
// blurred with vanilla's blur at that radius, so it holds the world or panorama without the screen's
|
||||
// own animated background blur.
|
||||
//
|
||||
// The GUI rewrites split this into three implementations:
|
||||
// - 1.21.6+: the GUI is drawn after the screen builds it, so the copy is taken from the main
|
||||
// framebuffer while the screen builds its GUI, and glass is a GUI element with its own pipeline
|
||||
// (shaders/core/glass.fsh). The blur is vanilla's effect rebuilt with the radius set.
|
||||
// - 1.21.5: the screen draws straight into the framebuffer, blurring it first, so the game is saved
|
||||
// before the blur (saveBackground). Glass is a render layer with its own pipeline
|
||||
// (shaders/core/glass_pre_1_21_6.fsh), and the blur takes the radius as it runs.
|
||||
// - 1.21.4: as 1.21.5, with GL framebuffers copied by blitting, and a shader program
|
||||
// (shaders/core/glass.json) instead of a pipeline.
|
||||
//? if >=1.21.6 {
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.textures.FilterMode;
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gl.PostEffectPipeline;
|
||||
import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.gl.RenderPipelines;
|
||||
import net.minecraft.client.gl.SimpleFramebuffer;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.render.ProjectionMatrix2;
|
||||
import net.minecraft.client.texture.AbstractTexture;
|
||||
import net.minecraft.client.texture.TextureSetup;
|
||||
import net.minecraft.client.util.Pool;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class GlassRenderer {
|
||||
public static final RenderPipeline PIPELINE = RenderPipeline.builder(RenderPipelines.POSITION_TEX_COLOR_SNIPPET)
|
||||
.withLocation(Identifier.of("saturnclient", "pipeline/glass"))
|
||||
.withFragmentShader(Identifier.of("saturnclient", "core/glass"))
|
||||
.withSampler("Sampler1")
|
||||
// The transforms block ends with LineWidth before 1.21.11 (see glass.fsh).
|
||||
//? if <1.21.11
|
||||
//.withShaderDefine("HAS_LINE_WIDTH")
|
||||
.build();
|
||||
|
||||
private static final Identifier BLUR = Identifier.ofVanilla("post_effect/blur.json");
|
||||
private static final ProjectionMatrix2 PROJECTION = new ProjectionMatrix2("saturn glass", 0.1f, 1000f, false);
|
||||
// For the blurs' intermediate targets, freed once unused for a few frames
|
||||
private static final Pool POOL = new Pool(3);
|
||||
|
||||
// By blur strength. A blur that failed to load is kept as null, so it isn't retried every frame.
|
||||
private static final Map<Integer, PostEffectProcessor> BLURS = new HashMap<>();
|
||||
private static final Map<Integer, SimpleFramebuffer> BACKDROPS = new HashMap<>();
|
||||
|
||||
private GlassRenderer() {
|
||||
}
|
||||
|
||||
// Copies the main framebuffer and blurs the copy by blur. Call once a frame for each blur, while
|
||||
// the screen builds its GUI, before drawing glass with it.
|
||||
public static void captureBackdrop(int blur) {
|
||||
Framebuffer main = SaturnClient.client.getFramebuffer();
|
||||
int width = main.textureWidth;
|
||||
int height = main.textureHeight;
|
||||
|
||||
SimpleFramebuffer backdrop = BACKDROPS.get(blur);
|
||||
if (backdrop == null) {
|
||||
backdrop = new SimpleFramebuffer("Saturn glass " + blur, width, height, false);
|
||||
BACKDROPS.put(blur, backdrop);
|
||||
} else if (backdrop.textureWidth != width || backdrop.textureHeight != height) {
|
||||
backdrop.resize(width, height);
|
||||
}
|
||||
//? if <1.21.11
|
||||
//backdrop.getColorAttachment().setTextureFilter(FilterMode.LINEAR, false);
|
||||
|
||||
RenderSystem.getDevice().createCommandEncoder().copyTextureToTexture(
|
||||
main.getColorAttachment(), backdrop.getColorAttachment(), 0, 0, 0, 0, 0, width, height);
|
||||
|
||||
PostEffectProcessor processor = getBlur(blur);
|
||||
if (processor != null) {
|
||||
processor.render(backdrop, POOL);
|
||||
}
|
||||
POOL.decrementLifespan();
|
||||
release(blur);
|
||||
}
|
||||
|
||||
// The mask, then the copy blurred by blur, as the glass pipeline samples them
|
||||
public static TextureSetup textures(AbstractTexture mask, int blur) {
|
||||
GpuTextureView backdrop = BACKDROPS.get(blur).getColorAttachmentView();
|
||||
//? if >=1.21.11
|
||||
return TextureSetup.of(mask.getGlTextureView(), mask.getSampler(), backdrop, RenderSystem.getSamplerCache().get(FilterMode.LINEAR));
|
||||
//? if <1.21.11
|
||||
//return TextureSetup.of(mask.getGlTextureView(), backdrop);
|
||||
}
|
||||
|
||||
// Frees the copies and blurs of strengths that are no longer set, besides kept
|
||||
private static void release(int kept) {
|
||||
BACKDROPS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && !isSet(entry.getKey());
|
||||
if (unused) {
|
||||
entry.getValue().delete();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
BLURS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && !isSet(entry.getKey());
|
||||
if (unused && entry.getValue() != null) {
|
||||
entry.getValue().close();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isSet(int blur) {
|
||||
return blur == Config.menuBlur.value || blur == Config.widgetBlur.value;
|
||||
}
|
||||
|
||||
private static PostEffectProcessor getBlur(int blur) {
|
||||
if (!BLURS.containsKey(blur)) {
|
||||
BLURS.put(blur, loadBlur(blur));
|
||||
}
|
||||
return BLURS.get(blur);
|
||||
}
|
||||
|
||||
// Vanilla's blur, with its radius set to blur. Vanilla's own leaves it at 0, which makes the shader
|
||||
// read the menu blur setting (Saturn's animated background blur while a Saturn screen is open).
|
||||
private static PostEffectProcessor loadBlur(int blur) {
|
||||
try (Reader reader = SaturnClient.client.getResourceManager().getResourceOrThrow(BLUR).getReader()) {
|
||||
JsonElement json = JsonParser.parseReader(reader);
|
||||
setRadius(json, blur);
|
||||
|
||||
PostEffectPipeline pipeline = PostEffectPipeline.CODEC.parse(JsonOps.INSTANCE, json).getOrThrow();
|
||||
return PostEffectProcessor.parseEffect(pipeline, SaturnClient.client.getTextureManager(),
|
||||
DefaultFramebufferSet.MAIN_ONLY, Identifier.of("saturnclient", "glass_blur_" + blur), PROJECTION);
|
||||
} catch (Exception e) {
|
||||
SaturnClient.LOGGER.error("Couldn't load the glass blur", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Sets every "Radius" uniform in the effect
|
||||
private static void setRadius(JsonElement json, int radius) {
|
||||
if (json.isJsonArray()) {
|
||||
json.getAsJsonArray().forEach(element -> setRadius(element, radius));
|
||||
} else if (json.isJsonObject()) {
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
if (object.has("name") && object.get("name").getAsString().equals("Radius")) {
|
||||
object.addProperty("value", (float) radius);
|
||||
}
|
||||
object.entrySet().forEach(entry -> setRadius(entry.getValue(), radius));
|
||||
}
|
||||
}
|
||||
}
|
||||
//?} else if >=1.21.5 {
|
||||
/*import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.textures.FilterMode;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.gl.RenderPipelines;
|
||||
import net.minecraft.client.gl.SimpleFramebuffer;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.util.Pool;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class GlassRenderer {
|
||||
private static final RenderPipeline PIPELINE = RenderPipeline.builder(RenderPipelines.POSITION_TEX_COLOR_SNIPPET)
|
||||
.withLocation(Identifier.of("saturnclient", "pipeline/glass"))
|
||||
.withFragmentShader(Identifier.of("saturnclient", "core/glass_pre_1_21_6"))
|
||||
.withSampler("Sampler1")
|
||||
.build();
|
||||
|
||||
private static final Identifier BLUR = Identifier.ofVanilla("blur");
|
||||
// For the blur's intermediate target, freed once unused for a few frames
|
||||
private static final Pool POOL = new Pool(3);
|
||||
|
||||
private static final Map<Integer, SimpleFramebuffer> BACKDROPS = new HashMap<>();
|
||||
// By mask and blur
|
||||
private static final Map<String, RenderLayer> LAYERS = new HashMap<>();
|
||||
// The game behind the screen before the screen blurs it, which glass is blurred from
|
||||
private static SimpleFramebuffer background;
|
||||
|
||||
private GlassRenderer() {
|
||||
}
|
||||
|
||||
// Saves the main framebuffer for glass. Call each frame before the screen blurs its background.
|
||||
public static void saveBackground() {
|
||||
background = copy(SaturnClient.client.getFramebuffer(), background, "Saturn glass background");
|
||||
}
|
||||
|
||||
// Copies the saved background and blurs the copy by blur. Call once a frame for each blur, before
|
||||
// drawing glass with it.
|
||||
public static void captureBackdrop(int blur) {
|
||||
Framebuffer from = background != null ? background : SaturnClient.client.getFramebuffer();
|
||||
SimpleFramebuffer backdrop = copy(from, BACKDROPS.get(blur), "Saturn glass " + blur);
|
||||
BACKDROPS.put(blur, backdrop);
|
||||
|
||||
PostEffectProcessor processor = SaturnClient.client.getShaderLoader().loadPostEffect(BLUR,
|
||||
DefaultFramebufferSet.MAIN_ONLY);
|
||||
if (processor != null) {
|
||||
processor.render(backdrop, POOL, pass -> pass.setUniform("Radius", (float) blur));
|
||||
}
|
||||
POOL.decrementLifespan();
|
||||
release(blur);
|
||||
}
|
||||
|
||||
// Draws glass through mask with the copy blurred by blur
|
||||
public static RenderLayer getLayer(Identifier mask, int blur) {
|
||||
return LAYERS.computeIfAbsent(mask + " " + blur, key -> RenderLayer.of("saturn_glass", 786432, PIPELINE,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(new RenderPhase.TextureBase(() -> {
|
||||
RenderSystem.setShaderTexture(0,
|
||||
SaturnClient.client.getTextureManager().getTexture(mask).getGlTexture());
|
||||
RenderSystem.setShaderTexture(1, BACKDROPS.get(blur).getColorAttachment());
|
||||
}, () -> {
|
||||
}))
|
||||
.build(false)));
|
||||
}
|
||||
|
||||
// Frees the copies of strengths that are no longer set, besides kept
|
||||
private static void release(int kept) {
|
||||
BACKDROPS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && entry.getKey() != Config.menuBlur.value
|
||||
&& entry.getKey() != Config.widgetBlur.value;
|
||||
if (unused) {
|
||||
entry.getValue().delete();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
}
|
||||
|
||||
// Copies from into to, made or resized to match
|
||||
private static SimpleFramebuffer copy(Framebuffer from, SimpleFramebuffer to, String name) {
|
||||
int width = from.textureWidth;
|
||||
int height = from.textureHeight;
|
||||
|
||||
if (to == null) {
|
||||
to = new SimpleFramebuffer(name, width, height, false);
|
||||
} else if (to.textureWidth != width || to.textureHeight != height) {
|
||||
to.resize(width, height);
|
||||
}
|
||||
to.getColorAttachment().setTextureFilter(FilterMode.LINEAR, false);
|
||||
|
||||
RenderSystem.getDevice().createCommandEncoder().copyTextureToTexture(
|
||||
from.getColorAttachment(), to.getColorAttachment(), 0, 0, 0, 0, 0, width, height);
|
||||
return to;
|
||||
}
|
||||
}
|
||||
*///?} else {
|
||||
/*import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
import net.minecraft.client.gl.Defines;
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.gl.ShaderProgramKey;
|
||||
import net.minecraft.client.gl.SimpleFramebuffer;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.util.Pool;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class GlassRenderer {
|
||||
private static final ShaderProgramKey PROGRAM = new ShaderProgramKey(Identifier.of("saturnclient", "core/glass"),
|
||||
VertexFormats.POSITION_TEXTURE_COLOR, Defines.EMPTY);
|
||||
|
||||
private static final Identifier BLUR = Identifier.ofVanilla("blur");
|
||||
// For the blur's intermediate target, freed once unused for a few frames
|
||||
private static final Pool POOL = new Pool(3);
|
||||
|
||||
private static final Map<Integer, SimpleFramebuffer> BACKDROPS = new HashMap<>();
|
||||
// By mask and blur
|
||||
private static final Map<String, RenderLayer> LAYERS = new HashMap<>();
|
||||
// The game behind the screen before the screen blurs it, which glass is blurred from
|
||||
private static SimpleFramebuffer background;
|
||||
|
||||
private GlassRenderer() {
|
||||
}
|
||||
|
||||
// Saves the main framebuffer for glass. Call each frame before the screen blurs its background.
|
||||
public static void saveBackground() {
|
||||
background = copy(SaturnClient.client.getFramebuffer(), background);
|
||||
}
|
||||
|
||||
// Copies the saved background and blurs the copy by blur. Call once a frame for each blur, before
|
||||
// drawing glass with it.
|
||||
public static void captureBackdrop(int blur) {
|
||||
Framebuffer from = background != null ? background : SaturnClient.client.getFramebuffer();
|
||||
SimpleFramebuffer backdrop = copy(from, BACKDROPS.get(blur));
|
||||
BACKDROPS.put(blur, backdrop);
|
||||
|
||||
PostEffectProcessor processor = SaturnClient.client.getShaderLoader().loadPostEffect(BLUR,
|
||||
DefaultFramebufferSet.MAIN_ONLY);
|
||||
if (processor != null) {
|
||||
processor.setUniforms("Radius", blur);
|
||||
processor.render(backdrop, POOL);
|
||||
}
|
||||
POOL.decrementLifespan();
|
||||
release(blur);
|
||||
SaturnClient.client.getFramebuffer().beginWrite(false);
|
||||
}
|
||||
|
||||
// Draws glass through mask with the copy blurred by blur
|
||||
public static RenderLayer getLayer(Identifier mask, int blur) {
|
||||
return LAYERS.computeIfAbsent(mask + " " + blur, key -> RenderLayer.of("saturn_glass",
|
||||
VertexFormats.POSITION_TEXTURE_COLOR, VertexFormat.DrawMode.QUADS, 786432,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(new RenderPhase.TextureBase(() -> {
|
||||
RenderSystem.setShaderTexture(0, mask);
|
||||
RenderSystem.setShaderTexture(1, BACKDROPS.get(blur).getColorAttachment());
|
||||
}, () -> {
|
||||
}))
|
||||
.program(new RenderPhase.ShaderProgram(PROGRAM))
|
||||
.transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY)
|
||||
.build(false)));
|
||||
}
|
||||
|
||||
// Frees the copies of strengths that are no longer set, besides kept
|
||||
private static void release(int kept) {
|
||||
BACKDROPS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && entry.getKey() != Config.menuBlur.value
|
||||
&& entry.getKey() != Config.widgetBlur.value;
|
||||
if (unused) {
|
||||
entry.getValue().delete();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
}
|
||||
|
||||
// Copies from into to, made or resized to match
|
||||
private static SimpleFramebuffer copy(Framebuffer from, SimpleFramebuffer to) {
|
||||
int width = from.textureWidth;
|
||||
int height = from.textureHeight;
|
||||
|
||||
if (to == null) {
|
||||
to = new SimpleFramebuffer(width, height, false);
|
||||
} else if (to.textureWidth != width || to.textureHeight != height) {
|
||||
to.resize(width, height);
|
||||
}
|
||||
to.setTexFilter(GL11.GL_LINEAR);
|
||||
|
||||
GlStateManager._glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, from.fbo);
|
||||
GlStateManager._glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, to.fbo);
|
||||
GlStateManager._glBlitFrameBuffer(0, 0, width, height, 0, 0, width, height, GL11.GL_COLOR_BUFFER_BIT,
|
||||
GL11.GL_NEAREST);
|
||||
SaturnClient.client.getFramebuffer().beginWrite(false);
|
||||
return to;
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
@@ -5,7 +5,9 @@ package org.saturnclient.impl.ui;
|
||||
//? if >=1.21.6 {
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix3x2f;
|
||||
@@ -40,7 +42,6 @@ import net.minecraft.client.render.entity.state.EntityRenderState;
|
||||
import net.minecraft.client.render.item.KeyedItemRenderState;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.item.ItemRenderState;
|
||||
//? if >=1.21.11
|
||||
import net.minecraft.client.texture.AbstractTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.TextureSetup;
|
||||
@@ -61,6 +62,8 @@ public class RenderScopeImpl implements RenderScope {
|
||||
|
||||
private ScissorStack scissorStack;
|
||||
private int opacity = 0xFF << 24;
|
||||
// The glass blurs made for this scope's frame
|
||||
private final Set<Integer> capturedBlurs = new HashSet<>();
|
||||
|
||||
public RenderScopeImpl(DrawContext context) {
|
||||
this(context.getMatrices(), ((DrawContextAccessor) (Object) context).getState());
|
||||
@@ -230,6 +233,25 @@ public class RenderScopeImpl implements RenderScope {
|
||||
this.scissorStack.peekLast()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGlass(IdentifierRef mask, int x, int y, int width, int height, int blur) {
|
||||
int color = getColor(0xFFFFFFFF);
|
||||
if (mask == null || color >>> 24 == 0)
|
||||
return;
|
||||
|
||||
if (capturedBlurs.add(blur)) {
|
||||
GlassRenderer.captureBackdrop(blur);
|
||||
}
|
||||
|
||||
AbstractTexture maskTexture = SaturnClient.client.getTextureManager().getTexture((Identifier) (Object) mask);
|
||||
this.state.addSimpleElement(new TexturedQuadGuiElementRenderState(
|
||||
GlassRenderer.PIPELINE,
|
||||
GlassRenderer.textures(maskTexture, blur),
|
||||
new Matrix3x2f(this.matrices.stack),
|
||||
x, y, x + width, y + height, 0, 1, 0, 1, color,
|
||||
this.scissorStack.peekLast()));
|
||||
}
|
||||
|
||||
// Scissor management
|
||||
@Override
|
||||
public void enableScissor(int x1, int y1, int x2, int y2) {
|
||||
@@ -368,7 +390,9 @@ public class RenderScopeImpl implements RenderScope {
|
||||
//?} else {
|
||||
/*import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -421,6 +445,8 @@ public class RenderScopeImpl implements RenderScope {
|
||||
public VertexConsumerProvider.Immediate vertexConsumers;
|
||||
private ScissorStack scissorStack = new ScissorStack();
|
||||
private int opacity = 255 << 24;
|
||||
// The glass blurs made for this scope's frame
|
||||
private final Set<Integer> capturedBlurs = new HashSet<>();
|
||||
private final ItemRenderState itemRenderState;
|
||||
|
||||
// ----------------------------
|
||||
@@ -660,6 +686,33 @@ public class RenderScopeImpl implements RenderScope {
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGlass(IdentifierRef mask, int x, int y, int width, int height, int blur) {
|
||||
int color = getColor(0xFFFFFFFF);
|
||||
if (mask == null || color >>> 24 == 0)
|
||||
return;
|
||||
|
||||
if (capturedBlurs.add(blur)) {
|
||||
GlassRenderer.captureBackdrop(blur);
|
||||
}
|
||||
|
||||
// In quarter units, as drawTexturedQuad draws
|
||||
int x1 = x * 4;
|
||||
int x2 = (x + width) * 4;
|
||||
int y1 = y * 4;
|
||||
int y2 = (y + height) * 4;
|
||||
|
||||
matrices.push();
|
||||
matrices.scale(0.25f, 0.25f, 1.0f);
|
||||
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
|
||||
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GlassRenderer.getLayer((Identifier) (Object) mask, blur));
|
||||
vertexConsumer.vertex(matrix4f, x1, y1, 0).texture(0, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x1, y2, 0).texture(0, 1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y2, 0).texture(1, 1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y1, 0).texture(1, 0).color(color);
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Items
|
||||
// ----------------------------
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.saturnclient.impl.ui;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.SaturnScreen;
|
||||
import org.saturnclient.ui.SaturnScreen.ScreenProvider;
|
||||
@@ -86,28 +87,29 @@ public class SaturnScreenFabric extends Screen implements ScreenProvider {
|
||||
}
|
||||
long elapsed = Duration.between(screen.start, Instant.now()).toMillis();
|
||||
|
||||
mouseX *= 2;
|
||||
mouseY *= 2;
|
||||
screen.updateScale();
|
||||
|
||||
// From 1.21.6 the panorama renderer has no opacity (and takes no delta), so it's drawn fully
|
||||
// opaque there.
|
||||
if (panoramaReady && client.world == null && client.getCurrentServerEntry() == null) {
|
||||
//? if >=1.21.6 {
|
||||
ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, true);
|
||||
//?} else
|
||||
//ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, screen.backgroundOpacity, delta);
|
||||
mouseX = (int) (mouseX / screen.scale);
|
||||
mouseY = (int) (mouseY / screen.scale);
|
||||
|
||||
// From 1.21.6 the background, blur included, is drawn in renderBackground.
|
||||
//? if <1.21.6 {
|
||||
/*if (isShowingPanorama()) {
|
||||
ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, screen.backgroundOpacity, delta);
|
||||
}
|
||||
|
||||
// TODO: the background blur (screen.backgroundBlur) is only drawn before 1.21.6 so far. See
|
||||
// also issue #23.
|
||||
// Glass is blurred from the game as it is before this screen blurs it.
|
||||
if (Config.usesGlass()) {
|
||||
context.draw();
|
||||
GlassRenderer.saveBackground();
|
||||
}
|
||||
|
||||
//? if <1.21.6 {
|
||||
/*PostEffectProcessor postEffectProcessor = this.client.getShaderLoader().loadPostEffect(
|
||||
float radius = screen.getBackgroundBlur();
|
||||
PostEffectProcessor postEffectProcessor = radius < 1 ? null : this.client.getShaderLoader().loadPostEffect(
|
||||
Identifier.ofVanilla("blur"),
|
||||
DefaultFramebufferSet.MAIN_ONLY);
|
||||
|
||||
if (postEffectProcessor != null) {
|
||||
float radius = screen.backgroundBlur * Math.min((float) elapsed / 700, 1.0f);
|
||||
//? if >=1.21.5
|
||||
postEffectProcessor.render(this.client.getFramebuffer(), this.pool, pass -> pass.setUniform("Radius", radius));
|
||||
//? if <1.21.5
|
||||
@@ -122,6 +124,32 @@ public class SaturnScreenFabric extends Screen implements ScreenProvider {
|
||||
screen.render(renderScope, mouseX, mouseY, delta, elapsed);
|
||||
}
|
||||
|
||||
//? if >=1.21.6 {
|
||||
// Vanilla's background would cover Saturn's panorama, and blurs by the vanilla setting. The
|
||||
// strength of this blur comes from GameRendererMixin, which gives Saturn's setting instead.
|
||||
@Override
|
||||
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
// The panorama renderer has no opacity (and takes no delta) from 1.21.6, so it's drawn fully
|
||||
// opaque.
|
||||
if (isShowingPanorama()) {
|
||||
ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, true);
|
||||
}
|
||||
|
||||
if (screen.getBackgroundBlur() >= 1) {
|
||||
context.applyBlur();
|
||||
}
|
||||
|
||||
if (client.world != null) {
|
||||
renderDarkening(context);
|
||||
}
|
||||
}
|
||||
//?}
|
||||
|
||||
/** Whether Saturn's panorama is behind the screen: outside a world, once it's loaded. */
|
||||
private boolean isShowingPanorama() {
|
||||
return panoramaReady && client.world == null && client.getCurrentServerEntry() == null;
|
||||
}
|
||||
|
||||
// 1.21.9 moved mouse and key events to Click and KeyInput.
|
||||
//? if >=1.21.9 {
|
||||
@Override
|
||||
@@ -226,11 +254,11 @@ public class SaturnScreenFabric extends Screen implements ScreenProvider {
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width * 2;
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height * 2;
|
||||
return height;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.common.provider.Providers;
|
||||
import org.saturnclient.client.ServiceClient;
|
||||
import org.saturnclient.emotes.fabric.Emotes;
|
||||
import org.saturnclient.impl.ui.SaturnScreenFabric;
|
||||
import org.saturnclient.ui.screens.EmoteWheel;
|
||||
import org.saturnclient.ui.screens.ShiftMenu;
|
||||
|
||||
@@ -51,12 +52,20 @@ public class KeyInputHandler {
|
||||
Providers.saturn.getClient().setScreen(new ShiftMenu());
|
||||
}
|
||||
|
||||
if (Config.openEmoteWheel.wasKeyPressed() && client.currentScreen == null
|
||||
// The emote wheel key opens the wheel, and closes it again while it's open. Closing it
|
||||
// from the screen's own key handling would reopen it on the next tick, since the key is
|
||||
// still down and no screen is open by then.
|
||||
if (Config.openEmoteWheel.wasKeyPressed()
|
||||
//? if >=1.21.9 {
|
||||
&& !InputUtil.isKeyPressed(client.getWindow(), GLFW.GLFW_KEY_F3)) {
|
||||
//?} else
|
||||
//&& !InputUtil.isKeyPressed(client.getWindow().getHandle(), GLFW.GLFW_KEY_F3)) {
|
||||
Providers.saturn.getClient().setScreen(new EmoteWheel());
|
||||
if (client.currentScreen == null) {
|
||||
Providers.saturn.getClient().setScreen(new EmoteWheel());
|
||||
} else if (client.currentScreen instanceof SaturnScreenFabric saturnScreen
|
||||
&& saturnScreen.screen instanceof EmoteWheel) {
|
||||
saturnScreen.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Sneaking cancels your own emote, for everyone.
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#version 330
|
||||
|
||||
// Saturn's glass: the blurred game behind the screen, cut to a panel's shape. For 1.21.6 and
|
||||
// later; glass_pre_1_21_6.fsh (with glass.json, the program 1.21.4 loads) is for older versions.
|
||||
|
||||
// Vanilla's transforms, laid out as the version has them: 1.21.6 to 1.21.10 end with LineWidth, which
|
||||
// 1.21.11 dropped (GlassRenderer defines HAS_LINE_WIDTH there). Not imported: the include only exists
|
||||
// from 1.21.6, and 1.21.4 and 1.21.5 still read every shader's imports while loading resources.
|
||||
layout(std140) uniform DynamicTransforms {
|
||||
mat4 ModelViewMat;
|
||||
vec4 ColorModulator;
|
||||
vec3 ModelOffset;
|
||||
mat4 TextureMat;
|
||||
#ifdef HAS_LINE_WIDTH
|
||||
float LineWidth;
|
||||
#endif
|
||||
};
|
||||
|
||||
// The panel's rounded rectangle, the same texture its background is drawn with
|
||||
uniform sampler2D Sampler0;
|
||||
// The game behind the screen, blurred, the size of the framebuffer
|
||||
uniform sampler2D Sampler1;
|
||||
|
||||
in vec2 texCoord0;
|
||||
in vec4 vertexColor;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
float mask = texture(Sampler0, texCoord0).a * vertexColor.a;
|
||||
if (mask == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// The blurred copy lines up with the framebuffer being drawn to.
|
||||
vec2 screenUv = gl_FragCoord.xy / vec2(textureSize(Sampler1, 0));
|
||||
fragColor = vec4(texture(Sampler1, screenUv).rgb, mask) * ColorModulator;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"vertex": "minecraft:core/position_tex_color",
|
||||
"fragment": "saturnclient:core/glass_pre_1_21_6",
|
||||
"samplers": [
|
||||
{ "name": "Sampler0" },
|
||||
{ "name": "Sampler1" }
|
||||
],
|
||||
"uniforms": [
|
||||
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
|
||||
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
|
||||
{ "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#version 150
|
||||
|
||||
// Saturn's glass (see glass.fsh), for 1.21.4 and 1.21.5, which set uniforms one by one instead of in
|
||||
// blocks.
|
||||
|
||||
uniform vec4 ColorModulator;
|
||||
|
||||
// The panel's rounded rectangle, the same texture its background is drawn with
|
||||
uniform sampler2D Sampler0;
|
||||
// The game behind the screen, blurred, the size of the framebuffer
|
||||
uniform sampler2D Sampler1;
|
||||
|
||||
in vec2 texCoord0;
|
||||
in vec4 vertexColor;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
float mask = texture(Sampler0, texCoord0).a * vertexColor.a;
|
||||
if (mask == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// The blurred copy lines up with the framebuffer being drawn to.
|
||||
vec2 screenUv = gl_FragCoord.xy / vec2(textureSize(Sampler1, 0));
|
||||
fragColor = vec4(texture(Sampler1, screenUv).rgb, mask) * ColorModulator;
|
||||
}
|
||||
Reference in New Issue
Block a user