0 votes

Hello,

I've been blocked on a problem for the last two days in my project, this problem concerning the use of shaders.

Consider the following : I have a certain shader A, let's say a texture. This shader is totally opaque, colored and is applied to a certain mesh. For various reasons, I would like to make certain pixels/vertices more or less transparent, with the help of a shader B in the next_pass category of shader A.

Can such a shader B exist, so that if he is applied to the "next_pass" category of any shader A he will affect the transparency of given pixels ? Or do I need to write a different shader A that will include the functionnalities of shader B ?

In my case shader B makes the pixels more or less transparent depending on the angles of the normal : I apply it to meshes of a MeshLibrary, those meshes being parts of a building. With a shader B like that, I could make the walls invisible, if they are a certain angle, and close to a certain coordinate (probably the player's point of view).

Thanks

in Engine by (350 points)

Ok. So if I'm understanding correctly, you want a shader that's opaque in some parts, but transparent in other parts yes? Couldn't just make one shader that does all that? Why would you need two separate shaders exactly?

SIsilicon,

So in my project there's a skyscraper, made of a Gridmap. The player has a camera revolving around this skyscraper, but it cannot go inside it. Instead, to see what happens inside, I was thinking it would be great if, when the player's camera is near enough, the walls near where his camera is could become invisible.

So right now I think I need two shaders because the "shader B", who would make walls invisible around a certain point, could be applied to every member of the MeshLibrary attributed to the GridMap. As such, there would be less ressources used and, when the position of the camera changes, there would be only one shader parameter to change.

I was thinking this was a good solution, but I don't know if it is feasable right.

One last thing, is that the members of the MeshLibrary are meshes imported from .obj, those .obj being created in Blender. As such, I would like if it was possible to not touch the original Material of the imported meshes.

Very cool ! That's practically exactly what I want. Do you think I can add my idea of making walls somewhere in this pipeline ?

If you want you can add your previous comment as an answer, so that I can validate it and so that some people in my situation can find your answer :)

That's what I plan on doing :)
And yeah. I don't see why you can't have this with your walls. It's just a material after all.

1 Answer

+2 votes
Best answer

Actually, there's a SpatialMaterial property specifically for this kind of case. It's called Distance Fade. It has a pixel alpha mode, a pixel dither mode, and an object dither mode.

  • Pixel Alpha Mode: The actual transparency of a pixel of the object changes with distance to the camera. This is the most effect, but forces the material into the transparency pipeline. So no shadows for you. :(
    Pixel Alpha
  • Pixel Dither Mode: What this does is sort of approximate the transparency by only having a fraction of the pixels rendered. This may or may not look good depending on your project. But hey. At least you got your shadows back. :)
    Pixel Dither
  • Object Dither Mode: Like the previous mode, but the calculated transparency is the same across the entire object's surface.
    Object Dither

In your case option 3 may not be what you want.

by (3,926 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.