Remove SheetType.DualIndexed from terrain rendering.
This commit is contained in:
@@ -48,6 +48,24 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SpriteWithSecondaryData : Sprite
|
||||||
|
{
|
||||||
|
public readonly Rectangle SecondaryBounds;
|
||||||
|
public readonly TextureChannel SecondaryChannel;
|
||||||
|
public readonly float SecondaryTop, SecondaryLeft, SecondaryBottom, SecondaryRight;
|
||||||
|
|
||||||
|
public SpriteWithSecondaryData(Sprite s, Rectangle secondaryBounds, TextureChannel secondaryChannel)
|
||||||
|
: base(s.Sheet, s.Bounds, s.ZRamp, s.Offset, s.Channel, s.BlendMode)
|
||||||
|
{
|
||||||
|
SecondaryBounds = secondaryBounds;
|
||||||
|
SecondaryChannel = secondaryChannel;
|
||||||
|
SecondaryLeft = (float)Math.Min(secondaryBounds.Left, secondaryBounds.Right) / s.Sheet.Size.Width;
|
||||||
|
SecondaryTop = (float)Math.Min(secondaryBounds.Top, secondaryBounds.Bottom) / s.Sheet.Size.Height;
|
||||||
|
SecondaryRight = (float)Math.Max(secondaryBounds.Left, secondaryBounds.Right) / s.Sheet.Size.Width;
|
||||||
|
SecondaryBottom = (float)Math.Max(secondaryBounds.Top, secondaryBounds.Bottom) / s.Sheet.Size.Height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enum TextureChannel : byte
|
public enum TextureChannel : byte
|
||||||
{
|
{
|
||||||
Red = 0,
|
Red = 0,
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
this.tileset = tileset;
|
this.tileset = tileset;
|
||||||
var allocated = false;
|
var allocated = false;
|
||||||
var type = tileset.EnableDepth ? SheetType.DualIndexed : SheetType.Indexed;
|
|
||||||
|
|
||||||
Func<Sheet> allocate = () =>
|
Func<Sheet> allocate = () =>
|
||||||
{
|
{
|
||||||
@@ -51,10 +50,10 @@ namespace OpenRA.Graphics
|
|||||||
throw new SheetOverflowException("Terrain sheet overflow. Try increasing the tileset SheetSize parameter.");
|
throw new SheetOverflowException("Terrain sheet overflow. Try increasing the tileset SheetSize parameter.");
|
||||||
allocated = true;
|
allocated = true;
|
||||||
|
|
||||||
return new Sheet(type, new Size(tileset.SheetSize, tileset.SheetSize));
|
return new Sheet(SheetType.Indexed, new Size(tileset.SheetSize, tileset.SheetSize));
|
||||||
};
|
};
|
||||||
|
|
||||||
sheetBuilder = new SheetBuilder(type, allocate);
|
sheetBuilder = new SheetBuilder(SheetType.Indexed, allocate);
|
||||||
random = new MersenneTwister();
|
random = new MersenneTwister();
|
||||||
|
|
||||||
var frameCache = new FrameCache(Game.ModData.DefaultFileSystem, Game.ModData.SpriteLoaders);
|
var frameCache = new FrameCache(Game.ModData.DefaultFileSystem, Game.ModData.SpriteLoaders);
|
||||||
@@ -71,10 +70,17 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
var f = allFrames[j];
|
var f = allFrames[j];
|
||||||
var s = sheetBuilder.Allocate(f.Size, f.Offset);
|
var s = sheetBuilder.Allocate(f.Size, f.Offset);
|
||||||
Util.FastCopyIntoChannel(s, 0, f.Data);
|
Util.FastCopyIntoChannel(s, f.Data);
|
||||||
|
|
||||||
if (tileset.EnableDepth)
|
if (tileset.EnableDepth)
|
||||||
Util.FastCopyIntoChannel(s, 1, allFrames[j + frameCount].Data);
|
{
|
||||||
|
var ss = sheetBuilder.Allocate(f.Size, f.Offset);
|
||||||
|
Util.FastCopyIntoChannel(ss, allFrames[j + frameCount].Data);
|
||||||
|
|
||||||
|
// s and ss are guaranteed to use the same sheet
|
||||||
|
// because of the custom terrain sheet allocation
|
||||||
|
s = new SpriteWithSecondaryData(s, ss.Bounds, ss.Channel);
|
||||||
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}).ToArray());
|
}).ToArray());
|
||||||
|
|||||||
@@ -31,16 +31,28 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public static void FastCreateQuad(Vertex[] vertices, float3 a, float3 b, float3 c, float3 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)
|
||||||
{
|
{
|
||||||
|
float sl = 0;
|
||||||
|
float st = 0;
|
||||||
|
float sr = 0;
|
||||||
|
float sb = 0;
|
||||||
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, 0, 0, paletteTextureIndex, attribC);
|
var ss = r as SpriteWithSecondaryData;
|
||||||
vertices[nv + 1] = new Vertex(b, r.Right, r.Top, 0, 0, paletteTextureIndex, attribC);
|
if (ss != null)
|
||||||
vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, 0, 0, paletteTextureIndex, attribC);
|
{
|
||||||
vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, 0, 0, paletteTextureIndex, attribC);
|
sl = ss.SecondaryLeft;
|
||||||
vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, 0, 0, paletteTextureIndex, attribC);
|
st = ss.SecondaryTop;
|
||||||
vertices[nv + 5] = new Vertex(a, r.Left, r.Top, 0, 0, paletteTextureIndex, attribC);
|
sr = ss.SecondaryRight;
|
||||||
|
sb = ss.SecondaryBottom;
|
||||||
|
attribC = -(attribC + ChannelSelect[(int)ss.Channel] / 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
vertices[nv] = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, attribC);
|
||||||
|
vertices[nv + 1] = new Vertex(b, r.Right, r.Top, sr, st, paletteTextureIndex, attribC);
|
||||||
|
vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, attribC);
|
||||||
|
vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, attribC);
|
||||||
|
vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, sl, sb, paletteTextureIndex, attribC);
|
||||||
|
vertices[nv + 5] = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, attribC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
|
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ void main()
|
|||||||
float depth = gl_FragCoord.z;
|
float depth = gl_FragCoord.z;
|
||||||
if (length(vDepthMask) > 0.0)
|
if (length(vDepthMask) > 0.0)
|
||||||
{
|
{
|
||||||
// Preview vertex aware depth
|
vec4 y = texture2D(DiffuseTexture, vTexCoord.pq);
|
||||||
depth = depth + DepthTextureScale * dot(x, vDepthMask);
|
depth = depth + DepthTextureScale * dot(y, vDepthMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to window coords
|
// Convert to window coords
|
||||||
|
|||||||
@@ -11,36 +11,27 @@ varying vec4 vDepthMask;
|
|||||||
|
|
||||||
vec4 DecodeChannelMask(float x)
|
vec4 DecodeChannelMask(float x)
|
||||||
{
|
{
|
||||||
float y = abs(x);
|
if (x > 0.7)
|
||||||
if (y > 0.7)
|
|
||||||
return vec4(0,0,0,1);
|
return vec4(0,0,0,1);
|
||||||
if (y > 0.5)
|
if (x > 0.5)
|
||||||
return vec4(0,0,1,0);
|
return vec4(0,0,1,0);
|
||||||
if (y > 0.3)
|
if (x > 0.3)
|
||||||
return vec4(0,1,0,0);
|
return vec4(0,1,0,0);
|
||||||
else
|
else
|
||||||
return vec4(1,0,0,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()
|
||||||
{
|
{
|
||||||
gl_Position = vec4((aVertexPosition.xyz - Scroll.xyz) * r1 + r2, 1);
|
gl_Position = vec4((aVertexPosition.xyz - Scroll.xyz) * r1 + r2, 1);
|
||||||
vTexCoord = aVertexTexCoord;
|
vTexCoord = aVertexTexCoord;
|
||||||
vTexMetadata = aVertexTexMetadata;
|
vTexMetadata = aVertexTexMetadata;
|
||||||
vChannelMask = DecodeChannelMask(aVertexTexMetadata.t);
|
vChannelMask = DecodeChannelMask(abs(aVertexTexMetadata.t));
|
||||||
vDepthMask = DecodeDepthChannelMask(aVertexTexMetadata.t);
|
if (aVertexTexMetadata.t < 0.0)
|
||||||
|
{
|
||||||
|
float x = -aVertexTexMetadata.t * 10.0;
|
||||||
|
vDepthMask = DecodeChannelMask(x - floor(x));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
vDepthMask = vec4(0,0,0,0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user