-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flow stencil information through post chains
- Loading branch information
1 parent
155b835
commit e354ca3
Showing
9 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch
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,46 @@ | ||
--- a/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java | ||
+++ b/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java | ||
@@ -173,6 +_,11 @@ | ||
public T get() { | ||
return this.resource; | ||
} | ||
+ | ||
+ @Override | ||
+ public ResourceDescriptor<T> getDescriptor() { | ||
+ return null; | ||
+ } | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@@ -211,6 +_,10 @@ | ||
public String toString() { | ||
return this.createdBy != null ? this.holder + "#" + this.version + " (from " + this.createdBy + ")" : this.holder + "#" + this.version; | ||
} | ||
+ | ||
+ public ResourceDescriptor<T> getDescriptor() { | ||
+ return this.holder.getDescriptor(); | ||
+ } | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@@ -265,6 +_,11 @@ | ||
this.physicalResource = null; | ||
} | ||
} | ||
+ | ||
+ @Override | ||
+ public ResourceDescriptor<T> getDescriptor() { | ||
+ return descriptor; | ||
+ } | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@@ -364,5 +_,8 @@ | ||
public String toString() { | ||
return this.name; | ||
} | ||
+ | ||
+ @Nullable | ||
+ public abstract ResourceDescriptor<T> getDescriptor(); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
patches/com/mojang/blaze3d/pipeline/TextureTarget.java.patch
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,14 @@ | ||
--- a/com/mojang/blaze3d/pipeline/TextureTarget.java | ||
+++ b/com/mojang/blaze3d/pipeline/TextureTarget.java | ||
@@ -7,7 +_,10 @@ | ||
@OnlyIn(Dist.CLIENT) | ||
public class TextureTarget extends RenderTarget { | ||
public TextureTarget(int p_166213_, int p_166214_, boolean p_166215_) { | ||
- super(p_166215_); | ||
+ this(p_166213_, p_166214_, p_166215_, false); | ||
+ } | ||
+ public TextureTarget(int p_166213_, int p_166214_, boolean p_166215_, boolean useStencil) { | ||
+ super(p_166215_, useStencil); | ||
RenderSystem.assertOnRenderThreadOrInit(); | ||
this.resize(p_166213_, p_166214_); | ||
} |
18 changes: 18 additions & 0 deletions
18
patches/com/mojang/blaze3d/resource/RenderTargetDescriptor.java.patch
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 @@ | ||
--- a/com/mojang/blaze3d/resource/RenderTargetDescriptor.java | ||
+++ b/com/mojang/blaze3d/resource/RenderTargetDescriptor.java | ||
@@ -6,9 +_,13 @@ | ||
import net.neoforged.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
-public record RenderTargetDescriptor(int width, int height, boolean useDepth) implements ResourceDescriptor<RenderTarget> { | ||
+public record RenderTargetDescriptor(int width, int height, boolean useDepth, boolean useStencil) implements ResourceDescriptor<RenderTarget> { | ||
+ public RenderTargetDescriptor(int width, int height, boolean useDepth) { | ||
+ this(width, height, useDepth, false); | ||
+ } | ||
+ | ||
public RenderTarget allocate() { | ||
- return new TextureTarget(this.width, this.height, this.useDepth); | ||
+ return new TextureTarget(this.width, this.height, this.useDepth, this.useStencil); | ||
} | ||
|
||
public void free(RenderTarget p_363223_) { |
10 changes: 10 additions & 0 deletions
10
patches/net/minecraft/client/renderer/LevelRenderer.java.patch
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
48 changes: 48 additions & 0 deletions
48
patches/net/minecraft/client/renderer/PostChain.java.patch
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,48 @@ | ||
--- a/net/minecraft/client/renderer/PostChain.java | ||
+++ b/net/minecraft/client/renderer/PostChain.java | ||
@@ -83,8 +_,8 @@ | ||
abstracttexture.setFilter(flag, false); | ||
postpass.addInput(new PostPass.TextureInput(s3, abstracttexture, i, j)); | ||
continue; | ||
- case PostChainConfig.TargetInput(String s1, ResourceLocation resourcelocation2, boolean flag1, boolean flag2): | ||
- postpass.addInput(new PostPass.TargetInput(s1, resourcelocation2, flag1, flag2)); | ||
+ case PostChainConfig.TargetInput(String s1, ResourceLocation resourcelocation2, boolean flag1, boolean flag2, boolean useStencilBuffer): | ||
+ postpass.addInput(new PostPass.TargetInput(s1, resourcelocation2, flag1, flag2, useStencilBuffer)); | ||
continue; | ||
default: | ||
throw new MatchException(null, null); | ||
@@ -99,17 +_,32 @@ | ||
Matrix4f matrix4f = new Matrix4f().setOrtho(0.0F, (float)p_361423_, 0.0F, (float)p_362735_, 0.1F, 1000.0F); | ||
Map<ResourceLocation, ResourceHandle<RenderTarget>> map = new HashMap<>(this.internalTargets.size() + this.externalTargets.size()); | ||
|
||
+ // Enable the depth and stencil buffers based on whether any external targets use them. | ||
+ // This is necessary so any created buffers get the correct parameters for blitting. | ||
+ boolean useDepth = false; | ||
+ boolean useStencil = false; | ||
for (ResourceLocation resourcelocation : this.externalTargets) { | ||
map.put(resourcelocation, p_361871_.getOrThrow(resourcelocation)); | ||
+ | ||
+ var handle = p_361871_.get(resourcelocation); | ||
+ | ||
+ if (handle instanceof FrameGraphBuilder.Handle<?> frameHandle | ||
+ && frameHandle.getDescriptor() instanceof RenderTargetDescriptor renderDescriptor) { | ||
+ useDepth |= renderDescriptor.useDepth(); | ||
+ useStencil |= renderDescriptor.useStencil(); | ||
+ } else { | ||
+ useDepth |= p_361871_.get(resourcelocation).get().useDepth; | ||
+ useStencil |= p_361871_.get(resourcelocation).get().useStencil; | ||
+ } | ||
} | ||
|
||
for (Entry<ResourceLocation, PostChainConfig.InternalTarget> entry : this.internalTargets.entrySet()) { | ||
ResourceLocation resourcelocation1 = entry.getKey(); | ||
RenderTargetDescriptor rendertargetdescriptor = switch (entry.getValue()) { | ||
case PostChainConfig.FixedSizedTarget(int i, int j) -> { | ||
- yield new RenderTargetDescriptor(i, j, true); | ||
+ yield new RenderTargetDescriptor(i, j, useDepth, useStencil); | ||
} | ||
- case PostChainConfig.FullScreenTarget postchainconfig$fullscreentarget -> new RenderTargetDescriptor(p_361423_, p_362735_, true); | ||
+ case PostChainConfig.FullScreenTarget postchainconfig$fullscreentarget -> new RenderTargetDescriptor(p_361423_, p_362735_, useDepth, useStencil); | ||
default -> throw new MatchException(null, null); | ||
}; | ||
map.put(resourcelocation1, p_362523_.createInternal(resourcelocation1.toString(), rendertargetdescriptor)); |
23 changes: 23 additions & 0 deletions
23
patches/net/minecraft/client/renderer/PostChainConfig.java.patch
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,23 @@ | ||
--- a/net/minecraft/client/renderer/PostChainConfig.java | ||
+++ b/net/minecraft/client/renderer/PostChainConfig.java | ||
@@ -103,13 +_,18 @@ | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
- public static record TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear) implements PostChainConfig.Input { | ||
+ public static record TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear, boolean useStencilBuffer) implements PostChainConfig.Input { | ||
+ public TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear) { | ||
+ this(samplerName, targetId, useDepthBuffer, bilinear, false); | ||
+ } | ||
+ | ||
public static final Codec<PostChainConfig.TargetInput> CODEC = RecordCodecBuilder.create( | ||
p_363892_ -> p_363892_.group( | ||
Codec.STRING.fieldOf("sampler_name").forGetter(PostChainConfig.TargetInput::samplerName), | ||
ResourceLocation.CODEC.fieldOf("target").forGetter(PostChainConfig.TargetInput::targetId), | ||
Codec.BOOL.optionalFieldOf("use_depth_buffer", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::useDepthBuffer), | ||
- Codec.BOOL.optionalFieldOf("bilinear", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::bilinear) | ||
+ Codec.BOOL.optionalFieldOf("bilinear", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::bilinear), | ||
+ Codec.BOOL.optionalFieldOf("neoforge:use_stencil_buffer", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::useStencilBuffer) | ||
) | ||
.apply(p_363892_, PostChainConfig.TargetInput::new) | ||
); |
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,28 @@ | ||
--- a/net/minecraft/client/renderer/PostPass.java | ||
+++ b/net/minecraft/client/renderer/PostPass.java | ||
@@ -122,7 +_,10 @@ | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
- public static record TargetInput(String samplerName, ResourceLocation targetId, boolean depthBuffer, boolean bilinear) implements PostPass.Input { | ||
+ public static record TargetInput(String samplerName, ResourceLocation targetId, boolean depthBuffer, boolean bilinear, boolean stencilBuffer) implements PostPass.Input { | ||
+ public TargetInput(String samplerName, ResourceLocation targetId, boolean depthBuffer, boolean bilinear) { | ||
+ this(samplerName, targetId, depthBuffer, bilinear, false); | ||
+ } | ||
private ResourceHandle<RenderTarget> getHandle(Map<ResourceLocation, ResourceHandle<RenderTarget>> p_364534_) { | ||
ResourceHandle<RenderTarget> resourcehandle = p_364534_.get(this.targetId); | ||
if (resourcehandle == null) { | ||
@@ -142,7 +_,12 @@ | ||
ResourceHandle<RenderTarget> resourcehandle = this.getHandle(p_361239_); | ||
RenderTarget rendertarget = resourcehandle.get(); | ||
rendertarget.setFilterMode(this.bilinear ? 9729 : 9728); | ||
- p_366564_.bindSampler(this.samplerName + "Sampler", this.depthBuffer ? rendertarget.getDepthTextureId() : rendertarget.getColorTextureId()); | ||
+ if (this.depthBuffer) | ||
+ p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getDepthTextureId()); | ||
+ else if (this.stencilBuffer) | ||
+ p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getStencilTextureId()); | ||
+ else | ||
+ p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getColorTextureId()); | ||
p_366564_.safeGetUniform(this.samplerName + "Size").set((float)rendertarget.width, (float)rendertarget.height); | ||
} | ||
|
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