- Home /
Question by
Velorexe · Oct 30, 2021 at 03:32 PM ·
lightingshadersgeometry shadervertex-lighting
unity_LightColor[1] and up are 0 with 2 point lights near the object.
I'm writing a geometry shader, with which I'm trying to add support for lights other than the Directional Light in my scene. With the help of this tutorial on how to add support for multiple lights to a shader, I've managed to add one point light to the shader, though when I add a second one only the one which is the brightest will show. I've narrowed down the problem to that only unity_LightColor[0]
contains the correct RGB values for the light, yet any index above this will be empty.
#ifdef VERTEXLIGHT_ON
o.vertexLighting = float3(0.0, 0.0, 0.0);
for (int index = 0; index < 4; index++)
{
float4 lightPosition = float4(unity_4LightPosX0[index],
unity_4LightPosY0[index],
unity_4LightPosZ0[index], 1.0);
float3 vertexToLightSource = lightPosition.xyz - o.world.xyz;
float3 lightDirection = normalize(vertexToLightSource);
float squaredDistance = dot(vertexToLightSource, vertexToLightSource);
float attenuation = 1.0 / (1.0 + unity_4LightAtten0[index] * squaredDistance);
float3 diffuseReflection = attenuation
* unity_LightColor[index].rgb * max(0.0, dot(lerp(o.normal, -normalize(o.world.xyz - lightPosition.xyz), _TranslucentGain), lightDirection));
o.vertexLighting = o.vertexLighting + diffuseReflection;
}
#endif
This is the code that I'm using to calculate the light in the vertex pass. Any help would be appreciated!
Comment