- Home /
Cheap options for making diffuse-lit objects "interesting"
Question for you shader/lighting/efficiency experts:
Take a look at this scene - it has a single directional light: https://twitter.com/AeornFlippout/status/300133754565976064/photo/1
I like the dramatic contrast on those cubes, but the one thing I don't like is that the faces opposite to and parallel to the light all have exactly the same shade. I realize this is "realistic" for a diffuse shader, but I want just a bit of variance so I can pick out the shapes a little bit better when looking at them. We also have some faceted, roughly spherical shapes, and have the same issue. Basically the whole game is looking at objects from the backsides as you fly past them, and we just want a bit more definition.
Can anyone suggest a cheap way to achieve something like this? We can add a 2nd light to the scene pointing in the opposite direction, but our goal is 60fps on tablets, and I'm worried about performance. The other idea I thought of is some kind of a fresnel shader.
But I wonder if there's something like a diffuse-type lighting shader that breaks the rules a bit and adds some lighting gradient even on the backfaces, perhaps just very slightly increasing light values as the faces face more and more away from the light?
Generally speaking, would it be cheaper to come up with some kind of shader solution, or to add a 2nd light to the scene? Or maybe there's an even cheaper method I'm not thinking of.
I'm open to suggestions!
How about going to Edit/Render Settings and giving the scene a bit of Ambient Light?
We do have some ambient light in the scene, but it adds equally to all surfaces so doesn't really solve our problem...
How about trying to make a "diffuse" texture, that makes it seem a bit more interesting (a little gradient effect maybe?)
Answer by electricsauce · Feb 18, 2013 at 04:34 AM
Try the Unity diffuse wrapped shader. It adds a little lighting to the sides of an object. http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLightingExamples.html
Shader "Example/Diffuse Wrapped" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf WrapLambert
half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
half NdotL = dot (s.Normal, lightDir);
half diff = NdotL * 0.5 + 0.5;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
c.a = s.Alpha;
return c;
}
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
}
Fallback "Diffuse"
}