Introduction to my galaxy engine 8 : Real Time Fluid Rendering
Introduction to my galaxy engine 8 : Real Time Fluid Rendering最近正在研究real time fluid effect方面的问题,主要适用于液体,烟雾,火焰方面的实时模拟。一般是通过GPGPU(general purpose GPU)来实现的。
以下是2D Fluid初步实验的截图:
http://pic002.cnblogs.com/images/2012/411346/2012061208520030.jpg
http://pic002.cnblogs.com/images/2012/411346/2012061208521498.jpg
要理解实现原理,首先要熟悉其基于的物理模型:“stable fluids” by Stam 1999. 从实现角度来说,根据fluid effect的计算公式
http://pic002.cnblogs.com/images/2012/411346/2012061209250126.png
主要考虑如下几个要素:Advection [气]水平对流, pressure, diffusion, (Vorticity [涡旋] Confinement 主要用于烟雾,火焰), external forces. 每一个要素的作用大小是通过读取其对应的图片来获取的。
具体实现步骤如下:
1.将屏幕分为一定大小数量的网格,如图所示:
http://pic002.cnblogs.com/images/2012/411346/2012061208551697.png
由于我的窗口大小设定为800*600,横行分为了80*2格,纵向分为了60*2格.之后的相关计算都是以格子为单位。蓝色为边界部分,不做为渲染区域。
2. 根据网格生成顶点。
VS_INPUT_FLUIDSIM_STRUCT tempVertex1; VS_INPUT_FLUIDSIM_STRUCT tempVertex2; VS_INPUT_FLUIDSIM_STRUCT tempVertex3; VS_INPUT_FLUIDSIM_STRUCT tempVertex4; int w = m_dim[0]; int h = m_dim[1]; float left = -1.0f + 2.0f/w;//exclude the boundary cell, each cell size is 2.0f/w float right=1.0f - 2.0f/w; float top =1.0f - 2.0f/h; float bottom = -1.0f + 2.0f/h; tempVertex1.Pos = D3DXVECTOR3( left, top, 0.0f);//projection screen pos tempVertex1.Tex = D3DXVECTOR3( 1.0f, 1.0f, 0.0f);//texture pos, exclude boundary cell tempVertex2.Pos = D3DXVECTOR3( right, top, 0.0f); tempVertex2.Tex = D3DXVECTOR3( (w-1.0f), 1.0f, 0.0f); tempVertex3.Pos = D3DXVECTOR3( right, bottom, 0.0f); tempVertex3.Tex = D3DXVECTOR3( (w-1.0f), (h-1.0f), 0.0f); tempVertex4.Pos = D3DXVECTOR3( left, bottom, 0.0f); tempVertex4.Tex = D3DXVECTOR3( 1.0f, (h-1.0f), 0.0f); (*vertices) = tempVertex1; (*vertices) = tempVertex2; (*vertices) = tempVertex3; (*vertices) = tempVertex1; (*vertices) = tempVertex3; (*vertices) = tempVertex4;
页:
[1]