I am trying to sample the lightmap color by:
- Casting a ray and sending the results to a raycasthit
- Getting a reference to the appropriate lightmap based on the hit object’s renderer’s lightmap index
- Passing the lightmapCoord of the raycasthit to GetPixelBilinear
I know I am hitting the proper lightmap, because I show the name of the file in the inspector, and if I paint this file a uniform color (such as green), the result is green.
What I am not getting is a valid lightmapCoord.
It is negative, and if sent to Debug.Log shows (0,0).
If I multiply its XY by the texture’s width/height, the result is (-3.1, -3.1).
This is true regardless of where I move the object.
The test case is in a “clean room” with one bright red baked light. The raycast is coming from an empty gameobject, so “own hits” don’t seem to be the issue.
My research on this has come up empty, so if you’ve used this recently…