First look at the final effect:
Our original artwork is a 3D model:
This effect is achieved through shader:
(Shader code from foreign blogs: http://www.thomas-joncorpuz.com/blog/2014/11/30/custom-unity-2d-sprite-shader)
Shader "Custom/spritenormal" {Properties {[perrendererdata] _maintex ("Sprite Texture", 2D) = "White" {} _normalstex ("Sprite Normals", 2D) = "Bump" {} _ramp ("Shading Ramp", 2D) = "White" {} _color ("Tint", Col OR) = (1,1,1,1) [Materialtoggle] Pixelsnap ("Pixel snap", Float) = 0 _cutoff ("Alpha Cutoff", Range (0,1)) = 0.5} subshader {Tags {"Queue" = "Transparent" "ignoreprojector" = "False" "Rendertype" = "Transparent" "previewtype" = "Plane" "canusespriteatlas" = "True"} Cull off Lighting on zwrite off Fog {Mode off} Blend srcalpha Oneminussrcalpha CG Program #pragma surface surf Customlambert Alpha Vertex:vert Addshadow alphatest:_cutoff #pragma multi_comp Ile DUMMY pixelsnap_on sampler2d _maintex; Sampler2d _normalstex; Sampler2d _ramp; Fixed4 _color; struct Input {FLOAT2 Uv_maintex; FIXED4 color; }; Half4 Lightingcustomlambert (surfaceoutput s, half3 Lightdir, Half3 viewdir, half atten) {half ndotl = dot (S. Normal, Lightdir); Half4 C; C.rgb = (S.albedo * _lightcolor0.rgb * (tex2d (_ramp, HALF2 (NDOTL * 0.5 + 0.5, 0))) * (Atten * 2); C.A = S.alpha; return C; } void Vert (InOut appdata_full V, out Input o) {#if defined (pixelsnap_on) &&!d efined (shader_api_flash) V.vertex = Unitypixelsnap (V.vertex); #endif v.normal = FLOAT3 (0,0,-1); V.tangent = FLOAT4 (-1, 0, 0, 1); Unity_initialize_output (Input, O); O.color = _color * V.COLOR; } void Surf (Input in, InOut surfaceoutput o) {fixed4 c = tex2d (_maintex, In.uv_maintex) * in.co Lor O.albedo = C.rgb; O.normal = UnpackNormal (tex2d (_normalstex, In.uv_maintex)); O.alpha = C.A; } ENDCG} FallBack "Diffuse"}
The normal map required by the shader can be generated by a software: pixplant, just provide the original footage, and the software will generate a normal map.
Also requires a shadow gradient plot:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Unity2d achieve texture bump and accept real-time lighting effects