- Home /
How to access all the lights in a scene in custom shader?
I'm writing my own vertex/fragment shader in Unity 5 and I'm a little confused about these built-in shader variables.
According to http://docs.unity3d.com/Manual/SL-UnityShaderVariables.html If I am using Forward Rendering Path with LightMode = ForwardBase, I should be able to access:
The most important light through _WorldSpaceLightPos0 which can be either directional or point light by looking at its alpha/w channel
The first 4 non-important point lights through a series of variables with unity_ prefix like unity_4LightPosX0 etc. (And there's a built-in function called Shade4PointLights to use them properly)
I've also read this http://docs.unity3d.com/Manual/RenderTech-ForwardRendering.html It said Base Pass handles the most important directional light and SH-lights, Additional Passes handle rest of the lights. So how do that apply to custom shader? In my case, I want to handle all the lights in one(Base) pass.
If there are way more lights in my test scene, how do I access all the lights in my shader?
There are 4 directional lights and 30~40 point lights in my test scene, all of them are set to Auto and Baked because I want my shader to support a scene without Lightmap and it is still shaded properly, then if I click Build Lightmap I can see the GI result immediately without changing materials/shaders.
Your answer
Follow this Question
Related Questions
U5 shader coming out solid black on newer iOS devices (iPad 2 Air / iPhone 6) 1 Answer
GrabPass and Transparent geometry 0 Answers
Emissive materials in urp 2 Answers
"Fading in" a Normal Map 2 Answers