-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
218 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/io/wispforest/lavender/client/BlitCutoutProgram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.wispforest.lavender.client; | ||
|
||
import io.wispforest.lavender.Lavender; | ||
import io.wispforest.owo.shader.GlProgram; | ||
import net.minecraft.client.gl.ShaderProgram; | ||
import net.minecraft.client.render.VertexFormats; | ||
|
||
public class BlitCutoutProgram extends GlProgram { | ||
|
||
public BlitCutoutProgram() { | ||
super(Lavender.id("blit_cutout"), VertexFormats.BLIT_SCREEN); | ||
} | ||
|
||
public ShaderProgram program() { | ||
return this.backingProgram; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/io/wispforest/lavender/mixin/FramebufferMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.wispforest.lavender.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import io.wispforest.lavender.client.LavenderClient; | ||
import io.wispforest.lavender.pond.LavenderFramebufferExtension; | ||
import net.minecraft.client.gl.Framebuffer; | ||
import net.minecraft.client.gl.ShaderProgram; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.function.Supplier; | ||
|
||
@Mixin(Framebuffer.class) | ||
public class FramebufferMixin implements LavenderFramebufferExtension { | ||
|
||
private boolean useCutoutBlit = false; | ||
|
||
@Override | ||
public void lavender$setUseCutoutBlit() { | ||
this.useCutoutBlit = true; | ||
} | ||
|
||
@ModifyExpressionValue(method = "drawInternal", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/GameRenderer;blitScreenProgram:Lnet/minecraft/client/gl/ShaderProgram;")) | ||
private ShaderProgram applyBlitProgram(ShaderProgram original) { | ||
if (!this.useCutoutBlit) return original; | ||
|
||
GlStateManager._colorMask(true, true, true, true); | ||
return LavenderClient.BLIT_CUTOUT_PROGRAM.program(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 25 additions & 1 deletion
26
src/main/java/io/wispforest/lavender/mixin/MinecraftClientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,46 @@ | ||
package io.wispforest.lavender.mixin; | ||
|
||
import io.wispforest.lavender.book.Book; | ||
import io.wispforest.lavender.book.LavenderBookItem; | ||
import io.wispforest.lavender.client.LavenderBookScreen; | ||
import io.wispforest.lavender.client.OffhandBookRenderer; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(MinecraftClient.class) | ||
public class MinecraftClientMixin { | ||
|
||
@Shadow | ||
@Nullable | ||
public ClientPlayerEntity player; | ||
|
||
@Shadow | ||
@Nullable | ||
public Screen currentScreen; | ||
|
||
@Inject(method = "render", at = @At("HEAD")) | ||
private void onFrameStart(boolean tick, CallbackInfo ci) { | ||
OffhandBookRenderer.beginFrame(); | ||
if (this.player == null) return; | ||
|
||
Book bookToRender = null; | ||
var offhandStack = this.player.getOffHandStack(); | ||
if (offhandStack.getItem() instanceof LavenderBookItem && LavenderBookItem.bookOf(offhandStack) != null && !(this.currentScreen instanceof LavenderBookScreen)) { | ||
bookToRender = LavenderBookItem.bookOf(offhandStack); | ||
} | ||
|
||
OffhandBookRenderer.beginFrame(bookToRender); | ||
} | ||
|
||
@Inject(method = "render", at = @At("TAIL")) | ||
private void onFrameEnd(boolean tick, CallbackInfo ci) { | ||
if (this.player == null) return; | ||
OffhandBookRenderer.endFrame(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/io/wispforest/lavender/pond/LavenderFramebufferExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.wispforest.lavender.pond; | ||
|
||
public interface LavenderFramebufferExtension { | ||
void lavender$setUseCutoutBlit(); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/resources/assets/lavender/shaders/core/blit_cutout.fsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#version 150 | ||
|
||
uniform sampler2D DiffuseSampler; | ||
|
||
uniform vec4 ColorModulator; | ||
|
||
in vec2 texCoord; | ||
in vec4 vertexColor; | ||
|
||
out vec4 fragColor; | ||
|
||
void main() { | ||
vec4 color = texture(DiffuseSampler, texCoord) * vertexColor; | ||
color.a = min(1.0f, color.a * 1e8f); | ||
|
||
// blit final output of compositor into displayed back buffer | ||
fragColor = color * ColorModulator; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/resources/assets/lavender/shaders/core/blit_cutout.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"blend": { | ||
"func": "add", | ||
"srcrgb": "srcalpha", | ||
"dstrgb": "1-srcalpha" | ||
}, | ||
"vertex": "blit_screen", | ||
"fragment": "lavender:blit_cutout", | ||
"attributes": [ | ||
"Position", | ||
"UV", | ||
"Color" | ||
], | ||
"samplers": [ | ||
{ "name": "DiffuseSampler" } | ||
], | ||
"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 ] } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters