top of page

Shader day 3

  • Writer: Asante Azevedo
    Asante Azevedo
  • Nov 13, 2022
  • 2 min read

Today I tackled more lighting in the shader. Yesterday I added support for directional lights. Today I added support for point and spot lights. Some of the things that I learned about were using multiple passes to because of the draw calls for multiple lights. The base pass is for the main directional lights. Then an additive pass is made for each additional light in the scene. These add to the color for the shader according to the light that the draw call is rendering from. I also learned how to use identifiers to control the code for the different kind of lights. I struggled with getting the attenuation for point and spot lights correct. I hadn't properly calculated the range of the light properly. This cause the attenuation to be square instead of spherical. There wasn't a gradual fall off. After double checking my code and comparing it the example that I was following, I found the equation that I was messing up. After that, the point lights looked much better. I also learned about vertex lighting. Vertex lighting is a lot cheaper than calculating the lighting in the fragment shader. There are a lot less verts to calculate lighting for than fragments. This is what allows the shader to support more than the standard 4 that are set in Unity's pixel light count. Extra lights are are furthest away and fairly weak are rendered with vertex lighting while the closer, stronger and more important lights are calculated in the fragment shader. Tomorrow I will finally get to shadows. Hopefully in the next few days, I'll be able to make a suitable shader for the leaves. I need to move on to other parts of the game.



Comments


© 2020 by ASANTE AZEVEDO. Proudly created with Wix.com

bottom of page