godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.04k stars 21.18k forks source link

Normal Buffer not working as expected if the current scene has no environment #75794

Closed uberfig closed 1 year ago

uberfig commented 1 year ago

Godot version

4.0.2 stable

System information

issue tested on win10 with ryzen 7 and rx 6600, win11 with ryzen 7 and gtx 3050

Issue description

When creating a screen reading post processing shader, the normal buffer functions correctly in the editor, but does not seem to be functioning as expected in debug, producing only a solid colour when run. I am unsure if this behaviour is intended, but if so, I feel it should be properly documented.

Running correctly in editor: image

Solid colour in debug: image

Steps to reproduce

this shader should be attached to a MeshInstance3D quadmesh minimal shader to reproduce:

shader_type spatial;
render_mode unshaded, cull_disabled;

uniform sampler2D NORMAL_TEXTURE : hint_normal_roughness_texture, filter_linear_mipmap;

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

void fragment(){
    ALBEDO = texture(NORMAL_TEXTURE, SCREEN_UV).rgb;
}

Minimal reproduction project

N/A

AThousandShips commented 1 year ago

What happens if you remove mipmaps from the filter?

AshuraDX commented 1 year ago

Same issue exists on Version 4.0., using Forward+ Renderer

AshuraDX commented 1 year ago

What happens if you remove mipmaps from the filter?

My tests were run using filter_nearest as shown in the docs initially, same issue.

AshuraDX commented 1 year ago

So I just discovered something strange!

If I disable the preview Environment in the editor, then resize the Preview Viewport vertically - I get the same solid color screen as I get when running the scene:

grafik

adding a basic WorldEnvironment Node to the scene fixes this again: grafik

including when running the project! grafik

I have no idea why this could be though

uberfig commented 1 year ago

Can confirm, adding the world environment fixed the problem on my end as well!

uberfig commented 1 year ago

Closing issue as a solution has been found

AThousandShips commented 1 year ago

This is still a bug and needs to be investigated, I don't think the normal texture not working is a normal thing to expect without an environment, this should probably be reopened

Lexpartizan commented 1 year ago

May I ask how to make the normals from this texture be in world space? Because my colors change when I move the camera.

cufbom commented 1 year ago

I found this issue very frustrating to debug, if it's a limitation of the renderer that the screen space normals aren't available without a world environment it would be good if it was mentioned in the shader docs.