How to keep material color/albedo in Shader pass

Godot Version

Godot Version 4.2.2

Question

Hello Guys. Sorry if this is a super basic question but I feel like I am missing something obvious here.

Goal: I want to keep the ALBEDO from the material when I add a shader as a second pass.

I have imported a tree mesh from Blender, it has texture and colours. The first pass is a StandardMaterial3D. I added a second pass and chose a shader, and the object turned white.

I have tried everything I can think of to try to “sample” the colours from before but nothing seems to be working. I feel like I am missing an obvious solution. Is there any way I can leave the colours/albedo untouched when doing a shader pass?

My ultimate goal is to make a distance-based fading shader, so it checks the distance from the camera/player and if it is beyond a certain point, it will slowly lower the alpha value.

Any help? Thanks


Not sure if this will be any help, but this is how I added the shader in, there is no code in the shader.

1 Like

This next pass system only seems to be to be an overlay type setup, where the opacity of the next pass just blends with the previous, you can only see to change the blend mode, but I see no way of inheriting the previous pass except maybe some access to scene buffers in the next pass material, but that might be overkill for what you want to do.

Why not do this in a single material/shader?

My ultimate goal is to make a distance-based fading shader, so it checks the distance from the camera/player and if it is beyond a certain point, it will slowly lower the alpha value.

When you say ‘fading’, are you meaning you want the mesh with these materials on them to visually disappear, or are you talking fading between the two materials you are talking about?

If it’s the latter, what does the next pass material supposed to change from the previous if not for the albedo pass?

1 Like

Thanks for replying.

I guess it’s just my own lack of experience that is stopping me from doing it in a single material/shader. My idea was to treat it like layers, the material “layer” applies texture, and then the shader pass “layer” applies the alpha based on distance.

By fading I meant visually disappears. I have terrain generation around the player but I want to avoid a hard pop-in when new terrain is generated. So I was going to fade out so it could pop in invisibly and then slowly fade in when the player gets closer.

I did find a solution last night, I could extract the 2D texture from the mesh, and then pass that to the shader as an input and apply it to the ALBEDO using UV as coordinates. It is basically the “pass-through” I wanted, and now I can code the rest of the shader as I want.

1 Like

There should be proximity settings in the standard material, I think transparency needs to be enabled and you can do it on the first pass.

1 Like

Yeah, I noticed the distance fade in the material, but I wanted to have more flexibility in the curve of the fade by writing it myself. And also because I wanted to try to write it myself to learn shaders better.

Thanks for pointing it out though, I easily could have missed that setting.