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

Expose often-used variables derived from built-ins as seperate visual shader nodes/ shader constants #4957

Closed
paddy-exe opened this issue Jul 23, 2022 · 3 comments
Milestone

Comments

@paddy-exe
Copy link

Describe the project you are working on

(Visual) Shaders and VFX

Describe the problem or limitation you are having in your project

Following up on: godotengine/godot-docs#5895 and godotengine/godot-docs#5963
It takes quite longer to create the same effects in Visual Shaders as the same ones in pure shader code. As an example you could copy paste the given examples of the PRs above and have very quickly access to the world's position of the object or the camera.
Furthermore since also for example people with a pure artistic background want to have quick access to these variables they usually have to ask in e.g. the Godot's Discord community how they can access a specific variable.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Expose the following variables which can be calculated with input matrices as Visual Shader Nodes:

  • Object's world position
  • Camera's World position
  • World space direction of the camera
  • Camera's view direction to the object in view space

Disclaimer:
I have mostly experience with Spatial Shaders and would happily expand the proposal to Canvas Item Shaders if given examples can be given.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

see the above mentioned godot-docs PRs:

vec3 model_world_space = MODEL_MATRIX[3].xyz; // Object's world space position. This is the equivalent to global_transform.origin in GDScript.
mat3 model_transform_basis = mat3(MODEL_MATRIX); // Object's world space transform basis. This is the equivalent to global_transform.basis in GDScript.
vec3 camera_world_space = INV_VIEW_MATRIX[3].xyz; // Camera's world space position. This is the equivalent to camera.global_transform.origin in GDScript.
vec3 camera_eye_world_space = VIEW_MATRIX[3].xyz; // Camera eye vector in world space direction of the camera.
vec3 camera_to_object_world_space = normalize(MODEL_MATRIX[3].xyz - INV_VIEW_MATRIX[3].xyz); // Camera's direction to the object in world space.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It could be created as a Custom Visual Shader Node add-on

Is there a reason why this should be core and not an add-on in the asset library?

This is a Quality of Life improvement for the Visual Shader Editor and would be used by everyone using the visual shader editor.

@Calinou
Copy link
Member

Calinou commented Jul 23, 2022

Should these also be exposed as constants for use in text-based shaders?

@paddy-exe
Copy link
Author

@Calinou I would absolutely argue for yes!👍🏻

@paddy-exe paddy-exe changed the title Expose often-used variables derived from built-ins as seperate visual shader nodes Expose often-used variables derived from built-ins as seperate visual shader nodes/ shader constants Jul 23, 2022
@akien-mga
Copy link
Member

Implemented by godotengine/godot#63597.

@akien-mga akien-mga added this to the 4.0 milestone Aug 2, 2022
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