Skip to content

Add a section about coordinate spaces to shader pages. #9757

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

Closed

Conversation

tetrapod00
Copy link
Contributor

@tetrapod00 tetrapod00 commented Aug 15, 2024

Resolves #9780.

This PR aims to add a list of coordinate spaces to various shader pages:

  • Spatial shaders will have a section with a table and some conversion snippets.
  • CanvasItem shaders will have a section with a table and some conversion snippets.
  • Particle shaders will link to Spatial and CanvasItem sections.
  • Fog and Sky could either link to Spatial, copy the entire section, or only list the world spaces they use.

@@ -83,6 +83,51 @@ Render modes
| **fog_disabled** | Disable receiving depth-based or volumetric fog. Useful for blend_add materials like particles. |
+-------------------------------+------------------------------------------------------------------------------------------------------+

Coordinate spaces
Copy link
Contributor Author

@tetrapod00 tetrapod00 Aug 15, 2024

Choose a reason for hiding this comment

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

We should either put this section here, or at the bottom of the page.
Pros for here:

  • It's a prerequisite for understanding everything else on the page.

Pros for end of page:

  • Once you already know what the spaces are, it may be annoying to scroll past it every time you're reading. The page already functions fine without a coordinate space section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upon further reflection, this section should go at the bottom of the page unless there's a strong argument otherwise.

@tetrapod00 tetrapod00 force-pushed the shader-coordinate-spaces branch from 7d9df6b to 07af357 Compare August 15, 2024 23:51
vec3 position_view = (VIEW_MATRIX * MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
}

You can transform to one coordinate space, do some operations, and transform back. This snippet scales ``VERTEX`` in model space,
Copy link
Contributor Author

@tetrapod00 tetrapod00 Aug 15, 2024

Choose a reason for hiding this comment

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

Maybe change this example. It might encourage bad practice, since in most cases you can do this with a single transformation, and without the expensive inverse().
On the other hand this specific example of manipulating vertices with both world and model space does come up a lot, including the lack of an INV_MODEL_MATRIX.

vec3 normal_world = (INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
}

You can also compose multiple transformations together. To transform ``VERTEX`` from model space to view space, first
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe change the example since MODELVIEW_MATRIX already does this.

@tetrapod00 tetrapod00 force-pushed the shader-coordinate-spaces branch 2 times, most recently from 9dfcdc8 to 9237a80 Compare August 16, 2024 04:50



Working with coordinate spaces
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arguably this whole section should be a separate page.

@tetrapod00 tetrapod00 force-pushed the shader-coordinate-spaces branch 3 times, most recently from f2d8faa to 11b1c9a Compare August 16, 2024 05:31

Screen space to clip space:

.. code-block:: glsl
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be some variation on the function for screen to view, but I can't figure it out

+-------------------------------+----------------------------------------------------------------------------------------+
| Screen space | TODO |
+-------------------------------+----------------------------------------------------------------------------------------+
| Normalized device coordinates | Usually not used directly. ``xy`` alues range from ``-1.0`` to ``1.0``, with |
Copy link
Contributor Author

@tetrapod00 tetrapod00 Aug 16, 2024

Choose a reason for hiding this comment

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

Is this actually guaranteed to be Vulkan NDC coordinates (-1,-1,0) to (1,1,1)? In the compatibility renderer, can it be in (-1,-1,-1) to (1,1,1)?

@skyace65
Copy link
Contributor

skyace65 commented Apr 7, 2025

@tetrapod00 is this something you're still working on?

@tetrapod00
Copy link
Contributor Author

Not actively working on this. We can archive it. If I pick it back up again, I'll either amend this PR or make a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archived area:manual Issues and PRs related to the Manual/Tutorials section of the documentation enhancement topic:shaders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add documentation about shader coordinate spaces
2 participants