11package btw .lowercase .optiboxes .skybox ;
22
3- import btw .lowercase .optiboxes .OptiBoxesClient ;
4- import btw .lowercase .optiboxes .mixins .RenderPipelinesAccessor ;
53import btw .lowercase .optiboxes .utils .CommonUtils ;
6- import btw .lowercase .optiboxes .utils .IrisUtil ;
74import btw .lowercase .optiboxes .utils .UVRange ;
8- import btw .lowercase .optiboxes .utils .components .Blend ;
9- import com .mojang .blaze3d .buffers .GpuBuffer ;
10- import com .mojang .blaze3d .pipeline .RenderTarget ;
11- import com .mojang .blaze3d .systems .RenderPass ;
125import com .mojang .blaze3d .systems .RenderSystem ;
136import com .mojang .blaze3d .vertex .*;
147import net .minecraft .client .Minecraft ;
15- import net .minecraft .client .renderer .texture .AbstractTexture ;
16- import net .minecraft .resources .ResourceLocation ;
8+ import net .minecraft .client .renderer .CoreShaders ;
179import net .minecraft .util .Mth ;
1810import net .minecraft .world .level .Level ;
19- import org .jetbrains .annotations .Nullable ;
20- import org .joml .*;
21-
22- import java .lang .Math ;
23- import java .util .HashMap ;
24- import java .util .Map ;
25- import java .util .OptionalDouble ;
26- import java .util .OptionalInt ;
11+ import org .joml .AxisAngle4f ;
12+ import org .joml .Matrix4f ;
13+ import org .joml .Matrix4fStack ;
14+ import org .joml .Quaternionf ;
2715
2816public final class OptiFineSkyRenderer {
2917 public static final OptiFineSkyRenderer INSTANCE = new OptiFineSkyRenderer ();
3018
31- private GpuBuffer skyBuffer ;
19+ //? >=1.21.5 {
20+ private com .mojang .blaze3d .buffers .GpuBuffer skyBuffer ;
3221 private RenderSystem .AutoStorageIndexBuffer skyBufferIndices ;
3322 private int skyBufferIndexCount ;
23+ //?} else {
24+ /*private com.mojang.blaze3d.vertex.VertexBuffer skyBuffer;
25+ */ //?}
3426
3527 private OptiFineSkyRenderer () {
3628 Minecraft .getInstance ().schedule (this ::buildSky );
@@ -52,29 +44,37 @@ private void buildSky() {
5244 builder .addVertex (CommonUtils .getMatrixTransform (matrix4f , quadSize , -quadSize , -quadSize )).setUv (uvRange .maxU (), uvRange .minV ());
5345 }
5446
47+ //? >=1.21.5
5548 skyBufferIndices = RenderSystem .getSequentialBuffer (vertexFormatMode );
5649 try (MeshData meshData = builder .buildOrThrow ()) {
50+ //? >=1.21.5 {
5751 skyBufferIndexCount = meshData .drawState ().indexCount ();
5852 skyBuffer = RenderSystem .getDevice ().createBuffer (
5953 () -> "OptiFine Skybox" ,
6054 //? >=1.21.6 {
61- GpuBuffer .USAGE_COPY_DST ,
55+ com . mojang . blaze3d . buffers . GpuBuffer .USAGE_COPY_DST ,
6256 //?} else {
6357 /*com.mojang.blaze3d.buffers.BufferType.VERTICES, com.mojang.blaze3d.buffers.BufferUsage.STATIC_WRITE,
64- */ //?}
58+ */ //?}
6559 meshData .vertexBuffer ()
6660 );
61+ //?} else {
62+ /*skyBuffer = new com.mojang.blaze3d.vertex.VertexBuffer(com.mojang.blaze3d.buffers.BufferUsage.STATIC_WRITE);
63+ skyBuffer.bind();
64+ skyBuffer.upload(meshData);
65+ com.mojang.blaze3d.vertex.VertexBuffer.unbind();
66+ */ //?}
6767 }
6868 }
6969
7070 //? >=1.21.5 {
7171 private final Map <ResourceLocation , com .mojang .blaze3d .pipeline .RenderPipeline > renderPipelineCache = new HashMap <>();
7272
73- public static com .mojang .blaze3d .pipeline .RenderPipeline getSkyboxPipeline (@ Nullable btw .lowercase .optiboxes .utils .BlendFunction blendFunction ) {
74- com .mojang .blaze3d .pipeline .RenderPipeline .Builder builder = com .mojang .blaze3d .pipeline .RenderPipeline .builder (RenderPipelinesAccessor .optiboxes$getMatricesProjectionSnippet ());
75- builder .withLocation (OptiBoxesClient .id ("pipeline/custom_skybox" ));
76- builder .withVertexShader (OptiBoxesClient .id ("core/custom_skybox" ));
77- builder .withFragmentShader (OptiBoxesClient .id ("core/custom_skybox" ));
73+ public static com .mojang .blaze3d .pipeline .RenderPipeline getSkyboxPipeline (@ org . jetbrains . annotations . Nullable btw .lowercase .optiboxes .utils .BlendFunction blendFunction ) {
74+ com .mojang .blaze3d .pipeline .RenderPipeline .Builder builder = com .mojang .blaze3d .pipeline .RenderPipeline .builder (btw . lowercase . optiboxes . mixins . RenderPipelinesAccessor .optiboxes$getMatricesProjectionSnippet ());
75+ builder .withLocation (btw . lowercase . optiboxes . OptiBoxesClient .id ("pipeline/custom_skybox" ));
76+ builder .withVertexShader (btw . lowercase . optiboxes . OptiBoxesClient .id ("core/custom_skybox" ));
77+ builder .withFragmentShader (btw . lowercase . optiboxes . OptiBoxesClient .id ("core/custom_skybox" ));
7878 builder .withDepthWrite (false );
7979 builder .withColorWrite (true , false );
8080 if (blendFunction != null ) {
@@ -101,8 +101,7 @@ public void renderSkybox(OptiFineSkybox optiFineSkybox, Matrix4fStack modelViewS
101101 }
102102
103103 //? <=1.21.5 {
104- /*Vector4f shaderColor = Blend.ADD.getShaderColor(1.0F - rainLevel);
105- RenderSystem.setShaderColor(shaderColor.x, shaderColor.y, shaderColor.z, shaderColor.w);
104+ /*btw.lowercase.optiboxes.utils.components.Blend.ADD.apply(1.0F - rainLevel);
106105 */ //?}
107106 }
108107
@@ -117,26 +116,25 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
117116 modelViewStack .rotate (new Quaternionf (new AxisAngle4f (this .getAngle (level , skyAngle , optiFineSkyLayer .speed ()), optiFineSkyLayer .axis ())));
118117 }
119118
120- Vector4f shaderColor = optiFineSkyLayer .blend ().getShaderColor (finalAlpha );
121- AbstractTexture skyTexture = Minecraft .getInstance ().getTextureManager ().getTexture (optiFineSkyLayer .source ());
122-
123119 //? >=1.21.6 {
124120 com .mojang .blaze3d .buffers .GpuBufferSlice transforms = btw .lowercase .optiboxes .utils .DynamicTransformsBuilder .of ()
125121 .withModelViewMatrix (modelViewStack )
126- .withShaderColor (shaderColor )
122+ .withShaderColor (optiFineSkyLayer . blend (). getShaderColor ( finalAlpha ) )
127123 .build ();
128124 //?} else {
129- /*RenderSystem.setShaderColor(shaderColor.x, shaderColor.y, shaderColor.z, shaderColor.w);
125+ /*RenderSystem.setShaderTexture(0, optiFineSkyLayer.source());
126+ RenderSystem.setShader(CoreShaders.POSITION_TEX);
127+ optiFineSkyLayer.blend().apply(finalAlpha);
130128 */ //?}
131129
132130 //? >=1.21.5 {
133131 com .mojang .blaze3d .pipeline .RenderPipeline renderPipeline = this .renderPipelineCache .computeIfAbsent (optiFineSkyLayer .source (), (resourceLocation ) -> {
134132 com .mojang .blaze3d .pipeline .RenderPipeline pipeline = getSkyboxPipeline (optiFineSkyLayer .blend ().getBlendFunction ());
135- IrisUtil .assignPipeline (pipeline , IrisUtil .skyTextured ());
133+ btw . lowercase . optiboxes . utils . IrisUtil .assignPipeline (pipeline , btw . lowercase . optiboxes . utils . IrisUtil .skyTextured ());
136134 return pipeline ;
137135 });
138136
139- RenderTarget renderTarget = Minecraft .getInstance ().getMainRenderTarget ();
137+ com . mojang . blaze3d . pipeline . RenderTarget renderTarget = Minecraft .getInstance ().getMainRenderTarget ();
140138
141139 //? >=1.21.6 {
142140 com .mojang .blaze3d .textures .GpuTextureView texture = skyTexture .getTextureView ();
@@ -148,8 +146,9 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
148146 com.mojang.blaze3d.textures.GpuTexture depthTexture = renderTarget.getDepthTexture();
149147 */ //?}
150148
151- GpuBuffer indexBuffer = this .skyBufferIndices .getBuffer (this .skyBufferIndexCount );
152- try (RenderPass renderPass = RenderSystem .getDevice ()
149+ net .minecraft .client .renderer .texture .AbstractTexture skyTexture = Minecraft .getInstance ().getTextureManager ().getTexture (optiFineSkyLayer .source ());
150+ com .mojang .blaze3d .buffers .GpuBuffer indexBuffer = this .skyBufferIndices .getBuffer (this .skyBufferIndexCount );
151+ try (com .mojang .blaze3d .systems .RenderPass renderPass = RenderSystem .getDevice ()
153152 .createCommandEncoder ()
154153 .createRenderPass (
155154 //? >=1.21.6
@@ -169,13 +168,15 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
169168 renderPass .bindSampler ("Sampler0" , texture );
170169 //? >=1.21.6 {
171170 renderPass .drawIndexed (0 , 0 , this .skyBufferIndexCount , 1 );
172- //?} else {
171+ //?} else {
173172 /*renderPass.drawIndexed(0, this.skyBufferIndexCount);
174- */ //?}
173+ */ //?}
175174 }
176175 //?} else {
177-
178- //?}
176+ /*this.skyBuffer.bind();
177+ this.skyBuffer.drawWithShader(modelViewStack, RenderSystem.getProjectionMatrix(), RenderSystem.getShader());
178+ com.mojang.blaze3d.vertex.VertexBuffer.unbind();
179+ */ //?}
179180
180181 modelViewStack .popMatrix ();
181182 }
@@ -196,6 +197,6 @@ private float getAngle(Level level, float skyAngle, float speed) {
196197 public void clearCache () {
197198 //? >=1.21.5 {
198199 this .renderPipelineCache .clear ();
199- //?}
200+ //?}
200201 }
201202}
0 commit comments