Hey, time for my monthly ramblings of the problems I’ve encountered.
First off, I’ve been having difficulty with my fade shader. The issue is that I use a restricted colour palette of 16 colours. I recently added a few transparent blue as well for water. To fade in and out, I want to keep the screen locked to these colours. I have a shader which essentially takes a colour and looks it up on a texture by its green value on the Y axis, then by its ‘brightness’ on the X axis. The shader is this:
sampler inputTexture;
float fadeVal;
sampler palette;
float4 MainPS(float2 textureCoordinates: TEXCOORD0): COLOR0
{
float4 color = tex2D(inputTexture, textureCoordinates);
float4 returnColor = tex2D(palette, float2(1-fadeVal, color.g));
return float4(returnColor.r, returnColor.g, returnColor.b, color.a);
};
technique Techninque1
{
pass Pass1
{
PixelShader = compile ps_3_0 MainPS();
AlphaBlendEnable = TRUE;
DestBlend = INVSRCALPHA;
SrcBlend = SRCALPHA;
}
};
This has worked fine but now with the transparent colours, the amount of colours that could be created means that colours are colliding a lot and I feel like this system is doomed to fail with these new colours. Any ideas, perhaps a different algorithm or a better way to do this one?
My other issue is how to manage water distortions with shaders, but not with how to get the distortions, rather how to select just the area with the water. I would have normally done this with a render target, but I’m not sure how to do this in this scenario. I would need to draw everything behind the water to the render target along with the water, but I’m already drawing a lot to different render targets, and I would need to draw the water on a separate layer to everything else, which is undesirable. Essentially, I’m just wondering the best way to easily apply a shader to a specific area of the screen that also needs to take into account the backgrounds.
Thanks for any responses, you can just reply to one query without addressing the other if you would like.