From 9a5483fea71bbb9f64cc43fa6f4d7ad6ad3ef5ae Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 16 Apr 2015 23:25:04 +0100 Subject: [PATCH] Send TS terrain depth data to the GPU. --- OpenRA.Game/Graphics/Util.cs | 4 +++- glsl/shp.frag | 1 + glsl/shp.vert | 29 +++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index 2f968a48ec..5167792447 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -19,7 +19,7 @@ namespace OpenRA.Graphics { // yes, our channel order is nuts. 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) { @@ -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) { 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 + 1] = new Vertex(b, r.Right, r.Top, paletteTextureIndex, attribC); diff --git a/glsl/shp.frag b/glsl/shp.frag index c5671026e1..1f5d378a69 100644 --- a/glsl/shp.frag +++ b/glsl/shp.frag @@ -2,6 +2,7 @@ uniform sampler2D DiffuseTexture, Palette; varying vec4 TexCoord; varying vec4 ChannelMask; +varying vec4 DepthMask; void main() { diff --git a/glsl/shp.vert b/glsl/shp.vert index 551294ffe1..18fd603a77 100644 --- a/glsl/shp.vert +++ b/glsl/shp.vert @@ -3,19 +3,40 @@ uniform vec2 r1,r2; // matrix elements varying vec4 TexCoord; varying vec4 ChannelMask; +varying vec4 DepthMask; -vec4 DecodeChannelMask( float x ) +vec4 DecodeChannelMask(float x) +{ + float y = abs(x); + 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 + return vec4(1,0,0,0); +} + +vec4 DecodeDepthChannelMask(float x) { if (x > 0.0) - return (x > 0.5) ? vec4(1,0,0,0) : vec4(0,1,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 (x < -0.5) ? vec4(0,0,0,1) : vec4(0,0,1,0); + return vec4(0,1,0,0); } void main() { - vec2 p = (gl_Vertex.xy - Scroll.xy)*r1 + r2; + vec2 p = (gl_Vertex.xy - Scroll.xy) * r1 + r2; gl_Position = vec4(p.x,p.y,0,1); TexCoord = gl_MultiTexCoord0; ChannelMask = DecodeChannelMask(gl_MultiTexCoord0.w); + DepthMask = DecodeDepthChannelMask(gl_MultiTexCoord0.w); }