Merge pull request #11058 from pchote/terrain-vertex-depth
Use vertex depths for rendering terrain depth preview.
This commit is contained in:
@@ -95,6 +95,7 @@ namespace OpenRA
|
||||
void SetBool(string name, bool value);
|
||||
void SetVec(string name, float x);
|
||||
void SetVec(string name, float x, float y);
|
||||
void SetVec(string name, float x, float y, float z);
|
||||
void SetVec(string name, float[] vec, int length);
|
||||
void SetTexture(string param, ITexture texture);
|
||||
void SetMatrix(string param, float[] mtx);
|
||||
|
||||
@@ -114,11 +114,17 @@ namespace OpenRA.Graphics
|
||||
shader.SetTexture("Palette", palette);
|
||||
}
|
||||
|
||||
public void SetViewportParams(Size screen, float zoom, int2 scroll)
|
||||
public void SetViewportParams(Size screen, float depthScale, float depthOffset, float zoom, int2 scroll)
|
||||
{
|
||||
shader.SetVec("Scroll", scroll.X, scroll.Y);
|
||||
shader.SetVec("r1", zoom * 2f / screen.Width, -zoom * 2f / screen.Height);
|
||||
shader.SetVec("r2", -1, 1);
|
||||
shader.SetVec("Scroll", scroll.X, scroll.Y, scroll.Y);
|
||||
shader.SetVec("r1",
|
||||
zoom * 2f / screen.Width,
|
||||
-zoom * 2f / screen.Height,
|
||||
-depthScale * zoom / screen.Height);
|
||||
shader.SetVec("r2", -1, 1, 1 - depthOffset);
|
||||
|
||||
// Texture index is sampled as a float, so convert to pixels then scale
|
||||
shader.SetVec("DepthTextureScale", 128 * depthScale * zoom / screen.Height);
|
||||
}
|
||||
|
||||
public void SetDepthPreviewEnabled(bool enabled)
|
||||
|
||||
@@ -68,12 +68,15 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void Update(CPos cell, Sprite sprite)
|
||||
{
|
||||
var pos = sprite == null ? float2.Zero :
|
||||
var xy = sprite == null ? float2.Zero :
|
||||
worldRenderer.ScreenPosition(map.CenterOfCell(cell)) + sprite.Offset - 0.5f * sprite.Size;
|
||||
Update(cell.ToMPos(map.Grid.Type), sprite, pos);
|
||||
|
||||
// TODO: Deal with sprite z offsets
|
||||
var z = worldRenderer.ScreenZPosition(map.CenterOfCell(cell), 0);
|
||||
Update(cell.ToMPos(map.Grid.Type), sprite, new float3(xy.X, xy.Y, z));
|
||||
}
|
||||
|
||||
public void Update(MPos uv, Sprite sprite, float2 pos)
|
||||
public void Update(MPos uv, Sprite sprite, float3 pos)
|
||||
{
|
||||
if (sprite != null)
|
||||
{
|
||||
|
||||
@@ -21,15 +21,15 @@ namespace OpenRA.Graphics
|
||||
static readonly int[] ChannelMasks = { 2, 1, 0, 3 };
|
||||
static readonly float[] ChannelSelect = { 0.2f, 0.4f, 0.6f, 0.8f };
|
||||
|
||||
public static void FastCreateQuad(Vertex[] vertices, float2 o, Sprite r, float paletteTextureIndex, int nv, float2 size)
|
||||
public static void FastCreateQuad(Vertex[] vertices, float3 o, Sprite r, float paletteTextureIndex, int nv, float3 size)
|
||||
{
|
||||
var b = new float2(o.X + size.X, o.Y);
|
||||
var c = new float2(o.X + size.X, o.Y + size.Y);
|
||||
var d = new float2(o.X, o.Y + size.Y);
|
||||
var b = new float3(o.X + size.X, o.Y, o.Z);
|
||||
var c = new float3(o.X + size.X, o.Y + size.Y, o.Z + size.Z);
|
||||
var d = new float3(o.X, o.Y + size.Y, o.Z + size.Z);
|
||||
FastCreateQuad(vertices, o, b, c, d, r, paletteTextureIndex, nv);
|
||||
}
|
||||
|
||||
public static void FastCreateQuad(Vertex[] vertices, float2 a, float2 b, float2 c, float2 d, Sprite r, float paletteTextureIndex, int nv)
|
||||
public static void FastCreateQuad(Vertex[] vertices, float3 a, float3 b, float3 c, float3 d, Sprite r, float paletteTextureIndex, int nv)
|
||||
{
|
||||
var attribC = ChannelSelect[(int)r.Channel];
|
||||
if (r.Sheet.Type == SheetType.DualIndexed)
|
||||
|
||||
@@ -18,11 +18,8 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
public readonly float X, Y, Z, U, V, P, C;
|
||||
|
||||
public Vertex(float2 xy, float u, float v, float p, float c)
|
||||
: this(xy.X, xy.Y, 0, u, v, p, c) { }
|
||||
|
||||
public Vertex(float[] xyz, float u, float v, float p, float c)
|
||||
: this(xyz[0], xyz[1], xyz[2], u, v, p, c) { }
|
||||
public Vertex(float3 xyz, float u, float v, float p, float c)
|
||||
: this(xyz.X, xyz.Y, xyz.Z, u, v, p, c) { }
|
||||
|
||||
public Vertex(float x, float y, float z, float u, float v, float p, float c)
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Graphics
|
||||
sheetBuilder = CreateSheetBuilder();
|
||||
}
|
||||
|
||||
Vertex[] GenerateSlicePlane(int su, int sv, Func<int, int, VxlElement> first, Func<int, int, VxlElement> second, Func<int, int, float[]> coord)
|
||||
Vertex[] GenerateSlicePlane(int su, int sv, Func<int, int, VxlElement> first, Func<int, int, VxlElement> second, Func<int, int, float3> coord)
|
||||
{
|
||||
var colors = new byte[su * sv];
|
||||
var normals = new byte[su * sv];
|
||||
@@ -158,21 +158,21 @@ namespace OpenRA.Graphics
|
||||
yield return GenerateSlicePlane(l.Size[1], l.Size[2],
|
||||
(u, v) => get(x, u, v),
|
||||
(u, v) => get(x - 1, u, v),
|
||||
(u, v) => new float[] { x, u, v });
|
||||
(u, v) => new float3(x, u, v));
|
||||
|
||||
for (var y = 0; y <= l.Size[1]; y++)
|
||||
if (yPlanes[y])
|
||||
yield return GenerateSlicePlane(l.Size[0], l.Size[2],
|
||||
(u, v) => get(u, y, v),
|
||||
(u, v) => get(u, y - 1, v),
|
||||
(u, v) => new float[] { u, y, v });
|
||||
(u, v) => new float3(u, y, v));
|
||||
|
||||
for (var z = 0; z <= l.Size[2]; z++)
|
||||
if (zPlanes[z])
|
||||
yield return GenerateSlicePlane(l.Size[0], l.Size[1],
|
||||
(u, v) => get(u, v, z),
|
||||
(u, v) => get(u, v, z - 1),
|
||||
(u, v) => new float[] { u, v, z });
|
||||
(u, v) => new float3(u, v, z));
|
||||
}
|
||||
|
||||
public VoxelRenderData GenerateRenderData(VxlLimb l)
|
||||
|
||||
Reference in New Issue
Block a user