日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Unity2D实现贴图凹凸感并接受实时光照效果

發布時間:2024/1/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity2D实现贴图凹凸感并接受实时光照效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先看終于效果:


我們的原圖是一個3D模型的截圖:



這一效果是通過Shader實現的:

(Shader代碼來自國外博客: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", Color) = (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 OffLighting OnZWrite OffFog { Mode Off }Blend SrcAlpha OneMinusSrcAlphaCGPROGRAM#pragma surface surf CustomLambert alpha vertex:vert addshadow alphatest:_Cutoff #pragma multi_compile DUMMY PIXELSNAP_ONsampler2D _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) && !defined(SHADER_API_FLASH)v.vertex = UnityPixelSnap (v.vertex);#endifv.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.color;o.Albedo = c.rgb;o.Normal = UnpackNormal (tex2D (_NormalsTex, IN.uv_MainTex));o.Alpha = c.a;}ENDCG} FallBack "Diffuse" }Shader須要的法線貼圖能夠通過一個軟件:PixPlant生成出來,僅僅需提供原素材圖。這個軟件就能生成一個法線貼圖了。

此外還須要一張陰影梯度圖:


總結

以上是生活随笔為你收集整理的Unity2D实现贴图凹凸感并接受实时光照效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。