• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Direct3D11.SamplerState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SharpDX.Direct3D11.SamplerState的典型用法代码示例。如果您正苦于以下问题:C# SamplerState类的具体用法?C# SamplerState怎么用?C# SamplerState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SamplerState类属于SharpDX.Direct3D11命名空间,在下文中一共展示了SamplerState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Initialize

        public void Initialize(Device Device)
        {
            _shaderSolution=ROD_core.ShaderBinding.GetCompatibleShader(this);
            layout = new InputLayout(Device, _shaderSolution.shaders_bytecode[Shaders.VertexShader], mesh._vertexStream.vertexDefinition.GetInputElements());

            mesh.Load(Device);
            material.LoadTextures(Device);
            sampler = new SamplerState(Device, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new SharpDX.Color4(0,0,0,1),
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod = -float.MaxValue,
                MaximumLod = float.MaxValue
            });

            List<Shaders> actual_shaders = (from sh in _shaderSolution.shaders_bytecode select sh.Key).ToList<Shaders>();
            foreach (Shaders sh in actual_shaders)
            {
                ShaderReflection _shaderReflection = new ShaderReflection(_shaderSolution.shaders_bytecode[sh]);
                int buffers_count = _shaderReflection.Description.ConstantBuffers;
                SharpDX.Direct3D11.Buffer[] _buffers = new SharpDX.Direct3D11.Buffer[buffers_count];
                for (int i = 0; i < buffers_count; i++)
                {
                    ConstantBuffer cb_buffer = _shaderReflection.GetConstantBuffer(i);
                    _buffers[i] = new SharpDX.Direct3D11.Buffer(Device, cb_buffer.Description.Size, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                }
                _shaderSolution.shaders_buffers[sh] = _buffers;
            }
        }
开发者ID:sinushawa,项目名称:ROD,代码行数:35,代码来源:Model.cs


示例2: WorldTerrainShader

        public WorldTerrainShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TerrainVertexShader", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TerrainPixelShader", "ps_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);

            Layout = VertexDefinition.PositionTexture.GetInputLayout(device, vertexShaderByteCode);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);

            var samplerDescMap = new SamplerStateDescription
            {
                Filter = Filter.MinMagMipPoint,
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                MipLodBias = 0,
                MaximumAnisotropy = 1,
                ComparisonFunction = Comparison.Always,
                BorderColor = Color.Transparent,
                MinimumLod = 0,
                MaximumLod = float.MaxValue
            };
            SamplerStateMap = new SamplerState(device, samplerDescMap);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:30,代码来源:WorldTerrainShader.cs


示例3: PathShader

        public PathShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "VS", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "PS", "ps_4_0", ShaderFlags);
            var geometryShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "GS", "gs_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);
            GeometryShader = new GeometryShader(device, geometryShaderByteCode);
            Layout = VertexDefinition.Path.GetInputLayout(device, vertexShaderByteCode);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();
            geometryShaderByteCode.Dispose();

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
            ConstantPathDataBuffer = new Buffer(device,
                new BufferDescription
                {
                    Usage = ResourceUsage.Dynamic,
                    SizeInBytes = Utilities.SizeOf<PathData>(),
                    BindFlags = BindFlags.ConstantBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    OptionFlags = ResourceOptionFlags.None,
                    StructureByteStride = 0
                });
            SamplerState = new SamplerState(device, WrapSamplerStateDescription);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:28,代码来源:PathShader.cs


示例4: SibenikMaterial

        public SibenikMaterial(Device device, TweakBar bar, String name)
            : base(device, bar, name)
        {
            bar.AddColor(Prefix + "diffuse", "Diffuse", name, new Color3(1, 1, 1));
            bar.AddColor(Prefix + "specular", "Specular", name, new Color3(1, 1, 1));
            bar.AddFloat(Prefix + "shininess", "Shininess", name, 1, 256, 64, 0.1, 2);
            bar.AddFloat(Prefix + "brightness", "Brightness", name, 0, 15000, 5, 50, 2);

            pixelShader = Material.CompileShader(device, "sibenik");

            constantBuffer = Material.AllocateMaterialBuffer(device, BufferSize);

            sampler = new SamplerState(device, new SamplerStateDescription()
            {
                ComparisonFunction = Comparison.Always,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.Anisotropic,
                BorderColor = Color4.Black,
                MaximumAnisotropy = 16,
                MaximumLod = 15,
                MinimumLod = 0,
                MipLodBias = 0,
            });
        }
开发者ID:TomCrypto,项目名称:Insight,代码行数:26,代码来源:SibenikMaterial.cs


示例5: CreateDeviceDependentResources

        protected override void CreateDeviceDependentResources()
        {
            RemoveAndDispose(ref vertexBuffer);
            RemoveAndDispose(ref indexBuffer);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Load texture (a DDS cube map)
            textureView = ShaderResourceView.FromFile(device, "CubeMap.dds");

            // Create our sampler state
            samplerState = new SamplerState(device, new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                BorderColor = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.MinMagMipLinear,
                MaximumLod = 9, // Our cube map has 10 mip map levels (0-9)
                MinimumLod = 0,
                MipLodBias = 0.0f
            });

            Vertex[] vertices;
            int[] indices;
            GeometricPrimitives.GenerateSphere(out vertices, out indices, Color.Gray);

            vertexBuffer = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices));
            vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf<Vertex>(), 0);

            indexBuffer = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, indices));
            totalVertexCount = indices.Length;
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:35,代码来源:SphereRenderer.cs


示例6: TextureShader

        public TextureShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TextureVertexShader", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TexturePixelShader", "ps_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);

            Layout = VertexDefinition.PositionTexture.GetInputLayout(device, vertexShaderByteCode);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);

            // Create a texture sampler state description.
            var samplerDesc = new SamplerStateDescription
            {
                Filter = Filter.Anisotropic,
                AddressU = TextureAddressMode.Mirror,
                AddressV = TextureAddressMode.Mirror,
                AddressW = TextureAddressMode.Mirror,
                MipLodBias = 0,
                MaximumAnisotropy = 16,
                ComparisonFunction = Comparison.Always,
                BorderColor = new Color4(1, 1, 1, 1),
                MinimumLod = 0,
                MaximumLod = 0
            };

            // Create the texture sampler state.
            SamplerState = new SamplerState(device, samplerDesc);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:33,代码来源:TextureShader.cs


示例7: ProjectiveTexturingShader

        public ProjectiveTexturingShader(Device device)
        {
            var shaderByteCode = new ShaderBytecode(File.ReadAllBytes("Content/DepthAndProjectiveTextureVS.cso"));
            vertexShader = new VertexShader(device, shaderByteCode);
            geometryShader = new GeometryShader(device, new ShaderBytecode(File.ReadAllBytes("Content/DepthAndColorGS.cso")));
            pixelShader = new PixelShader(device, new ShaderBytecode(File.ReadAllBytes("Content/DepthAndColorPS.cso")));

            // depth stencil state
            var depthStencilStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.LessEqual,
                IsStencilEnabled = false,
            };
            depthStencilState = new DepthStencilState(device, depthStencilStateDesc);

            // rasterizer states
            var rasterizerStateDesc = new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid,
                IsDepthClipEnabled = true,
                IsFrontCounterClockwise = true,
                IsMultisampleEnabled = true,
            };
            rasterizerState = new RasterizerState(device, rasterizerStateDesc);

            // constant buffer
            var constantBufferDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.ConstantBuffer,
                SizeInBytes = Constants.size,
                CpuAccessFlags = CpuAccessFlags.Write,
                StructureByteStride = 0,
                OptionFlags = 0,
            };
            constantBuffer = new SharpDX.Direct3D11.Buffer(device, constantBufferDesc);

            // user view sampler state
            var colorSamplerStateDesc = new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Border,
                AddressV = TextureAddressMode.Border,
                AddressW = TextureAddressMode.Border,
                //BorderColor = new SharpDX.Color4(0.5f, 0.5f, 0.5f, 1.0f),
                BorderColor = new SharpDX.Color4(0, 0, 0, 1.0f),
            };
            colorSamplerState = new SamplerState(device, colorSamplerStateDesc);

            vertexInputLayout = new InputLayout(device, shaderByteCode.Data, new[]
            {
                new InputElement("SV_POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
            });

        }
开发者ID:Dallemanden,项目名称:RoomAliveToolkit,代码行数:58,代码来源:ProjectiveTexturingShader.cs


示例8: TerrainMinimapShader

        public TerrainMinimapShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "MinimapTerrainVertexShader", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "MinimapTerrainPixelShader", "ps_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);

            Layout = VertexDefinition.TerrainVertex.GetInputLayout(device, vertexShaderByteCode);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
            ConstantSelectionBuffer = new Buffer(device, new BufferDescription
            {
                Usage = ResourceUsage.Dynamic,
                SizeInBytes = Utilities.SizeOf<SelectionBuffer>(),
                BindFlags = BindFlags.ConstantBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                StructureByteStride = 0
            });

            var samplerDescBorder = new SamplerStateDescription
            {
                Filter = Filter.Anisotropic,
                AddressU = TextureAddressMode.MirrorOnce,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                MipLodBias = 0,
                MaximumAnisotropy = 16,
                ComparisonFunction = Comparison.Always,
                BorderColor = Color.Transparent,
                MinimumLod = 0,
                MaximumLod = float.MaxValue
            };

            // Create the texture sampler state.
            SamplerStateBorder = new SamplerState(device, samplerDescBorder);

            var samplerDescColor = new SamplerStateDescription
            {
                Filter = Filter.Anisotropic,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                MipLodBias = 0,
                MaximumAnisotropy = 16,
                ComparisonFunction = Comparison.Always,
                BorderColor = Color.Transparent,
                MinimumLod = 0,
                MaximumLod = float.MaxValue
            };

            // Create the texture sampler state.
            SamplerStateColor = new SamplerState(device, samplerDescColor);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:58,代码来源:TerrainMinimapShader.cs


示例9: CreateDeviceDependentResources

        /// <summary>
        /// Create any device dependent resources here.
        /// This method will be called when the device is first
        /// initialized or recreated after being removed or reset.
        /// </summary>
        protected override void CreateDeviceDependentResources()
        {
            // Ensure that if already set the device resources
            // are correctly disposed of before recreating
            RemoveAndDispose(ref axisLinesVertices);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Load texture
            textureView = ToDispose(ShaderResourceView.FromFile(device, "Texture.png"));

            // Create our sampler state
            samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.MinMagMipLinear,
                MaximumAnisotropy = 16,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0.0f
            }));

            // Create xyz-axis arrows
            // X is Red, Y is Green, Z is Blue
            // The arrows point along the + for each axis
            axisLinesVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[]
            {
            /*  Vertex Position         Texture UV */
                                        // ~45x10
                -1f, 0f, 0f, 1f,        0.1757f, 0.039f, // - x-axis
                1f, 0f, 0f, 1f,         0.1757f, 0.039f,  // + x-axis
                0.9f, -0.05f, 0f, 1f,   0.1757f, 0.039f,// arrow head start
                1f, 0f, 0f, 1f,         0.1757f, 0.039f,
                0.9f, 0.05f, 0f, 1f,    0.1757f, 0.039f,
                1f, 0f, 0f, 1f,         0.1757f, 0.039f,  // arrow head end
                                        // ~135x35
                0f, -1f, 0f, 1f,        0.5273f, 0.136f, // - y-axis
                0f, 1f, 0f, 1f,         0.5273f, 0.136f,  // + y-axis
                -0.05f, 0.9f, 0f, 1f,   0.5273f, 0.136f,// arrow head start
                0f, 1f, 0f, 1f,         0.5273f, 0.136f,
                0.05f, 0.9f, 0f, 1f,    0.5273f, 0.136f,
                0f, 1f, 0f, 1f,         0.5273f, 0.136f,  // arrow head end
                                        // ~220x250
                0f, 0f, -1f, 1f,        0.859f, 0.976f, // - z-axis
                0f, 0f, 1f, 1f,         0.859f, 0.976f,  // + z-axis
                0f, -0.05f, 0.9f, 1f,   0.859f, 0.976f,// arrow head start
                0f, 0f, 1f, 1f,         0.859f, 0.976f,
                0f, 0.05f, 0.9f, 1f,    0.859f, 0.976f,
                0f, 0f, 1f, 1f,         0.859f, 0.976f,  // arrow head end
            }));
            axisLinesBinding = new VertexBufferBinding(axisLinesVertices, Utilities.SizeOf<float>() * 6, 0);
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:62,代码来源:AxisLinesRenderer.cs


示例10: LightShader

        public LightShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "LightVertexShader", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "LightPixelShader", "ps_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);

            Layout = VertexDefinition.PositionTextureNormal.GetInputLayout(device, vertexShaderByteCode);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);

            // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
            var lightBufferDesc = new BufferDescription
            {
                Usage = ResourceUsage.Dynamic, // Updated each frame
                SizeInBytes = Utilities.SizeOf<LightBuffer>(), // Contains three matrices
                BindFlags = BindFlags.ConstantBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                StructureByteStride = 0
            };
            ConstantLightBuffer = new Buffer(device, lightBufferDesc);

            // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
            var cameraBufferDesc = new BufferDescription
            {
                Usage = ResourceUsage.Dynamic, // Updated each frame
                SizeInBytes = Utilities.SizeOf<CameraBuffer>(), // Contains three matrices
                BindFlags = BindFlags.ConstantBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                StructureByteStride = 0
            };
            ConstantCameraBuffer = new Buffer(device, cameraBufferDesc);

            // Create a texture sampler state description.
            var samplerDesc = new SamplerStateDescription
            {
                Filter = Filter.Anisotropic,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                MipLodBias = 0,
                MaximumAnisotropy = 16,
                ComparisonFunction = Comparison.Always,
                BorderColor = new Color4(0, 0, 0, 0),
                MinimumLod = 0,
                MaximumLod = 10
            };

            // Create the texture sampler state.
            SamplerState = new SamplerState(device, samplerDesc);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:57,代码来源:LightShader.cs


示例11: InitializeInternal

 protected override void InitializeInternal()
 {
     var descr = new SamplerStateDescription
     {
         AddressU = GetTextureAddressMode(Settings.WrapU),
         AddressV = GetTextureAddressMode(Settings.WrapV),
         AddressW = GetTextureAddressMode(Settings.WrapW),
         Filter = GetFilterType(Settings.Filter)
     };
     SamplerState = new SamplerState(DeviceManager.Device, descr);
 }
开发者ID:gitter-badger,项目名称:Grasshopper,代码行数:11,代码来源:TextureSampler.cs


示例12: PassThroughFilter

 public PassThroughFilter(Device device)
 {
     this.pixelShaderByteCode = ShaderBytecode.CompileFromFile("Graphics/PassThrough.hlsl", "pixel", "ps_4_0", ShaderFlags.OptimizationLevel1, EffectFlags.None, null, null);
     this.pixelShader = new PixelShader(device, this.pixelShaderByteCode, null);
     this.sampler = new SamplerState(device, new SamplerStateDescription
     {
         MaximumAnisotropy = 16,
         Filter = SharpDX.Direct3D11.Filter.Anisotropic,
         AddressU = TextureAddressMode.Clamp,
         AddressV = TextureAddressMode.Clamp,
         AddressW = TextureAddressMode.Clamp,
         MinimumLod = 0f,
         MaximumLod = 100f
     });
 }
开发者ID:romanchom,项目名称:Luna,代码行数:15,代码来源:PassThroughFilter.cs


示例13: FontShader

        public FontShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "FontVertexShader", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "FontPixelShader", "ps_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);

            Layout = VertexDefinition.PositionTextureColor.GetInputLayout(device, vertexShaderByteCode);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
            SamplerState = new SamplerState(device, WrapSamplerStateDescription);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:16,代码来源:FontShader.cs


示例14: CreateDeviceDependentResources

        /// <summary>
        /// Create any device dependent resources here.
        /// This method will be called when the device is first
        /// initialized or recreated after being removed or reset.
        /// </summary>
        protected override void CreateDeviceDependentResources()
        {
            base.CreateDeviceDependentResources();

            // Ensure that if already set the device resources
            // are correctly disposed of before recreating
            RemoveAndDispose(ref triangleVertices);
            RemoveAndDispose(ref textureView);
            RemoveAndDispose(ref samplerState);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Create a triangle
            triangleVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] {
            /*  Vertex Position, normal, Color, UV */
            // Modified normals to work with Curved PN-Triangles
                new Vertex(new Vector3(0.75f, 0f, -0.001f), Vector3.Normalize(Vector3.UnitZ + Vector3.UnitX - Vector3.UnitY), Color.Black, new Vector2(1.0f, 1.0f)), // Base-right
                new Vertex(new Vector3(-0.75f, 0f, -0.001f),Vector3.Normalize(Vector3.UnitZ - Vector3.UnitX - Vector3.UnitY), Color.Black, new Vector2(0.0f, 1.0f)), // Base-left
                new Vertex(new Vector3(0f, 1.5f, -0.001f), Vector3.Normalize(Vector3.UnitZ + Vector3.UnitY), Color.Black, new Vector2(0.5f, 0.0f)), // Apex
            }));
            triangleBinding = new VertexBufferBinding(triangleVertices, Utilities.SizeOf<Vertex>(), 0);

            // Load texture
            textureView = ToDispose(ShaderResourceView.FromFile(device, "Texture2.png"));

            // Create our sampler state
            samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.MinMagMipLinear,
                MaximumAnisotropy = 16,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0.0f
            }));
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:46,代码来源:TriangleRenderer.cs


示例15: Initialize

        /// <summary>
        /// Binds the effect shader to the specified <see cref="Device"/>.
        /// </summary>
        /// <param name="device">The device to bind the shader to.</param>
        /// <returns>If the binding was successful.</returns>
        public bool Initialize(Device device)
        {
            try
            {
                matrixBuffer = new Buffer(device, Matrix.SizeInBytes * 3, ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0) {DebugName = "Matrix buffer"};
                using (var bytecode = ShaderBytecode.CompileFromFile("Shaders/Texture.vs", "TextureVertexShader", "vs_4_0"))
                {
                    layout = new InputLayout(device, ShaderSignature.GetInputSignature(bytecode), TextureDrawingVertex.VertexDeclaration) { DebugName = "Color vertex layout" };
                    vertexShader = new VertexShader(device, bytecode) { DebugName = "Texture vertex shader" };
                }

                using (var bytecode = ShaderBytecode.CompileFromFile("Shaders/Texture.ps", "TexturePixelShader", "ps_4_0"))
                {

                    pixelShader = new PixelShader(device, bytecode) { DebugName = "Texture pixel shader" };
                }

                var samplerDesc = new SamplerStateDescription
                {
                    AddressU = TextureAddressMode.Wrap,
                    AddressV = TextureAddressMode.Wrap,
                    AddressW = TextureAddressMode.Wrap,
                    Filter = Filter.ComparisonMinMagMipLinear,
                    MaximumAnisotropy = 1,
                    MipLodBias = 0f,
                    MinimumLod = 0,
                    MaximumLod = float.MaxValue,
                    BorderColor = Color.LimeGreen,
                    ComparisonFunction = Comparison.Always
                };
                pixelSampler = new SamplerState(device, samplerDesc);

                texture = new Texture();
                return texture.Initialize(device, "Textures/dirt.dds");
            }
            catch (Exception e)
            {
                MessageBox.Show("Shader error: " + e.Message);
                return false;
            }
        }
开发者ID:Earthmark,项目名称:RenderTest,代码行数:46,代码来源:TextureShader.cs


示例16: CreateDeviceDependentResources

        /// <summary>
        /// Create any device dependent resources here.
        /// This method will be called when the device is first
        /// initialized or recreated after being removed or reset.
        /// </summary>
        protected override void CreateDeviceDependentResources()
        {
            base.CreateDeviceDependentResources();

            // Ensure that if already set the device resources
            // are correctly disposed of before recreating
            RemoveAndDispose(ref vertices);
            RemoveAndDispose(ref textureView);
            RemoveAndDispose(ref samplerState);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Create a vertex to begin the parametric surface
            vertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] {
            /*  Vertex Position */
                new Vertex(new Vector3(0f, 0f, 0f)), // Base-right
            }));
            vertexBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vertex>(), 0);

            // Load texture
            textureView = ToDispose(ShaderResourceView.FromFile(device, "Texture2.png"));

            // Create our sampler state
            samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.MinMagMipLinear,
                MaximumAnisotropy = 16,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0.0f
            }));
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:43,代码来源:ParametricRenderer.cs


示例17: GroundMaterial

        public GroundMaterial(Device device, TweakBar bar, String name)
            : base(device, bar, name)
        {
            bar.AddFloat(Prefix + "albedo", "Albedo", name, 0, 100, 30, 0.1, 2);

            pixelShader = Material.CompileShader(device, "ground");

            constantBuffer = Material.AllocateMaterialBuffer(device, BufferSize);

            sampler = new SamplerState(device, new SamplerStateDescription()
            {
                ComparisonFunction = Comparison.Always,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.Anisotropic,
                BorderColor = Color4.Black,
                MaximumAnisotropy = 16,
                MaximumLod = 15,
                MinimumLod = 0,
                MipLodBias = 0,
            });
        }
开发者ID:TomCrypto,项目名称:Insight,代码行数:23,代码来源:GroundMaterial.cs


示例18: Pipeline

        // Constructor - Must be initialized before the assets.
        public Pipeline(Program program, String title, int initialWidth, int initialHeight)
        {
            // Set program reference.
            this.program = program;

            // Set dimentions.
            this.width = initialWidth;
            this.height = initialHeight;

            // Create Windows form.
            form = program.ToDispose(new RenderForm(title));
            form.ClientSize = new System.Drawing.Size(width, height);

            // Create SwapChain description
            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription =
                    new ModeDescription(width, height,
                                        new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput,
            };

            // Create Device, SwapChain and DeviceContext.
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);
            program.ToDispose(device);
            program.ToDispose(swapChain);
            context = program.ToDispose(device.ImmediateContext);

            // Create the RenderView.
            var backBuffer = program.ToDispose(Texture2D.FromSwapChain<Texture2D>(swapChain, 0));
            renderView = program.ToDispose(new RenderTargetView(device, backBuffer));

            // Create the DepthStencilView.
            var depthBuffer = program.ToDispose(new Texture2D(device, new Texture2DDescription()
            {
                Format = Format.D32_Float_S8X24_UInt,
                ArraySize = 1,
                MipLevels = 1,
                Width = form.ClientSize.Width,
                Height = form.ClientSize.Height,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            }));
            depthView = program.ToDispose(new DepthStencilView(device, depthBuffer));

            // Create the texture sampler.
            sampler = program.ToDispose(new SamplerState(device, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = Colors.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod = 0,
                MaximumLod = 16,
            }));
            context.PixelShader.SetSampler(0, sampler);

            // Initialise the transformation matrices.
            world = Matrix.Identity;
            view = Matrix.Identity;
            proj = Matrix.Identity;
            worldViewProj = Matrix.Identity;

            // Create the Constant Buffer.
            constantBuffer = program.ToDispose(new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            context.VertexShader.SetConstantBuffer(0, constantBuffer);

            // Set the view port.
            context.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));

            // Set the output target.
            context.OutputMerger.SetTargets(depthView, renderView);
        }
开发者ID:Ox5f3759df,项目名称:SharpDX-Abstraction-Maria,代码行数:86,代码来源:Pipeline.cs


示例19: CreateDeviceDependentResources

        protected override void CreateDeviceDependentResources()
        {
            // Dispose of each vertex and index buffer
            vertexBuffers.ForEach(vb => RemoveAndDispose(ref vb));
            vertexBuffers.Clear();
            indexBuffers.ForEach(ib => RemoveAndDispose(ref ib));
            indexBuffers.Clear();
            textureViews.ForEach(tv => RemoveAndDispose(ref tv));
            textureViews.Clear();
            RemoveAndDispose(ref samplerState);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Initialize vertex buffers
            for (int indx = 0; indx < mesh.VertexBuffers.Count; indx++)
            {
                var vb = mesh.VertexBuffers[indx];
                Vertex[] vertices = new Vertex[vb.Length];
                for (var i = 0; i < vb.Length; i++)
                {
                    // Retrieve skinning information for vertex
                    Common.Mesh.SkinningVertex skin = new Common.Mesh.SkinningVertex();
                    if (mesh.SkinningVertexBuffers.Count > 0)
                        skin = mesh.SkinningVertexBuffers[indx][i];

                    // Create vertex
                    vertices[i] = new Vertex(vb[i].Position, vb[i].Normal, vb[i].Color, vb[i].UV, skin);
                }

                vertexBuffers.Add(ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices.ToArray())));
                vertexBuffers[vertexBuffers.Count - 1].DebugName = "VertexBuffer_" + indx.ToString();
            }

            // Initialize index buffers
            foreach (var ib in mesh.IndexBuffers)
            {
                indexBuffers.Add(ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, ib)));
                indexBuffers[indexBuffers.Count - 1].DebugName = "IndexBuffer_" + (indexBuffers.Count - 1).ToString();
            }

            // Load textures if a material has any.
            foreach (var m in mesh.Materials)
            {
                for (var i = 0; i < m.Textures.Length; i++)
                {
                    if (System.IO.File.Exists(m.Textures[i]))
                        textureViews.Add(ToDispose(ShaderResourceView.FromFile(device, m.Textures[i])));
                    else
                        textureViews.Add(null);
                }
            }

            // Create our sampler state
            samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                BorderColor = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.MinMagMipLinear,
                MaximumAnisotropy = 16,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0.0f
            }));
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:68,代码来源:MeshRenderer.cs


示例20: DepthAndColorShader


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Direct3D11.SamplerStateDescription类代码示例发布时间:2022-05-26
下一篇:
C# Direct3D11.RenderTargetView类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap