Sign in to follow this  

DX9 pixel shader for shield impacts

This topic is 2573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am having trouble with my pixel shader and at this point I am totally lost on what to do next. Basically all I am doing is using a pixel shader to show the spots on a shield that have been hit. I have all the coords of the shield hit locations in the shader but what I don't know how to do is get the distance from a pixel to the hit location.

Basically I'm looking at something like this,


// ps_3_0
float4 ps_normal(in PS_INPUT In) : COLOR
{
float Distance;
float2 Pos;

float4 color= tex2D( Tex0, In.Texture );

for (int i = 0; i < CurHitSize; ++i)
{
Pos = PixelCoord - HitCoord[i]; // I dont know how to get the pixel coord

Distance = sqrt(Pos.x * Pos.x + Pos.y * Pos.y);

if (Distance < 10) // I'm just using 10 as an example as it will obviously change depending on how large you want the impact to be
{
// Here I don't know how to return color of the pixel
// I want all the pixels to be at 0 alpha except for the ones that are in the impact range
}
}
}





Any help would be great!

Thanks,
Jake

Share this post


Link to post
Share on other sites
You could add a world-space position to your PS_INPUT that you output from the vertex-shader. This way you will know the position of every pixel. There are other ways of doing it depending on how your rendering works and what coordinate system HitCoord is in.

As for the color, the easiest way is probably alpha = 1 - (distance/10).

Share this post


Link to post
Share on other sites

This topic is 2573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this