Exemple #1
0
        private void Initialize(int width, int height)
        {
            passes_ = new List <MaterialDX11>();

            // On Initialise le transform, puisqu'on se trouve en dehors de la scène
            transform_ = new Transform();
            transform_.SetScale(width, height, 1.0f);

            // Initialisation du material servant à dessiner le quad final
            m_DrawingMaterial = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefault.cso");


            m_currentoutput = 0;
            m_output        = new RenderTexture(width, height);
            m_outputSwitch  = new RenderTexture(width, height);

            // Initialisation du Quad que l'on utilise pour dessiner
            model_ = new MeshRenderer(m_DrawingMaterial, Quad.GetMesh());
            // Initialisation de la vue utilisé pour correspondre aux dimensions

            PostProcessingView = new View(new Transform(), new OrthoProjection(width, height, 0.1f, 100.0f));

            Quaternion xquat = Quaternion.RotationAxis(new Vector3(1.0f, 0.0f, 0.0f), 0 * 0.01f);
            Quaternion yquat = Quaternion.RotationAxis(new Vector3(0.0f, 1.0f, 0.0f), 0 * 0.01f);

            Quaternion rotQuat = Quaternion.Multiply(xquat, yquat);
            Matrix     mview   = Matrix.AffineTransformation(1.0f, rotQuat, new Vector3(00.0f, 0.0f, 10.0f));

            PostProcessingView.Transformation.SetLocalMatrix(mview);
            PostProcessingView.Transformation.Update();
        }
Exemple #2
0
        private void UpdatePasse(int index)
        {
            // On commence par récupérer le matérial que l'on souhaite appliquer à l'image
            MaterialDX11 mat = passes_[index];

            //// On met à jour la vue

            View.Current = PostProcessingView;

            ApplicationDX11.Instance.DeviceContext.OutputMerger.BlendState = ApplicationDX11.Instance.RenderToTextureBlendState;

            //// On définit le renderTargetView pour bien dessiner dans la bonne RenderTexture
            GetCurrentOutput().Bind();

            ApplicationDX11.Instance.DeviceContext.ClearRenderTargetView(
                GetCurrentOutput().RenderTargetView,
                new Color4(0.0f, 1.0f, 0.0f, 1.0f));

            if (mat.textures_.Count == 0)
            {
                mat.AddShaderResourceView(m_input);
            }
            else
            {
                mat.textures_[0] = m_input;
            }


            SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                BorderColor        = new Color4(0.0f, 1.0f, 0.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinLinearMagMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = 0,
                MinimumLod         = 0,
                MipLodBias         = 0
            });

            if (mat.samplers.Count == 0)
            {
                mat.samplers.Add(state);
            }
            else
            {
                mat.samplers[0] = state;
            }

            // On dessine
            model_.material_ = mat;

            transform_.Update();
            //model_.Draw(  );
        }
Exemple #3
0
        public void SetTileMap(int width, int height, TileSet tileset, float tilewidth = 1.0f, float tileheight = 1.0f)
        {
            tilemapdesc_ = new TilemapDesc();

            Width  = width;
            Height = height;

            tileset_ = tileset;

            TileSetWidth  = tileset.Width;
            TileSetHeight = tileset.Height;

            tilemapdesc_.TileWidth  = tileset.tilewidth_;
            tilemapdesc_.TileHeight = tileset.tileheight_;

            tilewidth_  = tilewidth;
            tileheight_ = tileheight;

            UpdateSize();

            InitializeTiles();
            InitializeTileMapTexture();

            // Ne pas oublier d'utiliser un sampler "pixel perfect" pour la tilemap
            SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new Color4(0.0f, 1.0f, 0.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinLinearMagMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = 0,
                MinimumLod         = 0,
                MipLodBias         = 0
            });

            tilemapmaterial_ = new MaterialDX11("vDefault.cso", "pTileMapping.cso", "gDefault.cso");
            tilemapmaterial_.samplers.Add(state);
            tilemapmaterial_.AddConstantBuffer <TilemapDesc>(tilemapdesc_);
            tilemapmaterial_.AddTexture(tileset_.texture_);
            tilemapmaterial_.AddTexture(tilemaptex_.GetTexture2D());

            if (m_meshRenderer == null)
            {
                m_meshRenderer = new MeshRenderer(tilemapmaterial_, Quad.GetMesh());
                m_entity.AddComponent(m_meshRenderer);
            }
            else
            {
                m_meshRenderer.material_ = tilemapmaterial_;
                m_meshRenderer.model_    = Quad.GetMesh();
            }
        }
Exemple #4
0
        public CollisionManager()
        {
            // Le CollisionManager charge aussi le matérial utilisé par défault par les bouding forms
            material_ = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefault.cso");
            material_.AddConstantBuffer <Vector4>(new Vector4(0.0f, 0.0f, 1.0f, 1.0f));

            Instance          = this;
            events_           = new Stack <CollisionEvent>();
            m_colliders       = new List <Collider>();
            collisionsenters_ = new List <CollisionEvent>();
        }
Exemple #5
0
        public void Initialize(Texture2D image, int offsetx, int offsety)
        {
            MaterialDX11 material = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefault.cso");

            material.AddTexture(image);

            Texture = image;
            Width   = image.Description.Width;
            Height  = image.Description.Height;
            //modelrenderer_ = new MeshRenderer( material, Quad.GetMesh() );
            Resize();
        }
Exemple #6
0
        public SceneGrid()
        {
            MaterialDX11 mat    = new MaterialDX11();
            TImage       timage = new TImage(401, 401);

            for (int i = 0; i < timage.Height; i++)
            {
                for (int j = 0; j < timage.Width; j++)
                {
                    if (i % 40 == 0 || j % 40 == 0 || i == 1 || i == 399 || j == 1 || j == 399)
                    {
                        timage.SetPixel(j, i, 1.0f, 1.0f, 1.0f, 1.0f);
                    }
                    else
                    {
                        timage.SetPixel(j, i, 0.0f, 0.0f, 0.0f, 0.0f);
                    }
                }
            }

            SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new Color4(0.0f, 1.0f, 0.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinLinearMagMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = 0,
                MinimumLod         = 0,
                MipLodBias         = 0
            });


            float scaleValue = 40.0f;

            mat.AddTexture(timage.GetTexture2D());
            mat.SetTextureHeight(0.1f * scaleValue);
            mat.SetTextureWidth(0.1f * scaleValue);
            mat.samplers.Add(state);
            //modelrenderer_ = new MeshRenderer( mat, Quad.GetMesh() );
            transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f);
            transform_.SetScale(scaleValue, scaleValue, 1.0f);

            IsPickingActivated = false;
        }
Exemple #7
0
        public Billboard()
        {
            MaterialDX11 mat = new MaterialDX11("vBillboarding.cso", "pUnlit.cso", "gBillboarding.cso");

            mat.SetMainColor(0.0f, 0.0f, 1.0f, 1.0F);

            PointMesh pm = new PointMesh();

            pm.AddVertex(new StandardVertex(new Vector3(0.0f, 0.0f, 0.0f)));
            pm.UpdateBuffers();

            //modelrenderer_ = new MeshRenderer( mat, pm );

            desc = new BillboardDesc()
            {
                CameraUpVector = new Vector3(1.0f, 0.0f, 0.0f),
                ScaleValue     = new Vector3(1.0f, 1.0f, 1.0f)
            };

            buffer_ = new CBuffer <BillboardDesc>(6, desc);
        }
Exemple #8
0
        public BitmapImage(ShaderResourceView src, MaterialDX11 mat = null, int offsetx = 0, int offsety = 0)
        {
            MaterialDX11 material;

            if (mat == null)
            {
                material = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefault.cso");
            }
            else
            {
                material = mat;
            }
            if (material.textures_.Count == 0)
            {
                material.AddShaderResourceView(src);
            }

            Width  = 200;
            Height = 200;
            //modelrenderer_ = new MeshRenderer(material, Quad.GetMesh());
            Resize();
        }
Exemple #9
0
        // Methods

        /// <summary>
        /// Comme on travail uniquement sur les pixels de l'image, on ne rajoute qu'un PixelShader
        /// </summary>
        /// <param name="material"></param>
        public void AddPasse(MaterialDX11 material)
        {
            passes_.Add(material);
        }
Exemple #10
0
        public void SetText(string text)
        {
            float offset = 0.0f;

            Width  = 0.0f;
            Height = 0.0f;

            for (int i = 0; i < text.Length; i++)
            {
                float coef = 0.1f;

                AtlasNode atlasnode = atlasfont.atlas.GetNode(text[i]);

                MaterialDX11 mat = new MaterialDX11("vDefault.cso", "pText.cso");
                mat.SetMainColor(1.0f, 0.0f, 0.0f, 1.0f);

                mat.AddShaderResourceView(atlasfont.atlas.SRV);

                Entity entity = new Entity();

                // On utilise XOffset et xadvance pour déterminer la position des caractères dans la ligne
                offset += atlasnode.XOffset * coef;

                entity.transform_.Translate(
                    offset + (( float )atlasnode.Width / 2.0f * coef),
                    -(atlasnode.Height * coef / 2.0f) - atlasnode.YOffset * coef,
                    0.0f);

                offset += atlasnode.XAdvance * coef;

                entity.transform_.SetScale(
                    atlasnode.Width * coef,
                    atlasnode.Height * coef,
                    1.0f);

                Width += atlasnode.Width * coef + atlasnode.XOffset * coef + atlasnode.XAdvance * coef;
                Height = atlasnode.Height * coef + atlasnode.YOffset * coef;

                Append(entity);

                //entity.modelrenderer_ = new MeshRenderer( mat, Quad.GetMesh() );

                SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription()
                {
                    AddressU           = TextureAddressMode.Wrap,
                    AddressV           = TextureAddressMode.Wrap,
                    AddressW           = TextureAddressMode.Wrap,
                    BorderColor        = new Color4(0.0f, 1.0f, 0.0f, 1.0f),
                    ComparisonFunction = Comparison.LessEqual,
                    Filter             = Filter.MinLinearMagMipPoint,
                    MaximumAnisotropy  = 0,
                    MaximumLod         = 0,
                    MinimumLod         = 0,
                    MipLodBias         = 0
                });
                mat.samplers.Add(state);
                mat.SetTextureXOffset(( float )atlasnode.X / ( float )atlasfont.atlas.Width);
                mat.SetTextureYOffset(( float )atlasnode.Y / ( float )atlasfont.atlas.Height);
                mat.SetTextureWidth(( float )atlasnode.Width / ( float )atlasfont.atlas.Width);
                mat.SetTextureHeight(( float )atlasnode.Height / ( float )atlasfont.atlas.Height);
            }

            if (CenterText)
            {
                transform_.Translate(-Width / 4.0f, Height / 2.0f, 0.0f);
            }
        }
Exemple #11
0
        public GlowingManager(int width, int height)
        {
            // On Initialise le transform, puisqu'on se trouve en dehors de la scène
            transform_ = new Transform();
            transform_.SetScale(Screen.Instance.Width, Screen.Instance.Height, 1.0f);
            transform_.Translate(0.0f, 0.0f, 0.5f);

            // Initialisation du material servant à dessiner le quad final
            m_DrawingMaterial = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefault.cso");

            // Initialisation du Quad que l'on utilise pour dessiner
            modelrenderer = new MeshRenderer(m_DrawingMaterial, Quad.GetMesh());

            PostProcessingView = new View(new Transform(), new OrthoProjection(Screen.Instance.Width, Screen.Instance.Height, 0.1f, 100.0f));

            Quaternion xquat = Quaternion.RotationAxis(new Vector3(1.0f, 0.0f, 0.0f), 0 * 0.01f);
            Quaternion yquat = Quaternion.RotationAxis(new Vector3(0.0f, 1.0f, 0.0f), 0 * 0.01f);

            Quaternion rotQuat = Quaternion.Multiply(xquat, yquat);
            Matrix     mview   = Matrix.AffineTransformation(1.0f, rotQuat, new Vector3(00.0f, 0.0f, 10.0f));

            Instance = this;

            MaterialDX11 HBlurMaterial = new MaterialDX11("vDefault.cso", "pHBlur.cso", "gDefault.cso");

            HBlurMaterial.AddConstantBuffer <HBlurDesc>(new HBlurDesc(width / 2, 50));

            MaterialDX11 VBlurMaterial = new MaterialDX11("vDefault.cso", "pVBlur.cso", "gDefault.cso");

            VBlurMaterial.AddConstantBuffer <VBlurDesc>(new VBlurDesc(height / 2, 50));

            m_Material = new MaterialDX11("vDefault.cso", "pGlow.cso", "gDefault.cso");
            m_Material.AddConstantBuffer <GlowDesc>(new GlowDesc(false, false, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)));

            m_RenderTexture   = new RenderTexture(width, height);
            m_ImageProcessing = new ImageProcessing(width, height, m_RenderTexture.SRV);

            m_ImageProcessing.AddPasse(HBlurMaterial);
            m_ImageProcessing.AddPasse(HBlurMaterial);

            m_ImageProcessing.AddPasse(VBlurMaterial);
            m_ImageProcessing.AddPasse(VBlurMaterial);

            // Additive Blending
            RenderTargetBlendDescription renderdesc = new RenderTargetBlendDescription()
            {
                BlendOperation      = BlendOperation.Add,
                AlphaBlendOperation = BlendOperation.Add,

                SourceAlphaBlend      = BlendOption.Zero,
                DestinationAlphaBlend = BlendOption.Zero,

                SourceBlend      = BlendOption.One,
                DestinationBlend = BlendOption.One,


                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            BlendStateDescription blendStateDesc2 = new BlendStateDescription()
            {
                IndependentBlendEnable = false,                // DirectX peut utiliser 8 RenderTarget simultanément, chauqe renderTarget
                // peut être lié à un RenderTargetBlendDescription différent
                AlphaToCoverageEnable = false
            };

            blendStateDesc2.RenderTarget[0] = renderdesc;

            glowingBlending = new BlendState(ApplicationDX11.Instance.Device, blendStateDesc2);
        }