public void Render() { RenderBase.SetWorld(Matrix.Identity); vertexShader.Set(); RenderBase.DeviceContext.PixelShader.Set(pixelShader); paramsBuffer.Set(2); RenderBase.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; //Draw Fish RenderBase.DeviceContext.OutputMerger.BlendState = RenderBase.BlendStates.Default; RenderBase.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <VertexPositionNormal>(), 0)); foreach (var f in Manager.FoodList) { var ds = paramsBuffer.Map(); ds.Write(f.Color); paramsBuffer.UnMap(); RenderBase.SetWorld(Matrix.Scaling(f.Size.X, f.Size.Y, (f.Size.X + f.Size.Y) / 2.0f) * Matrix.RotationZ(f.Rotation) * Matrix.Translation(f.Position.X, f.Position.Y, 0.0f)); RenderBase.DeviceContext.Draw(vertCount, 0); } /*{ * var ds = paramsBuffer.Map(); * ds.Write(new Vector4(1, 1, 1, 1)); * paramsBuffer.UnMap(); * RenderBase.SetWorld(Matrix.Scaling(0.15f) * Matrix.Translation(Input.XInputInput.State[0].RightThumbX / (float)short.MaxValue, Input.XInputInput.State[0].RightThumbY / (float)short.MaxValue, 0));//Matrix.Scaling(0.05f)); * RenderBase.DeviceContext.Draw(3 * 3, 0); * }*/ }
public void Render() { ET += 1.0f / 60.0f; RenderBase.SetWorld(Matrix.Identity); vertexShaderSway.Set(); RenderBase.DeviceContext.PixelShader.Set(plantPixelShader); paramsBuffer.Set(2); RenderBase.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; //Draw Fish RenderBase.DeviceContext.OutputMerger.BlendState = RenderBase.BlendStates.Default; //Console.WriteLine("A"); var di = plantInstanceBuffer.Map(); for (int i = 0; i < plantData.Length; i++) { //Console.WriteLine("B"); ////////var ds = paramsBuffer.Map(); ////////ds.Write(new Vector4(0.0f, plantData[i].W, 0.0f, 1.0f)); ////////ds.Write(ET * plantWaveSpeed[i] + (i % 100) * (i % 100)); ////////paramsBuffer.UnMap(); //RenderBase.SetWorld(Matrix.Scaling(plantData[i].Y) * Matrix.RotationZ(plantData[i].Z) * Matrix.Translation(plantData[i].X, -1.1f, -0.001f * (150 - plantData.Length + i))); di.Write(Matrix.Scaling(plantData[i].Y) * Matrix.RotationZ(plantData[i].Z) * Matrix.Translation(plantData[i].X, -1.1f, -0.001f * (i - plantData.Length * 7 / 10))); di.Write(new Vector4(0.0f, plantData[i].W, 0.0f, ET * plantWaveSpeed[i] + (i % 100) * (i % 100))); //RenderBase.DeviceContext.Draw(plantVertCount, 0); } plantInstanceBuffer.UnMap(); //Console.WriteLine("C"); RenderBase.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(plantVertexBuffer, Utilities.SizeOf <VertexPositionNormal>(), 0), new VertexBufferBinding(plantInstanceBuffer.Buffer, Utilities.SizeOf <Matrix>() + Utilities.SizeOf <Vector4>(), 0)); RenderBase.DeviceContext.DrawInstanced(plantVertCount, plantData.Length * 7 / 10, 0, 0); { vertexShader.Set(); RenderBase.DeviceContext.PixelShader.Set(pixelShader); RenderBase.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(floorVertexBuffer, Utilities.SizeOf <VertexPositionNormal>(), 0)); var ds = paramsBuffer.Map(); ds.Write(new Vector4(0.7f, 0.7f, 0.7f, 0.0f)); ds.Write(0); paramsBuffer.UnMap(); //paramsBuffer.Set(2); RenderBase.SetWorld(Matrix.Scaling((16.0f / 9.0f) / 4.0f) * Matrix.Translation(0, -1.0f, 0.0f)); //System.Threading.Thread.Sleep(250); RenderBase.DeviceContext.Draw(floorVertCount, 0); } /*{ * var ds = paramsBuffer.Map(); * ds.Write(new Vector4(1, 1, 1, 1)); * paramsBuffer.UnMap(); * RenderBase.SetWorld(Matrix.Scaling(0.15f) * Matrix.Translation(Input.XInputInput.State[0].RightThumbX / (float)short.MaxValue, Input.XInputInput.State[0].RightThumbY / (float)short.MaxValue, 0));//Matrix.Scaling(0.05f)); * RenderBase.DeviceContext.Draw(3 * 3, 0); * }*/ }
private void WriteWVP() { var ds = WVP.Map(); ds.Write(World); ds.Write(View); ds.Write(Projection); ds.Write(Normal); WVP.UnMap(); }
public void Render() { //RenderBase.DeviceContext.Rasterizer.State = RenderBase.RasterizerStates.None; var dt = 1.0f / 60.0f; et += dt; //RenderBase.SetWorld(Matrix.Identity); vertexShader.Set(); RenderBase.DeviceContext.PixelShader.Set(pixelShader); paramsBuffer.Set(2); RenderBase.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; RenderBase.DeviceContext.OutputMerger.BlendState = RenderBase.BlendStates.Additive; if ((Input.XInputInput.State[0].Buttons & SharpDX.XInput.GamepadButtonFlags.Y) == SharpDX.XInput.GamepadButtonFlags.Y) { //Draw Sight RenderBase.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(coneVertexBuffer, Utilities.SizeOf <VertexPositionColor>(), 0)); for (int i = 0; i < Manager.FishCount && i == 0; i++) { var fish = Manager.FishList[i]; for (int j = 0; j < fish.Sights.Length; j++) { var ds = paramsBuffer.Map(); if (fish.Sights[j].Color.W == 0.0f) { ds.Write(new Vector4(1, 1, 0, 0.05f)); } else { ds.Write(fish.Sights[j].Color); } ds.Write(0.0f); paramsBuffer.UnMap(); RenderBase.SetWorld(Matrix.Scaling((float)Math.Cos(fish.Sights[j].WidthAngle / 2.0f) * fish.Sights[j].Distance, (float)Math.Sin(fish.Sights[j].WidthAngle / 2.0f) * fish.Sights[j].Distance, 1.0f) * Matrix.RotationZ(fish.Sights[j].MidAngle) * Matrix.Translation(fish.Sights[j].Start.X, fish.Sights[j].Start.Y, 0.0f) * Matrix.RotationZ(fish.Rotation) * Matrix.Translation(fish.Position.X, fish.Position.Y, 0.0f));//Matrix.Scaling(0.05f)); RenderBase.DeviceContext.Draw(3, 0); } } } for (int mi = 0; mi < vertexBuffer.Length; mi++) { RenderBase.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer[mi], Utilities.SizeOf <VertexPositionNormal>(), 0)); foreach (var fish in Manager.DeadFish) { if (fish.MeshIndex != mi) { continue; } var ds = paramsBuffer.Map(); ds.Write(fish.Color.X); ds.Write(fish.Color.Y); ds.Write(fish.Color.Z); ds.Write(fish.Color.W * (1.0f + fish.FoodLevel / 3.0f)); ds.Write(fish.FoodLevel * 10.0f); ds.Write(fish.Seed); paramsBuffer.UnMap(); RenderBase.SetWorld(Matrix.Scaling(fish.Size.X, fish.Size.Y, (fish.Size.X + fish.Size.Y) / 2.0f) * Matrix.RotationX(fish.Roll) * Matrix.RotationZ(fish.Rotation) * Matrix.Translation(fish.Position.X, fish.Position.Y, 0.0f));//Matrix.Scaling(0.05f)); RenderBase.DeviceContext.Draw(vertexCount[mi], 0); } //Draw Fish RenderBase.DeviceContext.OutputMerger.BlendState = RenderBase.BlendStates.Default; for (int i = 0; i < Manager.FishCount; i++) { var fish = Manager.FishList[i]; if (fish.MeshIndex != mi) { continue; } var ds = paramsBuffer.Map(); ds.Write(Manager.FishList[i].Color); ds.Write(0); ds.Write(0); paramsBuffer.UnMap(); RenderBase.SetWorld(Matrix.Scaling(fish.Size.X, fish.Size.Y, (fish.Size.X + fish.Size.Y) / 2.0f) * Matrix.RotationX(fish.Roll) * Matrix.RotationZ(fish.Rotation) * Matrix.Translation(fish.Position.X, fish.Position.Y, 0.0f));//Matrix.Scaling(0.05f)); RenderBase.DeviceContext.Draw(vertexCount[mi], 0); } } /*{ * var ds = paramsBuffer.Map(); * ds.Write(new Vector4(1, 1, 1, 1)); * paramsBuffer.UnMap(); * RenderBase.SetWorld(Matrix.Scaling(0.15f) * Matrix.Translation(Input.XInputInput.State[0].RightThumbX / (float)short.MaxValue, Input.XInputInput.State[0].RightThumbY / (float)short.MaxValue, 0));//Matrix.Scaling(0.05f)); * RenderBase.DeviceContext.Draw(3 * 3, 0); * }*/ }