Jump to content


D3D10 water rendering


70 replies to this topic

#21 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 22 September 2008 - 08:26 PM

well no I was just wondering if you got the concept. It would be good if you did but it's not completley necessary for creating water. Baiscly you just need to make a small modification. Don't output the normals color to the screen, but instead use the normals colors to shift the ViewTexC coordinates. Then do the texture lookup of the screen image (refraction). Output those colors to the screen.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#22 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 22 September 2008 - 08:36 PM

Really thank you for all your help.
What do you mean for shift? The dictionary does not help me! Can you explain it better?

And what about the first problem?

#23 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 22 September 2008 - 08:40 PM

right before the screen image texture lookup, do this:
ViewTexC += normalMap.rg * .0001;

scale the .0001 as you need.

As for the first problem, I cant say anything but there isn't one. It's functioning as it should. Can you tell me what you're trying to get it to do?
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#24 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 22 September 2008 - 08:46 PM

starstutter said:

As for the first problem, I cant say anything but there isn't one. It's functioning as it should. Can you tell me what you're trying to get it to do?

Oh yes, you're right. To have a complete spot of water i must create a decent geometry, like a cube. I'm really going crazy, i should make a break :D

I will try your new code, (now i understand what do you mean for shift, damn dictionary...you meaned like the byteshift in C language :) ), but i've not understand why have i to make this...the concept behind it!

#25 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 22 September 2008 - 08:53 PM

XVincentX said:

I'm really going crazy, i should make a break :D
Probably a good idea. When I get stuck on a problem, I just walk away and think of the answer like 15 minutes later. Kind of a Daoist work ethic, it's cool :lol:

Quote

damn dictionary...you meaned like the byteshift in C language )
HA! That's dictionaries for ya! XD
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#26 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 22 September 2008 - 09:01 PM

Yes, i will try all tomorrow.
Now, if you want, i would talk about your 2 images, and next steps for water effect

Images questions:
a) D3D9 or D3D10? (d3d9, i suppose)
b) Are you using antialiasing? Anisotropic texture filter?
c) How many polygons there are in that scene?
f) Max and normal framerate?

Water questions:
I read a little bit the physics that manages the water and how all works, so
a) Refraction: how to simulate it? I thought to make a component to add, using the different refraction index in some ways....(1.0003 for air, 1.3333 for water)

Reflection: Via cubemap? i will study it

What do you say about?

#27 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 22 September 2008 - 09:03 PM

XVincentX said:

i must create a decent geometry, like a cube.

Rather than a cube you should just create a flat water surface that extends all the way to where the water meets the ground.

Quote

i've not understand why have i to make this...the concept behind it!

The idea is that instead of looking at the geometry under the water at the same point where it would be if the water wasn't there, you look at the geometry at a slightly different point. You move the point by a distance that depends on the water's normal. It produces a distorted image of what's under the water. It's not really refraction but can still look rather good.
reedbeta.com - developer blog, OpenGL demos, and other projects

#28 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 22 September 2008 - 09:06 PM

Reedbeta said:

Rather than a cube you should just create a flat water surface that extends all the way to where the water meets the ground.

And if i would go underwater?

#29 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 22 September 2008 - 09:38 PM

Underwater needs a different solution.

Although you can use this same technique to render the water surface as seen from below, distorting the view of objects above the water.
reedbeta.com - developer blog, OpenGL demos, and other projects

#30 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 22 September 2008 - 09:42 PM

ok! i do not need to go underwater for now :)

#31 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 22 September 2008 - 11:36 PM

XVincentX said:

a) D3D9 or D3D10? (d3d9, i suppose)
D3D9, but understand that besides new features, there's not an incredible amount of difference between the two. Not nearly as different as microsoft would have you belive

Quote

b) Are you using antialiasing? Anisotropic texture filter?
Antialiasing, no. My engine is a deferred renderer (well, it wasn't back then, but still) and that is incompatable with anti-alias. There are however post process solutions that work pretty well on modern hardware, and are techincally free if you program in Depth of Field effects.

Anisotropic, yes. Why wouldn't you? It makes surfaces look a lot better and it's a one word command in the shader declarations :)

Quote

c) How many polygons there are in that scene?
Not many, the left one probably had about 140 or so, and the right had around 600-700, but that was mostly the teapot mesh

Quote

f) Max and normal framerate?
for the left image, max framerate was when looking straght down into the water. If I remember right it came up to 300 or so, and the average was around 235-240.

The right image was using a higher polycount and an HDR environment so that drained it some. I think it was somewhere around 125-140 fps

Keep in mind however these framerates were recorded in windowed mode, which is substancially slower than fullscreen (in certain cases I see %25 speed increases).


Quote

Water questions:
I read a little bit the physics that manages the water and how all works, so
a) Refraction: how to simulate it? I thought to make a component to add, using the different refraction index in some ways....(1.0003 for air, 1.3333 for water)
You've pretty much already got refraction. Physically based approaches are impractical for modern hardware and some of the most recent games (like bioshock) used nothing but a simple distortion, and it's hard to argue with those guys about how to do water :)

Quote

Reflection: Via cubemap? i will study it
Thats the way I would go first off.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#32 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 23 September 2008 - 06:29 AM

The situation starts to get better, with your new formula, the water looks very better
Posted Image

This images uses this code
float4 ps_plane(PS_INPUT input)	:	SV_TARGET
{
	float2 ViewTexC = 0.5 * input.WorldPos.xy / input.WorldPos.w + float2( 0.5, 0.5 );
	ViewTexC.y	=	1.0f - ViewTexC.y;
	ViewTexC += NormalMap.Sample(SamplText,input.Tex).xy * 0.9f;
	return CurrentBackbuffer.Sample(SamplText,ViewTexC + EyePosition.xy);

}

Even if the water movement makes the texture move everytime in a single direction. So i modify the code to move toward a range with little oscillations.

Anyway, the water seems too rich of miniwaves. I've tryied to play with the .0001 value, but no results makes me satisfied. Mabye it's a normal map problem?

EDIT:

This code seems to work very better
float4 ps_plane(PS_INPUT input)	:	SV_TARGET
{
	float2 ViewTexC = 0.5 * input.WorldPos.xy / input.WorldPos.w + float2( 0.5, 0.5 );
	ViewTexC.y	=	1.0f - ViewTexC.y;
	ViewTexC += NormalMap.Sample(SamplText,ViewTexC).xy * 0.06f;
	return CurrentBackbuffer.Sample(SamplText,ViewTexC + EyePosition.xy);

}


#33 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 23 September 2008 - 02:20 PM

hmmm, image shack seems to be down.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#34 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 23 September 2008 - 02:47 PM

Doh!

Let's wait a while, else i will upload it again.

#35 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 23 September 2008 - 05:06 PM

Oh nice, that looks good! There's only one problem though and that's that the overall image shift is way too powerful. It's shifting the image incorrectly and making the entire thing move to another position. There should only be a small section rippling for that specific wave.

Make sure you're only modifying the image using the r and g channels of the texture.

EDIT:
actually on second thought, try and image bias:

ViewTexC += (NormalMap.Sample(SamplText,ViewTexC).xy * 0.06f) - bias;

I can't tell you the specific value of the bias, because that depends totally on your code. I would start at 0.1 and work your way either up or down (depending on which gets it closer) and just guess untill the image is aligned properly. Note that it's possible that the coordinates may not be the same scale. That means the x and y shifts could react differently to different values. So make bias a float2( +-0.1, +-0.1) and see if positive or nagitve numbers for either give you the right outcome. You may not have to do this at all though. Start with just positive and see if that does the trick.

EDIT AGAIN:
Wait, what's with the "+ eyePosition.xy" thing. That's probably what's messing the shift up. You should remove that as this is not yet a view dependant calculation.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#36 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 23 September 2008 - 06:41 PM

No, EyePosition it's only a name, but it contains the float that i increment for each frame rendered.
I was forced to used it becouse D3D10 has an orrible shader system:


float4x4	ViewMatrix;

float4x4	WorldMatrix;

float4x4	ProjMatrix;

float4		LightDirection;

float4		MaterialColor;

float3		EyePosition;

texture2D	Texture;

texture2D	CurrentBackbuffer;

texture2D	NormalMap;


Ok it works. If only i add a float, in this way

float4x4	ViewMatrix;

float4x4	WorldMatrix;

float4x4	ProjMatrix;

float4		LightDirection;

float4		MaterialColor;

float3		EyePosition;

texture2D	Texture;

texture2D	CurrentBackbuffer;

texture2D	NormalMap;

float          value;


D3D10 gives me Warnings becouse there are unbinded resources...so to make it work i'm forced to change variables position looking for the right order, and this is so bad.

D3D10 effect system, anyway has GetParameterByIndex and ByName, by ByName NEVER works.....and that's it.

I will try with bias value soon.

#37 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 23 September 2008 - 11:36 PM

well... still don't understand why you need to add a time based variable to the view coordinates :: ... I could understand adding them to the normalMap texture lookup to animate waves, but not to the view coordinate itself.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#38 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 24 September 2008 - 06:17 AM

Sorry for the adding value, i made a mistake in writing.

Anyway, i tried to use the bias value in this way

float4 ps_plane(PS_INPUT input)	:	SV_TARGET

{

	float2 ViewTexC = 0.5 * input.WorldPos.xy / input.WorldPos.w + float2( 0.5, 0.5 );

	ViewTexC.y	=	1.0f - ViewTexC.y;

	ViewTexC += ((NormalMap.Sample(SamplText,ViewTexC).xy  + EyePosition.xy) * 0.06f) - float2(-0.1,-0,1);

	return CurrentBackbuffer.Sample(SamplText,ViewTexC);


}


And what i can see it's only a texture movement on the surface. I tried some combinations: ++,+-,-+,-- also using higher values: with 0.5 the texture disappears and the surface becomes blue (that it's the Clear color in RenderTarget)

#39 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 24 September 2008 - 06:19 AM

From my experience, the distortion values should never be higher than 0.04
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#40 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 24 September 2008 - 06:27 AM

With 0.05 i can't see any change...

Without Bias:
Posted Image
With
Posted Image





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users