VertexLit path中读取lightProbe烘焙信息:
Shader "VertexLitProbe" { Properties { _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}//主贴图 } SubShader { LOD 100 Pass { Tags { "LightMode" = "VertexLit" } CGPROGRAM #pragma vertex vert #pragma fragment frag //#pragma target 3.0 #include "UnityCG.cginc" #include "Lighting.cginc" struct appdata_t { float4 vertex : POSITION; float3 normal : NORMAL; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; float3 wroldN : TEXCOORD01; half2 texcoord : TEXCOORD0; }; float4 _MainTex_ST; sampler2D _MainTex; v2f vert (appdata_t v) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.wroldN = mul((float3x3)_Object2World, v.normal); o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); return o; } fixed4 frag (v2f i) : SV_Target { fixed4 mainCol = tex2D(_MainTex, i.texcoord); mainCol.rgb = mainCol.rgb * ShadeSH9(half4(i.wroldN,1.0)); return mainCol; } ENDCG } } }
效果如下图:
Ps:unity 自带的diffuse(surface shader)中有在forwardBass pass中处理SH9,但是自带的VertexLit(cg)中没有,所以使用自带shader时,只有在forward pass中在能使用LightProbe,但是可以自己写
可以在surface shader中关闭:
时间: 2024-10-13 11:35:34