片段着色器:着色器中没有名称统一的着色器 [英] Fragment shader: No uniform with name in shader
问题描述
我在libgdx中的片段着色器有问题.下面是我的片段着色器.
I have problem with fragment shader in libgdx. Below is my fragment shader.
#ifdef GL_ES
precision mediump float;
#endif
uniform float u_aspectRatio;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main()
{
gl_FragColor = texture2D(u_texture, v_texCoords);
}
我在程序中完成
shader.setUniformi("u_texture", 0); // work fine
shader.setUniformf("u_aspectRatio", 0.0f); //no uniform with name 'u_aspectRatio' in shader
shader.isCompiled()返回true,并且第一个设置工作正常,但是第二个错误是着色器中没有名称'u_aspectRatio'的统一制服".如果删除行:
shader.isCompiled() return true and first set work fine, but in second I have error "no uniform with name 'u_aspectRatio' in shader". If delete line:
uniform float u_aspectRatio;
从着色器都可以正常工作,但是当我添加此行时(在功能上我要使用此对象)并尝试设置一些我有错误的数据.
from shader all work fine, but when I add this line(in feature I want work with this object) and try set some data I have error.
推荐答案
着色器编译器将优化未使用的制服,因此在运行时不存在u_aspectRatio
制服.参见 http://ogltotd.blogspot.com/2007/12/active-shader-uniforms-and-vertex.html
The shader compiler will optimize away unused uniforms, so there is no u_aspectRatio
uniform at run-time. See http://ogltotd.blogspot.com/2007/12/active-shader-uniforms-and-vertex.html
修复"此着色器的另一种方法是在某个位置使用变量(例如,将v_texCoords
乘以该变量).
The other way to "fix" this shader would be to use the variable somewhere (e.g., multiply v_texCoords
by it).
这篇关于片段着色器:着色器中没有名称统一的着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!