Home Technical Talk

Help with render target simulation

Elrinion
polycounter lvl 2
Offline / Send Message
Elrinion polycounter lvl 2

Hi. For my project, I'm trying to do a map editor with custom terrain. For that I intend to do a simple hydraulic erosion algorithm in the gpu to displace the water and generate some rivers.

I'm using a blueprint that switches between two render targets and a material that does the calculations. The texture's red channel is terrain height and green channel is water volume.

The problems is, no matter what I do, the water just grows uniformly throughout the terrain.

I'm trying to achieve a simpler version of this: https://www.youtube.com/watch?v=jfcIeog-lQo

Here's the custom node that does the simulation and doesn't work:

float dst = Dist/Res;

float4 buf[5];
buf[0] = Texture2DSample(Tex , TexSampler , UV);
buf[1] = Texture2DSample(Tex , TexSampler , float2(UV.x+dst,0));
buf[2] = Texture2DSample(Tex , TexSampler , float2(UV.x-dst,0));
buf[3] = Texture2DSample(Tex , TexSampler , float2(0,UV.y+dst));
buf[4] = Texture2DSample(Tex , TexSampler , float2(0,UV.y-dst));


float lhc = buf[0].x;
float wvc = buf[0].y;
float whc = wvc + lhc;



for (int i=1; i<5; i++)
{
float lhi = buf[i].x;  // land height (neighboring cell)
float wvi = buf[i].y;  // water volume (neighboring cell)
float whi = wvi + lhi; // water height (neighboring cell)
float wslope = whi - whc; // water slope
float lslope = lhi - lhc; // land slope

wvc += clamp(wslope/2,-wvc/2,wvi/2);
lhc += wslope*0.001;
}

// Rain

buf[0].y += 0.0001;

return buf[0];

Any help would be much appreciated.

Replies

  • Obscura
    Options
    Offline / Send Message
    Obscura grand marshal polycounter
    Sorry to let you know but you came to a really wrong place if you want to get answer to this one.  This is kinda hardcore stuff even if you know some hlsl. 

    You should rather post this one to like a shader group or something.
  • Elrinion
    Options
    Offline / Send Message
    Elrinion polycounter lvl 2
    Obscura said:
    Sorry to let you know but you came to a really wrong place if you want to get answer to this one.  This is kinda hardcore stuff even if you know some hlsl. 

    You should rather post this one to like a shader group or something.
    It was supposed to be something easy. Just average some height values between neighbors. Instead I'm just banging my head against the wall for days. lol
Sign In or Register to comment.