bradsk88 Posted June 16, 2022 Posted June 16, 2022 (edited) GitHub: https://github.com/bradsk88/EurekaCraft Problem: For some reason, the top of my model is darker than the bottom. IMO it would make sense for the "sunny" side to be brighter, but I'm not sure how to fix that. Image/Video of the problem: https://imgur.com/a/hAqpqcy Player Rendering Code: @SubscribeEvent public static void playerRender(final RenderPlayerEvent.Pre event) { PlayerDeployedBoardProvider.getBoardTypeFor(event.getPlayer()).ifPresent( (PlayerDeployedBoard.ColoredBoard bt) -> renderPlayerWithBoard(event, bt) ); } private static void renderPlayerWithBoard(final RenderPlayerEvent.Pre event, PlayerDeployedBoard.ColoredBoard bt) { if (BoardType.NONE.equals(bt.boardType)) { return; } AbstractBoardModel model = ModelsInit.getModel(bt.boardType, bt.r, bt.g, bt.b); PoseStack matrixStack = event.getPoseStack(); matrixStack.mulPose(Vector3f.YP.rotationDegrees(90)); LivingEntity living = event.getEntityLiving(); living.animationSpeed = 0; living.yHeadRot = living.yBodyRot + 90; float newYRot = (float) Math.toRadians(-living.yBodyRot); VertexConsumer ivertexbuilder = event.getMultiBufferSource().getBuffer(model.getRenderType()); model.getModelRenderer().yRot = newYRot; model.renderToBuffer( matrixStack, ivertexbuilder, event.getPackedLight(), OverlayTexture.WHITE_OVERLAY_V, 1.0F, 1.0F, 1.0F, 1.0F ); } Board Model Code: public abstract class AbstractBoardModel<M extends AbstractBoardModel<M>> extends EntityModel<Entity> { private final ModelPart VoxelShapes; private final ResourceLocation texture; protected float r; protected float g; protected float b; protected AbstractBoardModel() { this(1, 1, 1); } public AbstractBoardModel(float r, float g, float b) { this.VoxelShapes = this.build(); this.texture = this.getTexture(); this.r = r; this.g = g; this.b = b; } @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch){ //previously the render function, render code was moved to a method below } @Override public void renderToBuffer(PoseStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){ VoxelShapes.render( matrixStack, buffer, packedLight, packedOverlay, red * this.r, green * this.g, blue * this.b, alpha ); } public ModelPart getModelRenderer() { return VoxelShapes; } public void setRotationAngle(ModelPart modelRenderer, float x, float y, float z) { modelRenderer.xRot = x; modelRenderer.yRot = y; modelRenderer.zRot = z; } protected abstract ModelPart build(); public RenderType getRenderType() { return this.renderType(this.texture); } } Edit: And the baked model: @Override protected ModelPart build() { CubeListBuilder VoxelShapes = CubeListBuilder.create(); VoxelShapes.texOffs(0, 0).addBox(0.0F, 0.0F, -4.0F, 15.0F, -1.0F, 8.0F); VoxelShapes.texOffs(0, 0).addBox(-2.0F, 0.0F, -5.0F, 2.0F, -1.0F, 10.0F); VoxelShapes.texOffs(0, 0).addBox(-8.0F, 0.0F, -6.0F, 6.0F, -1.0F, 12.0F); VoxelShapes.texOffs(0, 0).addBox(-10.0F, 0.0F, -5.0F, 2.0F, -1.0F, 10.0F); VoxelShapes.texOffs(0, 0).addBox(-12.0F, 0.0F, -4.0F, 2.0F, -1.0F, 8.0F); VoxelShapes.texOffs(0, 0).addBox(-14.0F, 0.0F, -3.0F, 2.0F, -1.0F, 6.0F); VoxelShapes.texOffs(0, 0).addBox(5.0F, 0.0F, -5.0F, 6.0F, -1.0F, 10.0F); VoxelShapes.texOffs(0, 0).addBox(8.0F, 1.0F, -2.0F, 5.0F, -1.0F, 1.0F); VoxelShapes.texOffs(0, 0).addBox(7.0F, 2.0F, -2.0F, 5.0F, -1.0F, 1.0F); VoxelShapes.texOffs(0, 0).addBox(8.0F, 1.0F, 1.0F, 5.0F, -1.0F, 1.0F); VoxelShapes.texOffs(0, 0).addBox(7.0F, 2.0F, 1.0F, 5.0F, -1.0F, 1.0F); VoxelShapes.texOffs(0, 0).addBox(-10.0F, 1.0F, -2.0F, 5.0F, -1.0F, 4.0F); VoxelShapes.texOffs(0, 0).addBox(-10.0F, 2.0F, -1.0F, 3.0F, -1.0F, 2.0F); MeshDefinition meshdefinition = new MeshDefinition(); PartDefinition partdefinition = meshdefinition.getRoot(); partdefinition.addOrReplaceChild("board", VoxelShapes, PartPose.rotation( (float) Math.PI, 0, 0)); return LayerDefinition.create(meshdefinition, 0, 0).bakeRoot(); } Thanks for any help you can provide! Edited June 16, 2022 by bradsk88 Quote
bradsk88 Posted July 7, 2022 Author Posted July 7, 2022 Updating this as I was able to solve the problem on my own. TL;DR: I switched the `-1.0F` here to `1.0F` (for each box) VoxelShapes.texOffs(0, 0).addBox(0.0F, 0.0F, -4.0F, 15.0F, -1.0F, 8.0F); --- Here's why I think this was necessary. The -1.0F value represents the "Y dimension" of a CubeDefinition that is used to create a set of BakedQuad's for the entity model. Minecraft uses "BakedQuads" to render models. Those are 4-pointed shapes with a bit of additional metadata. Each cube is made up of six quads. One piece of metadata on a BakedQuad is "direction". I suspect minecraft uses that direction for shading purposes. Direction.UP gets shaded bright (due to sunlight) and Direction.DOWN gets shaded dark because it is in the shadows. By setting my Y dimension to negative, the "up" quad of the cube is actually baked and labeled as the "down" side of the cube. And vice versa of course. For more complex models, it might require a more comprehensive solution. But since my shape was only 1 "unit" thick, inverting the 1 worked out nicely. Result: https://imgur.com/a/JTi0oYt Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.