Beispiel #1
0
        /// <inheritdoc/>
        public override void Initialize(EffectContext effectContext, TransformGraph transformGraph)
        {
            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            effectContext.LoadPixelShader(GUID_RipplePixelShader, NativeFile.ReadAllBytes(path + "\\Ripple.cso"));
            transformGraph.SetSingleTransformNode(this);
        }
Beispiel #2
0
        //EffectContext _effectContext;
        public override void Initialize(EffectContext effectContext, TransformGraph transformGraph)
        {
            //WARNING : as soon as TransformGraph.SetSingleTransformNode is called it chain calls the
            //SetDrawInformation via a callbac. Unfortunately this is too early because the code below
            //within this method is used to populate stateful data needed by the SetDrawInformation call.
            //transformGraph.SetSingleTransformNode(this);

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            byte[] vertexShaderBytecode = NativeFile.ReadAllBytes(path + "\\WaveEffect.cso");
            effectContext.LoadVertexShader(GUID_WaveVertexShader, vertexShaderBytecode);

            // Only generate the vertex buffer if it has not already been initialized.
            vertexBuffer = effectContext.FindVertexBuffer(GUID_WaveVertexBuffer);

            if (vertexBuffer == null)
            {
                //InitializeVertexBuffer(effectContext);

                var mesh = GenerateMesh();

                // Updating geometry every time the effect is rendered can be costly, so it is
                // recommended that vertex buffer remain static if possible (which it is in this
                // sample effect).
                using (var stream = DataStream.Create(mesh, true, true))
                {
                    var vbProp = new VertexBufferProperties(1, VertexUsage.Static, stream);

                    var cvbProp = new CustomVertexBufferProperties(vertexShaderBytecode, new[] {
                        new InputElement("MESH_POSITION", 0, SharpDX.DXGI.Format.R32G32_Float, 0, 0),
                    }, Utilities.SizeOf <Vector2>());

                    // The GUID is optional, and is provided here to register the geometry globally.
                    // As mentioned above, this avoids duplication if multiple versions of the effect
                    // are created.
                    vertexBuffer = new VertexBuffer(effectContext, GUID_WaveVertexBuffer, vbProp, cvbProp);
                }
            }

            PrepareForRender(ChangeType.Properties | ChangeType.Context);
            transformGraph.SetSingleTransformNode(this);
        }
Beispiel #3
0
        public override void CreateDeviceResources()
        {
            base.CreateDeviceResources();

            Utilities.Dispose(ref _vertexShader);
            Utilities.Dispose(ref _pixelShader);
            Utilities.Dispose(ref _vertexLayout);
            Utilities.Dispose(ref _constantBuffer);

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCube_VS.fxo");

            _vertexShader = new VertexShader(_device, vertexShaderByteCode);

            // Loads pixel shader bytecode
            _pixelShader = new PixelShader(_device, NativeFile.ReadAllBytes(path + "\\MiniCube_PS.fxo"));

            // Layout from VertexShader input signature
            _vertexLayout = new InputLayout(_device, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
            });

            // Instantiate Vertex buffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(_device, BindFlags.VertexBuffer, new[]
            {
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),                       // Front
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),                        // BACK
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),                        // Top
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),

                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),                       // Bottom
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),                       // Left
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),

                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),                        // Right
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
            });

            _vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf <Vector4>() * 2, 0);

            // Create Constant Buffer
            _constantBuffer = new SharpDX.Direct3D11.Buffer(_device, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _clock = new Stopwatch();
            _clock.Start();

            _loadingComplete = true;
        }
        public override void Initialize(DeviceManager deviceManager)
        {
            base.Initialize(deviceManager);

            // Remove previous buffer
            if (this.constantBuffer != null)
            {
                this.constantBuffer.Dispose();
            }
            // RemoveAndDispose(ref constantBuffer);

            // Setup local variables
            var d3dDevice  = deviceManager.DeviceDirect3D;
            var d3dContext = deviceManager.ContextDirect3D;

            var path = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "HelixToolkit.Win8");

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCube_VS.fxo");

            this.vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            this.pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\MiniCube_PS.fxo"));

            // Layout from VertexShader input signature
            this.layout = new InputLayout(
                d3dDevice,
                vertexShaderByteCode,
                new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
            });

            // Instantiate Vertex buffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(
                d3dDevice,
                BindFlags.VertexBuffer,
                new[]
            {
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),         // Front
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),         // BACK
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),         // Top
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),         // Bottom
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),         // Left
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),         // Right
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
            });

            this.vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf <Vector4>() * 2, 0);

            // Create Constant Buffer
            this.constantBuffer = new SharpDX.Direct3D11.Buffer(
                d3dDevice,
                Utilities.SizeOf <SharpDX.Matrix>(),
                ResourceUsage.Default,
                BindFlags.ConstantBuffer,
                CpuAccessFlags.None,
                ResourceOptionFlags.None,
                0);

            this.clock = new Stopwatch();
            this.clock.Start();
        }
Beispiel #5
0
        /// <summary>
        /// Loads the content.
        /// </summary>
        public void LoadContent()
        {
            parts.Clear();
            var d3dDevice = deviceManager.DeviceDirect3D;

            white = Texture.LoadFromFile(d3dDevice, WhiteTexturePath).Result;

            Model treeBench   = Model.Load(d3dDevice, TreeBenchModelPath);
            Model treeParking = Model.Load(d3dDevice, TreeParkingModelPath);
            Model windowPost  = Model.Load(d3dDevice, WindowMailboxModelPath);
            Model windowWater = Model.Load(d3dDevice, WindowHidrantModelPath);

            Texture treeBenchLm   = Texture.LoadFromFile(d3dDevice, TreeBenchLightmapPath).Result;
            Texture treeParkingLm = Texture.LoadFromFile(d3dDevice, TreeParkingLightmapPath).Result;
            Texture windowPostLm  = Texture.LoadFromFile(d3dDevice, WindowMailboxLightmapPath).Result;
            Texture windowWaterLm = Texture.LoadFromFile(d3dDevice, WindowHidrantLightmapPath).Result;

            mapObjects.Add(new MapObject(treeBench, treeBenchLm));
            mapObjects.Add(new MapObject(treeParking, treeParkingLm));
            mapObjects.Add(new MapObject(windowPost, windowPostLm));
            mapObjects.Add(new MapObject(windowWater, windowWaterLm));

            Model roadModel = Model.Load(d3dDevice, RoadModelPath);

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            icon        = Model.Load(d3dDevice, IconeModelPath);
            iconPicture = Model.Load(d3dDevice, IconPictureModelPath);

            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Content\\Shaders\\DefaultShaderVS.fxo");

            vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);
            pixelShader  = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Content\\Shaders\\DefaultShaderPS.fxo"));

            layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0)
            });

            sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = Colors.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy  = 0,
                MipLodBias         = 0,
                MinimumLod         = -float.MaxValue,
                MaximumLod         = float.MaxValue
            });

            float roadDistance = (roadModel.BBox.Maximum.Z - roadModel.BBox.Minimum.Z);

            for (int i = 0; i < 18; i++)
            {
                Entity leftPart = factory.CreateEntity(WallModelPath, WallTexturePath);
                leftPart.Transform = Matrix.RotationX((float)Math.PI) * Matrix.Translation(0, 0, roadDistance * i);
                Entity rightPart = factory.CreateEntity(WallRModelPath, WallTexturePath);
                rightPart.Transform = Matrix.RotationX((float)Math.PI) * Matrix.Translation(0, 0, roadDistance * i);
                Entity roadPart = factory.CreateEntity(RoadModelPath, RoadTexturePath);
                roadPart.Transform = Matrix.Translation(0, 0, roadDistance * i);

                parts.Add(roadPart);
                parts.Add(leftPart);
                parts.Add(rightPart);

                if (randomizer.Next(0, 10) < 7)
                {
                    int    item  = randomizer.Next(0, mapObjects.Count);
                    Entity child = factory.CreateEntity(mapObjects[item].Model.modelPath, ObjectsTexturePath);
                    child.Transform = Matrix.Identity;
                    leftPart.SetChild(child);
                    leftPart.Lightmap = mapObjects[item].ParentLightmap;
                }
                if (randomizer.Next(0, 10) < 7)
                {
                    int    item  = randomizer.Next(0, mapObjects.Count);
                    Entity child = factory.CreateEntity(mapObjects[item].Model.modelPath, ObjectsTexturePath);
                    child.Transform = Matrix.Scaling(-1.0f, 1.0f, 1.0f);
                    rightPart.SetChild(child);
                    rightPart.Lightmap = mapObjects[item].ParentLightmap;
                }
            }

            playerEntity = factory.CreateEntity(HipsterModelPath, HipsterTexturePath);
            Entity skate = factory.CreateEntity(SkateModelPath, SkateTexturePath);

            playerEntity.SetChild(skate);

            BlendStateDescription blendDescription = new BlendStateDescription();

            blendDescription.RenderTarget[0].IsBlendEnabled        = true;
            blendDescription.RenderTarget[0].BlendOperation        = blendDescription.RenderTarget[0].AlphaBlendOperation = SharpDX.Direct3D11.BlendOperation.Add;
            blendDescription.RenderTarget[0].SourceBlend           = blendDescription.RenderTarget[0].SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.One;
            blendDescription.RenderTarget[0].DestinationBlend      = blendDescription.RenderTarget[0].DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha;
            blendDescription.RenderTarget[0].RenderTargetWriteMask = SharpDX.Direct3D11.ColorWriteMaskFlags.All;

            blend = new SharpDX.Direct3D11.BlendState(d3dDevice, blendDescription);

            RasterizerStateDescription rasterDescription = new RasterizerStateDescription();

            rasterDescription.CullMode                 = CullMode.None;
            rasterDescription.DepthBias                = 0;
            rasterDescription.DepthBiasClamp           = 0;
            rasterDescription.FillMode                 = FillMode.Solid;
            rasterDescription.IsAntialiasedLineEnabled = false;
            rasterDescription.IsDepthClipEnabled       = true;
            rasterDescription.IsFrontCounterClockwise  = false;
            rasterDescription.IsMultisampleEnabled     = false;
            rasterDescription.IsScissorEnabled         = false;
            rasterDescription.SlopeScaledDepthBias     = 0;

            raster = new RasterizerState(d3dDevice, rasterDescription);
        }
Beispiel #6
0
        public virtual void Initialize(DeviceManager devices)
        {
            // Remove previous buffer
            RemoveAndDispose(ref constantBuffer);

            // Setup local variables
            var d3dDevice  = devices.DeviceDirect3D;
            var d3dContext = devices.ContextDirect3D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            try {
                // Loads vertex shader bytecode
                var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCube_VS.fxo");
                vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

                // Loads pixel shader bytecode
                var pixelShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCube_PS.fxo");
                pixelShader = new PixelShader(d3dDevice, pixelShaderByteCode);

                // Layout from VertexShader input signature
                layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
                {
                    new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                    new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
                });
            }
            catch (FileNotFoundException ex)
            {
                //TODO: handle file not found
            }



            // Instantiate Vertex buffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(d3dDevice, BindFlags.VertexBuffer, new[]
            {
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),                       // Front
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),                        // BACK
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),                        // Top
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),

                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),                       // Bottom
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),                       // Left
                new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),

                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),                        // Right
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
            });

            vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf <Vector4>() * 2, 0);

            // Create Constant Buffer
            constantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            clock = new Stopwatch();
            clock.Start();
        }
Beispiel #7
0
            /// <inheritdoc/>
            public void SetWindow(CoreWindow window)
            {
                this.window = window;

                // Starts the timer
                clock = Stopwatch.StartNew();

                // Creates Direct3D11 device
                using (var defaultDevice = new Device(DriverType.Hardware, DeviceCreationFlags.None))
                    graphicsDevice = defaultDevice.QueryInterface <Device1>();


                // Setup swapchain, render target, depth stencil buffer.
                SetupScreenBuffers();

                string path = Package.Current.InstalledLocation.Path;

                // Loads vertex shader bytecode
                var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCube_VS.fxo");

                vertexShader = new VertexShader(graphicsDevice, vertexShaderByteCode);

                // Loads pixel shader bytecode
                pixelShader = new PixelShader(graphicsDevice, NativeFile.ReadAllBytes(path + "\\MiniCube_PS.fxo"));

                // Layout from VertexShader input signature
                layout = new InputLayout(graphicsDevice, vertexShaderByteCode, new[]
                {
                    new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                    new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 16, 0)
                });

                // Instantiate Vertex buffer from vertex data
                Buffer vertices = Buffer.Create(graphicsDevice, BindFlags.VertexBuffer, new[]
                {
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), Color.Orange),                                                                        // Front
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, -1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, -1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, -1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), Color.Orange),                                                                         // BACK
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, 1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f), Color.Orange),
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), Color.OrangeRed),                                                                         // Top
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, -1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), Color.OrangeRed),                                                                        // Bottom
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, 1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, -1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, 1.0f, 1.0f), Color.OrangeRed),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), Color.DarkOrange),                                                                        // Left
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, -1.0f, 1.0f), Color.DarkOrange),                                                                         // Right
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, 1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(1.0f, -1.0f, -1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, -1.0f, 1.0f), Color.DarkOrange),
                    new VertexPositionColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f), Color.DarkOrange),
                });

                vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf <VertexPositionColor>(), 0);

                // Create Constant Buffer
                constantBuffer = ToDispose(new Buffer(graphicsDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            }
Beispiel #8
0
        public virtual void Initialize(DeviceManager devices)
        {
            // Remove previous buffer
            RemoveAndDispose(ref constantBuffer);

            // Setup local variables
            var d3dDevice  = devices.DeviceDirect3D;
            var d3dContext = devices.ContextDirect3D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_VS.fxo");

            vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_PS.fxo"));

            // Layout from VertexShader input signature
            layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0)
            });

            // Instantiate Vertex buiffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(d3dDevice, BindFlags.VertexBuffer, new[]
            {
                // 3D coordinates              UV Texture coordinates
                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,                           // Front
                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,                            // BACK
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,

                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,                            // Top
                -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,                           // Bottom
                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,

                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,                           // Left
                -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,                            // Right
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
            });

            vertexBufferBinding = new VertexBufferBinding(vertices, sizeof(float) * 6, 0);

            // Create Constant Buffer
            constantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            // Load texture and create sampler
            using (var bitmap = TextureLoader.LoadBitmap(devices.WICFactory, "GeneticaMortarlessBlocks.jpg"))
                using (var texture2D = TextureLoader.CreateTexture2DFromBitmap(d3dDevice, bitmap))
                    textureView = new ShaderResourceView(d3dDevice, texture2D);

            sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy  = 16,
                MipLodBias         = 0,
                MinimumLod         = -float.MaxValue,
                MaximumLod         = float.MaxValue
            });

            clock = new Stopwatch();
            clock.Start();
        }
 public SoundDataBank()
 {
     bank = new Dictionary <eSFX, byte[]>();
     bank.Add(eSFX.planet, NativeFile.ReadAllBytes(curdir + @"\Assets\Planet.wav"));
     bank.Add(eSFX.base1, NativeFile.ReadAllBytes(curdir + @"\Assets\Base.wav"));
 }
Beispiel #10
0
        private void CreateD3D_rDto(string assetUrl)
        {
            RenderDTO rDto = new RenderDTO();

            rDto.D3DPrimitiveDTO = new D3DPrimitiveDTO();

            //SafeDispose(ref rDto.D3DPrimitiveDTO.VertexBuffer);
            //rDto.D3DPrimitiveDTO.IsRenderable = true;
            // Remove previous buffer
            //SafeDispose(ref rDto.D3DPrimitiveDTO.ConstantBuffer);

            // Setup local variables
            var d3dDevice  = _deviceManager.DeviceDirect3D;
            var d3dContext = _deviceManager.ContextDirect3D;
            var d2dDevice  = _deviceManager.DeviceDirect2D;
            var d2dContext = _deviceManager.ContextDirect2D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_VS.fxo");

            rDto.D3DPrimitiveDTO.VertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            rDto.D3DPrimitiveDTO.PixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_PS.fxo"));

            // Layout from VertexShader input signature
            rDto.D3DPrimitiveDTO.Layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0)
            });


            // Instantiate Vertex buffer from vertex data
            float thicknessToUse = 0.15f;

            thicknessToUse = 1.0f;                  //project.Thickness;

            rDto.D3DPrimitiveDTO.VertexCount  = 36; //6 * 6
            rDto.D3DPrimitiveDTO.VertexBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, sizeof(float) * 6, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            rDto.D3DPrimitiveDTO.VertexBuffer = GenerateVertexBuffer6Sided(d3dDevice, thicknessToUse);

            //vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0);
            rDto.D3DPrimitiveDTO.VertexBufferBinding = new VertexBufferBinding(rDto.D3DPrimitiveDTO.VertexBuffer, sizeof(float) * 6, 0);

            // Create Constant Buffer
            rDto.D3DPrimitiveDTO.ConstantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            //TextureView
            RenderD3DDto(assetUrl, rDto);

            rDto.D3DPrimitiveDTO.Sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy  = 16,
                MipLodBias         = 0,
                MinimumLod         = 0,
                MaximumLod         = 16,
            });

            BlendStateDescription1 blendDesc = new BlendStateDescription1();

            blendDesc.AlphaToCoverageEnable                   = true; //set to true to get nice blending betweent sprites
            blendDesc.IndependentBlendEnable                  = false;
            blendDesc.RenderTarget[0].IsBlendEnabled          = false;
            blendDesc.RenderTarget[0].IsLogicOperationEnabled = false;
            blendDesc.RenderTarget[0].SourceBlend             = BlendOption.SourceAlpha;
            blendDesc.RenderTarget[0].DestinationBlend        = BlendOption.SourceAlphaSaturate;
            blendDesc.RenderTarget[0].BlendOperation          = BlendOperation.Maximum;
            blendDesc.RenderTarget[0].SourceAlphaBlend        = BlendOption.One;
            blendDesc.RenderTarget[0].DestinationAlphaBlend   = BlendOption.One;
            blendDesc.RenderTarget[0].AlphaBlendOperation     = BlendOperation.Maximum; // set to maximum to blend 2 sprites nicely over each other
            blendDesc.RenderTarget[0].RenderTargetWriteMask   = ColorWriteMaskFlags.All;
            rDto.D3DPrimitiveDTO.BlendState                   = new BlendState1(d3dDevice, blendDesc);

            _renderTree.Add(rDto);
        }
Beispiel #11
0
 private static byte[] ReadData(string relativePath)
 {
     return(NativeFile.ReadAllBytes(Path.Combine(Package.Current.InstalledLocation.Path, relativePath)));
 }
        public void Initialize(Device1 d3dDevice, DeviceContext1 d3dContext, int capacity = 1024)
        {
            m_d3dDevice = d3dDevice;

            m_d3dContext = d3dContext;



            m_capacity = capacity;



            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;



            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Assets\\SpriteBatch.vs.cso");

            m_vertexShader = new VertexShader(m_d3dDevice, vertexShaderByteCode);

            m_pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Assets\\SpriteBatch.ps.cso"));



            // Layout from VertexShader input signature
            m_layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 16, 0),
                new InputElement("COLOR", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 24, 0),
            });



            SamplerStateDescription samplerDesc = SharpDX.Direct3D11.SamplerStateDescription.Default();

            m_sampler = new SamplerState(d3dDevice, samplerDesc);



            //BlendStateDescription1 blendDesc = new BlendStateDescription1();
            //blendDesc.AlphaToCoverageEnable = true;  //set to true to get nice blending betweent sprites
            //blendDesc.IndependentBlendEnable = false;
            //blendDesc.RenderTarget[0].IsBlendEnabled = true;
            //blendDesc.RenderTarget[0].IsLogicOperationEnabled = false;
            //blendDesc.RenderTarget[0].SourceBlend = BlendOption.SourceColor;
            //blendDesc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlphaSaturate;
            //blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Add;
            //blendDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One;
            //blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One
            //blendDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; // set to maximum to blend 2 sprites nicely over each other
            //blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            //m_blendStateAlpha = new BlendState1(d3dDevice, blendDesc);



            var description = BlendStateDescription1.Default();

            description.RenderTarget[0].IsBlendEnabled          = true;
            description.RenderTarget[0].SourceBlend             = BlendOption.SourceAlpha;
            description.RenderTarget[0].DestinationBlend        = BlendOption.One;
            description.RenderTarget[0].SourceAlphaBlend        = BlendOption.SourceAlpha;
            description.RenderTarget[0].DestinationAlphaBlend   = BlendOption.One;
            description.RenderTarget[0].BlendOperation          = BlendOperation.Add;
            description.RenderTarget[0].IsLogicOperationEnabled = false;
            description.RenderTarget[0].AlphaBlendOperation     = BlendOperation.Maximum;
            description.RenderTarget[0].RenderTargetWriteMask   = ColorWriteMaskFlags.All;
            description.AlphaToCoverageEnable  = true; //<==RT DOES NOT WORK
            description.IndependentBlendEnable = false;
            m_blendStateAlpha = new BlendState1(d3dDevice, description);



            //[BELOW] Windows RT this does not work
            //var description = BlendStateDescription1.Default();
            //description.RenderTarget[0].IsBlendEnabled = true;
            //description.RenderTarget[0].SourceBlend = BlendOption.SourceColor;
            //description.RenderTarget[0].DestinationBlend = BlendOption.SourceAlphaSaturate;
            //description.RenderTarget[0].SourceAlphaBlend = BlendOption.One;
            //description.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
            //description.RenderTarget[0].BlendOperation = BlendOperation.Add;
            //description.RenderTarget[0].IsLogicOperationEnabled = false;
            //description.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum;
            //description.AlphaToCoverageEnable = true;
            //description.IndependentBlendEnable = false;
            //description.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

            //m_blendStateAlpha = new BlendState1(d3dDevice, description);



            m_constantBufferVS = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            m_constantBufferPS = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));



            //=======================

            // Setup the pipeline

            //=======================

            m_vertices = ToDispose(BuildVerticesBuffer(d3dDevice, 1.0f, new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1)));

            m_vertexBufferBinding = new VertexBufferBinding(m_vertices, sizeof(float) * 10, 0);

            d3dContext.InputAssembler.SetVertexBuffers(0, m_vertexBufferBinding);



            d3dContext.InputAssembler.InputLayout = m_layout;

            d3dContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;



            d3dContext.VertexShader.SetConstantBuffer(0, m_constantBufferVS);

            d3dContext.VertexShader.Set(m_vertexShader);



            d3dContext.PixelShader.SetConstantBuffer(0, m_constantBufferPS);

            d3dContext.PixelShader.SetSampler(0, m_sampler);

            d3dContext.PixelShader.Set(m_pixelShader);



            d3dContext.OutputMerger.BlendState = m_blendStateAlpha; // m_blendStateAlpha, m_blendStateAdditive;
        }
Beispiel #13
0
        public virtual void Initialize(DeviceManager devices)
        {
            // Remove previous buffer
            RemoveAndDispose(ref constantBuffer);

            mediaPlayer.BackgroundColor = Color.Gray;

            // Initialize the MediaPlayer
            mediaPlayer.Initialize(devices);

            // Setup local variables
            var d3dDevice  = devices.DeviceDirect3D;
            var d3dContext = devices.ContextDirect3D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_VS.fxo");

            vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_PS.fxo"));

            // Layout from VertexShader input signature
            layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0)
            });

            // Instantiate Vertex buiffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(d3dDevice, BindFlags.VertexBuffer, new[]
            {
                // 3D coordinates              UV Texture coordinates
                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,                           // Front
                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,                            // BACK
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,

                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,                            // Top
                -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,                           // Bottom
                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,

                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,                           // Left
                -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,

                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,                            // Right
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
            });

            vertexBufferBinding = new VertexBufferBinding(vertices, sizeof(float) * 6, 0);

            // Create Constant Buffer
            constantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            // Load texture and create sampler
            var texture2D = new SharpDX.Direct3D11.Texture2D(d3dDevice, new SharpDX.Direct3D11.Texture2DDescription()
            {
                Width             = 512,
                Height            = 512,
                ArraySize         = 1,
                BindFlags         = SharpDX.Direct3D11.BindFlags.ShaderResource | BindFlags.RenderTarget,
                Usage             = SharpDX.Direct3D11.ResourceUsage.Default,
                CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                MipLevels         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
            });

            textureView = new ShaderResourceView(d3dDevice, texture2D);

            // Bind the media player with this output texture
            mediaPlayer.OutputVideoTexture = texture2D;

            sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                BorderColor        = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy  = 16,
                MipLodBias         = 0,
                MinimumLod         = -float.MaxValue,
                MaximumLod         = float.MaxValue
            });

            clock = new Stopwatch();
            clock.Start();

            // Plays the video
            mediaPlayer.Url = "bidon";
            mediaPlayer.SetBytestream(this.VideoStream);
        }