示例#1
0
        public void DrawBiomePreview()
        {
            if (m_drawPreview)
            {
                //Set up a multi-terrain operation once, all rules can then draw from the data collected here
                Terrain currentTerrain = GetCurrentTerrain();
                if (currentTerrain == null)
                {
                    return;
                }

                GaiaMultiTerrainOperation operation = new GaiaMultiTerrainOperation(currentTerrain, transform, m_settings.m_range * 2f);
                operation.GetHeightmap();


                //only re-generate all textures etc. if settings have changed and the preview is dirty, otherwise we can just use the cached textures
                if (m_biomePreviewDirty == true)
                {
                    //Get additional op data (required for certain image masks)
                    operation.GetNormalmap();
                    operation.CollectTerrainBakedMasks();

                    //Clear texture cache first
                    if (m_cachedPreviewRT != null)
                    {
                        m_cachedPreviewRT.Release();
                        DestroyImmediate(m_cachedPreviewRT);
                    }

                    m_cachedPreviewRT = new RenderTexture(operation.RTheightmap);
                    RenderTexture currentRT = RenderTexture.active;
                    RenderTexture.active = m_cachedPreviewRT;
                    GL.Clear(true, true, Color.black);
                    RenderTexture.active = currentRT;

                    Graphics.Blit(ApplyBrush(operation), m_cachedPreviewRT);
                    RenderTexture.active = currentRT;
                    //Everything processed, preview not dirty anymore
                    m_biomePreviewDirty = false;
                }

                //Now draw the preview according to the cached textures
                Material material = GaiaMultiTerrainOperation.GetDefaultGaiaSpawnerPreviewMaterial();
                material.SetInt("_zTestMode", (int)UnityEngine.Rendering.CompareFunction.Always);

                //assign the first color texture in the material
                material.SetTexture("_colorTexture0", m_cachedPreviewRT);

                //remove all other potential color textures, there can be caching issues if other visualisers were used in the meantime

                for (int colorIndex = 1; colorIndex < GaiaConstants.maxPreviewedTextures; colorIndex++)
                {
                    material.SetTexture("_colorTexture" + colorIndex, null);
                }



                //set the color
                material.SetColor("_previewColor0", m_settings.m_visualisationColor);

                Color seaLevelColor = GaiaSettings.m_stamperSeaLevelTintColor;
                if (!m_showSeaLevelinPreview)
                {
                    seaLevelColor.a = 0f;
                }
                material.SetColor("_seaLevelTintColor", seaLevelColor);
                material.SetFloat("_seaLevel", SessionManager.m_session.m_seaLevel);
                operation.Visualize(MultiTerrainOperationType.Heightmap, operation.RTheightmap, material, 1);

                //Clean up
                operation.CloseOperation();
                //Clean up temp textures
                GaiaUtils.ReleaseAllTempRenderTextures();
            }
        }