Send TS terrain depth data to the GPU.

This commit is contained in:
Paul Chote
2015-04-16 23:25:04 +01:00
parent d5fd8e5828
commit 9a5483fea7
3 changed files with 29 additions and 5 deletions

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Graphics
{ {
// yes, our channel order is nuts. // yes, our channel order is nuts.
static readonly int[] ChannelMasks = { 2, 1, 0, 3 }; static readonly int[] ChannelMasks = { 2, 1, 0, 3 };
static readonly float[] ChannelSelect = { 0.75f, 0.25f, -0.25f, -0.75f }; 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, float2 o, Sprite r, float paletteTextureIndex, int nv, float2 size)
{ {
@@ -32,6 +32,8 @@ namespace OpenRA.Graphics
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, float2 a, float2 b, float2 c, float2 d, Sprite r, float paletteTextureIndex, int nv)
{ {
var attribC = ChannelSelect[(int)r.Channel]; var attribC = ChannelSelect[(int)r.Channel];
if (r.Sheet.Type == SheetType.DualIndexed)
attribC *= -1;
vertices[nv] = new Vertex(a, r.Left, r.Top, paletteTextureIndex, attribC); vertices[nv] = new Vertex(a, r.Left, r.Top, paletteTextureIndex, attribC);
vertices[nv + 1] = new Vertex(b, r.Right, r.Top, paletteTextureIndex, attribC); vertices[nv + 1] = new Vertex(b, r.Right, r.Top, paletteTextureIndex, attribC);

View File

@@ -2,6 +2,7 @@ uniform sampler2D DiffuseTexture, Palette;
varying vec4 TexCoord; varying vec4 TexCoord;
varying vec4 ChannelMask; varying vec4 ChannelMask;
varying vec4 DepthMask;
void main() void main()
{ {

View File

@@ -3,13 +3,33 @@ uniform vec2 r1,r2; // matrix elements
varying vec4 TexCoord; varying vec4 TexCoord;
varying vec4 ChannelMask; varying vec4 ChannelMask;
varying vec4 DepthMask;
vec4 DecodeChannelMask(float x) vec4 DecodeChannelMask(float x)
{ {
if (x > 0.0) float y = abs(x);
return (x > 0.5) ? vec4(1,0,0,0) : vec4(0,1,0,0); if (y > 0.7)
return vec4(0,0,0,1);
if (y > 0.5)
return vec4(0,0,1,0);
if (y > 0.3)
return vec4(0,1,0,0);
else else
return (x < -0.5) ? vec4(0,0,0,1) : vec4(0,0,1,0); return vec4(1,0,0,0);
}
vec4 DecodeDepthChannelMask(float x)
{
if (x > 0.0)
return vec4(0,0,0,0);
if (x < -0.7)
return vec4(1,0,0,0);
if (x < -0.5)
return vec4(0,0,0,1);
if (x < -0.3)
return vec4(0,0,1,0);
else
return vec4(0,1,0,0);
} }
void main() void main()
@@ -18,4 +38,5 @@ void main()
gl_Position = vec4(p.x,p.y,0,1); gl_Position = vec4(p.x,p.y,0,1);
TexCoord = gl_MultiTexCoord0; TexCoord = gl_MultiTexCoord0;
ChannelMask = DecodeChannelMask(gl_MultiTexCoord0.w); ChannelMask = DecodeChannelMask(gl_MultiTexCoord0.w);
DepthMask = DecodeDepthChannelMask(gl_MultiTexCoord0.w);
} }