Jump to content
  • Advertisement
Sign in to follow this  

OpenGL surface reconstruction of sph fluid simulation

This topic is 2885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys,

currently i´m working on a soft particle hydrodynamics fluid simulation with c++ and opengl. the simulation works, but i have to reconstruct the water surface.

i want to implement a point based method based on metaballs/sprites. It´s based on a technical report, i found on the internet. i don´t know the link right now, but it´s in german and most of the people her couldn´t read it anyway.

the method is splitted in three parts.

1. rendering of metaballs

2. blurring the surface to form a water like look

3. rendering of water with reflection and refraction

my current problem is at the end of the first part. for every particle in the simulation, i wrote 4 points into the vertex buffer. they all have the same position, but different texture coordinates. with the help of these coordinates, i can span a quad in the vertex shader. the advantage is, that they are automaticly screen aligned. the next step is making a metaball from this quad.

first, i compute the radius of the circle, so that i can discard every pixel of the quad, that is outside the circle. next, i have to recompute the pixel depth to form the sphere volume. and here is the problem.

the code from the report looks like this:

float metaball_z = sqrt(1.0-radius*radius);

float virtual_depth = gl_FragCoord.z - (metaball_z * perspective_correction);

gl_FragDepth = virtual_depth;

in general, its clear, what it does. based on the radius, the current fragment depth is changed. my problem is the variable "perspective_correction". ther is nothing said about it in the report. i know the reason, why it has to be there, but i don´t know how to compute it. the value is important, because the computed depth is in the range of [0, 1] and the depth buffer is in the same range. i also know, that it have to be based on the current depth of the fragment, because an object, that is far away is smaller and so the depth offset has to be smaller. i can´t get behind the correct formular.

can anyone help me with this problem? if something is unclear, ask me. i´m sorry, english isn´t my native language and sometimes i have problems to find the right words.

a problem that will araise after this, is to compute the normal vector of the fragment based on the depth.

thanks in advance


Share this post

Link to post
Share on other sites

It doesn't look like perspective_correction is actual perspective correction. More likely, it's converting from world coordinates to depth coordinates. See here.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!