Пример #1
0
        public MTLSampler(ref SamplerDescription description, MTLGraphicsDevice gd)
        {
            MTLFormats.GetMinMagMipFilter(
                description.Filter,
                out MTLSamplerMinMagFilter min,
                out MTLSamplerMinMagFilter mag,
                out MTLSamplerMipFilter mip);

            MTLSamplerDescriptor mtlDesc = MTLSamplerDescriptor.New();

            mtlDesc.sAddressMode = MTLFormats.VdToMTLAddressMode(description.AddressModeU);
            mtlDesc.tAddressMode = MTLFormats.VdToMTLAddressMode(description.AddressModeV);
            mtlDesc.rAddressMode = MTLFormats.VdToMTLAddressMode(description.AddressModeW);
            mtlDesc.minFilter    = min;
            mtlDesc.magFilter    = mag;
            mtlDesc.mipFilter    = mip;
            if (gd.MetalFeatures.IsMacOS)
            {
                mtlDesc.borderColor = MTLFormats.VdToMTLBorderColor(description.BorderColor);
            }
            if (description.ComparisonKind != null)
            {
                mtlDesc.compareFunction = MTLFormats.VdToMTLCompareFunction(description.ComparisonKind.Value);
            }
            mtlDesc.lodMinClamp   = description.MinimumLod;
            mtlDesc.lodMaxClamp   = description.MaximumLod;
            mtlDesc.maxAnisotropy = (UIntPtr)(Math.Max(1, description.MaximumAnisotropy));
            DeviceSampler         = gd.Device.newSamplerStateWithDescriptor(mtlDesc);
            ObjectiveCRuntime.release(mtlDesc.NativePtr);
        }
Пример #2
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="context">レンダーコンテキスト</param>
        /// <param name="width">描画に利用するテクスチャの解像度の幅</param>
        /// <param name="height">描画に利用するテクスチャの解像度の高さ</param>
        public GDISpriteBatch(RenderContext context, int width, int height)
        {
            this.Context = context;
            Resize(width, height);
            SpriteEffect      = CGHelper.CreateEffectFx5("Shader\\sprite.fx", context.DeviceManager.Device);
            renderPass        = SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(0);
            VertexInputLayout = new InputLayout(context.DeviceManager.Device, SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, SpriteVertexLayout.InputElements);
            SamplerDescription desc = new SamplerDescription();

            desc.Filter   = Filter.MinMagMipLinear;
            desc.AddressU = TextureAddressMode.Wrap;
            desc.AddressV = TextureAddressMode.Wrap;
            desc.AddressW = TextureAddressMode.Wrap;
            sampler       = SamplerState.FromDescription(context.DeviceManager.Device, desc);
            mapedGraphic  = Graphics.FromImage(mapedBitmap);
            BlendStateDescription blendDesc = new BlendStateDescription();

            blendDesc.AlphaToCoverageEnable  = false;
            blendDesc.IndependentBlendEnable = false;
            for (int i = 0; i < blendDesc.RenderTargets.Length; i++)
            {
                blendDesc.RenderTargets[i].BlendEnable           = true;
                blendDesc.RenderTargets[i].SourceBlend           = BlendOption.SourceAlpha;
                blendDesc.RenderTargets[i].DestinationBlend      = BlendOption.InverseSourceAlpha;
                blendDesc.RenderTargets[i].BlendOperation        = BlendOperation.Add;
                blendDesc.RenderTargets[i].SourceBlendAlpha      = BlendOption.One;
                blendDesc.RenderTargets[i].DestinationBlendAlpha = BlendOption.Zero;
                blendDesc.RenderTargets[i].BlendOperationAlpha   = BlendOperation.Add;
                blendDesc.RenderTargets[i].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            }
            ViewMatrix = Matrix.LookAtLH(new Vector3(0, 0, -1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            state      = BlendState.FromDescription(context.DeviceManager.Device, blendDesc);
            NeedRedraw = true;
            Update();
        }
Пример #3
0
        public VkSampler(VkDevice device, ref SamplerDescription description)
        {
            _device = device;
            VkFormats.GetFilterParams(description.Filter, out VkFilter minFilter, out VkFilter magFilter, out VkSamplerMipmapMode mipmapMode);

            VkSamplerCreateInfo samplerCI = new VkSamplerCreateInfo
            {
                sType         = VkStructureType.SamplerCreateInfo,
                addressModeU  = VkFormats.VdToVkSamplerAddressMode(description.AddressModeU),
                addressModeV  = VkFormats.VdToVkSamplerAddressMode(description.AddressModeV),
                addressModeW  = VkFormats.VdToVkSamplerAddressMode(description.AddressModeW),
                minFilter     = minFilter,
                magFilter     = magFilter,
                mipmapMode    = mipmapMode,
                compareEnable = description.ComparisonKind != null,
                compareOp     = description.ComparisonKind != null
                    ? VkFormats.VdToVkCompareOp(description.ComparisonKind.Value)
                    : VkCompareOp.Never,
                anisotropyEnable = description.Filter == SamplerFilter.Anisotropic,
                maxAnisotropy    = description.MaximumAnisotropy,
                minLod           = description.MinimumLod,
                maxLod           = description.MaximumLod,
                mipLodBias       = description.LodBias,
                borderColor      = VkFormats.VdToVkSamplerBorderColor(description.BorderColor)
            };

            vkCreateSampler(device, ref samplerCI, null, out _sampler);
        }
Пример #4
0
        protected override Sampler CreateSamplerCore(ref SamplerDescription description)
        {
            Sampler sampler = Factory.CreateSampler(ref description);

            DisposeCollector.Add(sampler);
            return(sampler);
        }
Пример #5
0
        void CreateFontsTexture()
        {
            var   io = ImGui.GetIO();
            byte *pixels;
            int   width, height;

            io.Fonts.GetTexDataAsRGBA32(out pixels, out width, out height);

            var texDesc = new Texture2DDescription
            {
                Width             = width,
                Height            = height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.R8G8B8A8_UNorm,
                SampleDescription = new SampleDescription {
                    Count = 1
                },
                Usage          = Vortice.Direct3D11.Usage.Default,
                BindFlags      = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None
            };

            var subResource = new SubresourceData
            {
                DataPointer = (IntPtr)pixels,
                Pitch       = texDesc.Width * 4,
                SlicePitch  = 0
            };

            var texture = device.CreateTexture2D(texDesc, new[] { subResource });

            var resViewDesc = new ShaderResourceViewDescription
            {
                Format        = Format.R8G8B8A8_UNorm,
                ViewDimension = ShaderResourceViewDimension.Texture2D,
                Texture2D     = new Texture2DShaderResourceView {
                    MipLevels = texDesc.MipLevels, MostDetailedMip = 0
                }
            };

            fontTextureView = device.CreateShaderResourceView(texture, resViewDesc);
            texture.Release();

            io.Fonts.TexID = RegisterTexture(fontTextureView);

            var samplerDesc = new SamplerDescription
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                MipLODBias         = 0f,
                ComparisonFunction = ComparisonFunction.Always,
                MinLOD             = 0f,
                MaxLOD             = 0f
            };

            fontSampler = device.CreateSamplerState(samplerDesc);
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="StaticSamplerDescription"/> struct.
    /// </summary>
    /// <param name="samplerDescription">Sampler description</param>
    /// <param name="shaderVisibility">The shader visibility.</param>
    /// <param name="shaderRegister">The shader register.</param>
    /// <param name="registerSpace">The register space.</param>
    public StaticSamplerDescription(SamplerDescription samplerDescription, ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace) : this()
    {
        ShaderVisibility = shaderVisibility;
        ShaderRegister   = shaderRegister;
        RegisterSpace    = registerSpace;

        // Unlike regular samplers, static samplers only support three possible border colors: opaque white, opaque black, and transparent.
        // So if the sampler has a border color that matches one of those exactly, we can convert it; otherwise it's left as the default (transparent).
        if (samplerDescription.BorderColor == Colors.White)
        {
            BorderColor = StaticBorderColor.OpaqueWhite;
        }
        else if (samplerDescription.BorderColor == Colors.Black)
        {
            BorderColor = StaticBorderColor.OpaqueBlack;
        }
        else
        {
            BorderColor = StaticBorderColor.TransparentBlack;
        }

        Filter             = samplerDescription.Filter;
        AddressU           = samplerDescription.AddressU;
        AddressV           = samplerDescription.AddressV;
        AddressW           = samplerDescription.AddressW;
        MinLOD             = samplerDescription.MinLOD;
        MaxLOD             = samplerDescription.MaxLOD;
        MipLODBias         = samplerDescription.MipLODBias;
        MaxAnisotropy      = samplerDescription.MaxAnisotropy;
        ComparisonFunction = samplerDescription.ComparisonFunction;
    }
Пример #7
0
        public SamplerState getSamplerState()
        {
            SamplerState samplerState;

            if (samplerList.Count > 0)
            {
                return(samplerList[0]);
            }
            try
            {
                SamplerDescription description = new SamplerDescription
                {
                    Filter   = SlimDX.Direct3D11.Filter.Anisotropic,
                    AddressU = SlimDX.Direct3D11.TextureAddressMode.Wrap,
                    AddressV = SlimDX.Direct3D11.TextureAddressMode.Wrap,
                    AddressW = TextureAddressMode.Wrap,
                };
                samplerState = SamplerState.FromDescription(device, description);
                samplerList.Add(samplerState);
            }
            catch (Exception e)
            {
                samplerState = null;
            }

            return(samplerState);
        }
Пример #8
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInAddressU.IsChanged
                || this.FInAddressV.IsChanged
                || this.FInAddressW.IsChanged
                || this.FInBorderColor.IsChanged
                || this.FInComparison.IsChanged
                || this.FInFilterMode.IsChanged
                || this.FInMaximumAnisotropy.IsChanged
                || this.FInMaximumLod.IsChanged
                || this.FInMinimumLod.IsChanged
                || this.FInMipLodBias.IsChanged)
            {
                this.FOutSampler.SliceCount = 1;
                RGBAColor c = this.FInBorderColor[0];
                Color4 col = new Color4((float)c.R, (float)c.G, (float)c.B, (float)c.A);
                SamplerDescription sampler = new SamplerDescription()
                {
                    AddressU = this.FInAddressU[0],
                    AddressV = this.FInAddressV[0],
                    AddressW = this.FInAddressW[0],
                    BorderColor = col,
                    ComparisonFunction = this.FInComparison[0],
                    Filter = this.FInFilterMode[0],
                    MaximumAnisotropy = this.FInMaximumAnisotropy[0],
                    MaximumLod = this.FInMaximumLod[0],
                    MinimumLod = this.FInMinimumLod[0],
                    MipLodBias = this.FInMipLodBias[0]
                };
                this.FOutSampler.SliceCount = SpreadMax;

                this.FOutSampler[0] = sampler;

            }
        }
Пример #9
0
        public SurfaceMaterial(DX11Game game, ShaderResourceView diffuseTexture)
        {
            this.game = game;


            textures[0] = diffuseTexture;
            textures[1] = null; //normalTexture;
            textures[2] = null; //specularTexture;


            baseShader = BasicShader.LoadAutoreload(game, ShaderFiles.DCSurface, delegate { }, createShaderMacros());
            baseShader.SetTechnique("DCSurface");
            //baseShader.DiffuseTexture = checkerTexture;

            var desc = new SamplerDescription()
            {
                AddressU          = TextureAddressMode.Wrap,
                AddressV          = TextureAddressMode.Wrap,
                AddressW          = TextureAddressMode.Wrap,
                Filter            = Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            sampler = SamplerState.FromDescription(game.Device, desc);

            inputLayout = CreateInputLayout();
        }
Пример #10
0
        public override void Initialize()
        {
            base.Initialize();

            try
            {
                using (ShaderBytecode vertexShaderByteCode = ShaderBytecode.CompileFromFile(
                           "Shaders/GouraudTextured.fx",
                           "VShader",
                           "vs_4_0",
                           ShaderFlags.None,
                           EffectFlags.None,
                           null,
                           new IncludeFX("Shaders")))
                {
                    vertexShader   = new VertexShader(DeviceManager.Instance.device, vertexShaderByteCode);
                    inputSignature = ShaderSignature.GetInputSignature(vertexShaderByteCode);
                }

                using (ShaderBytecode pixelShaderByteCode = ShaderBytecode.CompileFromFile(
                           "Shaders/GouraudTextured.fx",
                           "PShader",
                           "ps_4_0",
                           ShaderFlags.None,
                           EffectFlags.None,
                           null,
                           new IncludeFX("Shaders")))
                {
                    pixelShader = new PixelShader(DeviceManager.Instance.device, pixelShaderByteCode);
                }

                layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements);

                ConstantsBuffer = new SlimDX.Direct3D11.Buffer(
                    DeviceManager.Instance.device,
                    0x140,                    //Marshal.SizeOf(Constants),
                    ResourceUsage.Dynamic,
                    BindFlags.ConstantBuffer,
                    CpuAccessFlags.Write,
                    ResourceOptionFlags.None,
                    0
                    );

                SamplerDescription sDefault = new SamplerDescription();
                sDefault.AddressU           = TextureAddressMode.Wrap;
                sDefault.AddressV           = TextureAddressMode.Wrap;
                sDefault.AddressW           = TextureAddressMode.Wrap;
                sDefault.Filter             = Filter.MinMagMipLinear;
                sDefault.ComparisonFunction = Comparison.Never;
                sDefault.MinimumLod         = 0;
                sDefault.MaximumLod         = float.MaxValue;

                Sampler = SamplerState.FromDescription(DeviceManager.Instance.device, sDefault);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #11
0
        public virtual bool Init(ID3D11Device device, ShaderInitParams InitParams)
        {
            // Attempt to construct pixel shader
            if (InitParams.PixelShaderFile.IsValid())
            {
                Blob PixelBytecode = ConstructBytecode(InitParams.PixelShaderFile);
                OurPixelShader = device.CreatePixelShader(PixelBytecode);
                PixelBytecode.Dispose();
            }

            // Attempt to construct vertex shader
            if (InitParams.VertexShaderFile.IsValid())
            {
                Blob VertexBytecode = ConstructBytecode(InitParams.VertexShaderFile);
                OurVertexShader = device.CreateVertexShader(VertexBytecode);
                Layout          = device.CreateInputLayout(InitParams.Elements, VertexBytecode);
                VertexBytecode.Dispose();
            }

            // Attempt to construct geometry shader
            if (InitParams.GeometryShaderFile.IsValid())
            {
                Blob GeometryBytecode = ConstructBytecode(InitParams.GeometryShaderFile);
                OurGeometryShader = device.CreateGeometryShader(GeometryBytecode);
                GeometryBytecode.Dispose();
            }

            SamplerDescription samplerDesc = new SamplerDescription()
            {
                Filter             = Filter.Anisotropic,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                MipLODBias         = 0,
                MaxAnisotropy      = 8,
                ComparisonFunction = ComparisonFunction.Always,
                BorderColor        = new Color4(0, 0, 0, 0),
                MinLOD             = 0,
                MaxLOD             = 0
            };

            SamplerState = device.CreateSamplerState(samplerDesc);

            ConstantCameraBuffer       = ConstantBufferFactory.ConstructBuffer <DCameraBuffer>(device, "CameraBuffer");
            ConstantLightBuffer        = ConstantBufferFactory.ConstructBuffer <LightBuffer>(device, "LightBuffer");
            ConstantMatrixBuffer       = ConstantBufferFactory.ConstructBuffer <MatrixBuffer>(device, "MatrixBuffer");
            ConstantEditorParamsBuffer = ConstantBufferFactory.ConstructBuffer <EditorParameterBuffer>(device, "EditorBuffer");

            return(true);
        }
        void CreateSamplers()
        {
            SamplerDescription desc = new SamplerDescription();

            desc.AddressU          = TextureAddressMode.Mirror;
            desc.AddressV          = TextureAddressMode.Mirror;
            desc.AddressW          = TextureAddressMode.Mirror;
            desc.Filter            = Filter.MinMagMipLinear;
            desc.MaximumAnisotropy = 16;
            desc.MaximumLod        = float.MaxValue;
            SamplerState s = SamplerState.FromDescription(device_, desc);

            samplerStates_.Add("minMagMipLinear", s);
        }
Пример #13
0
        /// <summary>
        /// Get the sampler key, a new one or an existing one.
        /// </summary>
        /// <param name="sampler">The sampler.</param>
        /// <param name="samplerKeys">The already defined keys.</param>
        /// <param name="samplerIndex">The current index of the sampler.</param>
        /// <returns>The ParameterKey.</returns>
        private void SetSamplerKey(NodeParameterSampler sampler, Dictionary <SamplerDescription, ParameterKey <SamplerState> > samplerKeys, ref int samplerIndex)
        {
            var state = new SamplerDescription {
                Filtering = sampler.Filtering, AddressModeU = sampler.AddressModeU, AddressModeV = sampler.AddressModeV, AddressModeW = TextureAddressMode.Wrap
            };
            ParameterKey <SamplerState> samplerParameterKey;

            if (!samplerKeys.TryGetValue(state, out samplerParameterKey))
            {
                samplerParameterKey = GetDefaultSamplerKey(samplerIndex);
                ++samplerIndex;
                samplerKeys.Add(state, samplerParameterKey);
            }
            sampler.SamplerParameterKey = samplerParameterKey;
        }
Пример #14
0
        public virtual void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneContext sc)
        {
            var factory = gd.ResourceFactory;

            ProjectionMatrixBuffer = factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic));
            ViewMatrixBuffer       = factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic));
            CameraInfoBuffer       = factory.CreateBuffer(new BufferDescription((uint)Unsafe.SizeOf <CameraInfo>(), BufferUsage.UniformBuffer | BufferUsage.Dynamic));
            WorldAndInverseBuffer  = factory.CreateBuffer(new BufferDescription((uint)Marshal.SizeOf <WorldAndInverse>(), BufferUsage.UniformBuffer | BufferUsage.Dynamic));
            LightingInfoBuffer     = factory.CreateBuffer(new BufferDescription((uint)Unsafe.SizeOf <LightingInfo>(), BufferUsage.UniformBuffer));

            //Float arrays are handled by padding each element up to the size of a vec4,
            //so we have to account for the padding in creating and initializing the buffer
            var numLightStyleElements = BSPConstants.MaxLightStyles * LightStylesElementMultiplier;

            LightStylesBuffer = factory.CreateBuffer(new BufferDescription((uint)(numLightStyleElements * Marshal.SizeOf <int>()), BufferUsage.UniformBuffer));

            //Initialize the buffer to all zeroes
            var lightStylesValues = new float[numLightStyleElements];

            Array.Fill(lightStylesValues, 0.0f);
            gd.UpdateBuffer(LightStylesBuffer, 0, lightStylesValues);

            //TODO: pull filter settings and anisotropy from config
            var mainSamplerDescription = new SamplerDescription
            {
                AddressModeU      = SamplerAddressMode.Wrap,
                AddressModeV      = SamplerAddressMode.Wrap,
                AddressModeW      = SamplerAddressMode.Wrap,
                Filter            = SamplerFilter.MinLinear_MagLinear_MipLinear,
                LodBias           = 0,
                MinimumLod        = 0,
                MaximumLod        = uint.MaxValue,
                MaximumAnisotropy = 4,
            };

            MainSampler = factory.CreateSampler(ref mainSamplerDescription);

            if (Camera != null)
            {
                UpdateCameraBuffers(cl);
            }

            TextureSamplerResourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                                            new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                                                                            new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment)));

            RecreateWindowSizedResources(gd, cl);
        }
Пример #15
0
        /// <summary>
        /// Creates a new <see cref="Sampler"/>.
        /// </summary>
        /// <param name="description">The desired properties of the created object.</param>
        /// <returns>A new <see cref="Sampler"/>.</returns>
        public Sampler CreateSampler(ref SamplerDescription description)
        {
#if VALIDATE_USAGE
            if (!Features.SamplerLodBias && description.LodBias != 0)
            {
                throw new VeldridException(
                          "GraphicsDevice does not support Sampler LOD bias. SamplerDescription.LodBias must be 0.");
            }
            if (!Features.SamplerAnisotropy && description.Filter == SamplerFilter.Anisotropic)
            {
                throw new VeldridException(
                          "SamplerFilter.Anisotropic cannot be used unless GraphicsDeviceFeatures.SamplerAnisotropy is supported.");
            }
#endif

            return(CreateSamplerCore(ref description));
        }
Пример #16
0
        public SamplerStates()
        {
            var samplerDesc = new SamplerDescription
            {
                AddressU   = TextureAddressMode.Wrap,
                AddressV   = TextureAddressMode.Wrap,
                AddressW   = TextureAddressMode.Wrap,
                Filter     = Filter.MinMagMipLinear,
                MinimumLod = 0,
                MaximumLod = 0
            };

            LinSampler = SamplerState.FromDescription(RenderFrame.Instance.device, samplerDesc);

            samplerDesc.Filter = Filter.MinMagPointMipLinear;
            PointSampler       = SamplerState.FromDescription(RenderFrame.Instance.device, samplerDesc);
        }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticSamplerDescription"/> struct.
        /// </summary>
        /// <param name="samplerDescription">Sampler description</param>
        /// <param name="shaderVisibility">The shader visibility.</param>
        /// <param name="shaderRegister">The shader register.</param>
        /// <param name="registerSpace">The register space.</param>
        public StaticSamplerDescription(SamplerDescription samplerDescription, ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace) : this()
        {
            ShaderVisibility = shaderVisibility;
            ShaderRegister   = shaderRegister;
            RegisterSpace    = registerSpace;
            BorderColor      = StaticBorderColor.TransparentBlack;

            Filter             = samplerDescription.Filter;
            AddressU           = samplerDescription.AddressU;
            AddressV           = samplerDescription.AddressV;
            AddressW           = samplerDescription.AddressW;
            MinLOD             = samplerDescription.MinLOD;
            MaxLOD             = samplerDescription.MaxLOD;
            MipLODBias         = samplerDescription.MipLODBias;
            MaxAnisotropy      = samplerDescription.MaxAnisotropy;
            ComparisonFunction = samplerDescription.ComparisonFunction;
        }
Пример #18
0
        public void SwitchWrapMode()
        {
            wrap = !wrap;
            var samplerDesc = new SamplerDescription
            {
                AddressU   = wrap ? TextureAddressMode.Wrap : TextureAddressMode.Clamp,
                AddressV   = wrap ? TextureAddressMode.Wrap : TextureAddressMode.Clamp,
                AddressW   = wrap ? TextureAddressMode.Wrap : TextureAddressMode.Clamp,
                Filter     = Filter.MinMagMipLinear,
                MinimumLod = 0,
                MaximumLod = 0
            };

            LinSampler = SamplerState.FromDescription(RenderFrame.Instance.device, samplerDesc);

            samplerDesc.Filter = Filter.MinMagPointMipLinear;
            PointSampler       = SamplerState.FromDescription(RenderFrame.Instance.device, samplerDesc);
        }
Пример #19
0
        public D2DSpriteBatch(RenderContext context)
        {
            this.context           = context;
            this.DeviceManager     = context.DeviceManager;
            this.SpriteEffect      = CGHelper.CreateEffectFx5FromResource("MMF.Resource.Shader.SpriteShader.fx", this.DeviceManager.Device);
            this.renderPass        = this.SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(1);
            this.VertexInputLayout = new InputLayout(this.DeviceManager.Device, this.SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, SpriteVertexLayout.InputElements);
            SamplerDescription desc = new SamplerDescription();

            desc.Filter   = Filter.MinMagMipLinear;
            desc.AddressU = TextureAddressMode.Wrap;
            desc.AddressV = TextureAddressMode.Wrap;
            desc.AddressW = TextureAddressMode.Wrap;
            this.sampler  = SamplerState.FromDescription(this.DeviceManager.Device, desc);
            BlendStateDescription blendDesc = new BlendStateDescription();

            blendDesc.AlphaToCoverageEnable  = false;
            blendDesc.IndependentBlendEnable = false;
            for (int i = 0; i < blendDesc.RenderTargets.Length; i++)
            {
                blendDesc.RenderTargets[i].BlendEnable           = true;
                blendDesc.RenderTargets[i].SourceBlend           = BlendOption.SourceAlpha;
                blendDesc.RenderTargets[i].DestinationBlend      = BlendOption.InverseSourceAlpha;
                blendDesc.RenderTargets[i].BlendOperation        = BlendOperation.Add;
                blendDesc.RenderTargets[i].SourceBlendAlpha      = BlendOption.One;
                blendDesc.RenderTargets[i].DestinationBlendAlpha = BlendOption.Zero;
                blendDesc.RenderTargets[i].BlendOperationAlpha   = BlendOperation.Add;
                blendDesc.RenderTargets[i].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            }
            this.state = BlendState.FromDescription(this.DeviceManager.Device, blendDesc);

            BlendStateDescription bsd = new BlendStateDescription();

            bsd.RenderTargets[0].BlendEnable           = true;
            bsd.RenderTargets[0].SourceBlend           = BlendOption.SourceAlpha;
            bsd.RenderTargets[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            bsd.RenderTargets[0].BlendOperation        = BlendOperation.Add;
            bsd.RenderTargets[0].SourceBlendAlpha      = BlendOption.One;
            bsd.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
            bsd.RenderTargets[0].BlendOperationAlpha   = BlendOperation.Add;
            bsd.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            this.TransParentBlendState = BlendState.FromDescription(this.DeviceManager.Device, bsd);
            Resize();
        }
Пример #20
0
        /// <summary>
        /// サンプラステート
        /// 現状フィルタはリニア固定
        /// </summary>
        static void InitializeSamplerState()
        {
            var device    = D3D11Device;
            int state_num = (int)RenderState.TextureAddressing.Max;

            samplerState_ = new SamplerState[state_num][];

            TextureAddressMode[] dx_list = new TextureAddressMode[] {
                TextureAddressMode.Clamp,
                TextureAddressMode.Wrap,
                TextureAddressMode.Mirror,
                TextureAddressMode.Border,
            };

            for (int i = 0; i < state_num; i++)
            {
                samplerState_[i] = new SamplerState[state_num];
                for (int j = 0; j < state_num; j++)
                {
                    SamplerDescription samplerDescription = new SamplerDescription()
                    {
                        AddressU = dx_list[i],
                        AddressV = dx_list[j],
                        AddressW = TextureAddressMode.Clamp,
                        Filter   = Filter.MinMagMipLinear,
                        //Filter = Filter.MinMagMipPoint,
                        //Filter = Filter.Anisotropic,		//とりあえず固定でAnisoに
                        MipLodBias        = -1,
                        MinimumLod        = 0,
                        MaximumLod        = 255,
                        MaximumAnisotropy = 4,
                        BorderColor       = new Color4(0, 0, 0, 1),
                    };

                    samplerState_[i][j] = SamplerState.FromDescription(device, samplerDescription);
                }
            }


            // 初期値
            int wrap = (int)RenderState.TextureAddressing.Wrap;

            D3D11ImmediateContext.PixelShader.SetSampler(samplerState_[wrap][wrap], 0);
        }
Пример #21
0
        public void Update(ResourceLayout TexLayout, int W, int H)
        {
            if (Width != W || Height != H)
            {
                Tex?.Dispose();
                TexView?.Dispose();

                Width  = W;
                Height = H;

                TextureDescription Desc = new TextureDescription((uint)W, (uint)H, 1, 1, 1, PixelFormat.B8_G8_R8_A8_UNorm, TextureUsage.Sampled, TextureType.Texture2D);
                Tex     = Fact.CreateTexture(Desc);
                TexView = Fact.CreateTextureView(Tex);

                SamplerDescription SamplerDesc = new SamplerDescription(SamplerAddressMode.Clamp, SamplerAddressMode.Clamp, SamplerAddressMode.Clamp,
                                                                        SamplerFilter.MinPoint_MagPoint_MipPoint, null, 0, 0, 0, 0, SamplerBorderColor.OpaqueBlack);
                TexSampler = Fact.CreateSampler(SamplerDesc);
            }
        }
Пример #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextureShader" /> class and creates the sampler.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="vertexShaderPath">The vertex shader path.</param>
        /// <param name="pixelShaderPath">The pixel shader path.</param>
        protected TextureShader(Device device, string vertexShaderPath, string pixelShaderPath, IInputLayoutProvider inputLayoutMaker)
            : base(device, vertexShaderPath, pixelShaderPath, inputLayoutMaker)
        {
            SamplerDescription sampleDesc = new SamplerDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                MipLodBias = 0f,
                MaximumAnisotropy = 1,
                ComparisonFunction = Comparison.Always,
                BorderColor = new Color4(0, 0, 0, 0),
                MinimumLod = 0,
                MaximumLod = float.MaxValue
            };

            sampler = SamplerState.FromDescription(device, sampleDesc);
        }
Пример #23
0
        public D3D11Sampler(Device device, ref SamplerDescription description)
        {
            Comparison comparision = description.ComparisonKind == null ? Comparison.Never : D3D11Formats.VdToD3D11DepthComparison(description.ComparisonKind.Value);
            SamplerStateDescription samplerStateDesc = new SamplerStateDescription
            {
                AddressU           = D3D11Formats.VdToD3D11AddressMode(description.AddressModeU),
                AddressV           = D3D11Formats.VdToD3D11AddressMode(description.AddressModeV),
                AddressW           = D3D11Formats.VdToD3D11AddressMode(description.AddressModeW),
                Filter             = D3D11Formats.ToD3D11Filter(description.Filter, description.ComparisonKind.HasValue),
                MinimumLod         = description.MinimumLod,
                MaximumLod         = description.MaximumLod,
                MaximumAnisotropy  = (int)description.MaximumAnisotropy,
                ComparisonFunction = comparision,
                MipLodBias         = description.LodBias,
                BorderColor        = ToRawColor4(description.BorderColor)
            };

            DeviceSampler = new SamplerState(device, samplerStateDesc);
        }
Пример #24
0
        /// <summary>
        /// Initializes device dependant resources.
        /// </summary>
        private void Initialize()
        {
            var device = m_directCanvasFactory.DeviceContext.Device;

            /* Here we create a new sampler for sampling input within
             * our pixel shader */
            var sampDesc = new SamplerDescription();
            sampDesc.AddressU = TextureAddressMode.Clamp;
            sampDesc.AddressV = TextureAddressMode.Clamp;
            sampDesc.AddressW = TextureAddressMode.Clamp;
            sampDesc.BorderColor = new Color4(0, 0, 0, 0).InternalColor4;
            sampDesc.ComparisonFunction = Comparison.Never;
            sampDesc.Filter = Filter.MinMagMipLinear;
            sampDesc.MaximumAnisotropy = 10;
            sampDesc.MaximumLod = float.MaxValue;
            sampDesc.MinimumLod = 0;
            sampDesc.MipLodBias = 0;
            m_linearSamplerState = SamplerState.FromDescription(device, sampDesc);

            sampDesc.Filter = Filter.MinMagMipPoint;
            m_pointSamplerState = SamplerState.FromDescription(device, sampDesc);

            /* Here we have a hard coded blend state.  This should be configurable in
             * the future. Like the composer has */
            var blendDesc = new BlendStateDescription();
            blendDesc.IsAlphaToCoverageEnabled = false;
            blendDesc.BlendOperation = BlendOperation.Add;
            blendDesc.AlphaBlendOperation = BlendOperation.Add;
            blendDesc.DestinationBlend = BlendOption.InverseSourceAlpha;
            blendDesc.DestinationAlphaBlend = BlendOption.One;
            blendDesc.SourceBlend = BlendOption.One;
            blendDesc.SourceAlphaBlend = BlendOption.One;

            for (uint i = 0; i < 8; i++)
            {
                blendDesc.SetWriteMask(i, ColorWriteMaskFlags.All);
                blendDesc.SetBlendEnable(i, true);
            }

            m_alphaBlendState = BlendState.FromDescription(device, blendDesc);
        }
Пример #25
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInAddressU.IsChanged ||
                this.FInAddressV.IsChanged ||
                this.FInAddressW.IsChanged ||
                this.FInBorderColor.IsChanged ||
                this.FInComparison.IsChanged ||
                this.FInFilterMode.IsChanged ||
                this.FInMaximumAnisotropy.IsChanged ||
                this.FInMaximumLod.IsChanged ||
                this.FInMinimumLod.IsChanged ||
                this.FInMipLodBias.IsChanged)
            {
                this.FOutSampler.SliceCount = SpreadMax;

                for (int i = 0; i < SpreadMax; i++)
                {
                    RGBAColor c = this.FInBorderColor[i];

                    Color4             col     = new Color4((float)c.R, (float)c.G, (float)c.B, (float)c.A);
                    SamplerDescription sampler = new SamplerDescription()
                    {
                        AddressU           = this.FInAddressU[i],
                        AddressV           = this.FInAddressV[i],
                        AddressW           = this.FInAddressW[i],
                        BorderColor        = col,
                        ComparisonFunction = this.FInComparison[i],
                        Filter             = this.FInFilterMode[i],
                        MaximumAnisotropy  = this.FInMaximumAnisotropy[i],
                        MaximumLod         = this.FInMaximumLod[i],
                        MinimumLod         = this.FInMinimumLod[i],
                        MipLodBias         = this.FInMipLodBias[i]
                    };

                    this.FOutSampler[i] = sampler;
                }
            }
        }
Пример #26
0
 public override Sampler CreateSampler(ref SamplerDescription description)
 {
     return(new OpenGLSampler(_gd, ref description));
 }
Пример #27
0
 private void setSampler()
 {
     SamplerDescription a = new SamplerDescription();
     a.AddressU = TextureAddressMode.Wrap;
     a.AddressV = TextureAddressMode.Wrap;
     a.AddressW = TextureAddressMode.Wrap;
     a.Filter = Filter.MinPointMagMipLinear;
     SamplerState b = SamplerState.FromDescription(device, a);
     device.PixelShader.SetSampler(b, 0);
 }
Пример #28
0
 /// <summary>
 /// Creates a new <see cref="Sampler"/>.
 /// </summary>
 /// <param name="description">The desired properties of the created object.</param>
 /// <returns>A new <see cref="Sampler"/>.</returns>
 public abstract Sampler CreateSampler(ref SamplerDescription description);
Пример #29
0
 /// <summary>
 /// Creates a new <see cref="Sampler"/>.
 /// </summary>
 /// <param name="description">The desired properties of the created object.</param>
 /// <returns>A new <see cref="Sampler"/>.</returns>
 public Sampler CreateSampler(SamplerDescription description) => CreateSampler(ref description);
Пример #30
0
        public static void Initialize(Device device)
        {
            m_Initialized = true;

            var samplerDescription = new SamplerDescription()
            {
                AddressU   = TextureAddressMode.Wrap,
                AddressV   = TextureAddressMode.Wrap,
                AddressW   = TextureAddressMode.Wrap,
                Filter     = Filter.MinMagMipPoint,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.PointWrap] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU   = TextureAddressMode.Clamp,
                AddressV   = TextureAddressMode.Clamp,
                AddressW   = TextureAddressMode.Clamp,
                Filter     = Filter.MinMagMipPoint,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.PointClamp] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU   = TextureAddressMode.Wrap,
                AddressV   = TextureAddressMode.Wrap,
                AddressW   = TextureAddressMode.Wrap,
                Filter     = Filter.MinMagMipLinear,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.LinearWrap] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU   = TextureAddressMode.Clamp,
                AddressV   = TextureAddressMode.Clamp,
                AddressW   = TextureAddressMode.Clamp,
                Filter     = Filter.MinMagMipLinear,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.LinearClamp] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                Filter             = Filter.ComparisonMinMagMipLinear,
                MinimumLod         = 0,
                MaximumLod         = 255,
                ComparisonFunction = Comparison.LessEqual
            };

            m_SamplerStates[(int)SamplerType.LinearComparisonClamp] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU          = TextureAddressMode.Clamp,
                AddressV          = TextureAddressMode.Clamp,
                AddressW          = TextureAddressMode.Clamp,
                Filter            = Filter.Anisotropic,
                MinimumLod        = 0,
                MaximumLod        = 255,
                MaximumAnisotropy = 4,
            };

            m_SamplerStates[(int)SamplerType.AnisotropicClamp] = SamplerState.FromDescription(device, samplerDescription);
        }
Пример #31
0
 protected override Sampler CreateSamplerCore(ref SamplerDescription description)
 {
     return(new OpenGLSampler(_gd, ref description));
 }
Пример #32
0
        public static void Initialize(Device device)
        {
            m_Initialized = true;

            var samplerDescription = new SamplerDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.MinMagMipPoint,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.PointWrap] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter = Filter.MinMagMipPoint,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.PointClamp] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.MinMagMipLinear,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.LinearWrap] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter = Filter.MinMagMipLinear,
                MinimumLod = 0,
                MaximumLod = 255,
            };

            m_SamplerStates[(int)SamplerType.LinearClamp] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter = Filter.ComparisonMinMagMipLinear,
                MinimumLod = 0,
                MaximumLod = 255,
                ComparisonFunction = Comparison.LessEqual
            };

            m_SamplerStates[(int)SamplerType.LinearComparisonClamp] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter = Filter.Anisotropic,
                MinimumLod = 0,
                MaximumLod = 255,
                MaximumAnisotropy = 4,
            };

            m_SamplerStates[(int)SamplerType.AnisotropicClamp] = SamplerState.FromDescription(device, samplerDescription);

            samplerDescription = new SamplerDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.Anisotropic,
                MinimumLod = 0,
                MaximumLod = 255,
                MaximumAnisotropy = 4,
            };

            m_SamplerStates[(int)SamplerType.AnisotropicWrap] = SamplerState.FromDescription(device, samplerDescription);
        }
Пример #33
0
 protected override Sampler CreateSamplerCore(ref SamplerDescription description)
 {
     return(new D3D11Sampler(_device, ref description));
 }
Пример #34
0
        public RenderObject(Device device)
        {
            cb.vp = Matrix.Identity;
            cb.world = Matrix.Identity;

            // load and compile the vertex shader
            using (var bytecode = ShaderBytecode.CompileFromFile("simple.fx", "VShader", "vs_4_0", ShaderFlags.None, EffectFlags.None))
            {
                vsInputSignature = ShaderSignature.GetInputSignature(bytecode);
                vertexShader = new VertexShader(device, bytecode);
            }

            // load and compile the pixel shader
            using (var bytecode = ShaderBytecode.CompileFromFile("simple.fx", "PShader", "ps_4_0", ShaderFlags.None, EffectFlags.None))
                pixelShader = new PixelShader(device, bytecode);

            // Old school style.
            /*
            vertexSize = 24;
            vertexCount = 3;
            var vertexStream = new DataStream(vertexSize * vertexCount, true, true);
            vertexStream.Write(new Vector3(0.0f, 5.0f, 0.5f));
            vertexStream.Write(new Vector3(1, 0, 0)); // color
            vertexStream.Write(new Vector3(5.0f, -5.0f, 0.5f));
            vertexStream.Write(new Vector3(0, 1, 0)); // color
            vertexStream.Write(new Vector3(-5.0f, -5.0f, 0.5f));
            vertexStream.Write(new Vector3(0, 0, 1)); // color
            vertexStream.Position = 0;
            */

            // Use struct
            Vertex[] vertices = new Vertex[] {
                new Vertex() { pos = new Vector3(0.0f, 50.0f, 0.5f), col = new Vector3(1, 0, 0), uv = new Vector2(0, 0) },
                new Vertex() { pos = new Vector3(50.0f, -50.0f, 0.5f), col = new Vector3(1, 1, 0), uv = new Vector2(1, 0) },
                new Vertex() { pos = new Vector3(-50.0f, -50.0f, 0.5f), col = new Vector3(0, 1, 1), uv = new Vector2(1, 1) },
            };
            vertexSize = Marshal.SizeOf(typeof(Vertex));
            vertexCount = vertices.Length;
            var vertexStream = new DataStream(vertexSize * vertexCount, true, true);
            foreach (var vertex in vertices)
            {
                vertexStream.Write(vertex);
            }
            vertexStream.Position = 0;

            // create the vertex layout and buffer
            var elements = new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0),
                new InputElement("COLOR", 0, Format.R32G32B32_Float, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0)
            };
            vertexBufferLayout = new InputLayout(device, vsInputSignature, elements);
            vertexBuffer = new Buffer(device, vertexStream, vertexSize * vertexCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            vertexStream.Close();

            // Setup Constant Buffers
            constantBuffer = new Buffer(device, Marshal.SizeOf(typeof(ConstantBuffer)), ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);

            // http://asc-chalmers-project.googlecode.com/svn-history/r26/trunk/Source/AdvGraphicsProject/Program.cs
            // Try load a texture
            SamplerDescription samplerDescription = new SamplerDescription();
            samplerDescription.AddressU = TextureAddressMode.Wrap;
            samplerDescription.AddressV = TextureAddressMode.Wrap;
            samplerDescription.AddressW = TextureAddressMode.Wrap;
            samplerDescription.Filter = Filter.MinPointMagMipLinear;
            samplerLinear = SamplerState.FromDescription(device, samplerDescription);

            texture = Texture2D.FromFile(device, "Data/cco.png");
            textureView = new ShaderResourceView(device, texture);

            var desc = new BlendStateDescription()
            {
                AlphaToCoverageEnable = true,
                IndependentBlendEnable = true
            };

            desc.RenderTargets[0].BlendEnable = false;
            desc.RenderTargets[0].BlendOperation = BlendOperation.Add;
            desc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
            desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.Alpha;
            desc.RenderTargets[0].SourceBlend = BlendOption.SourceAlpha;
            desc.RenderTargets[0].DestinationBlend = BlendOption.InverseSourceAlpha;
            desc.RenderTargets[0].DestinationBlendAlpha = BlendOption.InverseSourceAlpha;
            desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

            blendState = BlendState.FromDescription(device, desc);
        }
Пример #35
0
        /// <summary>
        /// Creates a new instance of the SpriteRenderer
        /// </summary>
        /// <param name="device">The device to use</param>
        /// <param name="maxSpriteInstances">The maximum sprite instances that can be cached before a flush happens</param>
        public SpriteRenderer(Device device, int maxSpriteInstances = 10000)
        {
            /* Initialize our arrays to hold our sprite data */
            m_spriteRenderData = new SpriteRenderData[maxSpriteInstances];
            m_spriteDrawData = new SpriteDrawData[maxSpriteInstances];

            /* Initialize all the items in the array */
            for (int i = 0; i < maxSpriteInstances; i++)
            {
                m_spriteRenderData[i] = new SpriteRenderData();
            }

            m_maxSpriteInstances = maxSpriteInstances;
            m_device = device;

            /* Create our default blend states using our helper */
            m_blendStates = SpriteRendererBlendStateHelper.InitializeDefaultBlendStates(m_device);

            /* Create our vertex shader */
            m_vertexShaderInstanced10 = new VertexShader10(device,
                                                           SHADER_RESOURCE_NAME, Assembly.GetExecutingAssembly(),
                                                           "SpriteInstancedVS", 
                                                           ShaderVersion.Vs_4_0);

            /* Create our pixel shader */
            m_pixelShader10 = new PixelShader10(device,
                                                SHADER_RESOURCE_NAME, Assembly.GetExecutingAssembly(),
                                                "SpritePS", 
                                                ShaderVersion.Ps_4_0,ShaderFlags.Debug);
            
            /* Create a new sprite quad that holds our GPU buffers */
            m_spriteQuad = new SpriteQuad(device, maxSpriteInstances);

            m_spriteQuadShaderBinding = new GeometryInputShaderBinding(m_spriteQuad, 
                                                                       m_vertexShaderInstanced10, 
                                                                       m_pixelShader10);

            var rastDesc = new RasterizerStateDescription();
            rastDesc.IsAntialiasedLineEnabled = false;
            rastDesc.CullMode = CullMode.None;
            rastDesc.DepthBias = 0;
            rastDesc.DepthBiasClamp = 1.0f;
            rastDesc.IsDepthClipEnabled = false;
            rastDesc.FillMode = FillMode.Solid;
            rastDesc.IsFrontCounterclockwise = false;
            rastDesc.IsMultisampleEnabled = false;
            rastDesc.IsScissorEnabled = false;
            rastDesc.SlopeScaledDepthBias = 0;
            m_rasterizerState = RasterizerState.FromDescription(m_device, rastDesc);
            
            var dsDesc = new DepthStencilStateDescription();
            dsDesc.IsDepthEnabled = false;
            dsDesc.DepthWriteMask = DepthWriteMask.All;
            dsDesc.DepthComparison = Comparison.Less;
            dsDesc.IsStencilEnabled = false;
            dsDesc.StencilReadMask = 0xff;
            dsDesc.StencilWriteMask = 0xff;
            dsDesc.FrontFace = new DepthStencilOperationDescription{ DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Replace, Comparison = Comparison.Always };
            dsDesc.BackFace = dsDesc.FrontFace;
            m_dsState = DepthStencilState.FromDescription(m_device, dsDesc);

            var sampDesc = new SamplerDescription();
            sampDesc.AddressU = TextureAddressMode.Wrap;
            sampDesc.AddressV = TextureAddressMode.Wrap;
            sampDesc.AddressW = TextureAddressMode.Wrap;
            sampDesc.BorderColor = new Color4(0, 0, 0, 0).InternalColor4;
            sampDesc.ComparisonFunction = Comparison.Never;
            sampDesc.Filter = Filter.MinMagMipLinear;
            sampDesc.MaximumAnisotropy = 1;
            sampDesc.MaximumLod = float.MaxValue;
            sampDesc.MinimumLod = 0;
            sampDesc.MipLodBias = 0;
            m_linearSamplerState = SamplerState.FromDescription(m_device, sampDesc);

            sampDesc.Filter = Filter.MinMagMipPoint;
            m_pointSamplerState = SamplerState.FromDescription(m_device, sampDesc);
        }
Пример #36
0
 protected override Sampler CreateSamplerCore(ref SamplerDescription description)
 {
     return(new MTLSampler(ref description, _gd));
 }
Пример #37
0
 public Sampler(GraphicsDevice device, SamplerDescription description)
 {
     GraphicsDevice      = device;
     Description         = description;
     CpuDescriptorHandle = CreateSampler();
 }
Пример #38
0
        public void CreateShaders(string code)
        {
            UpdateRenderer = true;
            // load and compile the vertex shader
            using (var bytecode = ShaderBytecode.Compile(code, "VShader", "vs_5_0", ShaderFlags.None, EffectFlags.None))
            {
                inputSignature = ShaderSignature.GetInputSignature(bytecode);
                vertexShader = new VertexShader(device, bytecode);
            }

            // load and compile the pixel shader
            using (var bytecode = ShaderBytecode.Compile(code, "PShader", "ps_5_0", ShaderFlags.None, EffectFlags.None))
                pixelShader = new PixelShader(device, bytecode);

            string compilationError = "";
            //ShaderBytecode compiledShader = ShaderBytecode.CompileFromFile("vteffect.fx", "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null, out compilationError);

            //fx = new Effect(device, compiledShader);

            // create test vertex data, making sure to rewind the stream afterward
            vertices = new DataStream(20 * 4, true, true);

            vertices.Write(new Vector3(-1f, -1f, 0.5f)); vertices.Write(new Vector2(0f, 1f));
            vertices.Write(new Vector3(-1f, 1f, 0.5f)); vertices.Write(new Vector2(0f, 0f));
            vertices.Write(new Vector3(1f, -1f, 0.5f)); vertices.Write(new Vector2(1f, 1f));
            vertices.Write(new Vector3(1f, 1f, 0.5f)); vertices.Write(new Vector2(1f, 0f));
            vertices.Position = 0;

            // create the vertex layout and buffer
            var elements = new[] {
            new InputElement("POSITION", 0, Format.R32G32B32_Float, 0),
            new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0)
            };
            layout = new InputLayout(device, inputSignature, elements);
            vertexBuffer = new SlimDX.Direct3D11.Buffer(device, vertices, 20 * 4, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);

            List<int> indices = new List<int>();
            indices.Add(0);
            indices.Add(1);
            indices.Add(2);
            indices.Add(2);
            indices.Add(1);
            indices.Add(3);
            var ibd = new BufferDescription(sizeof(int) * indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            indexBuffer = new SlimDX.Direct3D11.Buffer(device, new DataStream(indices.ToArray(), false, false), ibd);

            // configure the Input Assembler portion of the pipeline with the vertex data
            context.InputAssembler.InputLayout = layout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 20, 0));
            context.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0);

            // set the shaders
            context.VertexShader.Set(vertexShader);
            context.PixelShader.Set(pixelShader);

            SamplerDescription sampleDesc = new SamplerDescription();
            sampleDesc.Filter = Filter.MinMagMipPoint;
            sampleDesc.AddressU = TextureAddressMode.Clamp;
            sampleDesc.AddressV = TextureAddressMode.Clamp;
            sampleDesc.AddressW = TextureAddressMode.Clamp;
            sampleDesc.MipLodBias = 0.0f;
            sampleDesc.ComparisonFunction = Comparison.Always;
            sampleDesc.BorderColor = new Color4(0, 0, 0, 0);
            sampleDesc.MinimumLod = 0;
            sampleDesc.MaximumLod = 1;

            sampleState = SamplerState.FromDescription(device, sampleDesc);

            SamplerDescription indSampleDesc = new SamplerDescription();
            sampleDesc.Filter = Filter.MinMagMipPoint;
            sampleDesc.AddressU = TextureAddressMode.Wrap;
            sampleDesc.AddressV = TextureAddressMode.Wrap;
            sampleDesc.AddressW = TextureAddressMode.Wrap;
            sampleDesc.MipLodBias = 0.0f;
            sampleDesc.ComparisonFunction = Comparison.Always;
            sampleDesc.BorderColor = new Color4(0, 0, 0, 0);
            sampleDesc.MinimumLod = 0;
            sampleDesc.MaximumLod = 1;

            indSampleState = SamplerState.FromDescription(device, sampleDesc);

            ImageLoadInformation loadInfo = new ImageLoadInformation() { Width = 2, Height = 2 };
            loadInfo.BindFlags = BindFlags.ShaderResource;
            loadInfo.CpuAccessFlags = CpuAccessFlags.None;
            loadInfo.Depth = 4;
            loadInfo.FilterFlags = FilterFlags.Point;
            loadInfo.FirstMipLevel = 0;
            loadInfo.Format = Format.R8G8B8A8_SInt;
            loadInfo.MipLevels = 0;
            loadInfo.Usage = ResourceUsage.Default;
            texture = new Texture2D(device, new Texture2DDescription
            {
                BindFlags = BindFlags.ShaderResource,
                ArraySize = 1024,
                Width = 128,
                Height = 128,
                Usage = ResourceUsage.Default,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R8G8B8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None
            });//Texture2D.FromFile(device,"Tourism_Industrial_d.png");
            resourceView = new ShaderResourceView(device, texture);
            device.ImmediateContext.PixelShader.SetShaderResource(resourceView, 0);
            context.PixelShader.SetShaderResource(resourceView, 0);
            context.PixelShader.SetSampler(sampleState, 0);
            context.PixelShader.SetSampler(indSampleState, 1);
            if (currentEntry != null) SetTexture(currentEntry);
        }