I use these 2 function to sample light map & light probe color in cg shader.
//static object light map color, will return black if lightmap not baked
DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, unityLightMapUV));
//dynamic object light probe color, will return black if lightprobes not baked
ShadeSH9(worldNormal);
when light map & light probes were baked, it works perfectly.
but the following 2 cases will result in black color
light probes not baked(not exist) → dynamic objects will be black
light map & light probes not baked → everything will be black
Question is:
Is there a way to detect if light map and light probe is baked(not rely on C#)?
I tried multi compile the shader to support these cases
The almost completely undocumented #pragma multi_compile_fwd**** lines include a bunch of keywords for lightmaps and I think 5.4 added some addition ones for light probes.
There’s no simple list of the keywords they include, but you can go through the cginc files of the built-in shader source files, or use the frame debugger to see which keywords are in use on materials in the scene. Note there isn’t do much a list of what the multi compile command expand to add you can search the files for all of the #ifdef / #ifndef / #if defined() lines.
Thankyou.
I checked from FrameDebugger and find that standard shader use the keyword “LIGHTMAP_ON”.
I checked from some cginc files, some of them also using #ifdef LIGHTMAP_ON.
LIGHTMAP_ON is a keyword controlled by Unity,
so we just need to multi compile a shader for it.
//just pick 1 and it will work
#pragma multi_compile __ LIGHTMAP_ON
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile_fwdbase
#if LIGHTMAP_ON
//do the light map sampling
#endif
Hi , I have the same issue with you , but I only need to sample light probe, So I tried it according to the above method,
and when light probes not baked(not exist) ,it works fine ,but when light probes is baked ,ShadeSH9() failed,here is my code ,could you help me see why? I am very grateful !