NodeMaterial alpha makes Mesh see through

I used a shader to make an alpha cut out and when I use alpha in this way as in my PG, this makes mesh error that you can see polygons that are obscured behind it.

Without “needDepthPrePass” this error is purely visible, but I’m losing the alpha cut out of a mesh that I’m after.

And this cut out approach make quite a performance hit on my scenes.

My Questions:

  1. Am I making this in a good way, the alpha cut out? Or is there a better and lighter on performance way to do it?

  2. the “needDepthPrePass” it also takes some performance to calculate everything, Is there a way to fix it with the shader or material property that will fix this depth issue.

  3. Is there an easy way to mix different shaders conditionally? Something like mix shaders based on a mask or something? But not MixMaterial, this is not doing it right and I got a lot of errors.

Regards
Peter

You can use alpha cutoff instead of alpha blending:

https://playground.babylonjs.com/#7YK8NE#1

Look at the the updated material in the NME: the alpha component of the FragmentOutput block is not connected anymore (so no alpha blending) and there’s a Discard block instead that removes the fragment when the alpha value is below a given threshold.

That’s super nice. Did not know that exist. And to be honest the blocks documentation is not to clear what is doing what. And I got problems to find that stuff.

But Yes I removed in my model the extra depth pass used that Discard block and it works like intended.

I will have more questions about different things like:

  1. Is there an easy way to mix different shaders conditionally? Something like mix shaders based on a mask or something? But not MixMaterial, this is not doing it right and I got a lot of errors.

No, you can’t really mix shaders this way by code.

What you can do, however, if you are using the NME, is to make custom frames (meaning you create a frame around a set of blocks and decide which are the inputs/outputs of the frame) for each “sub shader” and then link them in the way you want.

Can you make a basic 3 colors output example what you mean by that?

it’s hard to understand clearly?

You can do things like that:

Click on the “+” of the frames to see the inside.

Are those boxes do anything else or just organize blocks in a nice way.

I was thinking more of a way that MixMaterial is doing it. is there anything like it? or I have to come with my idea of it??

And also go you got “if” block in the shader or you have to make with Step Node?

You can save and import custom frames, but you still have to layout them in the nme, yes.

You can’t do like the MixMaterial because the “mixing” must be coded in a specific way, you can’t take two generic shaders and expect to have them work together.

if does not exist in the nme, you have to use the step / lerp / sign blocks to “emulate” it.

Ok. Thank you for your help. I’m using Step now to do it.

Which one of them (step / lerp / sign blocks) is the fastest to perform?

I’m now shaving as much as I can to speed things up.

I have no idea but I don’t think it will make a difference, we are speaking of one or two cycles potentially saved in the shader here, compared to what the standard/PBR material are doing otherwise.