Fix editor grid gizmo when using Large Worlds
This commit is contained in:
BIN
Content/Shaders/Editor/Grid.flax
(Stored with Git LFS)
BIN
Content/Shaders/Editor/Grid.flax
(Stored with Git LFS)
Binary file not shown.
@@ -19,12 +19,11 @@ namespace FlaxEditor.Gizmo
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct Data
|
||||
{
|
||||
public Matrix WorldMatrix;
|
||||
public Matrix ViewProjectionMatrix;
|
||||
public Float4 GridColor;
|
||||
public Float3 ViewPos;
|
||||
public float Far;
|
||||
public Float3 Padding;
|
||||
public Float3 ViewOrigin;
|
||||
public float GridSize;
|
||||
}
|
||||
|
||||
@@ -62,7 +61,6 @@ namespace FlaxEditor.Gizmo
|
||||
Profiler.BeginEventGPU("Editor Grid");
|
||||
|
||||
var options = Editor.Instance.Options.Options;
|
||||
Float3 camPos = renderContext.View.WorldPosition;
|
||||
float gridSize = renderContext.View.Far + 20000;
|
||||
|
||||
// Lazy-init resources
|
||||
@@ -97,10 +95,10 @@ namespace FlaxEditor.Gizmo
|
||||
float y = 1.5f; // Add small bias to reduce Z-fighting with geometry at scene origin
|
||||
var vertices = new Float3[]
|
||||
{
|
||||
new Float3(-gridSize + camPos.X, y, -gridSize + camPos.Z),
|
||||
new Float3(gridSize + camPos.X, y, gridSize + camPos.Z),
|
||||
new Float3(-gridSize + camPos.X, y, gridSize + camPos.Z),
|
||||
new Float3(gridSize + camPos.X, y, -gridSize + camPos.Z),
|
||||
new Float3(-gridSize, y, -gridSize),
|
||||
new Float3(gridSize, y, gridSize),
|
||||
new Float3(-gridSize, y, gridSize),
|
||||
new Float3(gridSize, y, -gridSize),
|
||||
};
|
||||
fixed (Float3* ptr = vertices)
|
||||
{
|
||||
@@ -113,12 +111,12 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
var data = new Data();
|
||||
Matrix.Multiply(ref renderContext.View.View, ref renderContext.View.Projection, out var viewProjection);
|
||||
data.WorldMatrix = Matrix.Identity;
|
||||
Matrix.Transpose(ref viewProjection, out data.ViewProjectionMatrix);
|
||||
data.ViewPos = renderContext.View.WorldPosition;
|
||||
data.GridColor = options.Viewport.ViewportGridColor;
|
||||
data.Far = renderContext.View.Far;
|
||||
data.GridSize = options.Viewport.ViewportGridViewDistance;
|
||||
data.ViewOrigin = renderContext.View.Origin;
|
||||
context.UpdateCB(cb, new IntPtr(&data));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
#include "./Flax/Common.hlsl"
|
||||
|
||||
META_CB_BEGIN(0, Data)
|
||||
float4x4 WorldMatrix;
|
||||
float4x4 ViewProjectionMatrix;
|
||||
float4 GridColor;
|
||||
float3 ViewPos;
|
||||
float Far;
|
||||
float3 Padding;
|
||||
float3 ViewOrigin;
|
||||
float GridSize;
|
||||
META_CB_END
|
||||
|
||||
@@ -46,8 +45,9 @@ META_VS_IN_ELEMENT(TEXCOORD, 0, R16G16_FLOAT, 1, ALIGN, PER_VERTEX, 0, true)
|
||||
VertexOutput VS_Grid(ModelInput input)
|
||||
{
|
||||
VertexOutput output;
|
||||
output.WorldPosition = mul(float4(input.Position.xyz, 1), WorldMatrix).xyz;
|
||||
output.Position = mul(float4(input.Position.xyz, 1), ViewProjectionMatrix);
|
||||
output.WorldPosition = input.Position.xyz + ViewOrigin;
|
||||
float3 geoPosition = input.Position.xyz - float3(0, ViewOrigin.y, 0);
|
||||
output.Position = mul(float4(geoPosition, 1), ViewProjectionMatrix);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ float4 GetColor(float3 pos, float scale)
|
||||
color = lerp(color, float4(1,0,0,1), l2);
|
||||
color = lerp(color, float4(0,0,1,1), l1);
|
||||
color *= dist;
|
||||
color *= 1 - saturate(length(pos) - 600000); // Fade out when far from origin (60km)
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user