Jump to content

[1.19] Rendering a translucent cube in the world (Not filled all elements of the vertex)


bradsk88

Recommended Posts

Hello all,

I have a mod that renders a cube the size of a chunk to simulate a "rain"-like effect. This worked well in 1.18.2 using borrowed code from the vanilla rain rendering.

That stopped working, so I'm trying to actually understand the rendering process, rather than just copy-paste-praying.

I copied the code from `LevelRenderer.renderLineBox` which worked perfectly in a `RenderLevelStageEvent` handler, but only rendered lines.

I switched the RenderType to translucent and now I'm getting an IllegalStateException with the message "Not filled all elements of the vertex".

 

I understand this means I am missing a value from the vertex builder chain, but I'm not sure what I'm missing here.

The DefaultVertexFormat for "block" (used by RenderType.transparent) specifies that it needs 6 values: position, color, uv0, uv2, normal, and padding.

   public static final VertexFormat BLOCK = new VertexFormat(ImmutableMap.<String, VertexFormatElement>builder().put("Position", ELEMENT_POSITION).put("Color", ELEMENT_COLOR).put("UV0", ELEMENT_UV0).put("UV2", ELEMENT_UV2).put("Normal", ELEMENT_NORMAL).put("Padding", ELEMENT_PADDING).build());

In my code, I am providing 6 values: vertex, color, uv, uv2, normal, and I believe padding is automatically implied.

VertexConsumer vertex = vc.vertex(matrix4f, f3, f1, f2);
vertex = vertex.color(r, g2, b2, a);
vertex = vertex.normal(matrix3f, 1.0F, 0.0F, 0.0F);
vertex = vertex.uv(0, 0);
vertex = vertex.uv2(0, 0);
vertex.endVertex();

But my "elementIndex" ends up being "4", causing the exception.

F571oxF.png

Here is the link to the entire file:

https://github.com/bradsk88/EurekaCraft/blob/c4a3eb76468fef861fbcfbe7423f59683f9537ec/src/main/java/ca/bradj/eurekacraft/client/ChunkStormCubeForgeRendering.java#L99

Can anyone spot what I'm doing wrong here?

Edited by bradsk88
Link to comment
Share on other sites

  • 1 month later...

Turns out the order of calls in the chain is important.  I had to update my calls to vertex to be in the same order as `VertexFormat BLOCK`

VertexConsumer vertex = vc.vertex(matrix4f, f3, f1, f2);
vertex = vertex.color(r, g2, b2, a);
vertex = vertex.uv(0, 0);
vertex = vertex.uv2(0, 0);
vertex = vertex.normal(matrix3f, 1.0F, 0.0F, 0.0F);
vertex.endVertex();
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.