2727
2828import com .mojang .blaze3d .ProjectionType ;
2929import com .mojang .blaze3d .buffers .GpuBufferSlice ;
30+ import com .mojang .blaze3d .opengl .GlTexture ;
31+ import com .mojang .blaze3d .opengl .GlTextureView ;
3032import com .mojang .blaze3d .pipeline .BlendFunction ;
3133import com .mojang .blaze3d .pipeline .RenderPipeline ;
34+ import com .mojang .blaze3d .pipeline .RenderTarget ;
3235import com .mojang .blaze3d .platform .DestFactor ;
3336import com .mojang .blaze3d .platform .SourceFactor ;
3437import com .mojang .blaze3d .systems .GpuDevice ;
3538import com .mojang .blaze3d .systems .RenderSystem ;
3639import com .mojang .blaze3d .textures .FilterMode ;
37- import com .mojang .blaze3d .textures .GpuTexture ;
3840import com .mojang .blaze3d .textures .GpuTextureView ;
3941import com .mojang .blaze3d .textures .TextureFormat ;
4042import com .mojang .blaze3d .vertex .*;
5355import org .jetbrains .annotations .Nullable ;
5456import org .joml .Matrix3x2f ;
5557import org .joml .Matrix4fStack ;
58+ import org .joml .Vector4i ;
5659import org .visuals .legacy .animatium .Animatium ;
5760
5861@ UtilityClass
@@ -68,40 +71,36 @@ public class PanoramaRendererUtility {
6871 .withCull (false )
6972 .withDepthWrite (false )
7073 .withBlend (PANORAMA_BLEND )
71- // .withColorWrite(true, false)
74+ // .withColorWrite(true, false) // TODO/NOTE: Causes it to not render (alpha becomes 0.0?!??!?! )
7275 .withSampler ("Sampler0" )
7376 .withVertexFormat (DefaultVertexFormat .POSITION_TEX_COLOR , VertexFormat .Mode .QUADS )
7477 .build ();
7578
7679 private final CachedPerspectiveProjectionMatrixBuffer projectionMatrixBuffer = new CachedPerspectiveProjectionMatrixBuffer ("panorama" , 0.05F , 10.0F );
77- private final PanoramaTarget panoramaTarget = new PanoramaTarget () ;
78- private GpuTextureView backgroundTextureView = null ;
80+ private final GlTexture backgroundTexture ;
81+ private final GlTextureView backgroundTextureView ;
7982 private float spin = 0.0F ;
8083
8184 static {
82- setup ();
83- }
84-
85- private void setup () {
86- if (backgroundTextureView == null ) {
87- final GpuDevice device = RenderSystem .getDevice ();
88- final GpuTexture backgroundTexture = device .createTexture (() -> "Background texture" , 15 , TextureFormat .RGBA8 , 256 , 256 , 1 , 1 );
89- backgroundTexture .setTextureFilter (FilterMode .LINEAR , FilterMode .LINEAR , false );
90- backgroundTextureView = device .createTextureView (backgroundTexture );
91- }
85+ final GpuDevice device = RenderSystem .getDevice ();
86+ backgroundTexture = (GlTexture ) device .createTexture (() -> "Background texture" , 15 , TextureFormat .RGBA8 , 256 , 256 , 1 , 1 );
87+ backgroundTexture .setTextureFilter (FilterMode .LINEAR , FilterMode .LINEAR , false );
88+ backgroundTextureView = (GlTextureView ) device .createTextureView (backgroundTexture );
9289 }
9390
9491 public void render (final GuiGraphics guiGraphics , final int width , final int height ) {
95- renderPanorama (PANORAMA , width , height );
92+ final RenderTarget renderTarget = Minecraft .getInstance ().getMainRenderTarget ();
93+ RenderUtils .setRenderOverrides (new RenderUtils .RenderOverrides (new Vector4i (0 , 0 , 256 , 256 )));
94+ renderPanorama (PANORAMA , renderTarget , width , height );
9695 for (int layer = 0 ; layer < 7 ; ++layer ) {
97- RenderSystem .getDevice ().createCommandEncoder ().copyTextureToTexture (panoramaTarget .getColorTexture (), backgroundTextureView . texture () , 0 , 0 , 0 , 0 , 0 , 256 , 256 );
98- RenderUtils .drawInGui (panoramaTarget , DynamicTransformsBuilder .of (), new BlitBlurTexture (guiGraphics .pose (), backgroundTextureView , width , height ));
96+ RenderSystem .getDevice ().createCommandEncoder ().copyTextureToTexture (renderTarget .getColorTexture (), backgroundTexture , 0 , 0 , 0 , 0 , 0 , 256 , 256 );
97+ RenderUtils .drawInGui (renderTarget , DynamicTransformsBuilder .of (), new BlitBlurTexture (guiGraphics .pose (), backgroundTextureView , width , height ));
9998 }
100-
99+ RenderUtils . setRenderOverrides ( RenderUtils . RenderOverrides . DISABLED );
101100 guiGraphics .guiRenderState .submitGuiElement (new BlitFinalTexture (guiGraphics .pose (), backgroundTextureView , width , height , ARGB .white (1.0F )));
102101 }
103102
104- private void renderPanorama (final RenderPipeline pipeline , final int width , final int height ) {
103+ private void renderPanorama (final RenderPipeline pipeline , final RenderTarget renderTarget , final int width , final int height ) {
105104 RenderSystem .setProjectionMatrix (projectionMatrixBuffer .getBuffer (width , height , 120.0F ), ProjectionType .PERSPECTIVE );
106105 final Matrix4fStack modelViewStack = RenderSystem .getModelViewStack ();
107106 modelViewStack .pushMatrix ();
@@ -140,7 +139,7 @@ private void renderPanorama(final RenderPipeline pipeline, final int width, fina
140139 final GpuBufferSlice dynamicTransforms = DynamicTransformsBuilder .of ()
141140 .withModelViewMatrix (modelViewStack )
142141 .build ();
143- RenderUtils .drawWithPipeline (panoramaTarget , pipeline , builder .buildOrThrow (), (pass ) -> {
142+ RenderUtils .drawWithPipeline (renderTarget , pipeline , builder .buildOrThrow (), (pass ) -> {
144143 pass .setUniform ("DynamicTransforms" , dynamicTransforms );
145144 pass .bindSampler ("Sampler0" , panoramaTexture );
146145 });
@@ -179,7 +178,7 @@ private record BlitBlurTexture(
179178 @ Override
180179 public void buildVertices (VertexConsumer consumer ) {
181180 for (int cycle = 0 ; cycle < 3 ; cycle ++) {
182- final int color = ARGB .white (1.0F ); // ARGB.white(1.0F / ( cycle + 1)); // might be issue
181+ final int color = ARGB .white (1.0F / ( cycle + 1 ));
183182 final float growth = (cycle - 1 ) / 256.0F ;
184183 consumer .addVertexWith2DPose (this .pose , this .width , this .height ).setUv (0.0F + growth , 1.0F ).setColor (color );
185184 consumer .addVertexWith2DPose (this .pose , this .width , 0.0F ).setUv (1.0F + growth , 1.0F ).setColor (color );
@@ -193,7 +192,7 @@ public void buildVertices(VertexConsumer consumer) {
193192 return RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
194193 .withLocation (Animatium .location ("pipeline/panorama_blur" ))
195194 .withBlend (PANORAMA_BLEND )
196- // .withColorWrite(true, false)
195+ .withColorWrite (true , false )
197196 .build ();
198197 }
199198
@@ -222,8 +221,8 @@ public record BlitFinalTexture(
222221 @ Override
223222 public void buildVertices (VertexConsumer consumer ) {
224223 final float aspect = 120.0F / (Math .max (this .width , this .height ));
225- final float sw = this .width * aspect / panoramaTarget . width ;
226- final float sh = this .height * aspect / panoramaTarget . height ;
224+ final float sw = this .width * aspect / 256.0F ;
225+ final float sh = this .height * aspect / 256.0F ;
227226 consumer .addVertexWith2DPose (this .pose , 0.0F , this .height ).setUv (0.5F - sh , 0.5F + sw ).setColor (this .color );
228227 consumer .addVertexWith2DPose (this .pose , this .width , this .height ).setUv (0.5F - sh , 0.5F - sw ).setColor (this .color );
229228 consumer .addVertexWith2DPose (this .pose , this .width , 0.0F ).setUv (0.5F + sh , 0.5F - sw ).setColor (this .color );
0 commit comments