Pregunta

I would like to render a circle on to a triangle pair using a pixel shader written in HLSL. There is some pseudocode for this here, but I am running in to one problem after another while implementing it. This will be running on Windows RT, so I am limited to the DirectX 9.3 members of the Direct3D v11 API.

What is the general shape of the shader? For example, what parameters should be passed to the main method?

Any advice or working code would be greatly appreciated!

¿Fue útil?

Solución

You should use the texture coordinates as inputs to render the parametric circle.

Here is a question that I asked about anti-aliasing a circle rendered in HLSL. Here is the code from that question with a minor change to make use of TEXCOORD0 more clear:

float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
{
    float dist = texCoord.x * texCoord.x
               + texCoord.y * texCoord.y;
    if(dist < 1)
        return float4(0, 0, 0, 1);
    else
        return float4(1, 1, 1, 1);
}

It uses the formula for a circle which is r² = x² + y². It uses the constant 1 for the radius-squared (ie: a circle of radius 1, as measured in texture coordinates). All points inside the circle are coloured black, and those outside, white.

To use it, provide triangles with texture-coordinates in the range [-1, 1]. If you want to use the more traditional [0, 1] you will have to include some code to scale and offset coordinates in the shader, or you will get a quarter-circle.

Once you have this up and running, you can experiment to add other features (for example: anti-aliasing as per my linked question).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top