'Scale In Lightmap' accessible from shader?

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
        }
    }
}

I believe you also need

#pragma multi_compile __ LIGHTMAP_ON

and for the gameobject to be lightmap static (which isn’t clear if it already is from your screenshot) and probably you would also need to do a bake so the values get calculated.

The good thing is, if you don’t actually want to have baked lighting, you can store the values somewhere and set them with

transform.GetComponent().lightmapScaleOffset = mySavedScaledOffset;

(although you need to do this at runtime, since Unity does not serialize these values on the renderer like it used to a few years ago)

I want to replicate the checkerboard that unity displays; Somehow they show it even if the objects weren’t baked (as long as they are static). And they manage to update this checkerboard based on “Scale In Lightmap”

Added #pragma multi_compile __ LIGHTMAP_ON but the shader still can’t get hold of that lightmap-scale parameter

How accurate to Unity’s pattern do you need this to be? Does it have to be exact?

I’m not sure what Unity does exactly, but I’m pretty sure the pattern does change when you press bake, because that’s when the atlas-ing happens, so before you actually bake what you’re being shown is not “super” meaningful.

I hope to visualize the resolution, to compare the scales of objects in my scene.
In the current mode it’s difficult to see what’s happening, everything looks semi-transparent and gray :cry: