Sky rendering
This commit is contained in:
parent
8d07268aa1
commit
d488615e55
7 changed files with 37 additions and 18 deletions
|
@ -14,6 +14,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gl.VertexBuffer;
|
||||
import net.minecraft.client.render.BackgroundRenderer;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.BufferBuilderStorage;
|
||||
import net.minecraft.client.render.SkyProperties;
|
||||
|
@ -32,13 +33,15 @@ import ru.betterend.util.MHelper;
|
|||
|
||||
@Mixin(WorldRenderer.class)
|
||||
public class WorldRendererMixin {
|
||||
private static final Identifier SKY = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_2.png");
|
||||
private static final Identifier HORIZON = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_3.png");
|
||||
private static final Identifier NEBULA_1 = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_2_3.png");
|
||||
private static final Identifier NEBULA_2 = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_2_3_2.png");
|
||||
private static final Identifier HORIZON = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_3_4.png");
|
||||
|
||||
private static VertexBuffer customStarsBuffer1;
|
||||
private static VertexBuffer customStarsBuffer2;
|
||||
private static VertexBuffer customStarsBuffer3;
|
||||
private static VertexBuffer farFogBuffer;
|
||||
private static VertexBuffer nebulas_1;
|
||||
private static VertexBuffer nebulas_2;
|
||||
private static VertexBuffer horizon;
|
||||
private static Vector3f axis1;
|
||||
private static Vector3f axis2;
|
||||
|
@ -74,15 +77,30 @@ public class WorldRendererMixin {
|
|||
time += tickDelta * 0.001F;
|
||||
if (time > 360) time -= 360;
|
||||
|
||||
BackgroundRenderer.setFogBlack();
|
||||
|
||||
RenderSystem.enableAlphaTest();
|
||||
GlStateManager.alphaFunc(516, 0.0F);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableTexture();
|
||||
textureManager.bindTexture(HORIZON);
|
||||
renderBuffer(matrices, horizon, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 1F);
|
||||
|
||||
textureManager.bindTexture(SKY);
|
||||
renderBuffer(matrices, farFogBuffer, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.15F);
|
||||
matrices.push();
|
||||
matrices.multiply(new Quaternion(0, time, 0, true));
|
||||
textureManager.bindTexture(HORIZON);
|
||||
renderBuffer(matrices, horizon, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.7F);
|
||||
matrices.pop();
|
||||
|
||||
matrices.push();
|
||||
matrices.multiply(new Quaternion(0, -time, 0, true));
|
||||
textureManager.bindTexture(NEBULA_1);
|
||||
renderBuffer(matrices, nebulas_1, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.2F);
|
||||
matrices.pop();
|
||||
|
||||
matrices.push();
|
||||
matrices.multiply(new Quaternion(0, time * 2, 0, true));
|
||||
textureManager.bindTexture(NEBULA_2);
|
||||
renderBuffer(matrices, nebulas_2, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.2F);
|
||||
matrices.pop();
|
||||
|
||||
RenderSystem.disableTexture();
|
||||
|
||||
|
@ -119,10 +137,11 @@ public class WorldRendererMixin {
|
|||
|
||||
private void initStars() {
|
||||
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
|
||||
customStarsBuffer1 = buildBuffer(buffer, customStarsBuffer1, 0.05, 0.3, 3500, 41315);
|
||||
customStarsBuffer2 = buildBuffer(buffer, customStarsBuffer2, 0.07, 0.4, 2000, 35151);
|
||||
customStarsBuffer3 = buildBuffer(buffer, customStarsBuffer3, 0.1, 0.5, 1500, 61354);
|
||||
farFogBuffer = buildBufferFarFog(buffer, farFogBuffer, 40, 60, 60, 11515);
|
||||
customStarsBuffer1 = buildBuffer(buffer, customStarsBuffer1, 0.1, 0.30, 3500, 41315);
|
||||
customStarsBuffer2 = buildBuffer(buffer, customStarsBuffer2, 0.1, 0.35, 2000, 35151);
|
||||
customStarsBuffer3 = buildBuffer(buffer, customStarsBuffer3, 0.1, 0.40, 1500, 61354);
|
||||
nebulas_1 = buildBufferFarFog(buffer, nebulas_1, 40, 60, 30, 11515);
|
||||
nebulas_2 = buildBufferFarFog(buffer, nebulas_2, 40, 60, 10, 14151);
|
||||
horizon = buildBufferHorizon(buffer, horizon);
|
||||
}
|
||||
|
||||
|
@ -158,7 +177,7 @@ public class WorldRendererMixin {
|
|||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE);
|
||||
makeHorizon(bufferBuilder, 16);
|
||||
makeHorizon(bufferBuilder, 16, 50);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
|
@ -214,7 +233,7 @@ public class WorldRendererMixin {
|
|||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
double posX = random.nextDouble() * 2.0 - 1.0;
|
||||
double posY = random.nextDouble() * 0.5 - 0.25;
|
||||
double posY = random.nextDouble() - 0.5;
|
||||
double posZ = random.nextDouble() * 2.0 - 1.0;
|
||||
double size = MHelper.randRange(minSize, maxSize, random);
|
||||
double length = posX * posX + posY * posY + posZ * posZ;
|
||||
|
@ -259,7 +278,7 @@ public class WorldRendererMixin {
|
|||
}
|
||||
}
|
||||
|
||||
private void makeHorizon(BufferBuilder buffer, int segments) {
|
||||
private void makeHorizon(BufferBuilder buffer, int segments, double height) {
|
||||
buffer.begin(7, VertexFormats.POSITION_TEXTURE);
|
||||
for (int i = 0; i < segments; i ++)
|
||||
{
|
||||
|
@ -273,10 +292,10 @@ public class WorldRendererMixin {
|
|||
float u0 = (float) i / (float) segments;
|
||||
float u1 = (float) (i + 1) / (float) segments;
|
||||
|
||||
buffer.vertex(px1, -30, pz1).texture(u0, 0).next();
|
||||
buffer.vertex(px1, 30, pz1).texture(u0, 1).next();
|
||||
buffer.vertex(px2, 30, pz2).texture(u1, 1).next();
|
||||
buffer.vertex(px2, -30, pz2).texture(u1, 0).next();
|
||||
buffer.vertex(px1, -height, pz1).texture(u0, 0).next();
|
||||
buffer.vertex(px1, height, pz1).texture(u0, 1).next();
|
||||
buffer.vertex(px2, height, pz2).texture(u1, 1).next();
|
||||
buffer.vertex(px2, -height, pz2).texture(u1, 0).next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue