コード例 #1
0
 /// <summary>
 /// Получить эффект
 /// </summary>
 /// <param name="FileName"></param>
 /// <param name="inputElement"></param>
 /// <returns></returns>
 public static EffectContainer LoadEffect(string FileName, InputElement[] inputElement)
 {
     string Origin = FileName;
     if (Effects.ContainsKey(Origin) && Effects[Origin].IsAlive)
     {
         //Уже есть
         EffectContainer t = (EffectContainer)Effects[Origin].Target;
         return t;
     }
     else
     {
         //нужно загрузить
         if (File.Exists(FileName + ".fx"))
         {
             FileName += ".fx";
         }
         else if (File.Exists(FileName + ".ees"))
         {
             FileName += ".ees";
         }
         EffectContainer t = new EffectContainer(ModelViewer.Program.device, FileName, inputElement);
         t.Name = Origin;
         WeakReference wr = new WeakReference(t, false);
         Effects.Add(Origin, wr);
         return t;
         //TODO проверка на валидность загрузки
     }
 }
コード例 #2
0
        public TestSprite(Device device, DVector3 Position)
        {
            this.Position = Position;
            MMesh = ContentManager.LoadMesh("Content/Models/BaseSprite.mesh");
            EEEM = ContentManager.LoadEffect("Content/Shaders/BaseSprite");
            TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl");
            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
        }
コード例 #3
0
        public GSSprite(Device device, DVector3 Position)
        {
            //float3 Position //12
            //half2 Size //16
            //half4 AABBTexCoord //24
            //half4 AditiveColor //32
            InputElement[] elements = new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0),
                new InputElement("TEXCOORD", 1, Format.R16G16B16A16_Float, 16, 0),
                new InputElement("TEXCOORD", 2, Format.R16G16B16A16_Float, 24, 0),
            };

            BytesPerVertex = 32;
            VertexsCount = 1;

            var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true);

            vertices.Write(Conversion.ToVector3(Position));
            vertices.Write(new Half2(10, 10));
            vertices.Write(new Half4(0, 0, 1, 1));
            vertices.Write(new Half4(1, 0, 0, 1));
            vertices.Position = 0;

            Vertexs = new Buffer(device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
            binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
            vertices.Dispose();

            this.Position = Position;
            EEEM = ContentManager.LoadEffect("Content/Shaders/GSSprite", elements);
            TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl");
            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
        }
コード例 #4
0
        public void Initialize()
        {
            LoadSky(0);

            Texture2DDescription descTex = new Texture2DDescription();
            descTex.ArraySize = 6;
            descTex.Width = Size;
            descTex.Height = Size;
            descTex.Usage = ResourceUsage.Default;
            descTex.CpuAccessFlags = CpuAccessFlags.None;
            descTex.Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
            descTex.SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0);
            descTex.MipLevels = MipLevel;
            descTex.BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget;
            descTex.OptionFlags = ResourceOptionFlags.GenerateMipMaps | ResourceOptionFlags.TextureCube;

            //Create the texture and shader view
            CubeTexture = new Texture2D(ModelViewer.Program.device, descTex);
            CubeSRV = new ShaderResourceView(ModelViewer.Program.device, CubeTexture);

            RenderTargetViewDescription RTVD = new RenderTargetViewDescription();
            RTVD.Format = descTex.Format;
            RTVD.Dimension = RenderTargetViewDimension.Texture2DArray;
            RTVD.Texture2DArray.FirstArraySlice = 0;
            RTVD.Texture2DArray.ArraySize = 1;
            RTVD.Texture2DArray.MipSlice = 0;

            CubeRenderTarget = new RenderTargetView[6];

            for (int i = 0; i < 6; i++)
            {
                RTVD.Texture2DArray.FirstArraySlice = i;
                CubeRenderTarget[i] = new RenderTargetView(ModelViewer.Program.device, CubeTexture, RTVD);
            }

            SamplerStateDescription a = new SamplerStateDescription();
            a.AddressU = TextureAddressMode.Clamp;
            a.AddressV = TextureAddressMode.Clamp;
            a.AddressW = TextureAddressMode.Clamp;
            a.Filter = Filter.MinMagMipLinear;
            SSWrapMipLinear = new SamplerState(ModelViewer.Program.device, a);

            MContains = new MeshContainer();
            MContains.BytesPerVertex = 20;
            MContains.FaceCount = 12;
            MContains.VertexsCount = 24;

            Vector3 vExtents = new Vector3(500, 500, 500);

            var vertices = new DataStream(MContains.BytesPerVertex * MContains.VertexsCount, true, true);

            //Back
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            //Front
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            //Bottom
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            //Top
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            //Left
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            //Right
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 0));

            vertices.Position = 0;
            InputElement[] elements11 = new[] {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0) ,
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 12, 0)};

            MContains.Vertexs = new Buffer(ModelViewer.Program.device, vertices, MContains.BytesPerVertex * MContains.VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            var indices = new DataStream(4 * MContains.FaceCount * 3, true, true);
            for (int x = 0; x < 6; x++)
            {
                indices.Write((int)(x * 4 + 0));
                indices.Write((int)(x * 4 + 1));
                indices.Write((int)(x * 4 + 2));

                indices.Write((int)(x * 4 + 2));
                indices.Write((int)(x * 4 + 3));
                indices.Write((int)(x * 4 + 0));
            }
            indices.Position = 0;

            MContains.Indices = new Buffer(ModelViewer.Program.device, indices, 4 * MContains.FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            MContains.binding = new VertexBufferBinding(MContains.Vertexs, MContains.BytesPerVertex, 0);

            EEEM = ContentManager.LoadEffect("Content/Shaders/SkyBox", elements11);

            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(SkyShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            SkyConstantsBuffer = new Buffer(ModelViewer.Program.device, bd);
            SSC = new SkyShaderConstants();
        }
コード例 #5
0
        public static void Init(Device device)
        {
            InputElement[] elements11 = new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32_Float, 12, 0),
            };

            EEEM = ContentManager.LoadEffect("Content/Shaders/Line", elements11);

            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();

            Vertexs = new Buffer(device, BytesPerVertex * VertexsCount, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
            binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);

            CurrentBufferSize = 4;
        }
コード例 #6
0
        public MaterialContainer(Material M)
        {
            if (M != null)
            {
                Name = M.MaterialName;
                InputElement[] IE = GetInputElementFromShaderName(M.Shader);
                Effect = ContentManager.LoadEffect(M.Shader, IE);
                Diffuse = ContentManager.LoadTexture2D(M.Diffuse);
                UV2Diffuse = ContentManager.LoadTexture2D(M.UV2Diffuse);
                NormalMap = ContentManager.LoadTexture2D(M.NormalMap);
                SpecularMap = ContentManager.LoadTexture2D(M.SpecularMap);
                SelfMap = ContentManager.LoadTexture2D(M.SelfMap);

                MipNormal = NormalMap.Texture2d.Description.MipLevels > 7;
                MipSpecular = SpecularMap.Texture2d.Description.MipLevels > 7;
                MipDiffuse = Diffuse.Texture2d.Description.MipLevels > 7;
                MipSelf = SelfMap.Texture2d.Description.MipLevels > 7;
                MipUV2Diffuse = UV2Diffuse.Texture2d.Description.MipLevels > 7;

                DiffuseMultipler = M.DiffuseMultipler;
                SpecularMultipler = M.SpecularMultipler;
                SelfMultipler = M.SelfMultipler;
                DoubleSide = M.DoubleSide;
                Alpha = M.Alpha;

                if (Global.Settings.TextureFiltering > -1)
                {
                    if (MipDiffuse) DiffuseSamplerState = DrawHelper.SamplAnsWrapMip;
                    else DiffuseSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipSpecular) SpecularMapSamplerState = DrawHelper.SamplAnsWrapMip;
                    else SpecularMapSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipNormal) NormalMapSamplerState = DrawHelper.SamplAnsWrapMip;
                    else NormalMapSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipSelf) SelfMapSamplerState = DrawHelper.SamplAnsWrapMip;
                    else SelfMapSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipUV2Diffuse) UV2DiffuseSamplerState = DrawHelper.SamplAnsWrapMip;
                    else UV2DiffuseSamplerState = DrawHelper.SamplAnsWrap;
                }
                else if (Global.Settings.TextureFiltering == -1)
                {
                    if (MipDiffuse) DiffuseSamplerState = DrawHelper.SamplLinWrapMip;
                    else DiffuseSamplerState = DrawHelper.SamplLinWrap;
                    if (MipSpecular) SpecularMapSamplerState = DrawHelper.SamplLinWrapMip;
                    else SpecularMapSamplerState = DrawHelper.SamplLinWrap;
                    if (MipNormal) NormalMapSamplerState = DrawHelper.SamplLinWrapMip;
                    else NormalMapSamplerState = DrawHelper.SamplLinWrap;
                    if (MipSelf) SelfMapSamplerState = DrawHelper.SamplLinWrapMip;
                    else SelfMapSamplerState = DrawHelper.SamplLinWrap;
                    if (MipUV2Diffuse) UV2DiffuseSamplerState = DrawHelper.SamplLinWrapMip;
                    else UV2DiffuseSamplerState = DrawHelper.SamplLinWrap;
                }
                else
                {
                    if (MipDiffuse) DiffuseSamplerState = DrawHelper.SamplPntWrapMip;
                    else DiffuseSamplerState = DrawHelper.SamplPntWrap;
                    if (MipSpecular) SpecularMapSamplerState = DrawHelper.SamplPntWrapMip;
                    else SpecularMapSamplerState = DrawHelper.SamplPntWrap;
                    if (MipNormal) NormalMapSamplerState = DrawHelper.SamplPntWrapMip;
                    else NormalMapSamplerState = DrawHelper.SamplPntWrap;
                    if (MipSelf) SelfMapSamplerState = DrawHelper.SamplPntWrapMip;
                    else SelfMapSamplerState = DrawHelper.SamplPntWrap;
                    if (MipUV2Diffuse) UV2DiffuseSamplerState = DrawHelper.SamplPntWrapMip;
                    else UV2DiffuseSamplerState = DrawHelper.SamplPntWrap;
                }
            }
        }
コード例 #7
0
        public static void Init(Device device)
        {
            #region Sampler
            SamplerStateDescription desc = new SamplerStateDescription();
            desc.AddressU = TextureAddressMode.Wrap;
            desc.AddressV = TextureAddressMode.Wrap;
            desc.AddressW = TextureAddressMode.Wrap;
            desc.Filter = Filter.MinMagMipLinear;
            SamplLinWrap = new SamplerState(ModelViewer.Program.device, desc);
            desc.Filter = Filter.MinMagMipPoint;
            SamplPntWrap = new SamplerState(ModelViewer.Program.device, desc);
            desc.Filter = Filter.Anisotropic;
            if (Global.Settings.TextureFiltering > -1) desc.MaximumAnisotropy = System.Math.Min(Global.Settings.TextureFiltering, 16);
            else desc.MaximumAnisotropy = 0;
            SamplAnsWrap = new SamplerState(ModelViewer.Program.device, desc);
            desc.MaximumAnisotropy = 0;
            desc.MinimumLod = 0;
            desc.MaximumLod = 7;
            desc.Filter = Filter.MinMagMipLinear;
            SamplLinWrapMip = new SamplerState(ModelViewer.Program.device, desc);
            desc.Filter = Filter.MinMagMipPoint;
            SamplPntWrapMip = new SamplerState(ModelViewer.Program.device, desc);
            desc.Filter = Filter.Anisotropic;
            if (Global.Settings.TextureFiltering > -1) desc.MaximumAnisotropy = System.Math.Min(Global.Settings.TextureFiltering, 16);
            else desc.MaximumAnisotropy = 0;
            SamplAnsWrapMip = new SamplerState(ModelViewer.Program.device, desc);
            #endregion

            OcclViewport = new Viewport(0, 0, OcclPixelInTex, 1);

            OcclTexture = new Texture2D[1];
            OcclSRV = new ShaderResourceView[1];
            OcclRTV = new RenderTargetView[1];
            InitOcclInd(0);

            MConteints = new MeshContainer();

            MConteints.BytesPerVertex = 12;
            MConteints.FaceCount = 2;
            MConteints.VertexsCount = 4;

            var vertices = new DataStream(MConteints.BytesPerVertex * MConteints.VertexsCount, true, true);
            vertices.Write(new Vector3(0.0f, 0.0f, 0.5f));
            vertices.Write(new Vector3(1.0f, 0.0f, 0.5f));
            vertices.Write(new Vector3(1.0f, 1.0f, 0.5f));
            vertices.Write(new Vector3(0.0f, 1.0f, 0.5f));
            vertices.Position = 0;

            MConteints.Vertexs = new Buffer(device, vertices, MConteints.BytesPerVertex * MConteints.VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            var indices = new DataStream(4 * MConteints.FaceCount * 3, true, true);
            indices.Write(0);
            indices.Write(1);
            indices.Write(2);
            indices.Write(2);
            indices.Write(3);
            indices.Write(0);
            indices.Position = 0;

            MConteints.Indices = new Buffer(device, indices, 4 * MConteints.FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            MConteints.binding = new VertexBufferBinding(MConteints.Vertexs, MConteints.BytesPerVertex, 0);

            InputElement[] elements11 = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0) };
            EEEM = ContentManager.LoadEffect("Content/Shaders/OcclusionTest", elements11);

            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();

            constants.Resolution = new Vector4(Global.Settings.Width, Global.Settings.Height, OcclPixelInTex, 1);
            constants.WM = Matrix.Transpose(Matrix.OrthoLH(constants.Resolution.X, constants.Resolution.Y, 0.1f, 1000));

            LensBatching.Init(device);
            PSSMsHelper.Init(device);
        }
コード例 #8
0
        public static void Init(Device device)
        {
            MasterRequest = new Request[128];
            SlaveRequest = new Request[128];
            for (int i = 0; i < MasterRequest.Length; i++)
            {
                MasterRequest[i] = new Request();
                SlaveRequest[i] = new Request();
            }

            //float3 Position //12
            //half2 Size //16
            //half4 AABBTexCoord //24
            //half4 AditiveColor //32
            InputElement[] elements = new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0),
                new InputElement("TEXCOORD", 1, Format.R16G16B16A16_Float, 16, 0),
                new InputElement("TEXCOORD", 2, Format.R16G16B16A16_Float, 24, 0),
            };

            Vertexs = new Buffer(device, BytesPerVertex * MassSize, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
            //binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);

            EEEM = ContentManager.LoadEffect("Content/Shaders/GSSprite", elements);

            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();

            //int t = Utils.GetBinResize(17);
        }
コード例 #9
0
        public static void Init(Device device, int W, int H)
        {
            #region Mesh
            _MConteints = new MeshContainer();

            _MConteints.BytesPerVertex = 12;
            _MConteints.FaceCount = 2;
            _MConteints.VertexsCount = 4;

            var vertices = new DataStream(_MConteints.BytesPerVertex * _MConteints.VertexsCount, true, true);
            vertices.Write(new Vector3(0.0f, 0.0f, 0.5f));
            vertices.Write(new Vector3(1.0f, 0.0f, 0.5f));
            vertices.Write(new Vector3(1.0f, 1.0f, 0.5f));
            vertices.Write(new Vector3(0.0f, 1.0f, 0.5f));
            vertices.Position = 0;

            _MConteints.Vertexs = new Buffer(device, vertices, _MConteints.BytesPerVertex * _MConteints.VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            var indices = new DataStream(4 * _MConteints.FaceCount * 3, true, true);
            indices.Write(0);
            indices.Write(1);
            indices.Write(2);
            indices.Write(2);
            indices.Write(3);
            indices.Write(0);
            indices.Position = 0;

            _MConteints.Indices = new Buffer(device, indices, 4 * _MConteints.FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            _MConteints.binding = new VertexBufferBinding(_MConteints.Vertexs, _MConteints.BytesPerVertex, 0);

            InputElement[] elements11 = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0) };
            EEEM = ContentManager.LoadEffect("Content/Shaders/QuadShader", elements11);

            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
            constants.Resolution = new Vector4(W, H, 0, 0);
            constants.WM = Matrix.OrthoLH(constants.Resolution.X, constants.Resolution.Y, 0.1f, 1000);
            #endregion
            //RenderTargets
            Texture2DDescription BufDescription = new Texture2DDescription();
            BufDescription.MipLevels = 1;
            BufDescription.ArraySize = 1;
            BufDescription.Width = W/4;
            BufDescription.Height = H/4;
            BufDescription.Format = Format.R8G8B8A8_UNorm;
            BufDescription.SampleDescription = new SampleDescription(1, 0);
            BufDescription.Usage = ResourceUsage.Default;
            BufDescription.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
            BufDescription.CpuAccessFlags = CpuAccessFlags.None;
            BufDescription.OptionFlags = ResourceOptionFlags.None;

            BufTexture_1 = new Texture2D(device, BufDescription);
            BufTexture_2 = new Texture2D(device, BufDescription);

            BufSRV_1 = new ShaderResourceView(device, BufTexture_1);
            BufSRV_2 = new ShaderResourceView(device, BufTexture_2);

            RenderTargetViewDescription RTVD = new RenderTargetViewDescription();
            RTVD.Format = BufDescription.Format;
            RTVD.Dimension = RenderTargetViewDimension.Texture2D;
            RTVD.Texture2DArray.FirstArraySlice = 0;
            RTVD.Texture2DArray.ArraySize = 1;
            RTVD.Texture2D.MipSlice = 0;

            BufRTV_1 = new RenderTargetView(device, BufTexture_1, RTVD);
            BufRTV_2 = new RenderTargetView(device, BufTexture_2, RTVD);

            BufDescription.Width = W / 2;
            BufDescription.Height = H / 2;
            BufDescription.MipLevels = 0;

            BufDescription.OptionFlags = ResourceOptionFlags.GenerateMipMaps;
            BufDescription.Format = Format.R32G32B32A32_Float;
            RTVD.Format = BufDescription.Format;
            BufTexture_3 = new Texture2D(device, BufDescription);
            BufSRV_3 = new ShaderResourceView(device, BufTexture_3);
            BufRTV_3 = new RenderTargetView(device, BufTexture_3, RTVD);

            SamplerStateDescription sd = new SamplerStateDescription();
            sd.AddressU = TextureAddressMode.Clamp;
            sd.AddressV = TextureAddressMode.Clamp;
            sd.AddressW = TextureAddressMode.Clamp;
            sd.Filter = Filter.MinMagMipLinear;
            sd.MinimumLod = 0;
            sd.MaximumLod = 16;

            BufSS = new SamplerState(device, ref sd);

            HDRViewport = new Viewport(0, 0, W / 4, H / 4);
            DoubleHDRViewport = new Viewport(0, 0, W / 2, H / 2);

            BufDescription = new Texture2DDescription();
            BufDescription.MipLevels = 1;
            BufDescription.ArraySize = 1;
            BufDescription.Width = 1;
            BufDescription.Height = 1;
            BufDescription.Format = Format.R32G32B32A32_Float;
            BufDescription.SampleDescription = new SampleDescription(1, 0);
            BufDescription.Usage = ResourceUsage.Default;
            BufDescription.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
            BufDescription.CpuAccessFlags = CpuAccessFlags.None;
            BufDescription.OptionFlags = ResourceOptionFlags.None;

            RTVD = new RenderTargetViewDescription();
            RTVD.Format = BufDescription.Format;
            RTVD.Dimension = RenderTargetViewDimension.Texture2D;
            RTVD.Texture2DArray.FirstArraySlice = 0;
            RTVD.Texture2DArray.ArraySize = 1;
            RTVD.Texture2D.MipSlice = 0;

            T1x1 = new Texture2D(device, BufDescription);
            V1x1 = new Viewport(0, 0, 1, 1);
            SRV1x1 = new ShaderResourceView(device, T1x1);
            RTV1x1 = new RenderTargetView(device, T1x1, RTVD);

            device.ImmediateContext.ClearRenderTargetView(BufRTV_3, new Color4(0.0f, 0.0f, 0.0f, 1f));
        }
コード例 #10
0
        /// <summary>
        /// Получить эффект c дефолтным InputElement[]
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="inputElement"></param>
        /// <returns></returns>
        public static EffectContainer LoadEffect(string FileName)
        {
            string Origin = FileName;
            if (Effects.ContainsKey(Origin) && Effects[Origin].IsAlive)
            {
                //Уже есть
                EffectContainer t = (EffectContainer)Effects[Origin].Target;
                return t;
            }
            else
            {
                //нужно загрузить
                if (File.Exists(FileName + ".fx"))
                {
                    FileName += ".fx";
                }
                else if (File.Exists(FileName + ".ees"))
                {
                    FileName += ".ees";
                }

                InputElement[] inputElement = new InputElement[]{
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0),
                new InputElement("TEXCOORD", 1, Format.R16G16_Float, 16, 0),
                new InputElement("NORMAL", 0, Format.R8G8B8A8_UNorm, 20, 0),//w = bone3.w[0]
                new InputElement("TANGENT", 0, Format.R8G8B8A8_UNorm, 24, 0),//w = bone3.w[1]
                new InputElement("BLENDINDICES", 0, Format.R8G8B8A8_UNorm, 28, 0)};// bone3.w[3], bone3.i[0], bone3.i[1], bone3.i[2]

                EffectContainer t = new EffectContainer(ModelViewer.Program.device, FileName, inputElement);
                t.Name = Origin;
                WeakReference wr = new WeakReference(t, false);
                Effects.Add(Origin, wr);
                return t;
                //TODO проверка на валидность загрузки
            }
        }