Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot 4.0: Wrong VIEW vector in light() shader #68881

Open
alekseym88 opened this issue Nov 19, 2022 · 7 comments
Open

Godot 4.0: Wrong VIEW vector in light() shader #68881

alekseym88 opened this issue Nov 19, 2022 · 7 comments

Comments

@alekseym88
Copy link

Godot version

4.0.dev (84c404f), and same for 4.0b4

System information

MacOS Monterey 12.0.1, Intel Iris Graphics 550 1536 MB

Issue description

For orthogonal camera, VIEW vector in light() part of shader should be equal vec3(0.0, 0.0, 1.0), but in real this vector has different direction

Steps to reproduce

Add camera, sphere and source of light in your project, add this shader to sphere:

shader_type spatial;

void light() {
	DIFFUSE_LIGHT += vec3( pow( dot(VIEW, NORMAL), 3.0) );
}

in editor result will be fine:
Screenshot 2022-11-19 at 16 21 57

but in camera view:
Screenshot 2022-11-19 at 16 21 42

As a temporary solution can use just vector vec3(0.0, 0.0, 1.0) instead VIEW

Minimal reproduction project

test_view.7z.zip

@Chaosus
Copy link
Member

Chaosus commented Nov 19, 2022

I think it's related to the position of Spotlight in your scene. Try to cover the geometry by the light volume completely and the bug will be gone.

@alekseym88
Copy link
Author

Even it will be fully cover, VIEW vector is still remain wrong

Screenshot 2022-11-19 at 17 52 40

@Chaosus
Copy link
Member

Chaosus commented Nov 19, 2022

Ah, yes, but there is not much we can do with it. Maybe detecting the orthogonality of the camera in the scene shader and replace the VIEW to vec3(0, 0, 1) ? (I'm afraid it's too performance consuming for the little benefit). cc @clayjohn

@alekseym88
Copy link
Author

@Chaosus i think this solution is ok, its not a big problem to use just a vec3(0, 0, 1), but i think in this case better update this info in docs.godotengine.org, as it will be not so obvious for some people

@Chaosus
Copy link
Member

Chaosus commented Nov 19, 2022

Right, marked as documentation issue ^^.

@clayjohn
Copy link
Member

It looks like there was a lot of discussion about this on the Three.js github mrdoob/three.js#17662 They ended up switching it so that orthogonal cameras use a VIEW vector of vec3(0, 0, 1). As far as I can tell, both Unity and Unreal use the same VIEW vector for both perspective and orthogonal cameras.

It seems a VIEW vector of vec3(0, 0, 1) for orthogonal cameras is more "correct" in a certain sense. Oddly enough, when setting the viewport camera to "orthogonal" mode the VIEW vector is always vec3(0.0, 0.0, 1.0), I guess that it is set at a distance away from the origin sufficient that the VIEW vector is effectively always vec3(0.0, 0.0, 1.0).

I wonder if any people are currently relying on the current "incorrect" behaviour. If no one is, then I don't mind changing the VIEW vector to vec3(0, 0, 1) for orthogonal cameras

@tetrapod00
Copy link
Contributor

This was documented in godotengine/godot-docs#8708. Are we leaving this open to track potentially changing the actual behavior, or can it be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants