Jump to content
  • Advertisement
Sign in to follow this  
jake_Ghost

DX9 pixel shader for shield impacts

This topic is 2786 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 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!