For my mobile app, I use 2 opaque shaders.
Lightmapped:
Shader "Parabole/Unlit/Opaque"
{
Properties
{
_MainTex ("Base", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "BW"="True" }
Pass
{
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile LIGHTMAP_ON LIGHTMAP_OFF
struct v2f{
//half4 color : COLOR;
float4 pos : SV_POSITION;
fixed2 uv[2] : TEXCOORD0;
};
sampler2D _MainTex;
fixed4 _MainTex_ST;
#ifdef LIGHTMAP_ON
fixed4 unity_LightmapST;
sampler2D unity_Lightmap;
#endif
v2f vert(appdata_full v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv[0] = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON
o.uv[1] = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
//o.color = v.color;
return o;
}
fixed4 frag(v2f i) : COLOR
{
fixed4 c = tex2D(_MainTex, i.uv[0]);// * i.color;
#ifdef LIGHTMAP_ON
c.rgb *= DecodeLightmap(tex2D(unity_Lightmap, i.uv[1]));
#endif
return c;
}
ENDCG
}
}
fallback "Mobile/Unlit (Supports Lightmap)"
}
and Light Probed:
Shader "Parabole/Light Probes/Opaque"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
}
Subshader
{
Tags { "RenderType"="Opaque" "BW"="TrueProbes"}
Fog { Mode Off }
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct v2f
{
fixed4 pos : SV_POSITION;
fixed2 uv : TEXCOORD0;
fixed3 vlight : TEXCOORD1;
};
fixed4 _MainTex_ST;
v2f vert (appdata_full v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
fixed3 worldN = mul((float3x3)_Object2World, SCALED_NORMAL);
o.vlight = ShadeSH9 (float4(worldN,1.0));
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : COLOR
{
fixed4 c = tex2D(_MainTex,i.uv);
c.rgb *= i.vlight;
return c;
}
ENDCG
}
}
}
My artist colleague would like me to mix those shaders in a single one. Is there a way to detect the Use Light Probes option, either with a precompiler definition like the #ifdef LIGHTMAP_ON in my lightmapped shader, or with a tag I could use to differentiate 2 different passes? The only option I can see is to use a #else after my #ifdef LIGHTMAP_ON, but it will work if there's no lightmap, not if the probes are on. Any clue would be appreciated.
↧






