From b68fee9521ac816576479db747058f6a8ad78990 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 10 Apr 2016 15:13:35 -0400 Subject: [PATCH] Remove SheetType.DualIndexed from voxel rendering. --- OpenRA.Game/Graphics/VoxelLoader.cs | 31 ++++++++++++++++----------- OpenRA.Game/Graphics/VoxelRenderer.cs | 2 +- glsl/vxl.frag | 3 ++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/OpenRA.Game/Graphics/VoxelLoader.cs b/OpenRA.Game/Graphics/VoxelLoader.cs index 38c0cb3632..47bfb32c0e 100644 --- a/OpenRA.Game/Graphics/VoxelLoader.cs +++ b/OpenRA.Game/Graphics/VoxelLoader.cs @@ -54,10 +54,10 @@ namespace OpenRA.Graphics if (allocated) throw new SheetOverflowException(""); allocated = true; - return SheetBuilder.AllocateSheet(SheetType.DualIndexed, Game.Settings.Graphics.SheetSize); + return SheetBuilder.AllocateSheet(SheetType.Indexed, Game.Settings.Graphics.SheetSize); }; - return new SheetBuilder(SheetType.DualIndexed, allocate); + return new SheetBuilder(SheetType.Indexed, allocate); } public VoxelLoader(IReadOnlyFileSystem fileSystem) @@ -78,6 +78,7 @@ namespace OpenRA.Graphics var c = 0; for (var v = 0; v < sv; v++) + { for (var u = 0; u < su; u++) { var voxel = first(u, v) ?? second(u, v); @@ -85,22 +86,28 @@ namespace OpenRA.Graphics normals[c] = voxel == null ? (byte)0 : voxel.Normal; c++; } + } - var s = sheetBuilder.Allocate(new Size(su, sv)); - Util.FastCopyIntoChannel(s, 0, colors); - Util.FastCopyIntoChannel(s, 1, normals); + var size = new Size(su, sv); + var s = sheetBuilder.Allocate(size); + var t = sheetBuilder.Allocate(size); + Util.FastCopyIntoChannel(s, colors); + Util.FastCopyIntoChannel(t, normals); + + // s and t are guaranteed to use the same sheet because + // of the custom voxel sheet allocation implementation s.Sheet.CommitBufferedData(); var channelP = ChannelSelect[(int)s.Channel]; - var channelC = ChannelSelect[(int)s.Channel + 1]; + var channelC = ChannelSelect[(int)t.Channel]; return new Vertex[6] { - new Vertex(coord(0, 0), s.Left, s.Top, 0, 0, channelP, channelC), - new Vertex(coord(su, 0), s.Right, s.Top, 0, 0, channelP, channelC), - new Vertex(coord(su, sv), s.Right, s.Bottom, 0, 0, channelP, channelC), - new Vertex(coord(su, sv), s.Right, s.Bottom, 0, 0, channelP, channelC), - new Vertex(coord(0, sv), s.Left, s.Bottom, 0, 0, channelP, channelC), - new Vertex(coord(0, 0), s.Left, s.Top, 0, 0, channelP, channelC) + new Vertex(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC), + new Vertex(coord(su, 0), s.Right, s.Top, t.Right, t.Top, channelP, channelC), + new Vertex(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), + new Vertex(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), + new Vertex(coord(0, sv), s.Left, s.Bottom, t.Left, t.Bottom, channelP, channelC), + new Vertex(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC) }; } diff --git a/OpenRA.Game/Graphics/VoxelRenderer.cs b/OpenRA.Game/Graphics/VoxelRenderer.cs index a05bb105c1..cda6079646 100644 --- a/OpenRA.Game/Graphics/VoxelRenderer.cs +++ b/OpenRA.Game/Graphics/VoxelRenderer.cs @@ -332,7 +332,7 @@ namespace OpenRA.Graphics var size = new Size(renderer.SheetSize, renderer.SheetSize); var framebuffer = renderer.Device.CreateFrameBuffer(size); - var sheet = new Sheet(SheetType.DualIndexed, framebuffer.Texture); + var sheet = new Sheet(SheetType.BGRA, framebuffer.Texture); mappedBuffers.Add(sheet, framebuffer); return sheet; diff --git a/glsl/vxl.frag b/glsl/vxl.frag index c9373d5fb1..70293af91b 100644 --- a/glsl/vxl.frag +++ b/glsl/vxl.frag @@ -15,7 +15,8 @@ void main() if (color.a < 0.01) discard; - vec4 normal = (2.0 * texture2D(Palette, vec2(dot(x, vNormalsMask), PaletteRows.y)) - 1.0); + vec4 y = texture2D(DiffuseTexture, vTexCoord.pq); + vec4 normal = (2.0 * texture2D(Palette, vec2(dot(y, vNormalsMask), PaletteRows.y)) - 1.0); vec3 intensity = AmbientLight + DiffuseLight * max(dot(normal, LightDirection), 0.0); gl_FragColor = vec4(intensity * color.rgb, color.a); }