+1 vote

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);
    CAMERA = CAMERA_MATRIX;
}

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?

Godot version 3.2.2
in Engine by (88 points)
edited by

1 Answer

+1 vote
Best answer

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

by (1,648 points)
selected by

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;
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.