這篇文章主要介紹“unityshader怎么實現(xiàn)光照效果”,在日常操作中,相信很多人在unityshader怎么實現(xiàn)光照效果問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”unityshader怎么實現(xiàn)光照效果”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
創(chuàng)新互聯(lián)公司專注于肥西網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供肥西營銷型網(wǎng)站建設,肥西網(wǎng)站制作、肥西網(wǎng)頁設計、肥西網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務,打造肥西網(wǎng)絡公司原創(chuàng)品牌,更為您提供肥西網(wǎng)站排名全網(wǎng)營銷落地服務。本文實例為大家分享了unity shader實現(xiàn)光照效果的具體代碼,供大家參考,具體內(nèi)容如下
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'Shader "Unlit/lightFull"{ Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { Tags{"LightMode" = "ForwardBase"} CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fwdbase #include "UnityCG.cginc" #include "Lighting.cginc" #include "AutoLight.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; float3 normal : NORMAL; }; struct v2f { float2 uv : TEXCOORD0; float4 pos : POSITION; float4 pos_world : TEXCOORD1; float3 normal:TEXCOORD2; SHADOW_COORDS(3) }; sampler2D _MainTex; float4 _MainTex_ST; v2f vert (appdata v) { v2f o; o.pos_world = mul(UNITY_MATRIX_M, v.vertex); o.normal = v.normal; o.pos = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); TRANSFER_SHADOW(o); return o; } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv); float4 lightColor = _LightColor0; float3 lightDir = WorldSpaceLightDir(i.pos_world); UNITY_LIGHT_ATTENUATION(atten, i, i.pos_world.xyz); return col * lightColor * saturate(dot(lightDir, i.normal)) * atten; } ENDCG } pass { Tags{"LightMode" = "ForwardAdd"} Blend One One CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fwdadd_fullshadows #include "UnityCG.cginc" #include "Lighting.cginc" #include "AutoLight.cginc" struct v2f { float4 pos : POSITION; float4 vertex : TEXCOORD0; float3 normal : NORMAL; SHADOW_COORDS(2) }; v2f vert(appdata_full data) { v2f v; v.pos = UnityObjectToClipPos(data.vertex); v.vertex = mul(UNITY_MATRIX_M, data.vertex); v.normal = data.normal; TRANSFER_SHADOW(v); return v; } float4 frag(v2f v) :SV_Target { float3 lightColor = _LightColor0;#ifdef USING_DIRECTIONAL_LIGHT float3 lightDir = _WorldSpaceLightPos0;#else float3 lightDir = _WorldSpaceLightPos0 - v.vertex;#endif UNITY_LIGHT_ATTENUATION(atten, v, v.vertex.xyz); float3 color = lightColor * saturate(dot(lightDir, v.normal) * atten); return float4(color, 1); } ENDCG } } Fallback "Specular"}
到此,關于“unityshader怎么實現(xiàn)光照效果”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
網(wǎng)站標題:unityshader怎么實現(xiàn)光照效果-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://weahome.cn/article/dsdoge.html