Godot 4 Visual Shader Fragment / light inputs => vise versa
Asked Answered
T

8

0

hey there ! : )

I have a question for any godot 4 visual shader specialist.
i'm experimenting non-realistic rendering and i do have fun with the visual shader, the potential is great.
Coming from Unity , i do have a question about the fragment and lights inputs.

Is it possible to find a way to bring inputs from light to fragment and vise-versa ( like the light and attenuation inputs ) , or the screen_uv from convas_item etc ? with the expression node ?
or it's lock for shaders logic compilation ? i'm not a specialist, but in unity shader graph the non-separation of the light/vertex and fragment was very usefull in many ways.

Ton answered 17/9, 2023 at 18:33 Comment(0)
L
1

You can add varyings from fragment shader to light shader. I don't think going the other way is possible, because (IIRC) light shader runs after fragment shader.

Also, both fragment shader and light shader have access to ScreenUV input.

Lindbom answered 17/9, 2023 at 18:41 Comment(0)
T
0

Lindbom
i see, i have to find another logic a guess to create a full unlit non realistic shader, with a kind a screen position UV projection etc, not so easy with the light and fragment separation. ( i don't want to do this in a full screen shader since i need a full material by material control )
If i found a way, i will share it : ) thanks a lot for your answer !

Ton answered 17/9, 2023 at 19:51 Comment(0)
A
1

Ton You can pass several floats worth of data from fragment to light shader using built ins like ALBEDO, METALLIC and ROUGHNESS that can be written in fragment shader and read in light shader. Passing from vertex to light is done regularly via varyings.

Airless answered 17/9, 2023 at 21:24 Comment(0)
T
0

Airless thanks ! how by writing an expression ? i'm interested if you have an exemple .

Ton answered 17/9, 2023 at 21:49 Comment(0)
A
1

Ton Hm, although it's possible to do what I said above it won't be of much use if you need to fully control the color of the final pixel. Sadly the light shader can't do that. I guess your best bet is to do everything in the fragment shader. You'll have to manually pass all the light data via uniforms though.

The other, maybe better approach would be to render in two passes with two shaders. Let the first pass render only the lighting information and then the second pass can access it in the fragment shader by reading from the screen texture.

Airless answered 17/9, 2023 at 22:38 Comment(0)
T
0

Airless thanks again for your time on this ! 🙂 will try all the ways to get what i need.

Ton answered 17/9, 2023 at 23:12 Comment(0)
A
1

My second suggestion is probably the way to go. I made a quick test and it works fine:

On the left is just the light pass shader. On the right there are both passes. The second pass here just remaps the first one with a color gradient in an unshaded fragment shader.

Airless answered 17/9, 2023 at 23:16 Comment(0)
T
0

Airless i see ! i will experiment that thanks again ! 🙂

Ton answered 18/9, 2023 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.