Is it possible to change some pixels colors of a texture before this is being added to the scene?
const texture = new THREE.TextureLoader().load('./tiles.png')
// Making some pixel mutations here...
const material = new THREE.SpriteMaterial({
map: texture
})
// ...or here...
scene.add(new THREE.Sprite(material))
I don’t know. I guess it consumes more memory, at least. @prisoner849’s suggestion of using a shader (modification) may apply, depending on what kind of modifications are needed. If it is some kind of transform that is applied to all pixels, a shader is probably suitable. We would need to know more about the context.
Imagine a spritesheet that have some pixels in blue color, the blue represent the team. I want to change this blue programatically to red to use the same spritesheet.
Would it be an option to swap R and B channels completely in the fragment shader?
But seriously, it is possible to replace pure colors in the shader. But what if you have antialiasing gradients between the pure colors? Hm.
Is “segmentation textures” a thing? Where you have one texture that defines by integers which “tissue” (skin, hair, clothes, armor etc.) each pixel represents, and supply a color pallette array that the texture indexes into? (Still only for pure colors, though.)
Pass a texture in a uniform, then via UV coordinates you’ll get a texel and then change/swap r and b channels, if it’s in a condition. That’s what Elias provided.
Or I can’t get the problem
Shader - Shadertoy BETA just an example with swapping (you need to uncomment the line for effect)