Question

This is my first time working with HLSL, I'm trying to create an image transition like a circle wipe. To do this I want only the pixels within a certain radius to be visible, this is what I have so far...

float4 PixelShaderFunction(float2 inCoord: TEXCOORD0) : COLOR
{
    float4 color = tex2D(screen, inCoord);

    if (incoord 
    {
        color.rgba = color.rgba - 255
    }

    return color;
}

What I'm going for with that if statement in plain english is...

if incoor.X - center.X < 5 or > -5 and incoor.Y - center.Y < 5 or > -5

I might be going about this completely the wrong way so please just tell me how much of an idiot i'm being. Any help would be super appreciated, and i'll put you in the special thanks in my game credits!

P.S. I'm using XNA 4 and C#

Was it helpful?

Solution

In HLSL, all channel values are manipulated as float4s, meaning each channel is a float. Maximum value is not 255, but rather 1.0f.

The center of the texture will always be float2 center = float2(0.5f, 0.5f); as again all positions are based not on pixel nor texel, but normalized float position (with 0,0 being top-left and 1,1 being bottom right). Your pixel shader has no concept of the pixel dimentions of your texture unless you specifically set them in a SetParameter call to the effect, before you apply it.

From that information, it should be just a trivial matter of setting your desired theta (angle) and doing some simple trig in the shader to get distance from center, etc..

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top