SkyRenderer.java

net.minecraft.client.renderer.SkyRenderer

信息

  • 全限定名:net.minecraft.client.renderer.SkyRenderer
  • 类型:public class
  • 包:net.minecraft.client.renderer
  • 源码路径:src/main/java/net/minecraft/client/renderer/SkyRenderer.java
  • 起始行号:L46
  • 实现:AutoCloseable
  • 职责:

    TODO

字段/常量

  • SUN_SPRITE

    • 类型: Identifier
    • 修饰符: private static final
    • 源码定位: L47
    • 说明:

      TODO

  • END_FLASH_SPRITE

    • 类型: Identifier
    • 修饰符: private static final
    • 源码定位: L48
    • 说明:

      TODO

  • END_SKY_LOCATION

    • 类型: Identifier
    • 修饰符: private static final
    • 源码定位: L49
    • 说明:

      TODO

  • SKY_DISC_RADIUS

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L50
    • 说明:

      TODO

  • SKY_VERTICES

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L51
    • 说明:

      TODO

  • STAR_COUNT

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L52
    • 说明:

      TODO

  • SUN_SIZE

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L53
    • 说明:

      TODO

  • SUN_HEIGHT

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L54
    • 说明:

      TODO

  • MOON_SIZE

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L55
    • 说明:

      TODO

  • MOON_HEIGHT

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L56
    • 说明:

      TODO

  • SUNRISE_STEPS

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L57
    • 说明:

      TODO

  • END_SKY_QUAD_COUNT

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L58
    • 说明:

      TODO

  • END_FLASH_HEIGHT

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L59
    • 说明:

      TODO

  • END_FLASH_SCALE

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L60
    • 说明:

      TODO

  • celestialsAtlas

    • 类型: TextureAtlas
    • 修饰符: private final
    • 源码定位: L61
    • 说明:

      TODO

  • starBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L62
    • 说明:

      TODO

  • topSkyBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L63
    • 说明:

      TODO

  • bottomSkyBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L64
    • 说明:

      TODO

  • endSkyBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L65
    • 说明:

      TODO

  • sunBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L66
    • 说明:

      TODO

  • moonBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L67
    • 说明:

      TODO

  • sunriseBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L68
    • 说明:

      TODO

  • endFlashBuffer

    • 类型: GpuBuffer
    • 修饰符: private final
    • 源码定位: L69
    • 说明:

      TODO

  • quadIndices

    • 类型: RenderSystem.AutoStorageIndexBuffer
    • 修饰符: private final
    • 源码定位: L70
    • 说明:

      TODO

  • endSkyTexture

    • 类型: AbstractTexture
    • 修饰符: private final
    • 源码定位: L71
    • 说明:

      TODO

  • starIndexCount

    • 类型: int
    • 修饰符: private
    • 源码定位: L72
    • 说明:

      TODO

内部类/嵌套类型

构造器

public SkyRenderer(TextureManager textureManager, AtlasManager atlasManager) @ L74

  • 构造器名:SkyRenderer
  • 源码定位:L74
  • 修饰符:public

参数:

  • textureManager: TextureManager
  • atlasManager: AtlasManager

说明:

TODO

方法

下面的方法块按源码顺序生成。

private AbstractTexture getTexture(TextureManager textureManager, Identifier location) @ L101

  • 方法名:getTexture
  • 源码定位:L101
  • 返回类型:AbstractTexture
  • 修饰符:private

参数:

  • textureManager: TextureManager
  • location: Identifier

说明:

TODO

private GpuBuffer buildSunriseFan() @ L105

  • 方法名:buildSunriseFan
  • 源码定位:L105
  • 返回类型:GpuBuffer
  • 修饰符:private

参数:

说明:

TODO

private static GpuBuffer buildSunQuad(TextureAtlas atlas) @ L131

  • 方法名:buildSunQuad
  • 源码定位:L131
  • 返回类型:GpuBuffer
  • 修饰符:private static

参数:

  • atlas: TextureAtlas

说明:

TODO

private static GpuBuffer buildEndFlashQuad(TextureAtlas atlas) @ L135

  • 方法名:buildEndFlashQuad
  • 源码定位:L135
  • 返回类型:GpuBuffer
  • 修饰符:private static

参数:

  • atlas: TextureAtlas

说明:

TODO

private static GpuBuffer buildCelestialQuad(String name, TextureAtlasSprite sprite) @ L139

  • 方法名:buildCelestialQuad
  • 源码定位:L139
  • 返回类型:GpuBuffer
  • 修饰符:private static

参数:

  • name: String
  • sprite: TextureAtlasSprite

说明:

TODO

private static GpuBuffer buildMoonPhases(TextureAtlas atlas) @ L158

  • 方法名:buildMoonPhases
  • 源码定位:L158
  • 返回类型:GpuBuffer
  • 修饰符:private static

参数:

  • atlas: TextureAtlas

说明:

TODO

private GpuBuffer buildStars() @ L182

  • 方法名:buildStars
  • 源码定位:L182
  • 返回类型:GpuBuffer
  • 修饰符:private

参数:

说明:

TODO

private void buildSkyDisc(VertexConsumer builder, float yy) @ L216

  • 方法名:buildSkyDisc
  • 源码定位:L216
  • 返回类型:void
  • 修饰符:private

参数:

  • builder: VertexConsumer
  • yy: float

说明:

TODO

private static GpuBuffer buildEndSky() @ L225

  • 方法名:buildEndSky
  • 源码定位:L225
  • 返回类型:GpuBuffer
  • 修饰符:private static

参数:

说明:

TODO

public void renderSkyDisc(int skyColor) @ L263

  • 方法名:renderSkyDisc
  • 源码定位:L263
  • 返回类型:void
  • 修饰符:public

参数:

  • skyColor: int

说明:

TODO

public void extractRenderState(ClientLevel level, float partialTicks, Camera camera, SkyRenderState state) @ L280

  • 方法名:extractRenderState
  • 源码定位:L280
  • 返回类型:void
  • 修饰符:public

参数:

  • level: ClientLevel
  • partialTicks: float
  • camera: Camera
  • state: SkyRenderState

说明:

TODO

private boolean shouldRenderDarkDisc(float deltaPartialTick, ClientLevel level) @ L305

  • 方法名:shouldRenderDarkDisc
  • 源码定位:L305
  • 返回类型:boolean
  • 修饰符:private

参数:

  • deltaPartialTick: float
  • level: ClientLevel

说明:

TODO

public void renderDarkDisc() @ L309

  • 方法名:renderDarkDisc
  • 源码定位:L309
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public void renderSunMoonAndStars(PoseStack poseStack, float sunAngle, float moonAngle, float starAngle, MoonPhase moonPhase, float rainBrightness, float starBrightness) @ L331

  • 方法名:renderSunMoonAndStars
  • 源码定位:L331
  • 返回类型:void
  • 修饰符:public

参数:

  • poseStack: PoseStack
  • sunAngle: float
  • moonAngle: float
  • starAngle: float
  • moonPhase: MoonPhase
  • rainBrightness: float
  • starBrightness: float

说明:

TODO

private void renderSun(float rainBrightness, PoseStack poseStack) @ L354

  • 方法名:renderSun
  • 源码定位:L354
  • 返回类型:void
  • 修饰符:private

参数:

  • rainBrightness: float
  • poseStack: PoseStack

说明:

TODO

private void renderMoon(MoonPhase moonPhase, float rainBrightness, PoseStack poseStack) @ L381

  • 方法名:renderMoon
  • 源码定位:L381
  • 返回类型:void
  • 修饰符:private

参数:

  • moonPhase: MoonPhase
  • rainBrightness: float
  • poseStack: PoseStack

说明:

TODO

private void renderStars(float starBrightness, PoseStack poseStack) @ L409

  • 方法名:renderStars
  • 源码定位:L409
  • 返回类型:void
  • 修饰符:private

参数:

  • starBrightness: float
  • poseStack: PoseStack

说明:

TODO

public void renderSunriseAndSunset(PoseStack poseStack, float sunAngle, int sunriseAndSunsetColor) @ L434

  • 方法名:renderSunriseAndSunset
  • 源码定位:L434
  • 返回类型:void
  • 修饰符:public

参数:

  • poseStack: PoseStack
  • sunAngle: float
  • sunriseAndSunsetColor: int

说明:

TODO

public void renderEndSky() @ L465

  • 方法名:renderEndSky
  • 源码定位:L465
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public void renderEndFlash(PoseStack poseStack, float intensity, float xAngle, float yAngle) @ L486

  • 方法名:renderEndFlash
  • 源码定位:L486
  • 返回类型:void
  • 修饰符:public

参数:

  • poseStack: PoseStack
  • intensity: float
  • xAngle: float
  • yAngle: float

说明:

TODO

public void close() @ L515

  • 方法名:close
  • 源码定位:L515
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SkyRenderer implements AutoCloseable {
    private static final Identifier SUN_SPRITE = Identifier.withDefaultNamespace("sun");
    private static final Identifier END_FLASH_SPRITE = Identifier.withDefaultNamespace("end_flash");
    private static final Identifier END_SKY_LOCATION = Identifier.withDefaultNamespace("textures/environment/end_sky.png");
    private static final float SKY_DISC_RADIUS = 512.0F;
    private static final int SKY_VERTICES = 10;
    private static final int STAR_COUNT = 1500;
    private static final float SUN_SIZE = 30.0F;
    private static final float SUN_HEIGHT = 100.0F;
    private static final float MOON_SIZE = 20.0F;
    private static final float MOON_HEIGHT = 100.0F;
    private static final int SUNRISE_STEPS = 16;
    private static final int END_SKY_QUAD_COUNT = 6;
    private static final float END_FLASH_HEIGHT = 100.0F;
    private static final float END_FLASH_SCALE = 60.0F;
    private final TextureAtlas celestialsAtlas;
    private final GpuBuffer starBuffer;
    private final GpuBuffer topSkyBuffer;
    private final GpuBuffer bottomSkyBuffer;
    private final GpuBuffer endSkyBuffer;
    private final GpuBuffer sunBuffer;
    private final GpuBuffer moonBuffer;
    private final GpuBuffer sunriseBuffer;
    private final GpuBuffer endFlashBuffer;
    private final RenderSystem.AutoStorageIndexBuffer quadIndices = RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS);
    private final AbstractTexture endSkyTexture;
    private int starIndexCount;
 
    public SkyRenderer(TextureManager textureManager, AtlasManager atlasManager) {
        this.celestialsAtlas = atlasManager.getAtlasOrThrow(AtlasIds.CELESTIALS);
        this.starBuffer = this.buildStars();
        this.endSkyBuffer = buildEndSky();
        this.endSkyTexture = this.getTexture(textureManager, END_SKY_LOCATION);
        this.endFlashBuffer = buildEndFlashQuad(this.celestialsAtlas);
        this.sunBuffer = buildSunQuad(this.celestialsAtlas);
        this.moonBuffer = buildMoonPhases(this.celestialsAtlas);
        this.sunriseBuffer = this.buildSunriseFan();
 
        try (ByteBufferBuilder builder = ByteBufferBuilder.exactlySized(10 * DefaultVertexFormat.POSITION.getVertexSize())) {
            BufferBuilder bufferBuilder = new BufferBuilder(builder, VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION);
            this.buildSkyDisc(bufferBuilder, 16.0F);
 
            try (MeshData meshData = bufferBuilder.buildOrThrow()) {
                this.topSkyBuffer = RenderSystem.getDevice().createBuffer(() -> "Top sky vertex buffer", 32, meshData.vertexBuffer());
            }
 
            bufferBuilder = new BufferBuilder(builder, VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION);
            this.buildSkyDisc(bufferBuilder, -16.0F);
 
            try (MeshData meshData = bufferBuilder.buildOrThrow()) {
                this.bottomSkyBuffer = RenderSystem.getDevice().createBuffer(() -> "Bottom sky vertex buffer", 32, meshData.vertexBuffer());
            }
        }
    }
 
    private AbstractTexture getTexture(TextureManager textureManager, Identifier location) {
        return textureManager.getTexture(location);
    }
 
    private GpuBuffer buildSunriseFan() {
        int vertices = 18;
        int vtxSize = DefaultVertexFormat.POSITION_COLOR.getVertexSize();
 
        GpuBuffer var16;
        try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(18 * vtxSize)) {
            BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
            int centerColor = ARGB.white(1.0F);
            int ringColor = ARGB.white(0.0F);
            bufferBuilder.addVertex(0.0F, 100.0F, 0.0F).setColor(centerColor);
 
            for (int i = 0; i <= 16; i++) {
                float angle = i * (float) (Math.PI * 2) / 16.0F;
                float sinAngle = Mth.sin(angle);
                float cosAngle = Mth.cos(angle);
                bufferBuilder.addVertex(sinAngle * 120.0F, cosAngle * 120.0F, -cosAngle * 40.0F).setColor(ringColor);
            }
 
            try (MeshData mesh = bufferBuilder.buildOrThrow()) {
                var16 = RenderSystem.getDevice().createBuffer(() -> "Sunrise/Sunset fan", 32, mesh.vertexBuffer());
            }
        }
 
        return var16;
    }
 
    private static GpuBuffer buildSunQuad(TextureAtlas atlas) {
        return buildCelestialQuad("Sun quad", atlas.getSprite(SUN_SPRITE));
    }
 
    private static GpuBuffer buildEndFlashQuad(TextureAtlas atlas) {
        return buildCelestialQuad("End flash quad", atlas.getSprite(END_FLASH_SPRITE));
    }
 
    private static GpuBuffer buildCelestialQuad(String name, TextureAtlasSprite sprite) {
        VertexFormat format = DefaultVertexFormat.POSITION_TEX;
 
        GpuBuffer var6;
        try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(4 * format.getVertexSize())) {
            BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, format);
            bufferBuilder.addVertex(-1.0F, 0.0F, -1.0F).setUv(sprite.getU0(), sprite.getV0());
            bufferBuilder.addVertex(1.0F, 0.0F, -1.0F).setUv(sprite.getU1(), sprite.getV0());
            bufferBuilder.addVertex(1.0F, 0.0F, 1.0F).setUv(sprite.getU1(), sprite.getV1());
            bufferBuilder.addVertex(-1.0F, 0.0F, 1.0F).setUv(sprite.getU0(), sprite.getV1());
 
            try (MeshData mesh = bufferBuilder.buildOrThrow()) {
                var6 = RenderSystem.getDevice().createBuffer(() -> name, 32, mesh.vertexBuffer());
            }
        }
 
        return var6;
    }
 
    private static GpuBuffer buildMoonPhases(TextureAtlas atlas) {
        MoonPhase[] phases = MoonPhase.values();
        VertexFormat format = DefaultVertexFormat.POSITION_TEX;
 
        GpuBuffer var15;
        try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(phases.length * 4 * format.getVertexSize())) {
            BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, format);
 
            for (MoonPhase phase : phases) {
                TextureAtlasSprite sprite = atlas.getSprite(Identifier.withDefaultNamespace("moon/" + phase.getSerializedName()));
                bufferBuilder.addVertex(-1.0F, 0.0F, -1.0F).setUv(sprite.getU1(), sprite.getV1());
                bufferBuilder.addVertex(1.0F, 0.0F, -1.0F).setUv(sprite.getU0(), sprite.getV1());
                bufferBuilder.addVertex(1.0F, 0.0F, 1.0F).setUv(sprite.getU0(), sprite.getV0());
                bufferBuilder.addVertex(-1.0F, 0.0F, 1.0F).setUv(sprite.getU1(), sprite.getV0());
            }
 
            try (MeshData mesh = bufferBuilder.buildOrThrow()) {
                var15 = RenderSystem.getDevice().createBuffer(() -> "Moon phases", 32, mesh.vertexBuffer());
            }
        }
 
        return var15;
    }
 
    private GpuBuffer buildStars() {
        RandomSource random = RandomSource.createThreadLocalInstance(10842L);
        float starDistance = 100.0F;
 
        GpuBuffer var19;
        try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(DefaultVertexFormat.POSITION.getVertexSize() * 1500 * 4)) {
            BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
 
            for (int i = 0; i < 1500; i++) {
                float x = random.nextFloat() * 2.0F - 1.0F;
                float y = random.nextFloat() * 2.0F - 1.0F;
                float z = random.nextFloat() * 2.0F - 1.0F;
                float starSize = 0.15F + random.nextFloat() * 0.1F;
                float lengthSq = Mth.lengthSquared(x, y, z);
                if (!(lengthSq <= 0.010000001F) && !(lengthSq >= 1.0F)) {
                    Vector3f starCenter = new Vector3f(x, y, z).normalize(100.0F);
                    float zRot = (float)(random.nextDouble() * (float) Math.PI * 2.0);
                    Matrix3f rotation = new Matrix3f().rotateTowards(new Vector3f(starCenter).negate(), new Vector3f(0.0F, 1.0F, 0.0F)).rotateZ(-zRot);
                    bufferBuilder.addVertex(new Vector3f(starSize, -starSize, 0.0F).mul(rotation).add(starCenter));
                    bufferBuilder.addVertex(new Vector3f(starSize, starSize, 0.0F).mul(rotation).add(starCenter));
                    bufferBuilder.addVertex(new Vector3f(-starSize, starSize, 0.0F).mul(rotation).add(starCenter));
                    bufferBuilder.addVertex(new Vector3f(-starSize, -starSize, 0.0F).mul(rotation).add(starCenter));
                }
            }
 
            try (MeshData mesh = bufferBuilder.buildOrThrow()) {
                this.starIndexCount = mesh.drawState().indexCount();
                var19 = RenderSystem.getDevice().createBuffer(() -> "Stars vertex buffer", 40, mesh.vertexBuffer());
            }
        }
 
        return var19;
    }
 
    private void buildSkyDisc(VertexConsumer builder, float yy) {
        float x = Math.signum(yy) * 512.0F;
        builder.addVertex(0.0F, yy, 0.0F);
 
        for (int i = -180; i <= 180; i += 45) {
            builder.addVertex(x * Mth.cos(i * (float) (Math.PI / 180.0)), yy, 512.0F * Mth.sin(i * (float) (Math.PI / 180.0)));
        }
    }
 
    private static GpuBuffer buildEndSky() {
        GpuBuffer var10;
        try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(24 * DefaultVertexFormat.POSITION_TEX_COLOR.getVertexSize())) {
            BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
 
            for (int i = 0; i < 6; i++) {
                Matrix4f pose = new Matrix4f();
                switch (i) {
                    case 1:
                        pose.rotationX((float) (Math.PI / 2));
                        break;
                    case 2:
                        pose.rotationX((float) (-Math.PI / 2));
                        break;
                    case 3:
                        pose.rotationX((float) Math.PI);
                        break;
                    case 4:
                        pose.rotationZ((float) (Math.PI / 2));
                        break;
                    case 5:
                        pose.rotationZ((float) (-Math.PI / 2));
                }
 
                bufferBuilder.addVertex(pose, -100.0F, -100.0F, -100.0F).setUv(0.0F, 0.0F).setColor(-14145496);
                bufferBuilder.addVertex(pose, -100.0F, -100.0F, 100.0F).setUv(0.0F, 16.0F).setColor(-14145496);
                bufferBuilder.addVertex(pose, 100.0F, -100.0F, 100.0F).setUv(16.0F, 16.0F).setColor(-14145496);
                bufferBuilder.addVertex(pose, 100.0F, -100.0F, -100.0F).setUv(16.0F, 0.0F).setColor(-14145496);
            }
 
            try (MeshData meshData = bufferBuilder.buildOrThrow()) {
                var10 = RenderSystem.getDevice().createBuffer(() -> "End sky vertex buffer", 40, meshData.vertexBuffer());
            }
        }
 
        return var10;
    }
 
    public void renderSkyDisc(int skyColor) {
        GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
            .writeTransform(RenderSystem.getModelViewMatrix(), ARGB.vector4fFromARGB32(skyColor), new Vector3f(), new Matrix4f());
        GpuTextureView colorTexture = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
        GpuTextureView depthTexture = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
 
        try (RenderPass renderPass = RenderSystem.getDevice()
                .createCommandEncoder()
                .createRenderPass(() -> "Sky disc", colorTexture, OptionalInt.empty(), depthTexture, OptionalDouble.empty())) {
            renderPass.setPipeline(RenderPipelines.SKY);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.setUniform("DynamicTransforms", dynamicTransforms);
            renderPass.setVertexBuffer(0, this.topSkyBuffer);
            renderPass.draw(0, 10);
        }
    }
 
    public void extractRenderState(ClientLevel level, float partialTicks, Camera camera, SkyRenderState state) {
        state.skybox = level.dimensionType().skybox();
        if (state.skybox != DimensionType.Skybox.NONE) {
            if (state.skybox == DimensionType.Skybox.END) {
                EndFlashState endFlashState = level.endFlashState();
                if (endFlashState != null) {
                    state.endFlashIntensity = endFlashState.getIntensity(partialTicks);
                    state.endFlashXAngle = endFlashState.getXAngle();
                    state.endFlashYAngle = endFlashState.getYAngle();
                }
            } else {
                EnvironmentAttributeProbe attributeProbe = camera.attributeProbe();
                state.sunAngle = attributeProbe.getValue(EnvironmentAttributes.SUN_ANGLE, partialTicks) * (float) (Math.PI / 180.0);
                state.moonAngle = attributeProbe.getValue(EnvironmentAttributes.MOON_ANGLE, partialTicks) * (float) (Math.PI / 180.0);
                state.starAngle = attributeProbe.getValue(EnvironmentAttributes.STAR_ANGLE, partialTicks) * (float) (Math.PI / 180.0);
                state.rainBrightness = 1.0F - level.getRainLevel(partialTicks);
                state.starBrightness = attributeProbe.getValue(EnvironmentAttributes.STAR_BRIGHTNESS, partialTicks);
                state.sunriseAndSunsetColor = camera.attributeProbe().getValue(EnvironmentAttributes.SUNRISE_SUNSET_COLOR, partialTicks);
                state.moonPhase = attributeProbe.getValue(EnvironmentAttributes.MOON_PHASE, partialTicks);
                state.skyColor = attributeProbe.getValue(EnvironmentAttributes.SKY_COLOR, partialTicks);
                state.shouldRenderDarkDisc = this.shouldRenderDarkDisc(partialTicks, level);
            }
        }
    }
 
    private boolean shouldRenderDarkDisc(float deltaPartialTick, ClientLevel level) {
        return Minecraft.getInstance().player.getEyePosition(deltaPartialTick).y - level.getLevelData().getHorizonHeight(level) < 0.0;
    }
 
    public void renderDarkDisc() {
        Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
        modelViewStack.pushMatrix();
        modelViewStack.translate(0.0F, 12.0F, 0.0F);
        GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
            .writeTransform(modelViewStack, new Vector4f(0.0F, 0.0F, 0.0F, 1.0F), new Vector3f(), new Matrix4f());
        GpuTextureView colorTexture = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
        GpuTextureView depthTexture = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
 
        try (RenderPass renderPass = RenderSystem.getDevice()
                .createCommandEncoder()
                .createRenderPass(() -> "Sky dark", colorTexture, OptionalInt.empty(), depthTexture, OptionalDouble.empty())) {
            renderPass.setPipeline(RenderPipelines.SKY);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.setUniform("DynamicTransforms", dynamicTransforms);
            renderPass.setVertexBuffer(0, this.bottomSkyBuffer);
            renderPass.draw(0, 10);
        }
 
        modelViewStack.popMatrix();
    }
 
    public void renderSunMoonAndStars(
        PoseStack poseStack, float sunAngle, float moonAngle, float starAngle, MoonPhase moonPhase, float rainBrightness, float starBrightness
    ) {
        poseStack.pushPose();
        poseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
        poseStack.pushPose();
        poseStack.mulPose(Axis.XP.rotation(sunAngle));
        this.renderSun(rainBrightness, poseStack);
        poseStack.popPose();
        poseStack.pushPose();
        poseStack.mulPose(Axis.XP.rotation(moonAngle));
        this.renderMoon(moonPhase, rainBrightness, poseStack);
        poseStack.popPose();
        if (starBrightness > 0.0F) {
            poseStack.pushPose();
            poseStack.mulPose(Axis.XP.rotation(starAngle));
            this.renderStars(starBrightness, poseStack);
            poseStack.popPose();
        }
 
        poseStack.popPose();
    }
 
    private void renderSun(float rainBrightness, PoseStack poseStack) {
        Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
        modelViewStack.pushMatrix();
        modelViewStack.mul(poseStack.last().pose());
        modelViewStack.translate(0.0F, 100.0F, 0.0F);
        modelViewStack.scale(30.0F, 1.0F, 30.0F);
        GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
            .writeTransform(modelViewStack, new Vector4f(1.0F, 1.0F, 1.0F, rainBrightness), new Vector3f(), new Matrix4f());
        GpuTextureView color = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
        GpuTextureView depth = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
        GpuBuffer indexBuffer = this.quadIndices.getBuffer(6);
 
        try (RenderPass renderPass = RenderSystem.getDevice()
                .createCommandEncoder()
                .createRenderPass(() -> "Sky sun", color, OptionalInt.empty(), depth, OptionalDouble.empty())) {
            renderPass.setPipeline(RenderPipelines.CELESTIAL);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.setUniform("DynamicTransforms", dynamicTransforms);
            renderPass.bindTexture("Sampler0", this.celestialsAtlas.getTextureView(), this.celestialsAtlas.getSampler());
            renderPass.setVertexBuffer(0, this.sunBuffer);
            renderPass.setIndexBuffer(indexBuffer, this.quadIndices.type());
            renderPass.drawIndexed(0, 0, 6, 1);
        }
 
        modelViewStack.popMatrix();
    }
 
    private void renderMoon(MoonPhase moonPhase, float rainBrightness, PoseStack poseStack) {
        int baseVertex = moonPhase.index() * 4;
        Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
        modelViewStack.pushMatrix();
        modelViewStack.mul(poseStack.last().pose());
        modelViewStack.translate(0.0F, 100.0F, 0.0F);
        modelViewStack.scale(20.0F, 1.0F, 20.0F);
        GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
            .writeTransform(modelViewStack, new Vector4f(1.0F, 1.0F, 1.0F, rainBrightness), new Vector3f(), new Matrix4f());
        GpuTextureView color = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
        GpuTextureView depth = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
        GpuBuffer indexBuffer = this.quadIndices.getBuffer(6);
 
        try (RenderPass renderPass = RenderSystem.getDevice()
                .createCommandEncoder()
                .createRenderPass(() -> "Sky moon", color, OptionalInt.empty(), depth, OptionalDouble.empty())) {
            renderPass.setPipeline(RenderPipelines.CELESTIAL);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.setUniform("DynamicTransforms", dynamicTransforms);
            renderPass.bindTexture("Sampler0", this.celestialsAtlas.getTextureView(), this.celestialsAtlas.getSampler());
            renderPass.setVertexBuffer(0, this.moonBuffer);
            renderPass.setIndexBuffer(indexBuffer, this.quadIndices.type());
            renderPass.drawIndexed(baseVertex, 0, 6, 1);
        }
 
        modelViewStack.popMatrix();
    }
 
    private void renderStars(float starBrightness, PoseStack poseStack) {
        Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
        modelViewStack.pushMatrix();
        modelViewStack.mul(poseStack.last().pose());
        RenderPipeline renderPipeline = RenderPipelines.STARS;
        GpuTextureView colorTexture = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
        GpuTextureView depthTexture = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
        GpuBuffer indexBuffer = this.quadIndices.getBuffer(this.starIndexCount);
        GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
            .writeTransform(modelViewStack, new Vector4f(starBrightness, starBrightness, starBrightness, starBrightness), new Vector3f(), new Matrix4f());
 
        try (RenderPass renderPass = RenderSystem.getDevice()
                .createCommandEncoder()
                .createRenderPass(() -> "Stars", colorTexture, OptionalInt.empty(), depthTexture, OptionalDouble.empty())) {
            renderPass.setPipeline(renderPipeline);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.setUniform("DynamicTransforms", dynamicTransforms);
            renderPass.setVertexBuffer(0, this.starBuffer);
            renderPass.setIndexBuffer(indexBuffer, this.quadIndices.type());
            renderPass.drawIndexed(0, 0, this.starIndexCount, 1);
        }
 
        modelViewStack.popMatrix();
    }
 
    public void renderSunriseAndSunset(PoseStack poseStack, float sunAngle, int sunriseAndSunsetColor) {
        float alpha = ARGB.alphaFloat(sunriseAndSunsetColor);
        if (!(alpha <= 0.001F)) {
            poseStack.pushPose();
            poseStack.mulPose(Axis.XP.rotationDegrees(90.0F));
            float angle = Mth.sin(sunAngle) < 0.0F ? 180.0F : 0.0F;
            poseStack.mulPose(Axis.ZP.rotationDegrees(angle + 90.0F));
            Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
            modelViewStack.pushMatrix();
            modelViewStack.mul(poseStack.last().pose());
            modelViewStack.scale(1.0F, 1.0F, alpha);
            GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
                .writeTransform(modelViewStack, ARGB.vector4fFromARGB32(sunriseAndSunsetColor), new Vector3f(), new Matrix4f());
            GpuTextureView color = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
            GpuTextureView depth = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
 
            try (RenderPass renderPass = RenderSystem.getDevice()
                    .createCommandEncoder()
                    .createRenderPass(() -> "Sunrise sunset", color, OptionalInt.empty(), depth, OptionalDouble.empty())) {
                renderPass.setPipeline(RenderPipelines.SUNRISE_SUNSET);
                RenderSystem.bindDefaultUniforms(renderPass);
                renderPass.setUniform("DynamicTransforms", dynamicTransforms);
                renderPass.setVertexBuffer(0, this.sunriseBuffer);
                renderPass.draw(0, 18);
            }
 
            modelViewStack.popMatrix();
            poseStack.popPose();
        }
    }
 
    public void renderEndSky() {
        RenderSystem.AutoStorageIndexBuffer autoIndices = RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS);
        GpuBuffer indexBuffer = autoIndices.getBuffer(36);
        GpuTextureView colorTexture = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
        GpuTextureView depthTexture = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
        GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
            .writeTransform(RenderSystem.getModelViewMatrix(), new Vector4f(1.0F, 1.0F, 1.0F, 1.0F), new Vector3f(), new Matrix4f());
 
        try (RenderPass renderPass = RenderSystem.getDevice()
                .createCommandEncoder()
                .createRenderPass(() -> "End sky", colorTexture, OptionalInt.empty(), depthTexture, OptionalDouble.empty())) {
            renderPass.setPipeline(RenderPipelines.END_SKY);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.setUniform("DynamicTransforms", dynamicTransforms);
            renderPass.bindTexture("Sampler0", this.endSkyTexture.getTextureView(), this.endSkyTexture.getSampler());
            renderPass.setVertexBuffer(0, this.endSkyBuffer);
            renderPass.setIndexBuffer(indexBuffer, autoIndices.type());
            renderPass.drawIndexed(0, 0, 36, 1);
        }
    }
 
    public void renderEndFlash(PoseStack poseStack, float intensity, float xAngle, float yAngle) {
        poseStack.mulPose(Axis.YP.rotationDegrees(180.0F - yAngle));
        poseStack.mulPose(Axis.XP.rotationDegrees(-90.0F - xAngle));
        Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
        modelViewStack.pushMatrix();
        modelViewStack.mul(poseStack.last().pose());
        modelViewStack.translate(0.0F, 100.0F, 0.0F);
        modelViewStack.scale(60.0F, 1.0F, 60.0F);
        GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms()
            .writeTransform(modelViewStack, new Vector4f(intensity, intensity, intensity, intensity), new Vector3f(), new Matrix4f());
        GpuTextureView color = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
        GpuTextureView depth = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
        GpuBuffer indexBuffer = this.quadIndices.getBuffer(6);
 
        try (RenderPass renderPass = RenderSystem.getDevice()
                .createCommandEncoder()
                .createRenderPass(() -> "End flash", color, OptionalInt.empty(), depth, OptionalDouble.empty())) {
            renderPass.setPipeline(RenderPipelines.CELESTIAL);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.setUniform("DynamicTransforms", dynamicTransforms);
            renderPass.bindTexture("Sampler0", this.celestialsAtlas.getTextureView(), this.celestialsAtlas.getSampler());
            renderPass.setVertexBuffer(0, this.endFlashBuffer);
            renderPass.setIndexBuffer(indexBuffer, this.quadIndices.type());
            renderPass.drawIndexed(0, 0, 6, 1);
        }
 
        modelViewStack.popMatrix();
    }
 
    @Override
    public void close() {
        this.sunBuffer.close();
        this.moonBuffer.close();
        this.starBuffer.close();
        this.topSkyBuffer.close();
        this.bottomSkyBuffer.close();
        this.endSkyBuffer.close();
        this.sunriseBuffer.close();
        this.endFlashBuffer.close();
    }
}

引用的其他类

  • GpuBuffer

    • 引用位置: 字段/返回值
  • RenderSystem

    • 引用位置: 字段/方法调用
    • 关联成员: RenderSystem.bindDefaultUniforms(), RenderSystem.getDevice(), RenderSystem.getDynamicUniforms(), RenderSystem.getModelViewMatrix(), RenderSystem.getModelViewStack(), RenderSystem.getSequentialBuffer()
  • BufferBuilder

    • 引用位置: 构造调用
    • 关联成员: BufferBuilder()
  • ByteBufferBuilder

    • 引用位置: 方法调用
    • 关联成员: ByteBufferBuilder.exactlySized()
  • PoseStack

    • 引用位置: 参数
  • VertexConsumer

    • 引用位置: 参数
  • Camera

    • 引用位置: 参数
  • Minecraft

    • 引用位置: 方法调用
    • 关联成员: Minecraft.getInstance()
  • ClientLevel

    • 引用位置: 参数
  • SkyRenderState

    • 引用位置: 参数
  • AbstractTexture

    • 引用位置: 字段/返回值
  • TextureAtlas

    • 引用位置: 参数/字段
  • TextureAtlasSprite

    • 引用位置: 参数
  • TextureManager

    • 引用位置: 参数
  • AtlasManager

    • 引用位置: 参数
  • Identifier

    • 引用位置: 参数/字段/方法调用
    • 关联成员: Identifier.withDefaultNamespace()
  • ARGB

    • 引用位置: 方法调用
    • 关联成员: ARGB.alphaFloat(), ARGB.vector4fFromARGB32(), ARGB.white()
  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.cos(), Mth.lengthSquared(), Mth.sin()
  • RandomSource

    • 引用位置: 方法调用
    • 关联成员: RandomSource.createThreadLocalInstance()
  • MoonPhase

    • 引用位置: 参数/方法调用
    • 关联成员: MoonPhase.values()