コード例 #1
0
    /// <summary>
    /// 烘焙环境信息到指定RenderTextrue
    /// </summary>
    /// <param name="terrain"></param>
    /// <param name="size"></param>
    /// <returns></returns>
    public static int Bake(LODTerrain terrain, int size = 512)
    {
        RenderTexture renderTexture = null;
        int           num           = -1;

        for (int i = 0; i < Terrainmapping.mapIndex.Count; i++)
        {
            if (Terrainmapping.mapIndex[i] < 0)
            {
                num           = i;
                renderTexture = Terrainmapping.maps[i];
                Terrainmapping.mapIndex[i] = num;
                break;
            }
        }
        if (renderTexture != null)
        {
            Terrainmapping.CreateObjects();
            Terrainmapping.UpdateCameraModes();
            Terrainmapping.rttCamera.gameObject.SetActive(true);
            Terrainmapping.rttCamera.enabled                  = true;
            Terrainmapping.sntMat                             = terrain.matrial;
            Terrainmapping.quad.renderer.lightmapIndex        = terrain.renderer.lightmapIndex;
            Terrainmapping.quad.renderer.lightmapTilingOffset = terrain.renderer.lightmapTilingOffset;
            Terrainmapping.quad.renderer.material             = Terrainmapping.sntMat;
            Terrainmapping.rttCamera.targetTexture            = renderTexture;
            RenderTexture.active = renderTexture;
            Terrainmapping.rttCamera.Render();
            Terrainmapping.rttCamera.gameObject.SetActive(false);
            RenderTexture.active = null;
            Terrainmapping.quad.renderer.material = null;
            Terrainmapping.sntMat = null;
        }
        return(num);
    }
コード例 #2
0
 /// <summary>
 /// 取消烘焙材质,使用原始材质渲染
 /// </summary>
 public void CancelBake()
 {
     if (this.terrainMapIndex >= 0)
     {
         Terrainmapping.Cancel(this.terrainMapIndex);
         base.renderer.material = this.matrial;
         this.terrainMapIndex   = -1;
     }
 }
コード例 #3
0
 /// <summary>
 /// 烘焙得到的环境渲染RenderTexture作为地形贴图的主纹理
 /// </summary>
 public void Bake()
 {
     this.terrainMapIndex = Terrainmapping.Bake(this, 1024);
     if (this.terrainMapIndex > -1)
     {
         this.bakeMat = new Material(this.bakeShader);
         this.bakeMat.SetTexture("_MainTex", Terrainmapping.maps[this.terrainMapIndex]);
         base.renderer.material = this.bakeMat;
     }
 }