Exemplo n.º 1
0
        RGBExp32[] ReadHDRLighting()
        {
            br.BaseStream.Seek(header.lumps [SourceBSPStructs.LUMP_LIGHTING_HDR].fileofs, SeekOrigin.Begin);
            int lmapCount = header.lumps[SourceBSPStructs.LUMP_LIGHTING_HDR].filelen / 4;

            Debug.Log("HDR Lightmap lump size: " + header.lumps[SourceBSPStructs.LUMP_LIGHTING_HDR].filelen);

            if (lmapCount == 0)
            {
                hasLightmaps = false;
                Debug.Log("Map haven't hdr lightmaps");
                return(ReadHDRLighting());
            }
            hasLightmaps = true;

            RGBExp32[] temp = new RGBExp32[lmapCount];

            for (int i = 0; i < lmapCount; i++)
            {
                RGBExp32 col = new RGBExp32();
                col.r   = br.ReadByte();
                col.g   = br.ReadByte();
                col.b   = br.ReadByte();
                col.exp = br.ReadSByte();
                temp[i] = col;
            }

            return(temp);
        }
Exemplo n.º 2
0
        Texture2D CreateLightmapTex(face f)
        {
            int       rowColors = f.lightMapW;
            Texture2D tex       = new Texture2D(f.lightMapW, f.lightMapH, TextureFormat.RGB24, false, true);

            //tex.filterMode = FilterMode.Point;
            //Color32[] colors32 = new Color32[(f.lightMapW) * (f.lightMapH)];
            Color[] colors = new Color[(f.lightMapW) * (f.lightMapH)];

            int Offset = map.facesLump [f.index].lightofs / 4;

            if (map.facesLump [f.index].lightofs < 0 | map.lightingLump.Length == 0)
            {
                return(null);
            }

            int o = 0;
            int j = 0;

            for (int y = 0; y < f.lightMapH; y++)
            {
                o = (rowColors * (y));
                for (int x = 0; x < f.lightMapW; x++)
                {
                    RGBExp32 col = map.lightingLump[Offset + j++];

                    /*colors32[o] = new Color32(TexLightToLinearB(col.r, col.exp),
                     *                                              TexLightToLinearB(col.g, col.exp),
                     *                                              TexLightToLinearB(col.b, col.exp),
                     *                                                         255);*/
                    float exp = (float)Mathf.Pow(2, col.exp);
                    colors[o] = new Color(TexLightToLinearF(col.r, exp),
                                          TexLightToLinearF(col.g, exp),
                                          TexLightToLinearF(col.b, exp),
                                          1f);

                    o++;
                }
            }
            //=======fill borders================

            /*
             * for(int y=0; y<f.lightMapH+1;y++)
             * {
             *      o=rowColors * y;
             *      colors[o] = colors[o+1];
             *
             *      o=(rowColors * (y+1))-1;
             *      colors[o] = colors[o-1];
             * }
             *
             * int end=(f.lightMapW+2)*(f.lightMapH+2);
             * for(int x=0; x<f.lightMapW+2;x++)
             * {
             *      colors[x] = colors[x+rowColors];
             *      colors[(end-rowColors)+x] = colors[(end-(rowColors*2)+x)];
             * }
             */
            //=====================================

            //tex.SetPixels32 (colors32);
            tex.SetPixels(colors);
            tex.Apply();
            return(tex);
        }