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


C# ShaderProgram.SetUniform方法代码示例

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


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

示例1: ApplyState

		/// <summary>
		/// Set LineState state.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> which has defined the shader program <paramref name="shaderProgram"/>.
		/// </param>
		/// <param name="shaderProgram">
		/// The <see cref="ShaderProgram"/> which has the state set.
		/// </param>
		public override void ApplyState(GraphicsContext ctx, ShaderProgram shaderProgram)
		{
			if (ctx == null)
				throw new ArgumentNullException("ctx");

			Debug.Assert(Width >= 0.0f);
			Debug.Assert(!String.IsNullOrEmpty(UniformName));

			// Set the line width
			if ((ctx.IsCompatibleProfile == true) || (shaderProgram == null) || (_Width <= 1.0)) {
				float[] validRange = ctx.Caps.Limits.AliasedLineWidthRange;
				float actualWidth = Math.Max(validRange[0], Math.Min(_Width, validRange[1]));

				// LineWidth shall be called in the case drawing in immediate mode, or when no shader program
				// is bound or when the line width is less than 1.0f
				Gl.LineWidth(actualWidth);

			} else if ((shaderProgram != null) && (shaderProgram.IsActiveUniform(UniformName) == true)) {

				// Note that the width is not clamped in the higher boundary.

				// In forward compatibility profiles, it is not possible to draw lines with a width greater than 1.0f; this
				// mean that 'shaderProgram' possibly setup a geometry shader that takes the responsability of drawing a
				// line with a width greater than 1.0f
				shaderProgram.SetUniform(ctx, UniformName, _Width);
			}
		}
开发者ID:rhynodegreat,项目名称:OpenGL.Net,代码行数:36,代码来源:LineState.cs

示例2: ApplyState

		/// <summary>
		/// Apply this state to a shader program.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> used to share common state between shaders.
		/// </param>
		/// <param name="shaderProgram">
		/// A <see cref="ShaderProgram"/> that specify this uniform state.
		/// </param>
		/// <param name="uniformScope">
		/// A <see cref="String"/> that specify the scope the uniform variable.
		/// </param>
		private void ApplyState(GraphicsContext ctx, ShaderProgram shaderProgram, string uniformScope)
		{
			CheckCurrentContext(ctx);

			if (shaderProgram == null)
				throw new ArgumentNullException("shaderProgram");

			Dictionary<string, UniformStateMember> uniformState = UniformState;

			foreach (string uniformName in shaderProgram.ActiveUniforms) {
				UniformStateMember uniformStateMember;

				// Get the underlying member
				if (uniformState.TryGetValue(uniformName, out uniformStateMember) == false)
					continue;

				// Set the program uniform
				shaderProgram.SetUniform(ctx, uniformName, uniformStateMember.GetUniformValue(this));
			}
		}
开发者ID:rhynodegreat,项目名称:OpenGL.Net,代码行数:32,代码来源:ShaderUniformState.cs

示例3: SetupShaderProgram

        private void SetupShaderProgram(ref Matrix4 projection, ShaderProgram program)
        {
            IGraphicsContext context = program.GraphicsContext;
            context.UseShaderProgram(program);

            program.SetUniform(PROJ_MAT, ref projection);
            program.SetUniform(FORCES, ref this.settings.Forces);

            program.SetUniform(START_COLOR, settings.StartColor);
            program.SetUniform(END_COLOR, settings.EndColor);
            program.SetUniform(START_SIZE, settings.StartSize);
            program.SetUniform(END_SIZE, settings.EndSize);
            program.SetUniform(START_ANGULAR_VELOCITY, settings.StartAngularVelocity);
            program.SetUniform(END_ANGULAR_VELOCITY, settings.EndAngularVelocity);
            program.SetUniform(COLOR_VARIANCE, settings.ColorVariance);
            program.SetUniform(SIZE_VARIANCE, settings.SizeVariance);

            Vector3 g = new Vector3(500,500, -0);
            program.SetUniform("gravity_well_1", ref g);
            g = new Vector3(1550, 500, 0);
            program.SetUniform("gravity_well_2", ref g);

            program.SetUniform(START_ALPHA, 1.5f);
            program.SetUniform(END_ALPHA, 0f);

            program.SetUniform(LIFE_TIME, settings.LifeTime);
            program.SetUniform(CURRENT_TIME, this.currentTime);

            program.SetUniform(TEXTURE, 0);

            GL.BindVertexArray(this.vba);

            int posIndex = program.GetAttributeLocation(IN_POS);
            int veloIndex = program.GetAttributeLocation(IN_VEL);
            int randomIndex = program.GetAttributeLocation(IN_RANDOM);
            int offsetIndex = program.GetAttributeLocation(IN_OFFSET);
            int coordIndex = program.GetAttributeLocation(IN_COORDS);
            int timeIndex = program.GetAttributeLocation(IN_TIME);

            context.BindVertexBuffer(this.vertexBuffer);

            context.EnableVertexAttribArray(posIndex);
            context.EnableVertexAttribArray(veloIndex);
            context.EnableVertexAttribArray(randomIndex);
            context.EnableVertexAttribArray(offsetIndex);
            context.EnableVertexAttribArray(coordIndex);
            context.EnableVertexAttribArray(timeIndex);

            context.VertexAttribPointer(posIndex, 2, VertexAttribPointerType.Float,
                                             false, this.queue[0].SizeInBytes, 0);

            context.VertexAttribPointer(veloIndex, 2, VertexAttribPointerType.Float,
                                             false, this.queue[0].SizeInBytes, Vector2.SizeInBytes);

            context.VertexAttribPointer(randomIndex, 2, VertexAttribPointerType.Float,
                                            false, this.queue[0].SizeInBytes, Vector2.SizeInBytes * 2);

            context.VertexAttribPointer(offsetIndex, 2, VertexAttribPointerType.Float,
                                            false, this.queue[0].SizeInBytes, Vector2.SizeInBytes * 3);

            context.VertexAttribPointer(coordIndex, 2, VertexAttribPointerType.Float,
                                false, this.queue[0].SizeInBytes, Vector2.SizeInBytes * 4);

            context.VertexAttribPointer(timeIndex, 1, VertexAttribPointerType.Float,
                                             false, this.queue[0].SizeInBytes, Vector2.SizeInBytes * 5);

            GL.BindVertexArray(0);
        }
开发者ID:TheFlyingFiddle,项目名称:Project-Monocle,代码行数:68,代码来源:ParticleSystem.cs


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