Fixes for Terrain with Large Worlds usage
This commit is contained in:
@@ -67,6 +67,7 @@ namespace FlaxEditor.Gizmo
|
||||
var renderList = RenderList.GetFromPool();
|
||||
var prevList = renderContext.List;
|
||||
renderContext.List = renderList;
|
||||
renderContext.View.Pass = DrawPass.GBuffer | DrawPass.Forward;
|
||||
try
|
||||
{
|
||||
Viewport.DrawEditorPrimitives(context, ref renderContext, target, targetDepth);
|
||||
|
||||
@@ -24,10 +24,11 @@ namespace FlaxEditor.Tools.Terrain.Brushes
|
||||
/// <summary>
|
||||
/// Gets the brush material for the terrain chunk rendering. It must have domain set to Terrain. Setup material parameters within this call.
|
||||
/// </summary>
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="position">The world-space brush position.</param>
|
||||
/// <param name="color">The brush position.</param>
|
||||
/// <returns>The ready to render material for terrain chunks overlay on top of the terrain.</returns>
|
||||
public abstract MaterialInstance GetBrushMaterial(ref Vector3 position, ref Color color);
|
||||
public abstract MaterialInstance GetBrushMaterial(ref RenderContext renderContext, ref Vector3 position, ref Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the brush material from the internal location. It's later cached by the object and reused.
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace FlaxEditor.Tools.Terrain.Brushes
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override MaterialInstance GetBrushMaterial(ref Vector3 position, ref Color color)
|
||||
public override MaterialInstance GetBrushMaterial(ref RenderContext renderContext, ref Vector3 position, ref Color color)
|
||||
{
|
||||
var material = CacheMaterial(EditorAssets.TerrainCircleBrushMaterial);
|
||||
if (material)
|
||||
@@ -108,7 +108,7 @@ namespace FlaxEditor.Tools.Terrain.Brushes
|
||||
float falloff = halfSize * Falloff;
|
||||
float radius = halfSize - falloff;
|
||||
material.SetParameterValue("Color", color);
|
||||
material.SetParameterValue("BrushData0", new Float4(position, radius));
|
||||
material.SetParameterValue("BrushData0", new Float4(position - renderContext.View.Origin, radius));
|
||||
material.SetParameterValue("BrushData1", new Float4(falloff, (float)FalloffType, 0, 0));
|
||||
}
|
||||
return material;
|
||||
|
||||
@@ -88,14 +88,14 @@ namespace FlaxEditor.Tools.Terrain
|
||||
var patchCoord = Mode.SelectedPatchCoord;
|
||||
if (!terrain.HasPatch(ref patchCoord) && _planeModel)
|
||||
{
|
||||
var planeSize = 256.0f;
|
||||
var planeSize = 100.0f;
|
||||
var patchSize = terrain.ChunkSize * FlaxEngine.Terrain.UnitsPerVertex * FlaxEngine.Terrain.PatchEdgeChunksCount;
|
||||
Matrix world = Matrix.RotationZ(-Mathf.PiOverTwo) *
|
||||
Matrix world = Matrix.RotationX(-Mathf.PiOverTwo) *
|
||||
Matrix.Scaling(patchSize / planeSize) *
|
||||
Matrix.Translation(patchSize * (0.5f + patchCoord.X), 0, patchSize * (0.5f + patchCoord.Y)) *
|
||||
Matrix.Scaling(terrain.Scale) *
|
||||
Matrix.RotationQuaternion(terrain.Orientation) *
|
||||
Matrix.Translation(terrain.Position);
|
||||
Matrix.Translation(terrain.Position - renderContext.View.Origin);
|
||||
_planeModel.Draw(ref renderContext, _highlightMaterial, ref world);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace FlaxEditor.Tools.Terrain
|
||||
{
|
||||
var brushPosition = Mode.CursorPosition;
|
||||
var brushColor = new Color(1.0f, 0.85f, 0.0f); // TODO: expose to editor options
|
||||
var brushMaterial = Mode.CurrentBrush.GetBrushMaterial(ref brushPosition, ref brushColor);
|
||||
var brushMaterial = Mode.CurrentBrush.GetBrushMaterial(ref renderContext, ref brushPosition, ref brushColor);
|
||||
if (!brushMaterial)
|
||||
return;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace FlaxEditor.Tools.Terrain
|
||||
{
|
||||
var brushPosition = Mode.CursorPosition;
|
||||
var brushColor = new Color(1.0f, 0.85f, 0.0f); // TODO: expose to editor options
|
||||
var brushMaterial = Mode.CurrentBrush.GetBrushMaterial(ref brushPosition, ref brushColor);
|
||||
var brushMaterial = Mode.CurrentBrush.GetBrushMaterial(ref renderContext, ref brushPosition, ref brushColor);
|
||||
if (!brushMaterial)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user