Unity2d achieve texture bump and accept real-time lighting effects

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.