I allready searched half of the internet to get the idea, but i dont even know that this kind of effect or lighting or shading is called.
I dont want a smooth lighting like its built-in in unity. Instead i want a pixelated lighting for my 3D dungeon so it better fit with the pixel/retro look of the textures and 2D sprites. In addition to that i want this kind of depth/fog effect like in the picture.
Can someone tell me how to achive this kind of lighting/shading? anything would help. Thank you really much!
a simple solution would be to use a custom lighting function in your surface shader, that is used to create the banding effect.
It can be done in various ways, here are two examples:
As shown in the attached example project, just throwing away precision.
Using an additional texture that describes the falloff. A smooth gradient from white to black would be a linear falloff, but if you only use 10 colors for that white/black gradient, you would have banding. This is a nice and flexible solution, because it gives the artist very precise control of this effect. You use the NdL (Normal dot Lightdirection) to sample this texture to shade a pixel. You can take a look at the Toon Ramp example which is using this technique for a different but similar manner.
Here is a video of the example I just threw together for you. It is just something to look at and maybe it proves useful, I don’t know. It’s definitely not a fully-fledged retro dungeon solution. The download link can be found at the bottom of my post.
The idea is that the character controller moves a point light around, so you get that lighting around the player. The corridor fades to black using fog.
Here is the shader code that implements a custom lighting function to implement the banding effect. It can be found in the example project at “Assets/NewShader.shader”.
// this is the "Diffuse" shader example from
// http://docs.unity3d.com/Manual/SL-SurfaceShaderLightingExamples.html
// what has been added is the "Band" function which will cause the banding of the light
Shader "Example/Diffuse Texture" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Banding ("Banding", float) = 11
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf SimpleLambert
float _Banding;
float Band(float value)
{
return ((int)(value*(int)_Banding) / _Banding);
}
half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
half NdotL = dot (s.Normal, lightDir);
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * Band(NdotL * 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"
}
Yes, just use a depth node and multiply the result. Feel free to ask in the shadergraph section. As the thread contains outdated information for a different pipeline Unity is deprecating, I’ll lock this thread.