I’m having a weird issue with a procedurally generated DataTexture. I don’t think it’s a bug, but can’t figure out what I’m doing wrong.
The procedure I’m following goes more or less like this. I create my texture of side N, with an array of size 4N^2. This is done by filling in an array and then passing it to a DataTexture:
var dTex = new THREE.DataTexture(data, N, N, THREE.RGBAFormat);
dTex.needsUpdate = true;
Here data
is a Uint8ClampedArray
. Then I pass this to my ShaderMaterial
as a uniform:
var mat =new THREE.ShaderMaterial({
transparent: true,
depthTest: true,
uniforms: THREE.UniformsUtils.merge([{
color: { type: 'v3', value: new THREE.Vector3(1, 0, 0) },
alpha: { type: 'f', value: 0.7 },
shift: { type: 'v2', value: [0., 0.] },
ditherN: { type: 'f', value: dN},
ditherTex: {type: 't', value: dTex}
}, THREE.UniformsLib.lights]),
vertexShader: vertShader,
fragmentShader: fShader,
lights: true,
});
while the fragment shader looks like this:
fShader = " \
uniform float alpha; \
uniform vec3 color; \
uniform vec2 shift; \
uniform float ditherN; \
uniform sampler2D ditherTex; \
varying vec3 vNormal; \
\
void main() \
{ \
gl_FragColor = texture2D(ditherTex, vec2(0.5,0.5));\
//gl_FragColor = vec4(1, 1, 0, 1); \
}";
(for now this is just a test but it already reproduces the problem).
Long story short, ditherTex
appears to be completely black and transparent, despite me being sure it’s been filled with finite values. If I pass it as an alphaMap
to a different material it works too. The fragment shader itself works if I uncomment the last line, so it’s not like it isn’t compiling or anything. Literally the only thing missing is the texture, which for some reason seems to not arrive properly. Any clues as to what I might have been doing wrong?