void makeText3d()
    {
        //这里用9张图 可以压缩到7张 7个float4 够存入27

        Dictionary <int, int> posIndexs = new Dictionary <int, int>();

        for (int i = 0; i < LightmapSettings.lightProbes.positions.Length; i++)
        {
            var pos = LightmapSettings.lightProbes.positions[i] / cellSize;

            int index = ((int)pos.y) * cellX * cellZ + ((int)pos.z) * cellX + (int)pos.x;
            posIndexs[index] = i;
        }

        print(LightmapSettings.lightProbes.positions.Length);
        //  print(LightmapSettings.lightProbes.coefficients[0]);
        volumeGI            = new Texture3D(cellX, cellZ, cellY * 7, TextureFormat.RGBAFloat, false);
        volumeGI.filterMode = FilterMode.Trilinear;
        Color[] data          = new Color[cellX * cellZ * cellY * 7];
        int     shWriteOffset = cellX * cellZ * cellY;

        for (int y = 0; y < cellY; y++)
        {
            for (int z = 0; z < cellZ; z++)
            {
                for (int x = 0; x < cellX; x++)
                {
                    int index = y * cellX * cellZ + z * cellX + x;
                    if (posIndexs.ContainsKey(index) == false)
                    {
                        print(index + " not found");
                    }
                    int       shIndex = posIndexs[index];
                    var       sh      = LightmapSettings.lightProbes.bakedProbes[shIndex];
                    Vector4[] shdata  = new Vector4[7];

                    LightProbeMake.GetShaderConstantsFromNormalizedSH(sh, out shdata);

                    for (int i = 0; i < 7; i++)
                    {
                        //shdata[i] = shdata[i] * 1.1f+Vector4.one*0.1f;

//
                        print(shdata[i]);
                    }



                    // 如果贴图格式不支持负数 需要转到0-1
                    for (int i = 0; i < 7; i++)
                    {
                        data[index + shWriteOffset * (i)] = new Color(shdata[i].x, shdata[i].y, shdata[i].z, shdata[i].w);
                    }
                }
            }
        }
        volumeGI.SetPixels(data);
        volumeGI.Apply();
        Shader.SetGlobalTexture("_VolumeGITex", volumeGI);
    }
Exemple #2
0
    // Use this for initialization
    void OnEnable()
    {
        SHEncoding shEncoding = new SHEncoding();

        shEncoding.clearToBlack();
        Vector4[] shdata = new Vector4[7];
        var       sh     = LightmapSettings.lightProbes.bakedProbes[3];

        //  GetShaderConstantsFromNormalizedSH(sh, out shdata);
//		for (int i = 0; i < 7; i++)
//		{
//			shdata[i] = new Vector4(LightProbeMake.getFloatFromSH(sh, i*4),LightProbeMake.getFloatFromSH(sh, i*4+1),
//				LightProbeMake.getFloatFromSH(sh, i*4+2),LightProbeMake.getFloatFromSH(sh, i*4+3));
//		}
        LightProbeMake.GetShaderConstantsFromNormalizedSH(sh, out shdata);
        for (int i = 0; i < 7; i++)
        {
            shdata[i] = shdata[i] * 1.1f + Vector4.one * 0.1f;
//
            print(shdata[i]);
        }
//
//		{
//			shEncoding.c[i]=LightProbeMake.getFloatFromSH(sh, i);
//		}
//		shEncoding.copyToBuffer();
//
//		for(uint i = 0; i < 9; ++i) {
//			Shader.SetGlobalVector("_SH" + i, shEncoding.cBuffer[i]);
//		}
        for (int i = 0; i < LightmapSettings.lightProbes.positions.Length; i++)
        {
            print(i + ":" + LightmapSettings.lightProbes.positions[i]);
        }
        Shader.SetGlobalVectorArray("TestSHData", shdata);
    }