我正在尝试在片段Shader中初始化usampler2D
uniform vec3 lightColor;
uniform usampler2D texSampler;///////////
uniform vec3 ambientLight;
uniform vec3 lightPosition;
uniform vec3 cameraPosition;
in Vertex{
vec4 rawPosition;
vec2 uv;
vec4 normal;
}vertexIn;
in InstanceData{
unsigned int textureUnitIndex;
}instance;
out vec4 color;
void main(){
vec3 normal = normalize(vec3(vertexIn.normal.x, vertexIn.normal.y, vertexIn.normal.z));
vec3 worldPosition = vec3(vertexIn.rawPosition.x, vertexIn.rawPosition.y, vertexIn.rawPosition.z);
vec3 lightVector = normalize(lightPosition - worldPosition);
vec3 cameraVector = normalize(cameraPosition - worldPosition);
vec3 halfVec = normalize(lightVector + cameraVector);
float lightAngle = clamp(dot(lightVector, normal), 0.0f, 1.0f);
float specAngle = clamp(dot(halfVec, normal), 0.0f, PI);
float specular = clamp(pow(specAngle, 128), 0.0f, 1.0f);
unsigned int index = instance.textureUnitIndex;
vec4 actColor = texture2D(texSampler, vec2(vertexIn.uv)); //////////////////////
vec4 diffuseLight = sqrt(actColor * vec4(lightColor, 1.0)) * lightAngle;
vec4 specularLight = 1.0f - (cos(vec4(lightColor, 1.0f) * specular));
color = actColor * (vec4(ambientLight, 1.0) + diffuseLight) + specularLight;// + vec4(ambientLight, 1.0f);
}
喜欢这个
void ShaderProgram::addUniform(std::string uniformName, unsigned int uniformValue)
{
unsigned int loc = glGetUniformLocation(_programID, uniformName.c_str());
Graphic::checkOpenGLErrors("addUniform() - 1");
glUniform1ui(loc, (GLuint)uniformValue);
Graphic::checkOpenGLErrors("addUniform - 2");
}
loc结果为6且uniformValue等于2,但checkOpenGLErrors()仍然抛出
"OpenGL ERROR: GL_INVALID_OPERATION - At: addUniform - 2"
有关初始化采样器制服需要了解的内容吗?因为此函数通常不会在此GLSL程序中抛出错误
由于