View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Since we have an extra week

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1Sammie22  Members

Posted 02 February 2011 - 12:32 AM

I thought I'd play around with some shader effects, which I am really enjoying. In addition to gaining a better understanding of the XNA framework, it's one of the reasons I am really looking forward to this workshop. I have been messing around with some water effects, and have a nice wavy look to an underwater scene. So I thought it would be cool to have an effect where the user can click on the screen, and set off a ripple effect, like what happens when a small object falls into a body of water. I did a lot of googling around for some examples, but nothing is really setting in with me. Right now I have this, which is from the Microsoft example on applying shader effects to 2D textures:

uniform extern texture ScreenTexture;

sampler ScreenS = sampler_state
{
Texture = <ScreenTexture>;
};

float wave;                // pi/.75 is a good default
float distortion;        // 1 is a good default
float2 centerCoord;        // 0.5,0.5 is the screen center

float4 PS(float2 texCoord: TEXCOORD0) : COLOR0
{
float2 distance = abs(texCoord - centerCoord);
float scalar = length(distance);

// invert the scale so 1 is centerpoint
scalar = abs(1 - scalar);

// calculate how far to distort for this pixel
float sinoffset = sin(wave / scalar);
sinoffset = clamp(sinoffset, 0, 1);

// calculate which direction to distort
float sinsign = cos(wave / scalar);

// reduce the distortion effect
sinoffset = sinoffset * distortion/32;

// pick a pixel on the screen for this pixel, based on
// the calculated offset and direction
float4 color = tex2D(ScreenS, texCoord+(sinoffset*sinsign));

return color;
}

technique
{
pass P0
{
}
}


This does produce a ripple effect, but not the desired result. The ripple begins a bit away from center position, and has an ugly trailing effect. I think this is down to the timing as well as some missing variables needed to make the desired effect. For an example, I am going for something like: http://www.youtube.c...h?v=Nr42AG1aPAY

I would like to be able to adjust the initial radius, number of ripples, length of the ripples before they dampen out, and the time it takes for them to reach their dampened state. If anyone has any experience with this, I'd love some help.

Thanks

Edit: I should also add that I am applying this effect to a Texture2D, and would like to make it a pixel shader only.

### #2Sammie22  Members

Posted 02 February 2011 - 06:26 PM

I made some progress (using the code above) by changing the way the distortion value was calculated and set in the shader. Before I was increaing this value over time, but I should have been decreasing its value over time to 0 (so the wave smoothly dampens out). Now I'd like to control the speed at which the waves move, as well as the number of waves.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.