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

spatial shader: using VIEWPORT_SIZE in VERTEX calculation breaks shadows #82782

Closed
alexjhetherington opened this issue Oct 4, 2023 · 2 comments · Fixed by #83491
Closed

spatial shader: using VIEWPORT_SIZE in VERTEX calculation breaks shadows #82782

alexjhetherington opened this issue Oct 4, 2023 · 2 comments · Fixed by #83491

Comments

@alexjhetherington
Copy link

alexjhetherington commented Oct 4, 2023

Godot version

v4.1.1.stable.mono.official [bd6af8e]

System information

Godot v4.1.1.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 (NVIDIA; 31.0.15.3713) - Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 Threads)

Issue description

I'm trying to implement a vertex jitter shader to emulate psx style graphics.

See: https://github.com/AnalogFeelings/godot-psx for a public implementation I am using for reference.

The shader should support shadows but there appears to be a bug in Godot that is preventing shadows from appearing.

As far as I can tell, the issue relates to VIEWPORT_SIZE. The shader uses VIEWPORT_SIZE to scale the jitter based on screensize.

Steps to reproduce

  1. spatial shader
  2. include render mode render_mode skip_vertex_transform
  3. inside the vertex() function,
  4. use VIEWPORT_SIZE in some part of the calculation of VERTEX.

Minimal reproduction project

no_shadows.zip

See screenshot below:

  1. A cube with a default material; shadows are displayed correctly
  2. A cube with a custom material jitter-not-using-viewport.tres; shadows are displayed correctly
    The custom material essentially just does VERTEX = round(VERTEX * i) / i;, where i is set by the user
  3. A cube with a custom material jitter-using-viewport; shadows are not displayed correctly
    The custom material scales i by VIEWPORT_SIZE.y

cubes

@clayjohn
Copy link
Member

clayjohn commented Oct 4, 2023

Related: #41420

The underlying problem here is that the VIEWPORT_SIZE builtin changes depending on whether we are at the shadow pass or in a regular drawing pass. In the shadow pass it is Vector2(1, 1).

I don't think VIEWPORT_SIZE is used internally for anything. Therefore, we should be able to just pass the screen size in there when rendering shadows

@jsjtxietian
Copy link
Contributor

Lookes like if we want to pass the correct viewport to shadowpass, we have to add more argument to _render_shadow_pass and _render_shadow_append. I will create a pr for this.

Do we need to add the same to compatibility and mobile ? I guess yes.

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.

5 participants