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

Improve shader function descriptions #9338

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

AshbyGeek
Copy link

Adds much detail to the documentation on built-in shader functions, copied from (with a few modifications) and linked to official GLSL documentation.

That documentation was moved into a separate file due to its verbosity, and organized into smaller sections following the organizational comments in https://github.com/godotengine/godot/blob/master/servers/rendering/shader_language.cpp.

Style tries to generally follow the styling used in class documentation, but differences between .gdshader and .gdscript meant some changes had to be made.

@AshbyGeek
Copy link
Author

Pull request for issue #9310

@AThousandShips AThousandShips changed the title Ashbygeek/shader funcs Improve shader function descriptions May 7, 2024
@AThousandShips AThousandShips requested a review from a team May 7, 2024 09:31
@skyace65 skyace65 added enhancement area:manual Issues and PRs related to the Manual/Tutorials section of the documentation topic:shaders labels May 8, 2024
@AshbyGeek AshbyGeek marked this pull request as ready for review May 8, 2024 20:40
@skyace65
Copy link
Contributor

skyace65 commented May 9, 2024

CC @clayjohn

@clayjohn
Copy link
Member

clayjohn commented May 9, 2024

That was unbelievably fast. I'm going to need a few days to review this. But I am very excited!

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

This looks good, gonna go through it for style again but this was some that stuck out for now

tutorials/shaders/shader_reference/shader_functions.rst Outdated Show resolved Hide resolved
tutorials/shaders/shader_reference/shader_functions.rst Outdated Show resolved Hide resolved

.. rst-class:: classref-method

ivec2 **textureSize** ( samplerCubeArray s, int lod )
Copy link
Member

Choose a reason for hiding this comment

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

The following text is just a duplicated information, I think you should remove it, and instead add the overloads to header of first declaration eg:

ivec2 **textureSize** ( |gsampler2D| s, int lod )
ivec2 **textureSize** ( samplerCube s, int lod )
ivec3 **textureSize** ( |gsampler2DArray| s, int lod )
ivec3 **textureSize** ( |gsampler3D| s, int lod )

And do the same for other functions...

Copy link
Author

Choose a reason for hiding this comment

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

There were a number of these kinds of functions, in a few of them the text was exactly the same, but a lot of them had minor differences. For instance, the atan function has significant behavioral differences between its two overloads.

I decided that the documentation would be slightly clearer if these were addressed individually and that consistency of layout/format (in this case meaning each overload gets its own documentation) was more important than concerns about repetition.

Admittedly, most of them are not-just the difference between int and uint or similarly small, but even some of these behave differently, such as packUnorm2x16 which has a different snippet of equivalent code for each overload.

Copy link
Author

Choose a reason for hiding this comment

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

@Chaosus thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can separate them in cases like atan where you need two different descriptions. But in cases like textureSize, it makes sense to group them together. You are right not to worry about repetition, but some cases (like all the texture* functions) the sheer amount of repetition makes the document harder to navigate

Copy link
Author

Choose a reason for hiding this comment

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

Understood, I will add this to my todo list.

AshbyGeek and others added 2 commits May 10, 2024 10:45
Co-authored-by: Yuri Rubinsky <[email protected]>
Co-authored-by: A Thousand Ships <[email protected]>
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Amazing work! This looks really good so far.

I think I just have two general comments:

  1. I agree with Chaosus' comment earlier that, in most cases, functions with the same name should be grouped instead of duplicated. Especially for functions with really long descriptions.
  2. I like how you kept the short description in the table. But I think it needs to be truly a short description. Some of the entries have the entire description copied in the table and that ends up making the table bloated in hard to navigate.

See DfDx for example
image

In these cases, the table actually has more information than the long description below.


vec_type atan( |vec_type| y_over_x)

Calculate the arctangent given a tangent value of ``y/x``. Note: becuase of
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Calculate the arctangent given a tangent value of ``y/x``. Note: becuase of
Calculate the arctangent given a tangent value of ``y/x``. Note: because of


vec_type atanh( |vec_type| x)

Calculate the arctangent given a tangent value of ``y/x``. Note: becuase of
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Calculate the arctangent given a tangent value of ``y/x``. Note: becuase of
Calculate the arctangent given a tangent value of ``y/x``. Note: because of

Comment on lines -1134 to -1139
Built-in functions
------------------

A large number of built-in functions are supported, conforming to GLSL ES 3.0.
When vec_type (float), vec_int_type, vec_uint_type, vec_bool_type nomenclature
is used, it can be scalar or vector.
Copy link
Member

Choose a reason for hiding this comment

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

I think its worth keeping this section and only having one sentence that simply points to the new page. Users may have a hard time finding it otherwise

Comment on lines +37 to +48
.. note::
Most operations on vectors (multiplication, division, etc) are performed component-wise.
For example, the operation ``vec2(3, 4) * vec2(10, 20)`` would result in ``vec2(3 * 10, 4 * 20)``.
or the operation ``min(vec2(3, 4), vec2(1, 8))`` would result in ``vec2(min(3, 1), min(4, 8))``.

The `GLSL Language Specification <http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf>` says under section 5.10 Vector and Matrix Operations:

With a few exceptions, operations are component-wise. Usually, when an operator operates on a
vector or matrix, it is operating independently on each component of the vector or matrix,
in a component-wise fashion. [...] The exceptions are matrix multiplied by vector,
vector multiplied by matrix, and matrix multiplied by matrix. These do not operate component-wise,
but rather perform the correct linear algebraic multiply.
Copy link
Member

Choose a reason for hiding this comment

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

This is probably better suited in the section on data types rather than here.

https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/shading_language.html#data-types

Copy link
Author

Choose a reason for hiding this comment

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

I disagree. Operating primarily component-wise isn't really a feature of these data types, it's a feature of the functions that operate on them. I could see an argument for putting it in both places (or maybe one has a short reminder with a link).

It would also make sense to me if you wanted to remove this from the header and include it in each applicable method. Cause chances are if someone needs this reminder its while they're looking at a specific function. They may or may not look at data types documentation or general comments first.


.. note::

Available only in the fragment shader
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Available only in the fragment shader
Available only in the fragment shader
Not available when using the GL_Compatibility rendering backend.

The same note should be added for dFdyCoarse, dFdxFine, dFdyFine, fwidthFine, and fwidthCoarse

@AshbyGeek
Copy link
Author

Awesome! I'm glad you like it. I'm pushing hard to finish a project milestone this week, but I should be able to work on an update next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

None yet

5 participants