Hi, I'm new to shader programming and I'm trying to make simple pixel shader that fades between two textures.
I have a variable that gets increases every frame, I normalise it, then I set the texture using lerp (code below)
float4 TextureOne = TexOne.Sample(TexSampler, input.uv);
float4 TextureTwo = TexTwo.Sample(TexSampler, input.uv);
float n = normalize(transition);
float3 TextureDiffuse = lerp(TextureOne.rgb, TextureTwo.rgb, n);
float TextureSpecular = lerp(TextureOne.a, TextureTwo.a, n);
This doesn't have any impact and the texture is set to the second texture.
The other way I have tried is to do if statements
float4 TextureOne = TexOne.Sample(TexSampler, input.uv);
float4 TextureTwo = TexTwo.Sample(TexSampler, input.uv);
float n = normalize(transition);
float3 TextureDiffuse;
float TextureSpecular;
if (n == 0)
{
TextureDiffuse = TextureOne.rgb;
TextureSpecular = TextureOne.a;
}
if (n == 1)
{
TextureDiffuse = TextureTwo.rgb;
TextureSpecular = TextureTwo.a;
}
if (n > 0 && n < 1)
{
TextureDiffuse = lerp(TextureOne.rgb, TextureTwo.rgb, t);
TextureSpecular = lerp(TextureOne.a, TextureTwo.a, t);
}
The first two if statements on their own without the final if statement flickers between the two textures as expected but then adding the final if statement it flickers not as often as before but the texture one becomes black.
The final value that gets outputed is calculated with light otherwise there is no texture
float3 finalTexture = diffuseLight * TextureDiffuse + specularLight * TextureSpecular ;
return float4(finalTexture , 1.0f);
How can I get this to work? What am I missing?
Thank you