Using Threejs (67) with a Webgl renderer, I can't seem to get a plane with a shader material to wear its texture. No matter what I do the material would just stay black.
My code at the moment looks quite basic :
var grassT = new Three.Texture(grass); // grass is an already loaded image.
grassT.wrapS = grassT.wrapT = Three.ClampToEdgeWrapping;
grassT.flipY = false;
grassT.minFilter = Three.NearestFilter;
grassT.magFilter = Three.NearestFilter;
grassT.needsUpdate = true;
var terrainUniforms = {
grassTexture : { type: "t", value: grassT},
}
Then I just have this revelant part in the vertexShader :
vUv = uv;
And on the fragmentShader side :
gl_FragColor = texture2D(grassTexture, vUv);
This results in :
- Black material.
- No error in console.
- gl_FragColor value is always (0.0, 0.0, 0.0, 1.0).
What I tryed / checked:
- Everything works fine if I just apply custom plain colors.
- All is ok if I use vertexColors with plain colors too.
- My texture width / height is indeed a power of 2.
- The image is on the same server than the code.
- Tested others images with same result.
- The image is actually loading in the browser debugger.
- UVS for the mesh are corrects.
- Played around with wrapT, wrapS, minFilter, magFilter
- Adapted the mesh size so the texture has a 1:1 ratio.
- Preloaded the image with requirejs image plugin and created the texture from THREE.Texture() instead of using THREE.ImageUtils();
- Played around with needsUpdate : true;
- Tryed to add defines['USE_MAP'] during material instanciation.
- Tryed to add material.dynamic = true.
- I have a correct rendering loop (interraction with terrain is working).
What I still wonder :
- It's a multiplayer game using a custom port with express + socket.io. Am I hit by any Webgl security policy ?
- I have no lights logic at the moment, is that a problem ?
- Maybe the shader material needs other "defines" at instanciation ?
I guess I'm overlooking something simpler, this is why I'm asking... Thanks.