I have a HLSL shader (compiled using fxc and ps_2_b) that is giving me flickering artifacts. First I need to establish that all the variables seem to be constant, and their values with the following shader:
float4 src_rect : register(c0);
float4 main(float2 uv : TEXCOORD) : COLOR {
float2 uvmin = {src_rect.x, src_rect.z};
float2 uvmax = {src_rect.y, src_rect.w};
float2 uv1 = (uv - uvmin)/(uvmax - uvmin);
float4 c = 1;
c.rgb = 0;
if (uv.x == 639)
c.rg = 1;
else if (uv.y == 359)
c.g = 1;
else if (uv.y == 0)
c.b = 1;
else if (uv.x == 0)
c.gb = 1;
else {
if ((uvmin.x == 0) && (uvmin.y == 0)
&& (uvmax.x == 640) && (uvmax.y == 360))
c.rgb = float3(1, 0, 0);
}
return c;
}
Here is the output of this shader:
So uvmin = {0, 0} and uvmax = {640, 360}. The top-left pixel uv is (0, 0) and the bottom-right pixel uv is (639, 359). Here's a shader reproducing my issue:
float4 src_rect : register(c0);
float4 main(float2 uv : TEXCOORD) : COLOR {
float2 uvmin = {src_rect.x, src_rect.z};
float2 uvmax = {src_rect.y, src_rect.w};
float2 uv1 = (uv - uvmin)/(uvmax - uvmin);
float4 c = 1;
c.rgb = 0;
if (uv.x == 639)
c.rg = 1;
else if (uv.y == 359)
c.g = 1;
else if (uv.y == 0)
c.b = 1;
else if (uv.x == 0)
c.gb = 1;
else {
c.rgb = frac(floor(uv1.x*1.001)*9.999);
}
return c;
}
The output of this shader produces the output below, but with the white parts flickering black and white:
If I plug the values for uvmin and uvmax in as constants, the problem no longer occurs. Here is the shader:
float4 src_rect : register(c0);
float4 main(float2 uv : TEXCOORD) : COLOR {
float2 uvmin = {0, 0};
float2 uvmax = {640, 360};
float2 uv1 = (uv - uvmin)/(uvmax - uvmin);
float4 c = 1;
c.rgb = 0;
if (uv.x == 639)
c.rg = 1;
else if (uv.y == 359)
c.g = 1;
else if (uv.y == 0)
c.b = 1;
else if (uv.x == 0)
c.gb = 1;
else {
c.rgb = frac(floor(uv1.x*1.001)*9.999);
}
return c;
}
StackOVerflow won't let me include a link to the output, but it is the same as the initial image but with black instead of red.