My Fluid Simulation (SPH) Sample (3) – Optical Effects using GLSL, and Integration of Physical Model

来源:互联网 发布:delicious大金家淘宝店 编辑:程序博客网 时间:2024/03/29 07:46

I would say my SPH application is ALMOST done. In recent 2 days I finished optical effects of curvature flow using GLSL.

 

Cubemap using GLSL

As the paper titile indicates “Screen-Space”, the first rendering step is to the regular object, and the second rendering step is to calculate corresponding fluid positioned vertices, and these vertices will be post on the camera len directly (a QUAD). However, these vertices have been assigned calculated curvature/thickness/normal information then will be transferred to GLSL to get a finer shading effets. Cubemap is the best choice for GLSL implementation.

First a Cubemap texture should be setup using regular OpenGL, and I will offer the src here:

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);          
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  

glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X + i, …)

Another critical point for GLSL is as below:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, nCubemapTexId);
cubeMapInx = glGetUniformLocation(program, "cubemapTex");
glUniform1i(cubeMapInx, 0);
 

Please notice that GLSL counts its texture index from ‘GL_TEXTURE0’, and the corresponding pass-in var of texture index is 0. This is a rookie trivia but it still costs me several hours to figure out.

Using the intrinsic function “reflect()/refract()” in GLSL, you can achieve a really beautiful shading effect.

 

Integration of Physical Model

After shading part is over, I integrate the former Rigid/N-S model into this framework.

 

OK here are the screenshots:

 

0

 

1

 

 

3

 

2

 

4

 

5

 

6

 

7

 

8

 

9

 

 

 

TODO

1. Performance is still low.. most time is spent on curvature flow iterations. I’m considering to use CUDA to accelerate it.

2. As shown, the physical model still needs more fine tuning – the fluid is over compressive and spring force is not large enough…

Again, just wait for me !

 

原创粉丝点击