// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using FlaxEngine;
namespace FlaxEditor.Tools.Foliage
{
///
/// Foliage painting brush.
///
[HideInEditor]
public class Brush
{
///
/// The cached material instance for the brush usage.
///
protected MaterialInstance _material;
///
/// The brush size (in world units). Within this area, the brush will have effect.
///
[EditorOrder(0), Limit(0.0f, 1000000.0f, 10.0f), Tooltip("The brush size (in world units). Within this area, the brush will have effect.")]
public float Size = 800.0f;
///
/// If checked, brush will apply only once on painting start instead of continuous painting.
///
[EditorOrder(10), Tooltip("If checked, brush will apply only once on painting start instead of continuous painting.")]
public bool SingleClick = false;
///
/// The additional scale for foliage density when painting. Can be used to increase or decrease foliage density during painting.
///
[EditorOrder(20), Limit(0.0f, 1000.0f, 0.01f), Tooltip("The additional scale for foliage density when painting. Can be used to increase or decrease foliage density during painting.")]
public float DensityScale = 1.0f;
///
/// Gets the brush material for the terrain chunk rendering. It must have domain set to Terrain. Setup material parameters within this call.
///
/// The world-space brush position.
/// The brush position.
/// The scene depth buffer (used for manual brush pixels clipping with rendered scene).
/// The ready to render material for terrain chunks overlay on top of the terrain.
public MaterialInstance GetBrushMaterial(ref Vector3 position, ref Color color, GPUTexture sceneDepth)
{
if (!_material)
{
var material = FlaxEngine.Content.LoadAsyncInternal(EditorAssets.FoliageBrushMaterial);
material.WaitForLoaded();
_material = material.CreateVirtualInstance();
}
if (_material)
{
_material.SetParameterValue("Color", color);
_material.SetParameterValue("DepthBuffer", sceneDepth);
}
return _material;
}
}
}