Alpha splatting and unexpected behavior

Started by
3 comments, last by RobM 8 years, 5 months ago

My issue is explained in the attached images. I am attempting to texture splat by adjusting alpha values on seperate layers. The problem is when the alpha map runs through the shader multiple times, it affects previous alpha adjustments adversly. The shader is very simple and is as follows:


void psPPAlphaPaint(float2 iUV : TEXCOORD0,
                  out float4 color : COLOR0)

{
    color = tex2D(AlphaMap, iUV);    

    float2 distance = float2(0.0f, 0.0f);
    distance.x = uCoordinate - iUV.x;
    distance.y = vCoordinate - iUV.y;    

    float dist = sqrt(pow(uCoordinate - iUV.x, 2) + pow(vCoordinate - iUV.y, 2));
    if(dist < 0.05)
    {
        color.a = 1.0;
    }

}

Older alpha adjustments begin to blur and adust their position in the texture.

Any thoughts or clarifying questions?

Thank you

Edit: I am running the shader using a full screen quad to make adjustments to the alpha map as a render target

Advertisement

Older alpha adjustments begin to blur and adust their position in the texture.

Is this Direct3D9? Sounds like you're not accounting for D3D9's stupid half-pixel offset problem.

If you don't account for the fact that D3D9's pixel coordinate system is off by half a pixel, then all your tex2D(AlphaMap, iUV) calls will actually be using coordinates that are at the exact intersection of 4 source pixels, leading to 1px blurring and diagonal shifting.
See: Directly Mapping Texels to Pixels.

What Hodgman said, sounds like the most probable reason!

Also: I would do your shader like this:


void psPPAlphaPaint(float2 iUV : TEXCOORD0,
                  out float4 color : COLOR0)

{
    color = tex2D(AlphaMap, iUV);    

    float2 distance = float2(uCoordinate - iUV.x, vCoordinate - iUV.y);
//    float2 distance = float2(0.0f, 0.0f);
//    distance.x = uCoordinate - iUV.x;
//    distance.y = vCoordinate - iUV.y;    

    float dist = (distance.x * distance.x) + (distance.y * distance.y);
    if (dist < 0.0025)    // 0.05 * 0.05  =  0.0025
//    float dist = sqrt(pow(uCoordinate - iUV.x, 2) + pow(vCoordinate - iUV.y, 2));
//    if(dist < 0.05)
    {
        color.a = 1.0;
    }

}

.:vinterberg:.

Thank you so much for both of your input, that was indeed the problem.

Hendrix fan?

This topic is closed to new replies.

Advertisement