Skip to content

Commit

Permalink
begin porting shadow renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna0x01 committed Jan 1, 2025
1 parent 8bdbb4c commit 9299524
Show file tree
Hide file tree
Showing 33 changed files with 186 additions and 612 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.vexor.radium.compat.mojang.minecraft.render;

public class LightTexture {
public static final int FULL_BRIGHT = 0xF000F0;
public static final int FULL_SKY = 0xF00000;
public static final int FULL_SKY = 15728640;
public static final int FULL_BLOCK = 240;
public static final int FULL_BRIGHT = pack(FULL_SKY, FULL_BLOCK);

public static int pack(int n, int n2) {
return n << 4 | n2 << 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,17 @@ protected int compute(int x, int y, int z) {
boolean em = block.getLightLevel() != 0;
boolean op = block.isFullBlock() || block.getOpacity() != 0;
boolean fo = block.isNormalBlock();
boolean fc = block.isFullCube();
boolean fc = block.renderAsNormalBlock();

int lu = state.getBlock().getLightLevel();

// OPTIMIZE: Do not calculate light data if the block is full and opaque and does not emit light.
int bl;
int sl;
if (fo && lu == 0) {
bl = 0;
sl = 0;
} else {
if (em) {
bl = level.getLight(LightType.BLOCK, pos);
sl = level.getLight(LightType.SKY, pos);
} else {
int light = getLightColor(state, pos);
bl = LightTexture.block(light);
sl = LightTexture.sky(light);
}
}
int lm = (fo && !em) ? 0 : block.getBrightness(level, pos);

bl = LightTexture.block(lm);
sl = LightTexture.sky(lm);

float ao;
if (lu == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void calculate(ModelQuadView quad, BlockPos pos, QuadLightData out, Direc
}
}

Arrays.fill(out.lm, lightmap);
Arrays.fill(out.lm, LightTexture.FULL_BRIGHT);
}

/**
Expand All @@ -62,12 +62,12 @@ private int getOffsetLightmap(BlockPos pos, Direction face) {
int word = this.lightCache.get(pos);

// Check emissivity of the origin state
if (unpackEM(word)) {
return LightTexture.FULL_BRIGHT;
}
//if (unpackEM(word)) {
// return LightTexture.FULL_BRIGHT;
//}

// Use light values from the offset pos, but luminance from the origin pos
int adjWord = this.lightCache.get(pos, face);
int adjWord = this.lightCache.get(pos);
return LightTexture.pack(Math.max(unpackBL(adjWord), unpackLU(word)), unpackSL(adjWord));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.*;
import dev.vexor.radium.compat.mojang.minecraft.math.SectionPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.LightType;
import net.minecraft.world.World;
Expand Down Expand Up @@ -90,7 +87,7 @@ public final class LevelSlice implements BlockView {
private int originBlockX, originBlockY, originBlockZ;

// The volume that this WorldSlice contains
private Box volume;
private BlockBox volume;

public static ChunkRenderContext prepare(World level, SectionPos pos, ClonedChunkSectionCache cache) {
Chunk chunk = level.getChunk(pos.getX(), pos.getZ());
Expand All @@ -103,7 +100,7 @@ public static ChunkRenderContext prepare(World level, SectionPos pos, ClonedChun
return null;
}

Box box = new Box(pos.minBlockX() - NEIGHBOR_BLOCK_RADIUS,
BlockBox box = new BlockBox(pos.minBlockX() - NEIGHBOR_BLOCK_RADIUS,
pos.minBlockY() - NEIGHBOR_BLOCK_RADIUS,
pos.minBlockZ() - NEIGHBOR_BLOCK_RADIUS,
pos.maxBlockX() + NEIGHBOR_BLOCK_RADIUS,
Expand Down Expand Up @@ -262,7 +259,7 @@ public LevelGeneratorType getGeneratorType() {
}

public BlockState getBlockState(int blockX, int blockY, int blockZ) {
if (!this.volume.contains(new Vec3d(blockX, blockY, blockZ))) {
if (!this.volume.contains(new Vec3i(blockX, blockY, blockZ))) {
return EMPTY_BLOCK_STATE;
}

Expand All @@ -275,7 +272,7 @@ public BlockState getBlockState(int blockX, int blockY, int blockZ) {
}

public int getLight(LightType type, BlockPos pos) {
if (!this.volume.contains(new Vec3d(pos.getX(), pos.getY(), pos.getZ()))) {
if (!this.volume.contains(pos)) {
return 0;
}

Expand All @@ -296,7 +293,7 @@ public int getLight(LightType type, BlockPos pos) {

@Override
public int getLight(BlockPos pos, int ambientDarkness) {
if (!this.volume.contains(new Vec3d(pos.getX(), pos.getY(), pos.getZ()))) {
if (!this.volume.contains(pos)) {
return 0;
}

Expand All @@ -320,7 +317,7 @@ public int getLight(BlockPos pos, int ambientDarkness) {
blockLight = ambientDarkness;
}

return skyLight << 20 | blockLight << 4;
return blockLight << 4 | skyLight << 20;

//return Math.max(blockLight, skyLight);
}
Expand All @@ -331,7 +328,7 @@ public BlockEntity getBlockEntity(BlockPos pos) {
}

public BlockEntity getBlockEntity(int blockX, int blockY, int blockZ) {
if (!this.volume.contains(new Vec3d(blockX, blockY, blockZ))) {
if (!this.volume.contains(new Vec3i(blockX, blockY, blockZ))) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.caffeinemc.mods.sodium.client.world.cloned;

import dev.vexor.radium.compat.mojang.minecraft.math.SectionPos;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.Box;

import java.util.List;

public record ChunkRenderContext(SectionPos origin, ClonedChunkSection[] sections, Box volume) {
public record ChunkRenderContext(SectionPos origin, ClonedChunkSection[] sections, BlockBox volume) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMaps;
import net.irisshaders.batchedentityrendering.impl.ordering.GraphTranslucencyRenderOrderManager;
import net.irisshaders.batchedentityrendering.impl.ordering.RenderOrderManager;
import net.irisshaders.iris.layer.WrappingMultiBufferSource;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.vexor.radium.compat.mojang.math.PoseStack;
import net.irisshaders.batchedentityrendering.impl.Groupable;
import net.irisshaders.batchedentityrendering.impl.wrappers.TaggingRenderTypeWrapper;
import net.irisshaders.iris.layer.BufferSourceWrapper;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BannerRenderer;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9299524

Please sign in to comment.