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

CAMERA_DIRECTION_WORLD shader built-ins does not yield the expected results #86502

Closed
Solesaver opened this issue Dec 25, 2023 · 1 comment · Fixed by #86516
Closed

CAMERA_DIRECTION_WORLD shader built-ins does not yield the expected results #86502

Solesaver opened this issue Dec 25, 2023 · 1 comment · Fixed by #86516

Comments

@Solesaver
Copy link

Tested versions

Reproduceable in v4.2.1.stable.official [b09f793]. Looking at the history, it looks like this has never been correct.

System information

Godot v4.2.1.stable - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Laptop GPU (NVIDIA; 31.0.15.4633) - 12th Gen Intel(R) Core(TM) i7-12700H (20 Threads)

Issue description

CAMERA_DIRECTION_WORLD is filled with the incorrect vector, and appears to have been so when first implemented.

actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.view_matrix[3].xyz";

Steps to reproduce

Create a Camera3D at the origin facing in the negative Z direction. Make a child plane facing the camera, and give it a shader material with the following fragment shader:

void fragment () {
    ALBEDO = (normalize(CAMERA_DIRECTION_WORLD) + vec3(1.0f)) / 2.0f;
}

Translate the camera without rotating it. See that the texture changes color despite the camera's world direction not changing and the other operations being constant.

Replace the shader with the following:

void fragment () {
    vec3 dir = normalize(INV_VIEW_MATRIX * vec4(0.0f,0.0f,1.0f,0.0f)).xyz;
    ALBEDO = (normalize(dir) + vec3(1.0f)) / 2.0f;
}

Translate the camera without rotation and notice that the color does not change as expected. Rotate the camera and note that the color does change.

I believe the relevant line in godot/drivers/gles3/storage/material_storage.cpp should be:
'actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.inv_view_matrix[2].xyz";`

Minimal reproduction project (MRP)

mgp.zip

WASD to move. QE to turn left and right.
Feel free to delete the noise floor, but I find it helps me be sure that the camera is actually moving/rotation when necessary.

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Dec 26, 2023

actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.view_matrix[3].xyz";

Yes the [3] here is weird because normally the view matrix's forth column is 0 0 0 1

'actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.inv_view_matrix[2].xyz";`

I suppose we can use view_matrix too if negate it too.

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

Successfully merging a pull request may close this issue.

4 participants