Lua*_*ico 4 opengl shader textures colors lwjgl
所以,我需要制作一个着色器,用给定的颜色替换纹理中的灰色.如果我将颜色设置为给定的特定颜色,片段着色器可以正常工作
gl_FragColor = vec4(1, 1, 0, 1);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试检索纹理的原始颜色时,我收到错误.由于某种原因,它总是返回黑色.
uniform sampler2D texture; //texture to change
void main() {
vec2 coords = gl_TexCoord[0].xy;
vec3 normalColor = texture2D(texture, coords).rgb; //original color
gl_FragColor = vec4(normalColor.r, normalColor.g, normalColor.b, 1);
}
Run Code Online (Sandbox Code Playgroud)
从理论上讲,它应该什么也不做 - 纹理应该保持不变.但它完全变黑了.我认为问题在于我不确定如何将纹理作为参数传递给统一变量.我目前正在使用ID(整数),但似乎总是返回黑色.所以我基本上不知道如何设置均匀纹理的值(或者以任何其他方式获取它,而不使用参数).代码(用Java):
program.setUniform("texture", t.getTextureID());
Run Code Online (Sandbox Code Playgroud)
我正在使用我从这里获得的Program类,以及SlickUtils Texture类,但我相信这是无关紧要的.
program.setUniform("texture", t.getTextureID());
^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
不,不,不.
纹理对象ID 永远不会穿制服.
传入要从中采样的纹理单元的索引.
所以如果你想从n纹理unit(GL_TEXTURE0 + n)传入样本n:
program.setUniform("texture", 0);
^ or whatever texture unit you've bound `t` to
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2812 次 |
| 最近记录: |