Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

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

Sign up now

Projected Grid Ocean undersampling

4: Adsense

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.

  • You cannot reply to this topic
6 replies to this topic

#1 alkisbkn   Members   


Posted 26 June 2014 - 09:59 AM

So I've been implementing a projected grid ocean for our latest game and I ran into a what it seems, undersampling issue when I sample my displacement heightmaps. It seems that I can't tile the heightmaps a lot over the water surface - if I do so, the surface wobbles a lot. This leaves me with relatively big lumps of water of low amplitude. The heightmaps are 512x512 (I can't go much higher than that, the implementation is for iOS devices).


How do games like Assasin's creed and others fix this aliasing problem? I couldn't see it happening in their implementation and they have massive waves.


Here is my texture sampling code for the heightmap, if someone feels like helping smile.png

float dist = 0;
float3 ray = 0;
// calculate the water world space vertex position from the screen space quad
float3 waterWpos = reconstruct(v.vertex, dist, ray);
float fade = exp(-dist * _LodExponent);
float lod = _MaxLod * (1-fade);

// if _GridSize becomes too small, very obvious sampling artifacts occur
float4 tc = float4(waterWpos/_GridSize, 0, lod);
float4 texel = tex2Dlod (_HeightsTex, tc);
waterWpos = texel.r*_WaveHeight;

I have tried sampling the heightmap using a radial grid, however I have the same problem.

Any input is appreciated!

#2 cgrant   Members   


Posted 26 June 2014 - 12:23 PM

One thing to note is that LOD is more than just a function of distance, the regular mipmap selection criteria usually use a derivated to figure out changes in screen space to select the correct mipmap/LOD. So using a distance based calculation will still introduce some aliasing.

#3 Yourself   Members   


Posted 26 June 2014 - 12:26 PM

First thing I would try is sampling the heightmap multiple at different rates and do weighted blending on it.
Low frequency sampling will make the big waves while the higher frequences will add detail.

#4 alkisbkn   Members   


Posted 26 June 2014 - 01:45 PM


that was a good idea which I have already tried, unfortunately it didn't solve the problem. Moreover, it will be quite expensive to do that on lower end devices so it's not a direct solution I am afraid.


Another thing that I tried (I tried it even with a radial grid, I got a similar result), was to simply run a continous function like sin for the height as such:

height = 0.5 * sin (time + worldPos.x * factor);

which created horrible aliasing in the distance (see the following screenshot).

Screen Shot 2014-06-26 at 19.43.33.png


The funny thing is that I recently ran the projceted grid demo from Johanson (http://fileadmin.cs.lth.se/graphics/theses/projects/projgrid/) and it doesn't suffer from such aliasing or issues. It may be worth saying that the unprojection is done in the CPU in his case, whereas in mine, I do it in the shader.


One thing that I was thinking could be to change the position of the projector camera to be closer to the plane. I will try that first thing tomorrow.

#5 alkisbkn   Members   


Posted 27 June 2014 - 03:35 AM

Ok no luck with moving the projector, it's actually making things worse.

#6 Reitano   Members   


Posted 27 June 2014 - 04:58 AM

Think of the displacement map as a 2D signal that's sampled by the projected grid. All sampling techniques, projected grid included, have to take into account aliasing. In order to fight it, follow these steps:

- Build, either at runtime or offline, a full mipmap chain of the displacement map. Experiment with different downsampling filters, like box filters, simple point filters (which can be OK for displacement maps) or more advanced ones.
-In the shader, calculate the derivatives of the displacement map texture coordinates with respect to the projected grid x,y coordinates. You have some options here: forward differencing, ddx and ddy (not applicable in my vertex shaders) or analitically. I'd suggest the last option. Please ask me for formulas if you get stuck.
-Fetch the displacement map by passing the derivatives (tex2Dgrad in DirectX).
-For procedural waves (sin, cos etc), exploit the derivatives to filter them out analitically.

You might want to add a parameter (in the [0,1] range) that multiplies the derivatives in order to let artists control the tradeoff aliasing vs detail in the scene.
Also, as described in the original projected grid paper, the projective camera does not necessarily match the main camera. By changing some of its parameters you can bias the sampling and, for example, add more detail in the distance.
Last, wobbling is inevitable if the projected grid is too coarse. What is the resolution of the screen and the projected grid in your application ? I suggest a ratio of less than 4 before the two.

#7 alkisbkn   Members   


Posted 27 June 2014 - 05:26 AM

Hi Reitano,


I tried tex2Dgrad by calculating 3 world positions as such:

// _ScreenParams.xy = screenres (width, height)

float sizex = 1f/_ScreenParams.x * factor;
float sizey = 1f/_ScreenParams.y * factor;

float3 adj0 = reconstruct(v.vertex + float4(sizex, 0, 0, 0), dist, ray);
float3 adj1 = reconstruct(v.vertex + float4(0, sizey, 0, 0), dist, ray);
float3 waterVertex = reconstruct(v.vertex, dist, ray);
float2 ux = abs(adj0.xz - waterVertex.xz)*2;
float2 uy = abs(adj1.xz - waterVertex.xz)*2;

float4 texel = 	tex2Dgrad (_HeightsTex, tc, ux, uy);

Maybe I calculated the gradients wrong, this didn't have a good visual result. Could you help me out with the analytical approach equation?


The resolution of the screen varies (it's for iOS devices), but it ranges from 940x640 to 2048x1536. For the moment, I am using the max possible tesselation for the grid.

I also followed Johanson's paper, especially where he mentions to try and aim the projector camera to avoid looking at the horizon, so that vertices are not wasted. It could help a bit, as I can't see any visual artifacts in his original demo.

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.