Problem using quadmesh as screen space shader for 3D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By therealguy

I know you can use a canvas_item shader as a screen space shader for 3d games, but for my project I need access to the depth texture which isn’t available in a canvas_item shader.

I read that a quadmesh with a width and height of 2 with a spatial shader can be positioned to always be in front of the camera and work as a screen space shader with access to the depth information, but unfortunately the quadmesh makes the screen appear to be darker/lighter depending on where the camera is facing.

For example, a quadmesh with the shader code here:

shader_type spatial;
varying mat4 CAMERA;

void vertex() {
    POSITION = vec4(VERTEX, 1.0);

void fragment() {
	ALBEDO = textureLod(SCREEN_TEXTURE, SCREEN_UV, 2.0).rgb;

does blur the screen, but the screen also looks darker when the camera is facing toward the directional light and brighter than it should when facing away. I know that the example doesn’t use the depth information like I am needing and I could just use a canvas_item shader to make this work, but I wanted to provide a simple example using a spatial shader.

Here is an image of my game without the example shader above:

And here is the same scene but with the shader (as you can see it is indeed blurred, but is also darker and blueish from the world environment reflecting the sky I think)

For another example, here is an image of the game in a different area and with the camera facing away from the directional light and a shadow falling onto the screen quadmesh (as you can see the screen is now lighter):

To reiterate, I want to have a screen space shader that has access to the depth texture, but looks “clear” and does not make the screen be shaded darker/lighter depending on the light or be able to capture shadows.

How can I have the quadmesh that I’m using as a screen space shader ignore the directional light or is there a way to set the absolute pixel color inside fragment() rather than the albedo? Or is there an entirely different solution that I’m not understanding?

:bust_in_silhouette: Reply From: sash-rc

How can I have the quadmesh that I’m using as a screen space shader ignore the directional light

I think it could be done in material - flags - unshaded

I see that flag inside of a spatial material, but I don’t see it inside of the quadmesh’s shader material

EDIT: thanks to your response I was able to look up that I can set a shader material to be unshaded by simply adding this line to my shader code:

render_mode unshaded;

therealguy | 2020-12-19 03:12