• entries
743
1924
• views
580367

# Postprocessing and getting wet

150 views

Finally got round to learning how to do post-processing today. I've decided that the increase in minimum spec is worth it. The above water effect is the first thing I've done with this.

">IT IS WELL WORTH SEEING IT MOVING to get the full effect.

It's all hacked together at the moment, but eventually any level can have a given water level, that can be moved up and down. This can either be for Tomb Raider style raising and lowering water levels to solve puzzles, or have Squishy have limited breath and water level that chases him up a level or anything really.

It's a pretty simple shader (edited with Drillian's excellent suggestion below):

sampler tex : register(s0);struct INPUT{	float2 coord : TEXCOORD;};struct OUTPUT{	vector color : COLOR;};float timer=0;float level=0;OUTPUT main(INPUT input){	OUTPUT output;	float2 t=input.coord;	float s=sin((t.x+timer*0.05)*50)*0.0025;	float blend=saturate((t.y-s-level)/0.005);		vector c=tex2D(tex,t);	if(t.y>level+s)		{		t.x+=sin((t.y+(timer*0.05))*100)*0.0025;		vector a=tex2D(tex,t);		a.b=a.b*0.5;		a.r=a.r*0.25;		c=(c*(1-blend))+(a*blend);		}		output.color=c;	return output;}

As I want to keep using multi-sampling, I'm having to render to the back buffer, then StretchRect this onto a fixed size render target texture (currently 1024x1024 but I might make this configurable), then render the texture back to the back buffer with the shader enabled.

All good stuff. Probably be some more updates to this post later (as usual) as I'm thinking that once I've integrated this into the game properly, it might be worth looking at making stuff float.

------------------------------

Hmm. Floating is hard to get right. I've got some acceptable underwater behaviour for Squishy but getting debris to float is more tricky. For now, debris sinks but a bit slower than just falling through the air.

You can now trigger the water to raise and lower via the script, so attaching a button to a script gate that calls the appropriate procedure means you can move the water to different levels, also specifying the speed it moves at, which is pretty cool. A lot of the groundwork I've already done, particularly the logic gates and scripting system, is really starting to pay off now.

Going to have to get a demo out soon, see what you lot think.

------------------------------

Oh, I found out today I didn't get that job I went for last week. Never mind. Pinning all my hopes on the interview next Wednesday now.

Awesome again! And you seem to do in days what most people do in weeks...

##### Link to comment
Quote:
 Original post by Demosthenes Awesome again! And you seem to do in days what most people do in weeks...

Well, I've been bunking off work for two days with a bad back to be fair. [smile]

Landed weird at jujitsu about two weeks ago, took about a week to get better, thought I was fine and went back to jujitsu on Monday, woke up Tuesday morning barely able to move.

Better now, but think I have to give the old kung fu a miss until I'm properly better, which is a shame as I have a grading coming up in about six weeks and don't want to fall behind the guys I'm working with.

##### Link to comment
Man, you are just rocketing forward with progress! That ripple effect looks really cool in motion.

There are two ways I can think of to make the water softer:

1. Use actual vertices to denote the top of the water...but it sort of breaks the whole "render the postprocess as a quad" thing. Probably not the best choice.

2.

float blend = saturate((t.y - s - level)/someConstant);


That is, you now have a range from 0 (fully in water) to 1 (fully out of water).

It's not perfect, but it should help smooth a bit. The larger the constant, the blurrier that edge will get. I wasn't sure what kind of constant would be good for your purposes - if your y value is measured in pixels, you'd want it to be the number of pixels in the blur. You'd need to play around with the constant to get a value that looks good.

##### Link to comment
Quote:
 Original post by Drilian Man, you are just rocketing forward with progress! That ripple effect looks really cool in motion. There are two ways I can think of to make the water softer: 1. Use actual vertices to denote the top of the water...but it sort of breaks the whole "render the postprocess as a quad" thing. Probably not the best choice. 2. float blend = saturate((t.y - s - level)/someConstant);  That is, you now have a range from 0 (fully in water) to 1 (fully out of water). It's not perfect, but it should help smooth a bit. The larger the constant, the blurrier that edge will get. I wasn't sure what kind of constant would be good for your purposes - if your y value is measured in pixels, you'd want it to be the number of pixels in the blur. You'd need to play around with the constant to get a value that looks good.

You da man, Drillian. That works a treat with a constant of 0.005. Thanks very much indeed. [smile]

## 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