- Home /
Need help with lighting objects.
I am currently working on a basic FPS game. The problem is that the left side of the gun while looking at it in first person mode is brighter than the right side of it due to my directional lighting. I know how to use layers and all that to make light only affect certain objects, but I was looking for lighting similar to the environment lighting available in Blender, so that every face on the gun is equally lit. Is there a way to do this in Unity?
Answer by Vladimir-Shafran · Aug 13, 2014 at 12:24 PM
You can create a special shader for your gun like in Half-Life. This model of lighting is called Half Lambert.
Shader "Custom/NewShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf BasicDiffuse
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
inline float4 LightingBasicDiffuse(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
float difLight = dot(s.Normal, lightDir);
float hLambert = difLight * 0.5 + 0.5;
float4 col;
col.rgb = s.Albedo * _LightColor0.rgb * (hLambert * atten * 2);
col.a = s.Alpha;
return col;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
When you will change value of hLambert parameter, you will see how lighting will be pass through object. When
hLambert = 1
lighting will be identical for both side
Before
hLambert = 1
Thanks for the reply, but I'm not entirely sure how to go about making a shader. Can you explain it or should I just search for tutorials online (I'm O$$anonymous$$ with either)?
As I understood you have problem with lighting 3D weapon. Your weapon contains a material. You can create a new shader which will be similar with $$anonymous$$e. And add this shader to your weapon’s material. Thats all.
Your answer
Follow this Question
Related Questions
Lighting seams between objects 0 Answers
World object in front of GUI object 3 Answers
1stPersonController bigger than World. HELP PLS :( 3 Answers
Make multiple duplicated consecutive objects look like one 0 Answers
Light falling on whole object, instead in prescribed angle of spot light, how to fix it? 0 Answers