Пример #1
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();
            }
        }
Пример #2
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>();
        }
Пример #3
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);
        }