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

Vertex Shader Utilizing INV_VIEW_MATRIX not rendering shadows #91894

Open
svenar-nl opened this issue May 13, 2024 · 3 comments
Open

Vertex Shader Utilizing INV_VIEW_MATRIX not rendering shadows #91894

svenar-nl opened this issue May 13, 2024 · 3 comments

Comments

@svenar-nl
Copy link

Tested versions

  • Reproducible in: 4.3-dev6, 4.2.2, 4.0-stable, 3.6-beta4

System information

Godot v4.2.2.stable - Ubuntu 23.10 23.10 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 SUPER (nvidia; 545.29.06) - AMD Ryzen 7 3700X 8-Core Processor (16 Threads)

Issue description

Issue Description:
Creating a vertex bending shader using INV_VIEW_MATRIX produces no shadows wile using a different value (for example TIME) does produce a shadow.

Expected Behavior:
Shadows should be rendered accurately when utilizing the INV_VIEW_MATRIX in the vertex shader, similar to how they are rendered when using values like TIME.

image
Shader objects left (image):

void vertex() {
	VERTEX.y -= pow(length(INV_VIEW_MATRIX[3].zyz - VERTEX.zyz) / 20.0, 4);
}

Shader objects right (image):

void vertex() {
	VERTEX.y -= pow(length(sin(TIME) * 15.0 - VERTEX.zyz) / 20.0, 4);
}

This also exists in Godot 3 with the following shader:

shader_type spatial;

void vertex() {
	VERTEX.y -= pow(length(INV_CAMERA_MATRIX[3].zyz - VERTEX.zyz) / 20.0, 4);
}

Steps to reproduce

  1. Create a MeshInstance3D with a plane mesh
  2. Add the following shader to the MeshInstance3D
shader_type spatial;
render_mode world_vertex_coords;

void vertex() {
	VERTEX.y -= pow(length(INV_VIEW_MATRIX[3].zyz - VERTEX.zyz) / 20.0, 4);
}
  1. Add a MeshInstance3D with a cube mesh and the exact same shader and place it above the other
  2. Observe no shadows being casted from the cube onto the plane.

Minimal reproduction project (MRP)

@svenar-nl
Copy link
Author

Follow up

When manually supplying the shader with the position of the active camera the shadows are drawn correctly.
There is no visual difference between INV_VIEW_MATRIX and a manual camera position.

image
Left: Manual position
Right: INV_VIEW_MATRIX

Minimal reproduction project (MRP)

@clayjohn
Copy link
Member

In 4.3 we introduced a new built in variable to handle this situation: MAIN_CAM_INV_VIEW_MATRIX. Use that instead of INV_VIEW_MATRIX as INV_VIEW_MATRIX is the matrix used for rendering the object not the matrix from the camera in your scene.

There is an important distinction here because when rendering shadow maps the camera used is based on the position and orientation of the light.

@jsjtxietian
Copy link
Contributor

Sounds like something that need better documentation?

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

3 participants