#How to get a light value in a fragment

1 messages · Page 1 of 1 (latest)

iron dove
#

Greetings ! Noob with Godot here, I wanted to have a shader that would do two things :

  1. map the color of the fragment to the closest color in my palette
  2. using the amount of light the fragment gets to determine what shading color I want

What I figured out so far :

  1. Since my game is in 3D I want a spatial shader
  2. I can get the original color of the fragment so mapping this to my palette is easy

What I am not sure about :

  1. How can I apply this to my whole screen not to a specific object ? Right now I do this by having a big mesh right in front of the camera and the shader applied to it as a material
  2. Can I do everything in the fragment function ?

What I dont know :

  1. How can I get the light information and apply it to get the proper shading ? I get that there is a light function that I could override but I am fine with the default light function. So how can I just use the result of the light function once it has been applied for every light on this fragment ?

The goal is to achieve something similar to what I do here with libGDX but I do all that in software

iron dove
#

Bump !

past berry
#

Since nobody answered, I'll try to tell you something you don't already know. I'm not proficient with shaders, you'll likely know better than I. But sometimes the best way to get a response is to say something wrong or stupd 😉

So...

  • You can use a subviewport + subviewport container to apply a shader to the whole screen. I believe that would work well for colour manipulation, but not if the fragment light needs to be considered
  • You can accumulate light effects by adding them to DIFFUSE_LIGHT (https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/spatial_shader.html#light-built-ins), assuming that is per fragment and the initial value is 0, but dunno. I also don't know how to map the accumulated value to a [0, 1] range (maybe you can find the maximum via experimentation).

That's all I got ¯_(ツ)_/¯