HLSL着色器中的不确定性工件

时间:2015-10-06 03:09:06

标签: directx hlsl directx-9

我有一个HLSL着色器(使用fxc和ps_2_b编译),它给我闪烁的文物。首先,我需要确定所有变量看起来都是常量,并使用以下着色器确定它们的值:

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;
}

以下是此着色器的输出:

Image

所以uvmin = {0,0}和uvmax = {640,360}。左上角像素uv是(0,0),右下角像素uv是(639,359)。这是一个再现我的问题的着色器:

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;
}

此着色器的输出会产生下面的输出,但白色部分会闪烁黑白:

Image

如果我将uvmin和uvmax的值作为常量插入,则不再出现问题。这是着色器:

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不允许我包含输出的链接,但它与初始图像相同,但是用黑色代替红色。

0 个答案:

没有答案