Browse Source

Working on AtomicBlaster

Josh Engebretson 9 years ago
parent
commit
4fe3420b80

+ 89 - 0
AtomicNET/AtomicBlaster/Resources/RenderPath/BloomHDR.xml

@@ -0,0 +1,89 @@
+<renderpath>
+    <command type="sendevent" name="customrender" />
+    <rendertarget name="bright2" tag="BloomHDR" sizedivisor="2 2" format="rgba16f" filter="true" />
+    <rendertarget name="bright4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
+    <rendertarget name="bright8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
+    <rendertarget name="bright16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
+    <rendertarget name="blur2" tag="BloomHDR" sizedivisor="2 2" format="rgba16f" filter="true" />
+    <rendertarget name="blur4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
+    <rendertarget name="blur8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
+    <rendertarget name="blur16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BRIGHT" psdefines="BRIGHT" output="bright2">
+        <parameter name="BloomHDRThreshold" value="0.1" />
+        <texture unit="diffuse" name="viewport" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright4">
+        <texture unit="diffuse" name="bright2" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright8">
+        <texture unit="diffuse" name="bright4" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright16">
+        <texture unit="diffuse" name="bright8" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="blur16">
+        <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="bright16" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="bright16">
+        <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="blur16" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE16" psdefines="COMBINE16" output="blur8">
+        <texture unit="diffuse" name="bright8" />
+        <texture unit="normal" name="bright16" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="bright8">
+        <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="blur8" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="blur8">
+        <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="bright8" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE8" psdefines="COMBINE8" output="blur4">
+        <texture unit="diffuse" name="bright4" />
+        <texture unit="normal" name="blur8" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="bright4">
+        <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="blur4" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="blur4">
+        <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="bright4" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE4" psdefines="COMBINE4" output="blur2">
+        <texture unit="diffuse" name="bright2" />
+        <texture unit="normal" name="blur4" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="bright2">
+        <parameter name="BloomHDRBlurDir" value="1.0 0.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="blur2" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="blur2">
+        <parameter name="BloomHDRBlurDir" value="0.0 1.0" />
+        <parameter name="BloomHDRBlurRadius" value="1.0" />
+        <parameter name="BloomHDRBlurSigma" value="2.0" />
+        <texture unit="diffuse" name="bright2" />
+    </command>
+    <command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE2" psdefines="COMBINE2" output="viewport">
+        <parameter name="BloomHDRMix" value="1.0 0.4" />
+        <texture unit="diffuse" name="viewport" />
+        <texture unit="normal" name="blur2" />
+    </command>
+</renderpath>

+ 19 - 0
AtomicNET/AtomicBlaster/Resources/RenderPath/Blur.xml

@@ -0,0 +1,19 @@
+<renderpath>
+    <rendertarget name="blurh" tag="Blur" sizedivisor="1 1" format="rgba" filter="true" />
+    <rendertarget name="blurv" tag="Blur" sizedivisor="1 1" format="rgba" filter="true" />
+    <command type="quad" tag="Blur" vs="Blur" ps="Blur" psdefines="BLUR3" output="blurh">
+        <parameter name="BlurDir" value="1.0 0.0" />
+        <parameter name="BlurRadius" value="1" />
+        <parameter name="BlurSigma" value="1" />
+        <texture unit="diffuse" name="viewport" />
+    </command>
+    <command type="quad" tag="Blur" vs="Blur" ps="Blur" psdefines="BLUR3" output="blurv">
+        <parameter name="BlurDir" value="0.0 1.0" />
+        <parameter name="BlurRadius" value="1" />
+        <parameter name="BlurSigma" value="1" />
+        <texture unit="diffuse" name="blurh" />
+    </command>
+    <command type="quad" tag="Blur" vs="CopyFramebuffer" ps="CopyFramebuffer" output="viewport">
+        <texture unit="diffuse" name="blurv" />
+    </command>
+</renderpath>

+ 6 - 5
AtomicNET/AtomicBlaster/Resources/Scenes/Scene.scene

@@ -5,8 +5,8 @@
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Elapsed Time" value="0" />
-	<attribute name="Next Replicated Node ID" value="370" />
-	<attribute name="Next Replicated Component ID" value="1987" />
+	<attribute name="Next Replicated Node ID" value="373" />
+	<attribute name="Next Replicated Component ID" value="1990" />
 	<attribute name="Next Local Node ID" value="16778496" />
 	<attribute name="Next Local Component ID" value="16777216" />
 	<attribute name="Variables" />
@@ -38,15 +38,16 @@
 		<component type="Camera" id="1973">
 			<attribute name="Near Clip" value="0" />
 			<attribute name="Orthographic" value="true" />
-			<attribute name="Orthographic Size" value="5" />
+			<attribute name="Orthographic Size" value="1" />
+			<attribute name="Zoom" value="1" />
 		</component>
 	</node>
 	<node id="363">
 		<attribute name="Is Enabled" value="true" />
 		<attribute name="Name" value="Star" />
-		<attribute name="Position" value="0 0 3.4" />
+		<attribute name="Position" value="0 0 0" />
 		<attribute name="Rotation" value="1 0 0 0" />
-		<attribute name="Scale" value="1 1 1" />
+		<attribute name="Scale" value="1e-06 1e-06 1e-06" />
 		<attribute name="Variables" />
 		<component type="JSComponent" id="1977">
 			<attribute name="ComponentFile" value="JSComponentFile;Components/Spinner.js" />

+ 2 - 2
AtomicNET/AtomicBlaster/Resources/Scenes/Scene.scene.asset

@@ -2,7 +2,7 @@
 	"version": 1,
 	"guid": "d993277faa2b13758d981808e37b90eb",
 	"SceneImporter": {
-		"sceneCamRotation": "1 0 0 0",
-		"sceneCamPosition": "0 0 0"
+		"sceneCamRotation": "0.707107 0.707107 0 0",
+		"sceneCamPosition": "1.61521 5 3.4"
 	}
 }

+ 2 - 4
AtomicNET/AtomicBlaster/Resources/Scripts/BlackHole.cs

@@ -106,11 +106,9 @@ namespace AtomicBlaster
 
         public override void Draw(/*SpriteBatch spriteBatch*/)
         {
-            /*
             // make the size of the black hole pulsate
-            float scale = 1 + 0.1f * (float)Math.Sin(10 * GameRoot.GameTime.TotalGameTime.TotalSeconds);
-            spriteBatch.Draw(image, Position, null, color, Orientation, Size / 2f, scale, 0, 0);
-            */
+            float scale = 1 + 0.1f * (float)Math.Sin(10 * GameRoot.ElapsedTime);
+            CustomRenderer.Draw(image, Position, color, Orientation, Size / 2f, scale, 0);
         }
     }
 }

+ 354 - 2
AtomicNET/AtomicBlaster/Resources/Scripts/CustomRenderer.cs

@@ -1,17 +1,369 @@
 
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
 using AtomicEngine;
 
+
 namespace AtomicBlaster
 {
+
+    [StructLayout(LayoutKind.Sequential)]
+    struct PositionColorUVVertex
+    {
+        public float X, Y, Z;
+        public uint Color;
+        public float U, V;
+    };
+
+    class Batch
+    {
+        public Texture2D Texture;
+        public uint VertexCount = 0;
+        public PositionColorUVVertex[] Vertices = new PositionColorUVVertex[256];
+    }
+
     static class CustomRenderer
     {
+
+        // 250k max vertices
+        const uint maxVertices = 256 * 1024;
+
+        static uint totalVertex = 0;
+
         static VertexBuffer vertexBuffer;
 
+        static ShaderVariation pixelShader;
+        static ShaderVariation vertexShader;
+
+        static SortedDictionary<float, Dictionary<Texture2D, Batch>> layerBatches = new SortedDictionary<float, Dictionary<Texture2D, Batch>>();
+
         public static void Initialize()
         {
+
+            var graphics = AtomicNET.GetSubsystem<Graphics>();
+
+            pixelShader = graphics.GetShader(ShaderType.PS, "Atomic2D");
+            vertexShader = graphics.GetShader(ShaderType.VS, "Atomic2D");
+
             vertexBuffer = new VertexBuffer();
-            vertexBuffer.Shadowed = true;
+            vertexBuffer.SetSize(maxVertices, Constants.MASK_POSITION | Constants.MASK_COLOR | Constants.MASK_TEXCOORD1, true);
+
+        }
+
+        public static void Begin()
+        {
+            totalVertex = 0;
+
+            // reset batches
+            foreach (var layer in layerBatches)
+            {
+                foreach (var batch in layer.Value.Values)
+                {
+                    batch.VertexCount = 0;
+
+                }
+            }
+            
+        }
+
+        struct DrawItem
+        {
+            public Texture2D Texture;
+            public uint StartVertex;
+            public uint VertexCount;
+        }
+
+
+        unsafe public static void End()
+        {
+            
+            List<DrawItem> drawList = new List<DrawItem>();
+
+
+            if (totalVertex == 0)
+                return;
+
+            IntPtr vertexData = vertexBuffer.Lock(0, totalVertex, true);
+
+            if (vertexData == IntPtr.Zero)
+                return;
+
+            uint startVertex = 0;
+
+            PositionColorUVVertex* vout = (PositionColorUVVertex*)vertexData;
+
+            foreach (var layer in layerBatches)
+            {
+                foreach (var batch in layer.Value.Values)
+                {
+                    if (totalVertex + batch.VertexCount >= maxVertices)
+                    {
+                        throw new System.InvalidOperationException("Ran out of vertices");
+                    }
+
+                    if (batch.VertexCount == 0)
+                        continue;
+
+                    for (uint i = 0; i < batch.VertexCount; i++, vout++)
+                    {
+                        *vout = batch.Vertices[i];
+
+                        //vout->X -= 1280.0f / 2.0f;
+                        //vout->Y -= 720.0f / 2.0f;
+
+                        //vout->X /= 1280.0f / 2.0f;
+                        //vout->Y /= 720.0f / 2.0f;
+                    }
+
+                    var item = new DrawItem();
+                    item.Texture = batch.Texture;
+                    item.StartVertex = startVertex;
+                    item.VertexCount = batch.VertexCount;
+
+                    startVertex += batch.VertexCount;
+                    drawList.Add(item);
+
+                }
+
+            }
+
+
+            vertexBuffer.Unlock();
+
+            var renderer = AtomicNET.GetSubsystem<Renderer>();
+            var graphics = AtomicNET.GetSubsystem<Graphics>();
+
+            var view = renderer.GetViewport(0).View;
+            var camera = renderer.GetViewport(0).Camera;
+
+            if (view == null || camera == null)
+                return;
+
+            var vp = graphics.Viewport;
+
+            graphics.SetShaders(vertexShader, pixelShader);
+
+            graphics.SetBlendMode(BlendMode.BLEND_ADDALPHA);
+            graphics.SetCullMode(CullMode.CULL_NONE);
+            graphics.SetFillMode(FillMode.FILL_SOLID);
+            graphics.SetDepthTest(CompareMode.CMP_ALWAYS);
+
+            camera.Zoom = .027f;
+            camera.OrthoSize = 20f;
+            camera.AspectRatio = 1280.0f / 720.0f;
+            camera.Node.Position = new Vector3(1280.0f / 2.0f, 720.0f / 2.0f, 0.0f);
+
+            view.SetCameraShaderParameters(camera, true);
+            graphics.SetShaderParameter(ShaderParams.VSP_MODEL, Matrix3x4.IDENTITY);
+
+            graphics.SetVertexBuffer(vertexBuffer);
+
+            foreach (var item in drawList)
+            {
+                graphics.SetTexture((int) TextureUnit.TU_DIFFUSE, item.Texture);
+                graphics.Draw(PrimitiveType.TRIANGLE_LIST, item.StartVertex, item.VertexCount);
+            }
+
+            // graphics.SetTexture(0, null);
+
+
+        }
+
+        public static void Draw(Texture2D texture, Vector2 position, Color color, float rotation, Vector2 origin, float scale, float layerDepth)
+        {
+
+            var w = texture.Width * scale;
+            var h = texture.Height * scale;
+
+            DrawInternal(texture,
+                new Vector4(position.X, position.Y, w, h),
+                color,
+                rotation,
+                origin * scale,
+                layerDepth);
+        }
+
+        public static void Draw(Texture2D texture, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, float layerDepth)
+        {
+
+            var w = texture.Width * scale.X;
+            var h = texture.Height * scale.Y;
+
+            DrawInternal(texture,
+                new Vector4(position.X, position.Y, w, h),
+                color,
+                rotation,
+                origin * scale,
+                layerDepth);
+        }
+
+        public static void DrawLine(Vector2 start, Vector2 end, Color color, float thickness = 2f)
+        {
+            Vector2 delta = end - start;
+            Draw(Art.Pixel, start, color, delta.ToAngle(), new Vector2(0, 0.5f), new Vector2(delta.Length, thickness), 0f);
+        }
+
+
+        static void DrawInternal(Texture2D texture, Vector4 destinationRectangle, Color color, float rotation, Vector2 origin, float depth)
+        {
+            Dictionary<Texture2D, Batch> batches;
+
+            if (!layerBatches.TryGetValue(depth, out batches))
+            {
+                batches = new Dictionary<Texture2D, Batch>();
+                layerBatches[depth] = batches;
+            }
+
+            Batch batch;
+
+            if (!batches.TryGetValue(texture, out batch))
+            {
+                batch = new Batch();
+                batch.Texture = texture;
+                batches[texture] = batch;
+            }
+
+            if (totalVertex + 6 >= maxVertices)
+            {
+                throw new System.InvalidOperationException("Ran out of vertices");
+            }
+
+            totalVertex += 6;
+
+            if (batch.VertexCount + 6 >= batch.Vertices.Length)
+            {
+                Array.Resize(ref batch.Vertices, batch.Vertices.Length * 2);
+            }
+
+            if (rotation == 0f)
+            {
+                Set(batch.Vertices, ref batch.VertexCount, destinationRectangle.X - origin.X,
+                        destinationRectangle.Y - origin.Y,
+                        destinationRectangle.Z,
+                        destinationRectangle.W,
+                        color,
+                        _texCoordTL,
+                        _texCoordBR,
+                        depth);
+
+            }
+            else
+            {
+                Set(batch.Vertices, ref batch.VertexCount, destinationRectangle.X,
+                        destinationRectangle.Y,
+                        -origin.X,
+                        -origin.Y,
+                        destinationRectangle.Z,
+                        destinationRectangle.W,
+                        (float)Math.Sin(rotation),
+                        (float)Math.Cos(rotation),
+                        color,
+                        _texCoordTL,
+                        _texCoordBR,
+                        depth);
+
+            }
+
+        }
+
+
+        static Vector2 _texCoordTL = new Vector2(0, 0);
+        static Vector2 _texCoordBR = new Vector2(1, 1);
+
+        static PositionColorUVVertex vertexTL = new PositionColorUVVertex();
+        static PositionColorUVVertex vertexTR = new PositionColorUVVertex();
+        static PositionColorUVVertex vertexBL = new PositionColorUVVertex();
+        static PositionColorUVVertex vertexBR = new PositionColorUVVertex();
+
+        // Portions Copyright (C) The MonoGame Team
+        static public void Set(PositionColorUVVertex[] vertices, ref uint vertexCount, float x, float y, float dx, float dy, float w, float h, float sin, float cos, Color color, Vector2 texCoordTL, Vector2 texCoordBR, float depth)
+        {
+            uint ucolor = color.ToUInt();
+
+            vertexTL.X = x + dx * cos - dy * sin;
+            vertexTL.Y = y + dx * sin + dy * cos;
+            vertexTL.Z = depth;
+            vertexTL.Color = ucolor;
+            vertexTL.U = texCoordTL.X;
+            vertexTL.V = texCoordTL.Y;
+
+            vertexTR.X = x + (dx + w) * cos - dy * sin;
+            vertexTR.Y = y + (dx + w) * sin + dy * cos;
+            vertexTR.Z = depth;
+            vertexTR.Color = ucolor;
+            vertexTR.U = texCoordBR.X;
+            vertexTR.V = texCoordTL.Y;
+
+            vertexBL.X = x + dx * cos - (dy + h) * sin;
+            vertexBL.Y = y + dx * sin + (dy + h) * cos;
+            vertexBL.Z = depth;
+            vertexBL.Color = ucolor;
+            vertexBL.U = texCoordTL.X;
+            vertexBL.V = texCoordBR.Y;
+
+            vertexBR.X = x + (dx + w) * cos - (dy + h) * sin;
+            vertexBR.Y = y + (dx + w) * sin + (dy + h) * cos;
+            vertexBR.Z = depth;
+            vertexBR.Color = ucolor;
+            vertexBR.U = texCoordBR.X;
+            vertexBR.V = texCoordBR.Y;
+
+            vertices[vertexCount++] = vertexTL;
+            vertices[vertexCount++] = vertexTR;
+            vertices[vertexCount++] = vertexBL;
+
+            vertices[vertexCount++] = vertexTR;
+            vertices[vertexCount++] = vertexBR;
+            vertices[vertexCount++] = vertexBL;
+
         }
 
+        static public void Set(PositionColorUVVertex[] vertices, ref uint vertexCount, float x, float y, float w, float h, Color color, Vector2 texCoordTL, Vector2 texCoordBR, float depth)
+        {
+            uint ucolor = color.ToUInt();
+
+            vertexTL.X = x;
+            vertexTL.Y = y;
+            vertexTL.Z = depth;
+            vertexTL.Color = ucolor;
+            vertexTL.U = texCoordTL.X;
+            vertexTL.V = texCoordTL.Y;
+
+            vertexTR.X = x + w;
+            vertexTR.Y = y;
+            vertexTR.Z = depth;
+            vertexTR.Color = ucolor;
+            vertexTR.U = texCoordBR.X;
+            vertexTR.V = texCoordTL.Y;
+
+            vertexBL.X = x;
+            vertexBL.Y = y + h;
+            vertexBL.Z = depth;
+            vertexBL.Color = ucolor;
+            vertexBL.U = texCoordTL.X;
+            vertexBL.V = texCoordBR.Y;
+
+            vertexBR.X = x + w;
+            vertexBR.Y = y + h;
+            vertexBR.Z = depth;
+            vertexBR.Color = ucolor;
+            vertexBR.U = texCoordBR.X;
+            vertexBR.V = texCoordBR.Y;
+
+            vertices[vertexCount++] = vertexTL;
+            vertices[vertexCount++] = vertexTR;
+            vertices[vertexCount++] = vertexBL;
+
+            vertices[vertexCount++] = vertexTR;
+            vertices[vertexCount++] = vertexBR;
+            vertices[vertexCount++] = vertexBL;
+
+        }
+
+
+
+
     }
-}
+}
+

+ 2 - 4
AtomicNET/AtomicBlaster/Resources/Scripts/Enemy.cs

@@ -64,16 +64,14 @@ namespace AtomicBlaster
 
         public override void Draw(/*SpriteBatch spriteBatch*/)
         {
-            /*
             if (timeUntilStart > 0)
             {
                 // Draw an expanding, fading-out version of the sprite as part of the spawn-in effect.
                 float factor = timeUntilStart / 60f;    // decreases from 1 to 0 as the enemy spawns in
-                spriteBatch.Draw(image, Position, null, Color.White * factor, Orientation, Size / 2f, 2 - factor, 0, 0);
+                CustomRenderer.Draw(image, Position, Color.White * factor, Orientation, Size / 2f, 2 - factor, 0);
             }
 
-            base.Draw(spriteBatch);
-            */
+            base.Draw();
         }
 
         private void AddBehaviour(IEnumerable<int> behaviour)

+ 2 - 1
AtomicNET/AtomicBlaster/Resources/Scripts/Entity.cs

@@ -30,7 +30,8 @@ namespace AtomicBlaster
 
         public virtual void Draw(/*SpriteBatch spriteBatch*/)
         {
-            //SpriteBatch.Draw(image, Position, null, color, Orientation, Size / 2f, 1f, 0);
+            CustomRenderer.Draw(image, Position, color, Orientation, Size / 2, 1.0f, 0);
+            //spriteBatch.Draw(image, Position, null, color, Orientation, Size / 2f, 1f, 0, 0);
         }
     }
 }

+ 1 - 3
AtomicNET/AtomicBlaster/Resources/Scripts/EntityManager.cs

@@ -143,10 +143,8 @@ namespace AtomicBlaster
 
         public static void Draw(/*SpriteBatch spriteBatch*/)
         {
-            /*
             foreach (var entity in entities)
-                entity.Draw(spriteBatch);
-                */
+                entity.Draw();
         }
     }
 }

+ 38 - 6
AtomicNET/AtomicBlaster/Resources/Scripts/GameRoot.cs

@@ -45,18 +45,53 @@ namespace AtomicBlaster
 
             SubscribeToEvent("Update", HandleUpdate);
 
+            SubscribeToEvent("RenderPathEvent", HandleRenderPathEvent);
+
             Scene = AtomicNET.GetSubsystem<Player>().LoadScene("Scenes/Scene.scene");
 
+            var renderer = AtomicNET.GetSubsystem<Renderer>();
+            var viewport = renderer.GetViewport(0);
+
+            renderer.HDRRendering = true;
+
+            var renderpath = viewport.GetRenderPath().Clone();
+            renderpath.Append(AtomicNET.Cache.GetResource<XMLFile>("RenderPath/BloomHDR.xml"));
+            renderpath.Append(AtomicNET.Cache.GetResource<XMLFile>("RenderPath/Blur.xml"));
+            viewport.SetRenderPath(renderpath);
+
             CustomRenderer.Initialize();
 
         }
 
+        void HandleRenderPathEvent(uint eventType, ScriptVariantMap eventData)
+        {
+            if (eventData.GetString("name") != "customrender")
+                return;
+
+            CustomRenderer.Begin();
+
+            Draw();
+
+            CustomRenderer.End();
+
+        }
+
+        float deltaTime = 0.0f;
+
         void HandleUpdate(uint eventType, ScriptVariantMap eventData)
         {
             float time = eventData.GetFloat("timestep");
-            ElapsedTime += time;
 
-            // Input.Update();
+            deltaTime += time;
+
+            ElapsedTime += time;// / 2.0f;
+
+            if (deltaTime < 1.0f / 60.0f)
+                return;
+
+            deltaTime = 0.0f;
+
+            ShipInput.Update();
 
             if (!paused)
             {
@@ -67,14 +102,11 @@ namespace AtomicBlaster
                 Grid.Update();
             }
 
-            Draw();
-
         }
 
         void Draw()
-        {
+        {                        
             EntityManager.Draw();
-
             Grid.Draw();
             ParticleManager.Draw();
 

+ 9 - 11
AtomicNET/AtomicBlaster/Resources/Scripts/Grid.cs

@@ -193,12 +193,11 @@ namespace AtomicBlaster
 
         public void Draw(/*SpriteBatch spriteBatch*/)
         {
-            /*
             screenSize = GameRoot.ScreenSize;
 
             int width = points.GetLength(0);
             int height = points.GetLength(1);
-            Color color = new Color(30, 30, 139, 85);   // dark blue
+            Color color = new Color(30/255.0f, 30/255.0f, 139/255.0f, 100/255.0f);   // dark blue
 
             for (int y = 1; y < height; y++)
             {
@@ -219,11 +218,11 @@ namespace AtomicBlaster
                         // new interpolated midpoint
                         if (Vector2.DistanceSquared(mid, (left + p) / 2) > 1)
                         {
-                            spriteBatch.DrawLine(left, mid, color, thickness);
-                            spriteBatch.DrawLine(mid, p, color, thickness);
+                            CustomRenderer.DrawLine(left, mid, color, thickness);
+                            CustomRenderer.DrawLine(mid, p, color, thickness);
                         }
                         else
-                            spriteBatch.DrawLine(left, p, color, thickness);
+                            CustomRenderer.DrawLine(left, p, color, thickness);
                     }
                     if (y > 1)
                     {
@@ -234,11 +233,11 @@ namespace AtomicBlaster
 
                         if (Vector2.DistanceSquared(mid, (up + p) / 2) > 1)
                         {
-                            spriteBatch.DrawLine(up, mid, color, thickness);
-                            spriteBatch.DrawLine(mid, p, color, thickness);
+                            CustomRenderer.DrawLine(up, mid, color, thickness);
+                            CustomRenderer.DrawLine(mid, p, color, thickness);
                         }
                         else
-                            spriteBatch.DrawLine(up, p, color, thickness);
+                            CustomRenderer.DrawLine(up, p, color, thickness);
                     }
 
                     // Add interpolated lines halfway between our point masses. This makes the grid look
@@ -246,12 +245,11 @@ namespace AtomicBlaster
                     if (x > 1 && y > 1)
                     {
                         Vector2 upLeft = ToVec2(points[x - 1, y - 1].Position);
-                        spriteBatch.DrawLine(0.5f * (upLeft + up), 0.5f * (left + p), color, 1f);   // vertical line
-                        spriteBatch.DrawLine(0.5f * (upLeft + left), 0.5f * (up + p), color, 1f);   // horizontal line
+                        CustomRenderer.DrawLine(0.5f * (upLeft + up), 0.5f * (left + p), color, 1f);   // vertical line
+                        CustomRenderer.DrawLine(0.5f * (upLeft + left), 0.5f * (up + p), color, 1f);   // horizontal line
                     }
                 }
             }
-            */
         }
 
         public Vector2 ToVec2(Vector3 v)

+ 1 - 1
AtomicNET/AtomicBlaster/Resources/Scripts/ParticleManager.cs

@@ -70,7 +70,7 @@ namespace AtomicBlaster
                 var particle = particleList[i];
 
                 Vector2 origin = new Vector2(particle.Texture.Width / 2, particle.Texture.Height / 2);
-                //spriteBatch.Draw(particle.Texture, particle.Position, null, particle.Tint, particle.Orientation, origin, particle.Scale, 0, 0);
+                CustomRenderer.Draw(particle.Texture, particle.Position, particle.Tint, particle.Orientation, origin, particle.Scale, 0);
             }
         }
 

+ 6 - 4
AtomicNET/AtomicBlaster/Resources/Scripts/PlayerShip.cs

@@ -54,7 +54,7 @@ namespace AtomicBlaster
                 return;
             }
 
-            var aim = new Vector2(); // Input.GetAimDirection();
+            var aim = ShipInput.GetAimDirection();
 
             if (aim.LengthSquared > 0 && cooldowmRemaining <= 0)
             {
@@ -79,7 +79,7 @@ namespace AtomicBlaster
 
             const float speed = 8;
 
-            //Velocity += speed * Input.GetMovementDirection();
+            Velocity += speed * ShipInput.GetMovementDirection();
 
             Position += Velocity;
             Position = Vector2.Clamp(Position, Size / 2, GameRoot.ScreenSize - Size / 2);
@@ -105,8 +105,10 @@ namespace AtomicBlaster
                 // Calculate the sideways velocity for the two side streams. The direction is perpendicular to the ship's velocity and the
                 // magnitude varies sinusoidally.
                 Vector2 perpVel = new Vector2(baseVel.Y, -baseVel.X) * (0.6f * (float)Math.Sin(t * 10));
-                Color sideColor = new Color(200, 38, 9);    // deep red
-                Color midColor = new Color(255, 187, 30);   // orange-yellow
+
+                Color sideColor = new Color(200.0f/255.0f, 38.0f/255.0f, 9.0f/255.0f);    // deep red
+                Color midColor = new Color(255/255.0f, 187/255.0f, 30/255.0f);   // orange-yellow
+
                 Vector2 pos = Position + Vector2.Transform(new Vector2(-25, 0), rot);   // position of the ship's exhaust pipe.
                 const float alpha = 0.7f;
 

+ 70 - 0
AtomicNET/AtomicBlaster/Resources/Scripts/ShipInput.cs

@@ -0,0 +1,70 @@
+using System;
+using AtomicEngine;
+
+namespace AtomicBlaster
+{
+    static class ShipInput
+    {
+        private static bool isAimingWithMouse = false;
+
+        public static void Update()
+        {
+            isAimingWithMouse = true;
+        }
+    
+        public static Vector2 GetMovementDirection()
+        {
+
+            var input = AtomicNET.GetSubsystem<Input>();
+
+            Vector2 direction = new Vector2(0, 0);
+
+            if (input.GetKeyDown((int) SDL.SDL_Keycode.SDLK_a))
+                direction.X -= 1;
+            if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_d))
+                direction.X += 1;
+            if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_s))
+                direction.Y -= 1;
+            if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_w))
+                direction.Y += 1;
+
+            // Clamp the length of the vector to a maximum of 1.
+            if (direction.LengthSquared > 1)
+                direction.Normalize();
+
+            return direction;
+        }
+
+        public static Vector2 GetAimDirection()
+        {
+            return GetMouseAimDirection();
+        }
+
+        private static Vector2 GetMouseAimDirection()
+        {
+            var input = AtomicNET.GetSubsystem<Input>();
+
+            Vector2 direction = new Vector2((float)input.GetMousePosition().X, (float)input.GetMousePosition().Y);            
+
+            Vector2 shipPos = PlayerShip.Instance.Position;
+
+            shipPos.Y = GameRoot.ScreenBounds.Height - shipPos.Y;          
+
+            direction -= shipPos;
+
+            direction.Y = -direction.Y;
+           
+            if (direction == Vector2.Zero)
+                return Vector2.Zero;
+            else
+                return Vector2.Normalize(direction);
+        }
+
+        public static bool WasBombButtonPressed()
+        {
+            var input = AtomicNET.GetSubsystem<Input>();
+            return input.GetKeyPress((int)SDL.SDL_Keycode.SDLK_SPACE);
+        }
+    }
+
+}

+ 5 - 0
AtomicNET/AtomicBlaster/Resources/Scripts/ShipInput.cs.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "aa13f65def6ba0af4280cf745cadc9b1",
+	"CSharpImporter": null
+}

BIN
AtomicNET/AtomicBlaster/Resources/Sprites/Laser.png


BIN
AtomicNET/AtomicBlaster/Resources/Sprites/Pixel.png