Ayfel / PrefabLightmapping

Script for saving lightmapping data to prefabs. Used through the Assets tab in Unity. Place your prefbas in the scene with this script at the root. Set up your lighting and in the editor go to Assets->Bake Prefab Lightmaps. After is processed you can now spawn your prefabs in different scenes and they will use the lightmapping from the original scene.
618 stars 88 forks source link

PrefabLightmapData (script) sets all material custom render queues to -1 #45

Closed jaspervandenbarg closed 2 years ago

jaspervandenbarg commented 2 years ago

As the titles states.

The scripts sets all the custom render queues of the materials on the child objects to -1. This cause my materials to render improperly.

Normally opaque materials will render on queue/layer 2000 and transparent materials on queue/layer 3000.

Because they all get set to layer -1 the transparent materials dissapear.

jaspervandenbarg commented 2 years ago

I solved the problem by commenting out the following:

static void ApplyRendererInfo(RendererInfo[] infos, int[] lightmapOffsetIndex, LightInfo[] lightsInfo)
    {
        for (int i = 0; i < infos.Length; i++)
        {
            var info = infos[i];

            info.renderer.lightmapIndex = lightmapOffsetIndex[info.lightmapIndex];
            info.renderer.lightmapScaleOffset = info.lightmapOffsetScale;

            // You have to release shaders.
            //Material[] mat = info.renderer.sharedMaterials;
            //for (int j = 0; j < mat.Length; j++)
            //{
            //    if (mat[j] != null && Shader.Find(mat[j].shader.name) != null)
            //        mat[j].shader = Shader.Find(mat[j].shader.name);
            //}
        }
Ayfel commented 2 years ago

Yes, I was going to mention that, the shader "release" is there for some issues that were found on some versions/builds/bundles