r/GraphicsProgramming • • Mar 26 '16

How to achieve camera-hit shockwave post-processing effect?

I'm using DirectX/HLSL for post-processing and I want to create a post-processing effect of the screen shaking suddenly.

Any idea how I can achieve this? thanks

1 Upvotes

9 comments sorted by

5

u/[deleted] Mar 26 '16

Usually a screen-shake is achieved by randomly moving the camera position and rotation multiplied by some kind of pre-determined intensity.

1

u/SYCarrot Mar 26 '16

true, but I'm strictly talking about it as a post-processing effect

8

u/tylercamp Mar 26 '16

Render your target with a shader that takes some vec2, when sampling your screen texture with the shader offset all sample locations by that vec2

... although, just randomly moving the camera would still be an overall higher-quality solution

8

u/Rangsk Mar 26 '16

The issue with using post processing for this is you're going to run into issues at the edges of the screen. Shaking the camera is an overall better solution for a slew of reasons.

That said, you just need to pass in a UV offset for sampling the screen, and change it every frame.

2

u/[deleted] Mar 27 '16

You could get around it by zooming in, and somehow covering up the transfer by eg drawing the attention to the centre.

1

u/goal2004 Mar 27 '16

You could get away with doing a motion blur shake, where you blend gradual offsets uniformly in a randomized direction, and at random intensities. Just make sure the texture is set to clamp mode (instead of repeat) and it should still look good enough for screen edges.

3

u/HighRelevancy Mar 27 '16

Screen shake or shockwave? The shockwave is done by drawing a wave that floats outwards from the centre point, and is used as a displacement map (i.e. each pixel's colour gets replaced with the pixel that is the wave's magnitude as a distance away from/towards the centre of the wave).

1

u/skytomorrownow Mar 27 '16

Even then, you'd probably have to sell it with some screen shake when the displacement reaches the camera position.

1

u/ultrapingu Mar 27 '16

To do this in post, you will need to render a larger render target than what you are actually sending to the screen buffer. Then you can just offset that by an amount each frame.

It's a pretty bad way of doing it because you will always have to draw parts of the scene which won't be seen/you have to constantly re size the render target.

The best option is to just rotate the camera a bit per frame, but if you can't access that for some reason, the above answer is your best bet.