当前位置: 首页>>代码示例>>C#>>正文


C# Shader.SetConstantBuffer方法代码示例

本文整理汇总了C#中Shader.SetConstantBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Shader.SetConstantBuffer方法的具体用法?C# Shader.SetConstantBuffer怎么用?C# Shader.SetConstantBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shader的用法示例。


在下文中一共展示了Shader.SetConstantBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanExecuteVertexShader

		public void CanExecuteVertexShader()
		{
			// Arrange.
            var shader = new Shader(ShaderTestUtility.CompileShader(
                "Shaders/VS/BasicHLSL.fx", "RenderSceneVS", "vs_4_0"));
		    shader.SetConstantBuffer("$Globals", new BasicHlsl.VertexConstantBufferGlobals
		    {
                World = Matrix.Identity,
		        WorldViewProjection =
                    Matrix.LookAtRH(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY) *
                    Matrix.PerspectiveFovRH(MathUtil.PiOverFour, 1, 1, 10),
		        LightDir = Vector3.Normalize(new Vector3(0.3f, 0.5f, 0.7f)),
                LightDiffuse = Vector4.One,
                LightAmbient = new Vector4(0.1f, 0.1f, 0.1f, 1.0f),
                MaterialDiffuseColor = new Vector4(0.8f, 0.5f, 0.3f, 1.0f),
                MaterialAmbientColor = new Vector4(0.2f, 0.1f, 0.15f, 1.0f)
		    });
            shader.SetConstantBuffer("$Params", new BasicHlsl.VertexConstantBufferParams
            {
                NumLights = 3,
                Texture = true
            });
			var vertexInput = new BasicHlsl.VertexShaderInput
			{
				Position = new Vector4(3, 0, 2, 1),
				Normal = new Vector3(0, 1, 0),
				TextureCoordinate = new Vector2(0, 1)
			};

			// Act.
			var output = shader.Execute<BasicHlsl.VertexShaderInput, BasicHlsl.VertexShaderOutput>(vertexInput);

			// Assert.
            Assert.That(output, Is.EqualTo(new BasicHlsl.VertexShaderOutput
            {
                Position = new Vector4(7.24264f, 0, -3.222222f, 1),
                Diffuse = new Vector4(1.337171f, 0.833232f, 0.5089392f, 1),
                TextureUV = new Vector2(0, 1)
            }));
		}
开发者ID:modulexcite,项目名称:slimshader,代码行数:40,代码来源:ShaderTests.cs

示例2: CanExecutePixelShader

        public void CanExecutePixelShader()
        {
            // Arrange.
            var shader = new Shader(ShaderTestUtility.CompileShader(
                "Shaders/VS/BasicHLSL.fx", "RenderScenePS", "ps_4_0",
                ShaderFlags.EnableBackwardsCompatibility));
            shader.SetConstantBuffer("$Params", new BasicHlsl.PixelConstantBufferParams
            {
                Texture = true
            });
            shader.SetResource("MeshTextureSampler", (u, v, w, i) => new Vector4(0.5f, 1.0f, 0.0f, 1.0f));
            var vertexOutput = new BasicHlsl.VertexShaderOutput
            {
                Position = new Vector4(0, 1, 2, 1),
                Diffuse = new Vector4(0.8f, 0.7f, 0.6f, 1.0f),
                TextureUV = new Vector2(0.5f, 0.3f)
            };

            // Act.
            var output = shader.Execute<BasicHlsl.VertexShaderOutput, Vector4>(vertexOutput);

            // Assert.
            Assert.That(output, Is.EqualTo(new Vector4(0.4f, 0.7f, 0.0f, 1.0f)));
        }
开发者ID:modulexcite,项目名称:slimshader,代码行数:24,代码来源:ShaderTests.cs


注:本文中的Shader.SetConstantBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。