I am trying to create a Shader (for debugging purposes) that will show checkerboard on any object.
However, the checkerboard must correspond to the “Lightmap Scale” parameter from the MeshRenderer component:
I can’t get my shader to work. Tried using unity_LightmapST variable, but it’s always (1,1,0,0).
This will be a ReplacementShader for the SceneView (I will use System.Reflection hack) meaning I cannot use any c# script to manually upload the value into the shader properties.
Is there a shader-keyword for this Scale-in-Lightmap, so I can scale my uv1 coordinates?
Shader "Whaleride/LightmapCheckerScieneView"
{
Properties
{
_ColorA("Color A", Color) = (1, 0.95, 0.9, 1.0)
_ColorB("Color B", Color) = (0.9, 0.85, 0.8, 1.0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv1 : TEXCOORD1;
};
struct v2f
{
float2 uv1 : TEXCOORD1;
float4 vertex : SV_POSITION;
};
fixed4 _ColorA;
fixed4 _ColorB;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv1 = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw; //not working :(
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed2 val = step(0.5f, frac(i.uv1));
fixed4 col = lerp(_ColorA, _ColorB, val.x*val.y);
return col;
}
ENDCG
}
}
}