mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
Allow faces of an "elements" model to have disabled ambient occlusion (#9019)
This commit is contained in:
1 parent
94e1e54b53
commit
e0477f8776
25 files changed
+341
-11
No files matched your search
@@ -55,6 +55,7 @@ import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.culling.Frustum;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
@@ -561,6 +562,18 @@ public class ForgeHooksClient
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
public static boolean calculateFaceWithoutAO(BlockAndTintGetter getter, BlockState state, BlockPos pos, BakedQuad quad, boolean isFaceCubic, float[] brightness, int[] lightmap)
|
||||
{
|
||||
if (quad.hasAmbientOcclusion())
|
||||
return false;
|
||||
|
||||
BlockPos lightmapPos = isFaceCubic ? pos.relative(quad.getDirection()) : pos;
|
||||
|
||||
brightness[0] = brightness[1] = brightness[2] = brightness[3] = getter.getShade(quad.getDirection(), quad.isShade());
|
||||
lightmap[0] = lightmap[1] = lightmap[2] = lightmap[3] = LevelRenderer.getLightColor(getter, state, lightmapPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void loadEntityShader(Entity entity, GameRenderer entityRenderer)
|
||||
{
|
||||
if (entity != null)
|
||||
|
||||
@@ -92,7 +92,7 @@ public interface IQuadTransformer
|
||||
private static BakedQuad copy(BakedQuad quad)
|
||||
{
|
||||
var vertices = quad.getVertices();
|
||||
return new BakedQuad(Arrays.copyOf(vertices, vertices.length), quad.getTintIndex(), quad.getDirection(), quad.getSprite(), quad.isShade());
|
||||
return new BakedQuad(Arrays.copyOf(vertices, vertices.length), quad.getTintIndex(), quad.getDirection(), quad.getSprite(), quad.isShade(), quad.hasAmbientOcclusion());
|
||||
}
|
||||
|
||||
private static int findOffset(VertexFormatElement element)
|
||||
|
||||
@@ -320,6 +320,9 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
if (face.emissivity > 0) {
|
||||
faceObj.addProperty("emissivity", face.emissivity);
|
||||
}
|
||||
if (!face.hasAmbientOcclusion) {
|
||||
faceObj.addProperty("ambientocclusion", face.hasAmbientOcclusion);
|
||||
}
|
||||
faces.add(dir.getSerializedName(), faceObj);
|
||||
}
|
||||
if (!part.faces.isEmpty()) {
|
||||
@@ -517,6 +520,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
private float[] uvs;
|
||||
private FaceRotation rotation = FaceRotation.ZERO;
|
||||
private int emissivity = 0;
|
||||
private boolean hasAmbientOcclusion = true;
|
||||
|
||||
FaceBuilder(Direction dir) {
|
||||
// param unused for functional match
|
||||
@@ -583,11 +587,22 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
return emissivity(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ambient occlusion of the face.
|
||||
*
|
||||
* @param ao the ambient occlusion
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder ao(boolean ao) {
|
||||
this.hasAmbientOcclusion = ao;
|
||||
return this;
|
||||
}
|
||||
|
||||
BlockElementFace build() {
|
||||
if (this.texture == null) {
|
||||
throw new IllegalStateException("A model face must have a texture");
|
||||
}
|
||||
return new BlockElementFace(cullface, tintindex, texture, new BlockFaceUV(uvs, rotation.rotation), emissivity);
|
||||
return new BlockElementFace(cullface, tintindex, texture, new BlockFaceUV(uvs, rotation.rotation), emissivity, hasAmbientOcclusion);
|
||||
}
|
||||
|
||||
public ElementBuilder end() { return ElementBuilder.this; }
|
||||
|
||||
+32
-2
@@ -7,6 +7,7 @@ package net.minecraftforge.client.model.lighting;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.ModelBlockRenderer;
|
||||
@@ -67,8 +68,11 @@ public class ForgeModelBlockRenderer extends ModelBlockRenderer
|
||||
|
||||
public static boolean render(VertexConsumer vertexConsumer, QuadLighter lighter, BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, boolean checkSides, RandomSource rand, long seed, int packedOverlay, ModelData modelData, RenderType renderType)
|
||||
{
|
||||
ForgeModelBlockRenderer renderer = (ForgeModelBlockRenderer)Minecraft.getInstance().getBlockRenderer().getModelRenderer();
|
||||
var pose = poseStack.last();
|
||||
var empty = true;
|
||||
var smoothLighter = lighter instanceof SmoothQuadLighter;
|
||||
QuadLighter flatLighter = null;
|
||||
|
||||
rand.setSeed(seed);
|
||||
List<BakedQuad> quads = model.getQuads(state, null, rand, modelData, renderType);
|
||||
@@ -78,7 +82,19 @@ public class ForgeModelBlockRenderer extends ModelBlockRenderer
|
||||
lighter.setup(level, pos, state);
|
||||
for (BakedQuad quad : quads)
|
||||
{
|
||||
lighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
if (smoothLighter && !quad.hasAmbientOcclusion())
|
||||
{
|
||||
if (flatLighter == null)
|
||||
{
|
||||
flatLighter = renderer.flatLighter.get();
|
||||
flatLighter.setup(level, pos, state);
|
||||
}
|
||||
flatLighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
else
|
||||
{
|
||||
lighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,11 +115,25 @@ public class ForgeModelBlockRenderer extends ModelBlockRenderer
|
||||
}
|
||||
for (BakedQuad quad : quads)
|
||||
{
|
||||
lighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
if (smoothLighter && !quad.hasAmbientOcclusion())
|
||||
{
|
||||
if (flatLighter == null)
|
||||
{
|
||||
flatLighter = renderer.flatLighter.get();
|
||||
flatLighter.setup(level, pos, state);
|
||||
}
|
||||
flatLighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
else
|
||||
{
|
||||
lighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lighter.reset();
|
||||
if (flatLighter != null)
|
||||
flatLighter.reset();
|
||||
return !empty;
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -44,6 +44,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
private Direction direction = Direction.DOWN;
|
||||
private TextureAtlasSprite sprite = UnitTextureAtlasSprite.INSTANCE;
|
||||
private boolean shade;
|
||||
private boolean hasAmbientOcclusion;
|
||||
|
||||
public QuadBakingVertexConsumer(Consumer<BakedQuad> quadConsumer)
|
||||
{
|
||||
@@ -127,7 +128,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
if (++vertexIndex != 4)
|
||||
return;
|
||||
// We have a full quad, pass it to the consumer and reset
|
||||
quadConsumer.accept(new BakedQuad(quadData, tintIndex, direction, sprite, shade));
|
||||
quadConsumer.accept(new BakedQuad(quadData, tintIndex, direction, sprite, shade, hasAmbientOcclusion));
|
||||
vertexIndex = 0;
|
||||
quadData = new int[QUAD_DATA_SIZE];
|
||||
}
|
||||
@@ -161,4 +162,9 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
{
|
||||
this.shade = shade;
|
||||
}
|
||||
|
||||
public void setHasAmbientOcclusion(boolean hasAmbientOcclusion)
|
||||
{
|
||||
this.hasAmbientOcclusion = hasAmbientOcclusion;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user