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

Add double precision support for World Triplanar Mapping #75577

Conversation

joao-pedro-braz
Copy link
Contributor

@joao-pedro-braz joao-pedro-braz commented Apr 1, 2023

Description

This PR adds emulated doubles support for the World UV Triplanar Mapping. It also adds some QoL features to both ease the "integration" with the double precision pipeline and also to allow greater flexibility when dealing with Triplanar UVs.

Features:

  • New mat4 TRIPLANAR_MATRIX vertex-only property (the same as MODEL_MATRIX by default).
  • New "hint_triplanar_mat" hint for mat4 uniforms, which allow users to specify a custom TRIPLANAR_MATRIX. Naturally, only a single instance of the hint is allowed per shader.
  • New vec3 TRIPLANAR_POSITION vertex-only property, which holds the VERTEX transformed by the TRIPLANAR_MATRIX (With emulated doubles, if applicable).
  • Updated Standard 3D Material to make use of the above features.
  • Updated VisualShader to include the TRIPLANAR_MATRIX and TRIPLANAR_POSITION as valid Inputs.
  • Added a "hint_triplanar_enabled" toggle to the VisualShaderNodeTransformParameter to allow the new "hint_triplanar_mat" hint to be set.

Below is a Demo which was tailored to showcase these additions.
Video:

2023-04-01_17-57-04.mp4

Project: TestDoubles.zip

Note: The shader related changes were applied to all renderers (Forward+, Mobile and Compatibility).

Note²: Given the lack of emulated doubles support for the Compatibility renderer, only the single precision path was implemented.

Note³: Related to #75462, where the need for this was brought up by @Zylann (specifically the support for custom matrices when computing the TRIPLANAR_POSITION).

@joao-pedro-braz
Copy link
Contributor Author

(forgot to --doctool, sorry about that)

@joao-pedro-braz joao-pedro-braz force-pushed the implement_double_precision_for_world_triplanar branch from 6963388 to 27075ab Compare April 1, 2023 23:34
@Chaosus
Copy link
Member

Chaosus commented Apr 2, 2023

Would you like to change the existed VisualShaderNodeTextureParameterTriplanar to support this by default or (if its break compatibility) by setting a flag?

@joao-pedro-braz
Copy link
Contributor Author

That's actually a great idea!
A simple "World Triplanar" toggle should suffice, I'll have a go at it rn

@joao-pedro-braz
Copy link
Contributor Author

image
So much simpler

@joao-pedro-braz joao-pedro-braz force-pushed the implement_double_precision_for_world_triplanar branch from 27075ab to 1d52989 Compare April 2, 2023 07:24
@joao-pedro-braz
Copy link
Contributor Author

I think I ran --doctool with a double precision build 😒

@joao-pedro-braz joao-pedro-braz force-pushed the implement_double_precision_for_world_triplanar branch from 1d52989 to 7f2f145 Compare April 2, 2023 15:36
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it mostly works as expected. World triplanar now works correctly on still objects (even if the camera moves), but moving the object when far away from the world origin will have visible snapping in the final UV.

Testing project: test_triplanar_double.zip

All videos below taken at X = 5,000,000. The object uses a StandardMaterial3D and is moved using a script.

master, single precision

single_world_triplanar.mp4

master, double precision

double_master_world_triplanar.mp4

This PR, double precision

double_pr_world_triplanar.mp4

@fire fire requested a review from a team January 14, 2024 02:34
Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request is a good idea but needs a rebase. Calinou tested on the last version.

@joao-pedro-braz joao-pedro-braz force-pushed the implement_double_precision_for_world_triplanar branch from 7f2f145 to 2d281d6 Compare January 28, 2024 20:11
@joao-pedro-braz
Copy link
Contributor Author

The pull request is a good idea but needs a rebase. Calinou tested on the last version.

Rebased.
Thanks!

@fire
Copy link
Member

fire commented Feb 27, 2024

There are some rebases needed, I'll try to see if anything's blocking this for 4.3.

servers/rendering/shader_language.cpp Outdated Show resolved Hide resolved
servers/rendering/shader_language.cpp Outdated Show resolved Hide resolved
scene/resources/visual_shader_nodes.cpp Outdated Show resolved Hide resolved
This commit adds emulated doubles support for the World UV Triplanar Mapping.
It also adds some QoL features to both ease the "integration" with the double
precision pipeline and also to allow greater flexibility when dealing
with Triplanar UVs.

Features:
  - New mat4 TRIPLANAR_MATRIX vertex-only property (the same as MODEL_MATRIX by default).
  - New "hint_triplanar_mat" hint for mat4 uniforms, which allow users
    to specify a custom TRIPLANAR_MATRIX. Naturally, only a single
    instance of the hint is allowed per shader.
  - New vec3 TRIPLANAR_POSITION vertex-only property, which holds the
    VERTEX transformed by the TRIPLANAR_MATRIX (With emulated doubles, if
    applicable).
  - Updated Standard 3D Material to make use of the above features.
  - Updated VisualShader to include the TRIPLANAR_MATRIX and
    TRIPLANAR_POSITION as valid Inputs.
  - Added a "hint_triplanar_enabled" toggle to the VisualShaderNodeTransformParameter to allow
    the new "hint_triplanar_mat" hint to be set.

Note: The shader related changes were applied to all renderers (Forward+,
Mobile and Compatibility).

Note²: Given the lack of emulated doubles support for the Compatibility
renderer, only the single precision path was implemented.
@fire
Copy link
Member

fire commented Apr 30, 2024

I did a push to salvage the pr.

image

Changes here.

@fire
Copy link
Member

fire commented Apr 30, 2024

Superseded by: #91380

@Calinou
Copy link
Member

Calinou commented May 2, 2024

Superseded by #91380. Thanks for the contribution nonetheless!

@Calinou Calinou closed this May 2, 2024
@Calinou Calinou removed this from the 4.x milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

World Triplanar is broken with double-precision build
5 participants