diff --git a/OpenRA.Game/Graphics/VoxelAnimation.cs b/OpenRA.Game/Graphics/VoxelAnimation.cs new file mode 100644 index 0000000000..7cbb003878 --- /dev/null +++ b/OpenRA.Game/Graphics/VoxelAnimation.cs @@ -0,0 +1,35 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using OpenRA.Traits; + +namespace OpenRA.Graphics +{ + public struct VoxelAnimation + { + public readonly Voxel Voxel; + public readonly Func OffsetFunc; + public readonly Func> RotationFunc; + public readonly Func DisableFunc; + public readonly Func FrameFunc; + + public VoxelAnimation(Voxel voxel, Func offset, Func> rotation, Func disable, Func frame) + { + Voxel = voxel; + OffsetFunc = offset; + RotationFunc = rotation; + DisableFunc = disable; + FrameFunc = frame; + } + } +} + diff --git a/OpenRA.Game/Graphics/VoxelRenderable.cs b/OpenRA.Game/Graphics/VoxelRenderable.cs new file mode 100644 index 0000000000..168d3b0513 --- /dev/null +++ b/OpenRA.Game/Graphics/VoxelRenderable.cs @@ -0,0 +1,106 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; + +namespace OpenRA.Graphics +{ + public struct VoxelRenderable : IRenderable + { + readonly IEnumerable voxels; + readonly WPos pos; + readonly int zOffset; + readonly WRot camera; + readonly WRot lightSource; + readonly float[] lightAmbientColor; + readonly float[] lightDiffuseColor; + readonly PaletteReference palette; + readonly PaletteReference normalsPalette; + readonly PaletteReference shadowPalette; + readonly float scale; + + public VoxelRenderable(IEnumerable voxels, WPos pos, int zOffset, WRot camera, float scale, + WRot lightSource, float[] lightAmbientColor, float[] lightDiffuseColor, + PaletteReference color, PaletteReference normals, PaletteReference shadow) + { + this.voxels = voxels; + this.pos = pos; + this.zOffset = zOffset; + this.scale = scale; + this.camera = camera; + this.lightSource = lightSource; + this.lightAmbientColor = lightAmbientColor; + this.lightDiffuseColor = lightDiffuseColor; + this.palette = color; + this.normalsPalette = normals; + this.shadowPalette = shadow; + } + + public WPos Pos { get { return pos; } } + public float Scale { get { return scale; } } + public PaletteReference Palette { get { return palette; } } + public int ZOffset { get { return zOffset; } } + + public IRenderable WithScale(float newScale) + { + return new VoxelRenderable(voxels, pos, zOffset, camera, newScale, + lightSource, lightAmbientColor, lightDiffuseColor, + palette, normalsPalette, shadowPalette); + } + + public IRenderable WithPalette(PaletteReference newPalette) + { + return new VoxelRenderable(voxels, pos, zOffset, camera, scale, + lightSource, lightAmbientColor, lightDiffuseColor, + newPalette, normalsPalette, shadowPalette); + } + + public IRenderable WithZOffset(int newOffset) + { + return new VoxelRenderable(voxels, pos, newOffset, camera, scale, + lightSource, lightAmbientColor, lightDiffuseColor, + palette, normalsPalette, shadowPalette); + } + + public IRenderable WithPos(WPos newPos) + { + return new VoxelRenderable(voxels, newPos, zOffset, camera, scale, + lightSource, lightAmbientColor, lightDiffuseColor, + palette, normalsPalette, shadowPalette); + } + + public void Render(WorldRenderer wr) + { + // Depth and shadow buffers are cleared between actors so that + // overlapping units and shadows behave like overlapping sprites. + var vr = Game.Renderer.WorldVoxelRenderer; + var draw = voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); + + foreach (var v in draw) + v.Voxel.PrepareForDraw(wr, pos + v.OffsetFunc(), v.RotationFunc(), camera, + v.FrameFunc(), scale, lightSource); + + Game.Renderer.EnableDepthBuffer(); + Game.Renderer.EnableStencilBuffer(); + foreach (var v in draw) + v.Voxel.DrawShadow(vr, shadowPalette.Index); + Game.Renderer.DisableStencilBuffer(); + Game.Renderer.DisableDepthBuffer(); + + Game.Renderer.EnableDepthBuffer(); + foreach (var v in draw) + v.Voxel.Draw(vr, lightAmbientColor, lightDiffuseColor, palette.Index, normalsPalette.Index); + Game.Renderer.DisableDepthBuffer(); + } + } +} diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 01c53d1d11..e16d1f3b80 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -231,6 +231,8 @@ + +