Hey, guys. I’m trying to write a custom shader that reads and displays lightmaps generated in Unity. The shader is almost working but I still need to access the light map texture matrix in the shader to get correct lightmap UVs.I know I need this because currently the UVs are not entirely correct, but if I manually copy the offset and tilling from the lightmapping->object>atlas to the material texture properties in the inspector the UVs become fine. So, how can I make Unity feed the shader with the appropriate lightmap texture matrices?
As you can see in the code, I’m already applying the texture matrix of the light map to the UVs with “o.uv2 = TRANSFORM_TEX (v.texcoord1, _LightMap);” but it has no effect, it seems that the matrix is empty.
I believe shader bindings are not necessary when you use a Cg shader.
Nevertheless, the UV2 is feed correctly because I can render the lightmaps if I feed the texture matrix by hand. So, now I only need that matrix to be fed correctly.
However, I am trying to realize the same effect as a fixed function effect, but have troubles with the texture coordinates of the lightmap again.
This is what my code looks like:
Any ideas on how to solve that would be really great!
Is it possible to set the texture transformation matrix directly from within the .shader file?
Like: matrix (unity_LightmapST.x, 0.0, 0.0, unity_LightmapST.z, 0.0, unity_LightmapST.y, 0.0, unity_LightmapST.w, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0) How to do something like this correctly, or doesn´t it work at all?
(Diggin up an old post but this is really relevant.)
I’m doing the same thing, using the lightmaps only as ambient occlusion. It works great when there’s baked lighting but when it isn’t the lightmap texture obviously doesn’t exist. And it doesn’t look good. What I want to do is use the LIGHTMAP_ON ifdef to detect if there are lightmaps for this object but since #pragma nolightmap sets every pass to LIGHTMAP_OFF I can’t.
Does any of you know how I can detect if there are lightmaps for an object and only apply them if they exists?