|
25 | 25 |
|
26 | 26 | package org.visuals.legacy.animatium.util; |
27 | 27 |
|
| 28 | +import com.mojang.blaze3d.opengl.GlStateManager; |
| 29 | +import com.mojang.blaze3d.opengl.GlTexture; |
28 | 30 | import com.mojang.blaze3d.opengl.GlTextureView; |
29 | 31 | import com.mojang.blaze3d.pipeline.BlendFunction; |
30 | 32 | import com.mojang.blaze3d.pipeline.RenderPipeline; |
31 | 33 | import com.mojang.blaze3d.pipeline.RenderTarget; |
32 | 34 | import com.mojang.blaze3d.platform.DestFactor; |
33 | 35 | import com.mojang.blaze3d.platform.SourceFactor; |
| 36 | +import com.mojang.blaze3d.systems.GpuDevice; |
34 | 37 | import com.mojang.blaze3d.systems.RenderSystem; |
35 | 38 | import com.mojang.blaze3d.textures.FilterMode; |
| 39 | +import com.mojang.blaze3d.textures.TextureFormat; |
36 | 40 | import com.mojang.blaze3d.vertex.BufferBuilder; |
37 | 41 | import com.mojang.blaze3d.vertex.ByteBufferBuilder; |
38 | 42 | import com.mojang.blaze3d.vertex.DefaultVertexFormat; |
|
41 | 45 | import net.minecraft.client.Minecraft; |
42 | 46 | import net.minecraft.client.renderer.RenderPipelines; |
43 | 47 | import net.minecraft.util.ARGB; |
| 48 | +import net.minecraft.util.Mth; |
44 | 49 | import org.joml.Matrix3x2f; |
45 | 50 | import org.visuals.legacy.animatium.Animatium; |
46 | 51 |
|
47 | 52 | @UtilityClass |
48 | 53 | // Ported code of the old <=1.12.2 panorama renderer (w/ blur) |
49 | 54 | public class PanoramaRendererUtility { |
50 | | - private static final RenderPipeline.Snippet TEXTURE_SNIPPET = |
| 55 | + private final RenderPipeline.Snippet TEXTURE_SNIPPET = |
51 | 56 | RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET) |
52 | 57 | .withVertexShader("core/position_tex") |
53 | 58 | .withFragmentShader("core/position_tex") |
54 | 59 | .withSampler("Sampler0") |
55 | 60 | .withVertexFormat(DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS) |
56 | 61 | .buildSnippet(); |
57 | 62 |
|
58 | | - private static final RenderPipeline BLUR_TEXTURED_PIPELINE = |
| 63 | + private final RenderPipeline BLUR_TEXTURED_PIPELINE = |
59 | 64 | RenderPipeline.builder(TEXTURE_SNIPPET) |
60 | 65 | .withLocation(Animatium.location("pipeline/blur_texture")) |
61 | 66 | .withColorWrite(true, false) |
62 | 67 | .withBlend(new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO)) |
63 | 68 | .build(); |
64 | 69 |
|
65 | | - private static final RenderPipeline BASIC_TEXTURED_PIPELINE = |
| 70 | + private final RenderPipeline BASIC_TEXTURED_PIPELINE = |
66 | 71 | RenderPipeline.builder(TEXTURE_SNIPPET) |
67 | 72 | .withLocation(Animatium.location("pipeline/basic_texture")) |
68 | 73 | .build(); |
69 | 74 |
|
| 75 | + private GlTextureView backgroundTextureView = null; |
| 76 | + private float spin = 0.0F; |
| 77 | + |
| 78 | + public void setup() { |
| 79 | + if (backgroundTextureView == null) { |
| 80 | + final GpuDevice device = RenderSystem.getDevice(); |
| 81 | + final GlTexture animatium$backgroundTexture = (GlTexture) device.createTexture(() -> "Background texture", 15, TextureFormat.RGBA8, 256, 256, 1, 1); |
| 82 | + backgroundTextureView = (GlTextureView) device.createTextureView(animatium$backgroundTexture); |
| 83 | + } |
| 84 | + |
| 85 | + GlStateManager._viewport(0, 0, 256, 256); |
| 86 | + } |
| 87 | + |
70 | 88 | /** |
71 | 89 | * In PanoramaRenderer, before ``cubeMap.render``, set viewPort to (0, 0, 256, 256) |
72 | 90 | * then call this method after ``cubeMap.render`` |
73 | 91 | * |
74 | | - * @param matrix The 2D GUI matrix |
75 | | - * @param textureView The texture we are drawing to |
76 | | - * @param width Screen width |
77 | | - * @param height Screen Height |
| 92 | + * @param matrix The 2D GUI matrix |
| 93 | + * @param width Screen width |
| 94 | + * @param height Screen Height |
78 | 95 | */ |
79 | | - public void render(Matrix3x2f matrix, GlTextureView textureView, int width, int height) { |
| 96 | + public void render(Matrix3x2f matrix, int width, int height) { |
80 | 97 | final RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget(); |
81 | 98 | for (int i = 0; i < 7; ++i) { |
82 | | - writeAndBlitBlurTexture(matrix, renderTarget, textureView, width, height); |
| 99 | + writeAndBlitBlurTexture(matrix, renderTarget, backgroundTextureView, width, height); |
83 | 100 | } |
84 | 101 |
|
85 | | - renderFinalTexture(matrix, renderTarget, textureView, width, height); |
| 102 | + renderFinalTexture(matrix, renderTarget, backgroundTextureView, width, height); |
| 103 | + } |
| 104 | + |
| 105 | + public void update(float tickDelta) { |
| 106 | + spin += tickDelta; |
| 107 | + } |
| 108 | + |
| 109 | + public float getXRot() { |
| 110 | + return Mth.sin(spin / 400.0F) * 25.0F + 20.0F; |
86 | 111 | } |
87 | 112 |
|
| 113 | + public float getYRot() { |
| 114 | + return -spin * 0.1F; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Render & Blur the texture |
| 119 | + * |
| 120 | + * @param matrix The 2D GUI matrix |
| 121 | + * @param renderTarget The texture we are drawing to |
| 122 | + * @param texture The temporary texture |
| 123 | + * @param width Screen width |
| 124 | + * @param height Screen Height |
| 125 | + */ |
88 | 126 | private void writeAndBlitBlurTexture(Matrix3x2f matrix, RenderTarget renderTarget, GlTextureView texture, int width, int height) { |
89 | 127 | texture.texture().setTextureFilter(FilterMode.LINEAR, FilterMode.LINEAR, false); |
90 | 128 | // Ensures enough width/height for it to not crash when window is resized |
|
0 commit comments