Question

Here is the code I use for my add blend method:

public int add(int a, int b) {
    return min(a + b, 255);
}

public int min(int a, int b) {
    return (a < b) ? a : b;
}

Now if I loop through my two pixel arrays like this:

for (int i = 0; i < Game.WIDTH * Game.HEIGHT; i++) {
    Game.pixels[i] = add(Game.pixels[i], lighting.pixels[i]);
}

The result is supposed to look like this (reproduced on paint.NET):

enter image description here

Instead, it looks like this:

enter image description here

My question is: Why are there oval shaped artefacts where the colours blend and how can I fix this? Additionally, I cannot replicate multiply blend mode either, potentially for the same reason...

Was it helpful?

Solution

Actually, adding two integers straight from an array is not how to do it. Instead you need to split the number up in to it's separate RGB, and then add them up individually, then compile them back into a single number.

(Yeah I found out how to in the end. Just in case someone has similar problem)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top