- Home /
How do I add up Color Values of Textures with Different Resolutions?
How do I add up the black and white color values of textures with different resolutions?
Example:
+ =
NOTE: these textures are their apparent resolutions; I have just resized them for visualization.
We will need to find the color array of the first image, and somehow "add" it to the color array of the second image, and so on until complete. Then, store the final color values array.
The resolution of the highest resolution image will always be the resolution of the final product image, of course.
Does anyone know exactly how to do this?
Thanks.
I think what you're actually doing here is 'subtracting', but that's beside the point.
Well, it's subtraction because white is (1, 1, 1) and black is (0, 0, 0). If you were doing addition, the last square would be entirely white, except for those few places where there are a black part on a grey part (which would be grey).
No wait, that's wrong. I'm not quite sure what operation is going on there! It's not addition, not subtraction, not even multiplication or division! I think what's going on there is
image2 = image0 < image1
image 2 takes the darkest parts of each input image.
Answer by syclamoth · Jan 08, 2012 at 07:06 AM
Just out of interest, why are you doing this? In any case, I'd assume that the correct method would be to scale up the smaller images and then just add the images in whatever way you choose (shader, manual addition on every element of the color array, etc.).
To resample the texture, you could create a new texture, and then use
newTexture.SetPixel(x, y, oldTexture.GetPixel(x / 2, y / 2));
for each pixel in the new texture. I'm pretty sure this would be quite slow.
Another option would be to use a shader for this. Is there any reason why you can't just use a subtractive shader that takes several texture inputs?
Basically, just use a shader. It's the graphics card's job to do this kind of work, so you may as well use it!
I am using this to add up multiple octaves for a perlin noise function.
EDIT: Oh, I see what you mean there ;)
I will be dealing relatively small resolutions (
As for using a shader, I may look into that. I am not very knowledgeable with shaders yet, however.
Nobody is very knowledgeable about shaders. (or at least, if someone is, they keep their knowledge to themselves!) If you learn them, they'll be very useful to you.
The reason I recommend using a shader is because as far as I know, shaders can automatically resample input textures.
Your answer
Follow this Question
Related Questions
Null Reference Exception After refering to an Array 1 Answer
Exception: not implemented? 2 Answers
Creating Perlin Noise 2 Answers
Why does Perlin-generated Texture lose gradient when with colour? 1 Answer
Link image sequence to an array 2 Answers