Unity_lightmap texelsize

How do I get the size of the lightmap in pixels in the shader? I tried using “unity_Lightmap_TexelSize”, but as I expected, I got an empty variable as a result.

I found that the following function can be used to calculate texture resolution in Shader Model 4.0 and higher:

half2 WidthHeight = 0;
half NumberOfLevels = 0;
unity_Lightmap.GetDimensions(0, WidthHeight.x, WidthHeight.y, NumberOfLevels);

Maybe it will help someone.

2 Likes