hlsl : 1 - 0.999 < 0?
So, I'm working on a shader right now, and I stumbled over a problem I
don't understand:
float4 GetColor(float t)
{
float4 col = tex2D(ctSampler, float2(t,0));
t+=decayRate;
if(maxAge <= 0)
t = min(0.999, t);
return float4(1-t, col.g, col.b, 1);
}
So if I'm correct, the r component of the return value CAN NEVER be less
or equal to 0, right?
So, I'm using this to never let drop the r component to 0.
In the pixel shader function I have this:
float t = 1-tex2D(s0, input.Position).r;
if(t < 1)
{
if(survival[n])
return GetColor(t);
}
else if(birth[n])
{
return float4(1,1,1,1);
}
return float4(0,0,0,0);
I apply the shader in an alternating fashion to draw from one texture to
another and back.
The XNA code looks like this:
g.GraphicsDevice.SetRenderTarget(target);
g.GraphicsDevice.Clear(Color.Transparent);
sb.Begin(SpriteSortMode.Immediate, BlendState.Opaque,
SamplerState.LinearWrap, null, null, pause ? null : e); //
sb.Draw(source, Vector2.Zero, Color.White);
sb.End();
[...]
var tmp = source;
source = target;
target = tmp;
g.GraphicsDevice.SetRenderTarget(null);
Weirdly, the screen will fade out, but loop back to white, meaning the
if(t < 1) statement returned false, which IMO should never happen.
So, what am I missing? I looked for the problem for hours, and I just
can't find it :/
No comments:
Post a Comment