public FishRenderer(RenderBase rb, FishManager manager)
        {
            RenderBase = rb;
            Manager    = manager;

            paramsBuffer = new UConstantBuffer(RenderBase, Utilities.SizeOf <Vector4>() * 2);

            var shaderFlags =
#if DEBUG
                ShaderFlags.Debug;
#else
                ShaderFlags.None;
#endif

            vertexShader = new UVertexShader(RenderBase, "shaders/Vertex_PC_Explode.hlsl", VertexPositionNormal.InputElements);
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile("shaders/Pixel_PC_FishPointLights.hlsl", "main", "ps_4_0", shaderFlags))
                pixelShader = new PixelShader(RenderBase.Device, pixelShaderByteCode);

            vertexBuffer    = new Buffer[3];
            vertexCount     = new int[vertexBuffer.Length];
            vertexBuffer[0] = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer, VertexPositionNormal.LoadSTL("models/fish.stl", out vertexCount[0]));
            vertexBuffer[1] = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer, VertexPositionNormal.LoadSTL("models/fish4.stl", out vertexCount[1]));
            vertexBuffer[2] = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer, VertexPositionNormal.LoadSTL("models/fish5.stl", out vertexCount[2]));

            coneVertexBuffer = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer,
                                             new VertexPositionColor[] { new VertexPositionColor(new Vector3(0.0f, 0.0f, 0.0f), Color.White), new VertexPositionColor(new Vector3(1.0f, 1.0f, 0.0f), Color.White), new VertexPositionColor(new Vector3(1.0f, -1.0f, 0.0f), Color.White) });
        }
Exemplo n.º 2
0
        public DecorRenderer(RenderBase rb)
        {
            RenderBase = rb;

            paramsBuffer = new UConstantBuffer(RenderBase, Utilities.SizeOf <Vector4>() * 2);

            var shaderFlags =
#if DEBUG
                ShaderFlags.Debug;
#else
                ShaderFlags.None;
#endif

            vertexShaderSway = new UVertexShader(RenderBase, "shaders/Vertex_PNI_Wave.hlsl", VertexPositionNormal.InputElementsInstanced);
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile("shaders/Pixel_PNI_FishPointLightsAbs.hlsl", "main", "ps_4_0", shaderFlags))
                plantPixelShader = new PixelShader(RenderBase.Device, pixelShaderByteCode);
            vertexShader = new UVertexShader(RenderBase, "shaders/Vertex_PN_Standard.hlsl", VertexPositionNormal.InputElements);
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile("shaders/Pixel_PC_FishPointLightsAbs.hlsl", "main", "ps_4_0", shaderFlags))
                pixelShader = new PixelShader(RenderBase.Device, pixelShaderByteCode);

            plantVertexBuffer = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer,
                                              VertexPositionNormal.LoadSTL("models/plant.stl", out plantVertCount));

            floorVertexBuffer = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer,
                                              VertexPositionNormal.LoadSTL("models/tankFloor.stl", out floorVertCount));

            /*plantData = new Vector4[]
             * {
             *  new Vector4(-0.8f, .07f, 0, 0.1f),
             *  new Vector4(0.9f, .04f, 0, 0.2f),
             *  new Vector4(-0.95f, .06f, 0, 0.15f),
             * };
             * plantWaveSpeed = new float[]
             * {
             *  1.0f,
             *  1.2f,
             *  0.6f,
             * };*/

            Random rnd = new Random();
            plantData      = new Vector4[500];
            plantWaveSpeed = new float[plantData.Length];
            for (int i = 0; i < plantData.Length; i++)
            {
                var sizeMul = 0.333f;
                if (rnd.Next(0, 25) == 0)
                {
                    sizeMul = 0.5f;
                }
                plantData[i]      = new Vector4(rnd.NextFloat(-16.0f / 9.0f * 1.5f, 16.0f / 9.0f * 1.5f), rnd.NextFloat(0.01f, 0.1f) * sizeMul, 0, rnd.NextFloat(0.05f, 0.3f));
                plantWaveSpeed[i] = rnd.NextFloat(0.01f, 2.0f);
            }

            plantInstanceBuffer = new DynamicVertexBuffer(rb, (Utilities.SizeOf <Matrix>() + Utilities.SizeOf <Vector4>()) * plantData.Length);
        }
Exemplo n.º 3
0
        public DynamicVertexBuffer(RenderBase rb, int size)
        {
            this.RenderBase = rb;

            Buffer = new Buffer(rb.Device, new BufferDescription()
            {
                Usage          = ResourceUsage.Dynamic,
                SizeInBytes    = size,
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags    = ResourceOptionFlags.None,
            });
        }
Exemplo n.º 4
0
        private static void StartSim(int adapterIndex)
        {
            using (RenderBase rb = new RenderBase(adapterIndex))
            {
                rb.Run();
            }

            var liveObjs = ObjectTracker.FindActiveObjects();

            Console.WriteLine(liveObjs.Count + " live objects");
            foreach (var o in liveObjs)
            {
                Console.WriteLine(o.ToString());
            }
            //Console.WriteLine(ObjectTracker.ReportActiveObjects());
            //Console.ReadKey(true);
        }
Exemplo n.º 5
0
        public RaysRenderer(RenderBase rb)
        {
            RenderBase = rb;

            var shaderFlags =
#if DEBUG
                ShaderFlags.Debug;
#else
                ShaderFlags.None;
#endif

            vertexShader = new UVertexShader(RenderBase, "shaders/Vertex_FS.hlsl", null);
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile("shaders/Pixel_GodRays.hlsl", "main", "ps_4_0", shaderFlags))
                pixelShader = new PixelShader(RenderBase.Device, pixelShaderByteCode);

            cb = new ConstantBuffers.UConstantBuffer(RenderBase, 4 * 4 * 2);
        }
        public FishGlow(RenderBase rb, FishManager manager)
        {
            RenderBase = rb;
            Manager    = manager;

            var shaderFlags =
#if DEBUG
                ShaderFlags.Debug;
#else
                ShaderFlags.None;
#endif

            vertexShader = new UVertexShader(RenderBase, "shaders/Vertex_FS.hlsl", null);
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile("shaders/Pixel_FishGlow.hlsl", "main", "ps_4_0", shaderFlags))
                pixelShader = new PixelShader(RenderBase.Device, pixelShaderByteCode);

            cb = new ConstantBuffers.UConstantBuffer(RenderBase, 4 * 4 + FishManager.MAX_FISH_COUNT * 2 * 4 * 4);
        }
        public UVertexShader(RenderBase rb, string filename, InputElement[] inputElements)
        {
            RenderBase = rb;

            var shaderFlags =
#if DEBUG
                ShaderFlags.Debug;
#else
                ShaderFlags.None;
#endif
            using (var vertexShaderByteCode = ShaderBytecode.CompileFromFile(filename, "main", "vs_4_0", shaderFlags))
            {
                inputSignature = ShaderSignature.GetInputSignature(vertexShaderByteCode);
                VertexShader   = new VertexShader(rb.Device, vertexShaderByteCode);
            }

            if (inputElements != null)
            {
                inputLayout = new InputLayout(rb.Device, inputSignature, inputElements);
            }
        }
Exemplo n.º 8
0
        public RenderTarget2D(RenderBase rb, int width, int height, bool depth)
        {
            RenderBase = rb;

            Texture = new Texture2D(RenderBase.Device, new Texture2DDescription()
            {
                Width          = width,
                Height         = height,
                OptionFlags    = ResourceOptionFlags.None,
                BindFlags      = BindFlags.ShaderResource | BindFlags.RenderTarget,
                Format         = Format.R32G32B32A32_Float,
                CpuAccessFlags = CpuAccessFlags.None,

                ArraySize         = 1,
                MipLevels         = 1,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default
            });
            SRV = new ShaderResourceView(RenderBase.Device, Texture);
            RTV = new RenderTargetView(RenderBase.Device, Texture);

            if (depth)
            {
                DepthTexture = new Texture2D(RenderBase.Device, new Texture2DDescription()
                {
                    Width          = width,
                    Height         = height,
                    OptionFlags    = ResourceOptionFlags.None,
                    BindFlags      = BindFlags.DepthStencil,
                    Format         = Format.D24_UNorm_S8_UInt,
                    CpuAccessFlags = CpuAccessFlags.None,

                    ArraySize         = 1,
                    MipLevels         = 1,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = ResourceUsage.Default
                });
                DSV = new DepthStencilView(RenderBase.Device, DepthTexture);
            }
        }
        public FoodRenderer(RenderBase rb, FoodManager manager)
        {
            RenderBase = rb;
            Manager    = manager;

            paramsBuffer = new UConstantBuffer(RenderBase, Utilities.SizeOf <Vector4>() * 2);

            var shaderFlags =
#if DEBUG
                ShaderFlags.Debug;
#else
                ShaderFlags.None;
#endif

            vertexShader = new UVertexShader(RenderBase, "shaders/Vertex_PN_Standard.hlsl", VertexPositionNormal.InputElements);
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile("shaders/Pixel_PC_FishPointLights.hlsl", "main", "ps_4_0", shaderFlags))
                pixelShader = new PixelShader(RenderBase.Device, pixelShaderByteCode);

            vertexBuffer = Buffer.Create(RenderBase.Device, BindFlags.VertexBuffer,
                                         //new VertexPositionColor[] { new VertexPositionColor(new Vector3(-0.5f, 0.5f, 0.0f), Color.White), new VertexPositionColor(new Vector3(0.5f, 0.5f, 0.0f), Color.White), new VertexPositionColor(new Vector3(-0.5f, -0.5f, 0.0f), Color.White),
                                         //                            new VertexPositionColor(new Vector3(0.5f, -0.5f, 0.0f), Color.White), new VertexPositionColor(new Vector3(-0.5f, -0.5f, 0.0f), Color.White), new VertexPositionColor(new Vector3(0.5f, 0.5f, 0.0f), Color.White)});
                                         VertexPositionNormal.LoadSTL("models/food.stl", out vertCount));
        }
 internal SunBuffer(RenderBase rb)
 {
     cb = new ConstantBuffers.UConstantBuffer(rb, Utilities.SizeOf <Vector4>() * 2);
 }