欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

learnopengl——Shaders

程序员文章站 2022-07-04 11:06:59
...

https://learnopengl.com/Getting-started/Shaders

uniform
uniforms are another way to pass data from our application on the CPU to the shaders on the GPU.
uniforms are however slightly different compared to vertex attributes.
first of all, uniforms are global.
global, meaning that a uniform variable is unique per shader program object, and can be accessed from any shader at any stage in the shader program.
second, whatever u set the uniform value to, uniforms will keep their values until they are either reset or updated.

To declare a uniform in GLSL we simply add the uniform keyword to a shader with a type and a name. From that point on we can use the newly declared uniform in the shader. Let’s see if this time we can set the color of the triangle via a uniform:

#version 330 core
out vec4 FragColor;
  
uniform vec4 ourColor; // we set this variable in the OpenGL code.

void main()
{
    FragColor = ourColor;
}   
相关标签: learn opengl