Hello all. I'm trying to do my first pixel shader, one to fade out a sprite. I've done the following:
So, my logic is that my shader should get the R, G and B components of each pixel during rendering, subtract FadeValue from each, if it winds up less than 0 then set it to 0, and then return a pixel based on those RGB values.
What I'm getting is not that... It looks more like a flashing than a fade. Anyone spot my problem? Thanks!
- Code:
// These are globals:
int FadeValue = 0;
struct FadeShader : public PixelShader {
Pixel operator() (Pixel src, Pixel dest) const {
int colR = src & RED_MASK;
int colG = src & GREEN_MASK;
int colB = src & BLUE_MASK;
colR = colR - FadeValue;
colG = colG - FadeValue;
colB = colB - FadeValue;
if (colR < 0) { colR = 0; }
if (colG < 0) { colG = 0; }
if (colB < 0) { colB = 0; }
return (Pixel(RGB(colR, colG, colB)));
}
};
FadeShader fadeShader;
// Then in GameInit():
DisplayDevice* display = GetDisplay();
display->SetPixelShader(&fadeShader;);
// Then in GameLoop():
display->Blit(10, 10, myImage);
if (FadeValue < 255) {
FadeValue++;
}
So, my logic is that my shader should get the R, G and B components of each pixel during rendering, subtract FadeValue from each, if it winds up less than 0 then set it to 0, and then return a pixel based on those RGB values.
What I'm getting is not that... It looks more like a flashing than a fade. Anyone spot my problem? Thanks!