我想有準備着色器組件(用於多采樣特)WebGL的着色檢查紋理狀態sampler2D
在我使用(激活和綁定)僅2紋理圖像我的當前狀態。
,但此行:
gl_FragColor = textureColor + textureColor1 + textureColor2;
製造麻煩與我的紋理視圖的紋理我從沒有結合的樣品textureColor2。
在着色器中無法使用console.log或任何其他標準調試方法。我有興趣瞭解有關着色器的更多信息,但我被卡住了。
代碼:
...
precision mediump float;
varying vec2 vTextureCoord;
varying vec3 vLightWeighting;
uniform sampler2D uSampler;
uniform sampler2D uSampler1;
uniform sampler2D uSampler2;
uniform sampler2D uSampler3;
uniform sampler2D uSampler4;
uniform sampler2D uSampler5;
uniform sampler2D uSampler6;
uniform sampler2D uSampler7;
uniform sampler2D uSampler8;
uniform sampler2D uSampler9;
uniform sampler2D uSampler10;
uniform sampler2D uSampler11;
uniform sampler2D uSampler12;
uniform sampler2D uSampler13;
void main(void) {
vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
vec4 textureColor1 = texture2D(uSampler1, vec2(vTextureCoord.s, vTextureCoord.t));
vec4 textureColor2 = texture2D(uSampler2, vec2(vTextureCoord.s, vTextureCoord.t));
// Need help here
gl_FragColor = textureColor + textureColor1 ;
//gl_FragColor = textureColor + textureColor1 + textureColor2;
//修訂問題
if ( ${numTextures} == 1)
{
gl_FragColor = textureColor;
}
else if (${numTextures} == 2)
{
gl_FragColor = textureColor + textureColor1;
}
else if (${numTextures} == 3)
{
gl_FragColor = textureColor + textureColor1 + textureColor2;
}
//我用簡單實用的if else現在。
//我通過值到着色器上負載
// i的運行時仍然無法更新着色
////////////////// /////////////////////
//這是繪製函數段:
for (var t=0;t<object.textures.length;t++) {
eval(" world.GL.gl.activeTexture(world.GL.gl.TEXTURE"+t+"); ")
world.GL.gl.bindTexture(world.GL.gl.TEXTURE_2D, object.textures[t]);
world.GL.gl.pixelStorei(world.GL.gl.UNPACK_FLIP_Y_WEBGL, false);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MAG_FILTER, world.GL.gl.NEAREST);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MIN_FILTER, world.GL.gl.NEAREST);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_S, world.GL.gl.CLAMP_TO_EDGE);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_T, world.GL.gl.CLAMP_TO_EDGE);
// -- Allocate storage for the texture
//world.GL.gl.texStorage2D(world.GL.gl.TEXTURE_2D, 1, world.GL.gl.RGB8, 512, 512);
//world.GL.gl.texSubImage2D(world.GL.gl.TEXTURE_2D, 0, 0, 0, world.GL.gl.RGB, world.GL.gl.UNSIGNED_BYTE, image);
//world.GL.gl.generateMipmap(world.GL.gl.TEXTURE_2D);
world.GL.gl.uniform1i(object.shaderProgram.samplerUniform, t);
}
...
也許在運行最好的方法是用object.textures數組操作?!
最後:
- 用新標誌覆蓋着色器
- 編譯着色器 新材料更新
你可能想要混合你的顏色,而不是總結它們。我有許多着色器示例[這裏](http://blog.2pha.com/experimenting-threejs-shaders-and-shadermaterial),還有一些在我的jsfiddle [HERE](https://jsfiddle.net/user/2pha /撥弄/)。請注意,這些示例適用於舊版本的three.js,並且照明信息發送到着色器的方式已更改。 – 2pha
謝謝你,很好的例子,我會探討這個肯定... –