#Stencil Rendering with AlphaBlend + AlphaTest

1 messages · Page 1 of 1 (latest)

restive tusk
#

Hello! I'm working on a label model that needs to render similarly to in-game nametags. For that, I needed two main things:

  1. A background (using AlphaBlend)
  2. A text layer (using AlphaTest)

Both should always render through blocks, with the text rendering on top of the background. To achieve this, I set both materials to use "depthFunc": "Always". However, I ran into an issue with how the game orders material rendering: the background always rendered through the text.

I'm not deeply experienced with custom materials, but after reading some discussions here on the server and experimenting with AI suggestions, I found a partial solution using a stencil mask. It got me close to the desired effect.

However, I’m still facing some inconsistencies:

  • In certain conditions (e.g., rendering through nether portals), the layering gets buggy.
  • Sometimes, text from one label renders through another, even though texts should not render through other texts that are in front of them.

I'd really appreciate if anyone with experience in material stencils could take a look at my current materials. I’d like to know if my approach makes sense, or if there’s a more reliable way to solve these rendering issues. I'm also searching for ways to optimize my materials in case there is any ambiguity.

Thanks in advance!

#

Materials:

{
  "materials": {
    "version": "1.0.0",
    "hologram_background:entity_alphablend": { // BACKGROUND: First in the render_controllers, but last to render
      "+states": [
        "EnableStencilTest",
        "DisableDepthWrite",
        "DisableDepthTest"
      ],
      "-states": ["DisableCulling"],
      "frontFace": {
        "stencilFunc": "Equal"
      },
      "backFace": {
        "stencilFunc": "Equal"
      },
      "stencilRef": 1,
      "stencilReadMask": 2,
      "depthFunc": "Always"
    },
    "hologram_char_mask:entity": { // MASK: Renders first
      "+states": [
        "StencilWrite",
        "DisableColorWrite",
        "DisableDepthWrite"
      ],
      "-states": ["DisableCulling"],
      "stencilRef": 2,
      "stencilWriteMask": 2,
      "depthFunc": "Always"
    },
    "hologram_char:entity_alphatest": { // TEXT: Renders after the mask
      "+defines": ["USE_UV_ANIM"],
      "-defines": ["FANCY"],
      "+states": ["EnableStencilTest"],
      "-states": ["DisableCulling"],
      "frontFace": {
        "stencilFunc": "Always",
        "stencilPassOp": "Replace"
      },
      "backFace": {
        "stencilFunc": "Always",
        "stencilPassOp": "Replace"
      },
      "stencilRef": 2,
      "stencilWriteMask": 2,
      "depthFunc": "Always"
    }
  }
}
placid palm
placid palm
restive tusk
#

I can't share because I made this system to a team. But it basically uses setPropertyOverrideForEntity

placid palm
#

but like how the heck does it work does it use entity nametag or what

placid palm
#

@restive tusk wait is this using a entity or not?

restive tusk
#

Let's consider you need a 15 characters support per entity. You'll need 15 properties that carries all the character data (like index, length if passing via server, etc.), everything is predefined including the characters it support

#

Then, animations do the rest of the magic

placid palm
#

so you needa make a bunch of properties for the entity and set them individually through client entity??? and also adding color??? and whatt???????????????????/

restive tusk
# placid palm so you needa make a bunch of properties for the entity and set them individually...

Yes, xD. Every data the character need. It's such an advanced system... It would work perfectly if it didn't lag so much due to a bunch of render controllers per entity. But I did 30 characters, if you make 15 for example it'll lag much less, less than using 2 entities of 15 I think. Or if you don't need color or something... I added all the Java Edition formatting codes too. The system of converting text into properties is via scripting
Obs: an entity is limited to 32 properties

placid palm
#

Thats crazy what?? Did you separate all the textures of each letter out to set in the entity file???

restive tusk
#

Nope. Same texture + uv_anim

placid palm
north seal
#

If name tags are not supposed to move, instead of using depthFunc, you can scale down the geometry from the camera position. That will physically move name tags closer, without changing their perspective. Transparent blocks will still render on top of the background, but not over the characters themselves. Also with this set-up, you don't need the mask, just setting stencil on the characters themselves would be enough. You can also technically do that without stencil at all, if you use can repurpose the characters as the background and change their texture to translucent black. But that only works if you can actually reuse that geo, as it requires the same exact geo in order for depth testing to result in the same exact depth values

restive tusk
placid palm
restive tusk
placid palm
#

How are you animating each bone??? Is it also with another property?

#

Also how did you use uv_anim for each bone on mutiple things at once?

restive tusk
# placid palm How are you animating each bone??? Is it also with another property?

Take the golden tips:

  1. Do all the characters positioned at the same place, following the a chaining hierarchy. 2nd chirlden of the 1st, 3rd chirlden of the 2nd, and so on...
  2. The initial position is: the bone anchors from the model center to right.
  3. You'll have to calculate the total width = which is the sum of each character's width, and offset the first character exactly by half of that to left (which offsets the entire text due to hierarchy).
  4. Each individual bone is offseted to right by the size of the last character before it, which offsets all the following chars

I sent a set of data via only one integer property per character. So you can send index, width, color data, etc... (ask chat GPT about how to "encode" multiple info in an int).

restive tusk
#

So, make the render_controller of that character use the characters geo but only render the bone(s) of that character

placid palm
restive tusk
#

Yep

#

Unless you have multiple geometries for each character (still following the hierarchy). I'll consider testing that btw to try to get some optimization 🤔 but I doubt I'll

placid palm
#

Did you set the length of the black box (that goes behind the text) dynamically too?

restive tusk
#

initially it has a width of 1 pixel, so scale is exactly by amount of pixels + some border value you use. Ensure the pivots are aligned on the left of the bone btw to avoid misaligning

#

and in the hierarchy I used, the background is chirlden of the char_0 bone to offset together

placid palm
#

Oh the background isnt its own other geometry?

restive tusk
#

basically root (pivot centered to make it face you or do any other anim) -> char_0 -> background
In the char: root -> char_0 -> char_1...
Keep same pivots as well

placid palm
#

YOOO I THINK IM UNDERSTANDING NOW TYSM

#

Wait but for the black box scaling it does this???

#

I think its because its the parent of all the other char_1 and other

#

but I thought thats how you did it right?

restive tusk
placid palm
restive tusk
#

Nope. Other letters are not needed in the background geo.

other letters are in char_0 of the chars geo, so scaling background is independent

placid palm
#

ohhhhhhh I thought you said yeah they were all in one folder together

#

mb

#

But why is my text being written from right to left?

#
writeTextToEntity(text, "Testing")```
#

are my pivot points wrong?

restive tusk
restive tusk
placid palm
#

ok

#

Now i fixed it slightly but its still bugging because the billboard for the thing is weird it look like the first image when looking at it from the front but the second one when looking from the back

restive tusk
placid palm
placid palm
#

like is the billboard effect a applied animation

#

or is it set into the model

placid palm
restive tusk
restive tusk
lavish lantern
#

HI

restive tusk
#

Hi

placid palm
lavish lantern
#

Why won't my stone texture work

#

It's so frustrating

placid palm
#

But now its being so weird with the text

lavish lantern
restive tusk
placid palm
#

but this is fine??

lavish lantern
#

Maybe it's the spacing?

restive tusk
placid palm
#

the spacing is being buggy

restive tusk
#

When does it bug?

#

with t only?

placid palm
#

idk

#

its with

#

all

placid palm
#

I think i figured it out!

#

wait but how did you set the text's color?

slate veldt
#

I want to bring this idea to life, but it’s so frustrating not being able to.

placid palm
#

i even made it up to 30 characters now

placid palm
#

w

#

@restive tusk are you proud of me

sharp wasp
#

Dayumm

restive tusk
restive tusk
#

Isn't it lagging? When setting like 3 entities

placid palm
restive tusk
#

Great to know! 🤩 Congrats

placid palm
#

@restive tusk how did you deal with the limit set on property overrides

restive tusk
# placid palm <@596091801429999616> how did you deal with the limit set on property overrides

To be honest, I did nothing about it in this system... xD, as I didn't write enough texts to reach the limit. I only discovered that limit later when doing another system, which I was setting property overrides much more frequently, and what I did was make sure that all the properties were being removed (as I didn't need older properties). But luckily they are removing this limitation in the preview versions, so we won't have to worry too much about it.

placid palm
restive tusk
#

It was but in preview versions only, according to the changelog

placid palm
#

D:

fading aspen
# placid palm

One question, is it possible to remove this background from the texts?

#

I spent ages trying to remove this black background, but I never managed to do it.

#

@restive tusk

#

in case leave the nickname transparent without the black background

fading aspen
#

what?

placid palm
#

u can remove the black bg

fading aspen
#

Can you tell me how to do this?

fading aspen
#

@placid palm

placid palm
#

ye

#

uh

#

u just like remove the texture of the black bg