Ejemplo n.º 1
0
        private void SetupAlbedoMetallicSmoothnessPreview(GStylizedTerrain t)
        {
            Material mat = t.TerrainData.Shading.MaterialToRender;

            if (mat == null)
            {
                return;
            }
            int           albedoResolution = t.TerrainData.Shading.AlbedoMapResolution;
            RenderTexture previewAlbedo    = GetPreviewTexture(t, "albedo", albedoResolution, t.TerrainData.Shading.AlbedoMap.filterMode);

            GCommon.ClearRT(previewAlbedo);

            int           metallicResolution = t.TerrainData.Shading.MetallicMapResolution;
            RenderTexture previewMetallic    = GetPreviewTexture(t, "metallic", metallicResolution, t.TerrainData.Shading.MetallicMap.filterMode);

            GCommon.ClearRT(previewMetallic);
            instance.Internal_ApplyAlbedoMetallicSmoothness(t, previewAlbedo, previewMetallic);

            //previewPropertyBlock.Clear();
            //if (!string.IsNullOrEmpty(t.TerrainData.Shading.AlbedoMapPropertyName))
            //{
            //    previewPropertyBlock.SetTexture(t.TerrainData.Shading.AlbedoMapPropertyName, previewAlbedo);
            //}
            //if (!string.IsNullOrEmpty(t.TerrainData.Shading.MetallicMapPropertyName))
            //{
            //    previewPropertyBlock.SetTexture(t.TerrainData.Shading.MetallicMapPropertyName, previewMetallic);
            //}
        }
Ejemplo n.º 2
0
        private void SetupSplatPreview(GStylizedTerrain t)
        {
            Material mat = t.TerrainData.Shading.MaterialToRender;

            if (mat == null)
            {
                return;
            }
            int controlMapResolution = t.TerrainData.Shading.SplatControlResolution;
            int controlMapCount      = t.TerrainData.Shading.SplatControlMapCount;

            if (controlMapCount == 0)
            {
                return;
            }
            RenderTexture[] rtControls = new RenderTexture[controlMapCount];
            for (int i = 0; i < controlMapCount; ++i)
            {
                Texture2D splatControl = t.TerrainData.Shading.GetSplatControl(i);
                rtControls[i] = GetPreviewTexture(t, "splatControl" + i, controlMapResolution, splatControl.filterMode);
                GCommon.ClearRT(rtControls[i]);
            }
            instance.Internal_ApplySplat(t, rtControls);
            previewPropertyBlock.Clear();
            //for (int i = 0; i < controlMapCount; ++i)
            //{
            //    if (!string.IsNullOrEmpty(t.TerrainData.Shading.SplatControlMapPropertyName))
            //    {
            //        previewPropertyBlock.SetTexture(t.TerrainData.Shading.SplatControlMapPropertyName + i, rtControls[i]);
            //    }
            //}
        }
        public void Internal_Apply(GStylizedTerrain t, RenderTexture rt, List <Vector4> vertices)
        {
            GCommon.ClearRT(rt);
            Material mat = GInternalMaterials.FoliageRemoverMaterial;

            mat.SetTexture("_Falloff", falloffTexture);
            mat.SetTexture("_FalloffNoise", FalloffNoise);
            mat.SetTextureScale("_FalloffNoise", new Vector2(
                                    FalloffNoiseSize.x != 0 ? 1f / FalloffNoiseSize.x : 0,
                                    FalloffNoiseSize.y != 0 ? 1f / FalloffNoiseSize.y : 0));
            mat.SetTextureOffset("_FalloffNoise", Vector2.zero);
            int pass = 0;

            DrawOnTexture(rt, mat, pass, vertices, t);
        }
Ejemplo n.º 4
0
        public void Internal_Apply(GStylizedTerrain t, RenderTexture rt, List <Vector4> vertices)
        {
            GCommon.ClearRT(rt);
            Material mat = GInternalMaterials.FoliageRemoverMaterial;

            mat.SetTexture("_Falloff", falloffTexture);
            mat.SetTexture("_FalloffNoise", FalloffNoise);
            mat.SetTextureScale("_FalloffNoise", new Vector2(
                                    FalloffNoiseSize.x != 0 ? 1f / FalloffNoiseSize.x : 0,
                                    FalloffNoiseSize.y != 0 ? 1f / FalloffNoiseSize.y : 0));
            mat.SetTextureOffset("_FalloffNoise", Vector2.zero);
            if (SplineCreator.EnableTerrainMask)
            {
                mat.SetTexture("_TerrainMask", t.TerrainData.Mask.MaskMap);
            }
            else
            {
                mat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }
            int pass = 0;

            DrawOnTexture(rt, mat, pass, vertices, t);
        }
        public static void Render(
            RenderTexture rt,
            GConditionalStampLayer layer,
            GStylizedTerrain terrain,
            Matrix4x4 stamperTransform,
            Texture mask,
            Texture falloffTexture,
            Vector2[] uvPoints,
            bool useTerrainMask)
        {
            GCommon.ClearRT(rt);
            if (layer.Ignore)
            {
                return;
            }

            Material brushMat = GInternalMaterials.TextureStamperBrushMaterial;

            int resolution = Mathf.Max(rt.width, rt.height);
            //no need to release these maps
            RenderTexture heightMap = terrain.GetHeightMap(resolution);
            RenderTexture normalMap =
                layer.NormalMapMode == GNormalMapMode.Sharp ? terrain.GetSharpNormalMap(resolution) :
                layer.NormalMapMode == GNormalMapMode.Interpolated ? terrain.GetInterpolatedNormalMap(resolution) :
                layer.NormalMapMode == GNormalMapMode.PerPixel ? terrain.GetPerPixelNormalMap(resolution) : null;

            brushMat.SetTexture("_HeightMap", heightMap);

            Vector3 position = stamperTransform.MultiplyPoint(Vector3.zero);
            Vector3 scale    = stamperTransform.lossyScale;

            float stamperMinHeight = terrain.WorldPointToNormalized(position).y;
            float stamperMaxHeight = terrain.WorldPointToNormalized(position + Vector3.up * scale.y).y;

            brushMat.SetFloat("_StamperMinHeight", stamperMinHeight);
            brushMat.SetFloat("_StamperMaxHeight", stamperMaxHeight);

            Vector3 terrainSize = new Vector3(
                terrain.TerrainData.Geometry.Width,
                terrain.TerrainData.Geometry.Height,
                terrain.TerrainData.Geometry.Length);

            brushMat.SetTexture("_Mask", mask);
            brushMat.SetTexture("_Falloff", falloffTexture);
            brushMat.SetFloat("_MinHeight", GUtilities.InverseLerpUnclamped(0, terrainSize.y, layer.MinHeight));
            brushMat.SetFloat("_MaxHeight", GUtilities.InverseLerpUnclamped(0, terrainSize.y, layer.MaxHeight));
            brushMat.SetTexture("_HeightTransition", layer.heightTransitionTexture);
            brushMat.SetFloat("_MinSlope", layer.MinSlope * Mathf.Deg2Rad);
            brushMat.SetFloat("_MaxSlope", layer.MaxSlope * Mathf.Deg2Rad);
            brushMat.SetTexture("_SlopeTransition", layer.slopeTransitionTexture);
            brushMat.SetVector("_NoiseOrigin", layer.NoiseOrigin);
            brushMat.SetFloat("_NoiseFrequency", layer.NoiseFrequency);
            brushMat.SetInt("_NoiseOctaves", layer.NoiseOctaves);
            brushMat.SetFloat("_NoiseLacunarity", layer.NoiseLacunarity);
            brushMat.SetFloat("_NoisePersistence", layer.NoisePersistence);
            brushMat.SetTexture("_NoiseRemap", layer.noiseRemapTexture);
            brushMat.SetTexture("_NormalMap", normalMap);
            if (useTerrainMask)
            {
                brushMat.SetTexture("_TerrainMask", terrain.TerrainData.Mask.MaskMap);
            }
            else
            {
                brushMat.SetTexture("_TerrainMask", Texture2D.blackTexture);
            }

            GCommon.SetMaterialKeywordActive(brushMat, BLEND_HEIGHT_KW, layer.BlendHeight);
            GCommon.SetMaterialKeywordActive(brushMat, BLEND_SLOPE_KW, layer.BlendSlope);
            GCommon.SetMaterialKeywordActive(brushMat, BLEND_NOISE_KW, layer.BlendNoise);
            DrawOnBrushTexture(rt, uvPoints, brushMat, 0);
        }