虽然不是什么新的东西, 但是因为觉得很好玩, 所以还是自己抽空实现了一下, 顺便也是要分享一些自己的学习心得.
1. 什么是流体?
自然界中有很多东西是流体, 包括占据了将近半个地球体积的空气, 覆盖了70%地表的水体, 还有那在太阳系的中央, 永恒地燃烧着的火焰.
2. 流体的行为?
在上个世纪的早些年代,Navier和Stokes共同发现了流体运动的规律, 从而写下了著名的Navier-Stokes流体动力学方程,当然它假设流体是不可压缩(体积不变)和均匀(密度不变)的:

其中, u是指速度场, ∇, ∇^2, ∇•分别是梯度算子, 拉普拉斯算子和散度算子.其对应的运算如下:

值得注意标量场的梯度是矢量, 而矢量场的散度是标量.上表中拉普拉斯算子的微分形式的v改成u
Navier-stokes方程的实际意义是速度场在单位时间里的改变量=加速度∂u/∂t=F/m;
所以, 速度的即时改变量主要由该方程式的右边项决定
推导如下,
求解像这样的偏微分方程, 通常不可能获得解析解, 所以要使用数值方法
首先, 让我介绍求解中最重要的概念之一Splitting:

所以, 求解上式被拆解成以下几个步骤:

来看其中的最后一个步骤:
写成离散形式, 有:

所以 求解压力的伯松方程, 再从散度速度场中减去压力的梯度, 就得到了新的divergince free的速度场
注意上图有个加号错了.
方程的求解:

已经被证明, 对于矩阵表示的线性方程, jacobi迭代也照样可行Ax=b, 而伯松压力方程, 就正好是这样的一类方程.

by run the iteration times, we can get the pressure field.
at last, let's look at the advection term.

Implementation:
所有的东西都是2维数组, 所有的运算都是数据运算, 所以, 数组就是2D texture, 运算就是画屏幕大小的quad.
以下是一个实现

done by..zxx 
posted @
2008-09-11 14:32 Anything interesting? 阅读(1846) |
评论 (33) |
编辑
In order to practise english and share what i have learned about the instanced tessellation, i wrote this artical, just talking about the Instance tessellation pipeline, not the mathematical research about the surface soomthing.--Zxx
Days buried myself in the *.cpp and *.pdf files, i finally got the idea of the Instanced tessellation, which has been implemented in the earlier days after when DX10 is released and Nvidia added a Geometry Process part to the GPU pipeline (you can also find the ppt Inst_Tess_Compatible.pdf from the NV's developer web site http://developer.nvidia.com, which is released months ago together with their GDC08 talk notes), but "geometry shader isn't for the tessellation"(reference 1)--in my understanding, it doesn't suit for the job, although it can do some small tasks like Bezier line evaluate with a small input of control points. But it works much much better while processing volume data with the matching cubics algorithm, and is also helpful in a tessellation pipeline, which will be described in detail in the following part.
I am writing this tring to make others have a clear concept of the Instanced tessellation based on my understanding, and will keep the words as simple as it can be.
1. What is Instanced tessellation?
Take a 4^4 or 16*16 or 32*32 or (even more...) patch with each of its grid point contains a uv value only(or point ID from zero to density*density) as a Instance, replace the original patchs in the model by this patch, and in a VS, compute what position of each grid point of the Instance patch should be by the uv coordinate and its instanceID, which is used to index its control point values already being stored in a Vertex Buffer in the prior pass.
High light point:
the only attribute the instance patch has (or saying, we need for a patch) is the uv value(or point ID) and its patch index(instance_ID), which were than transformed into the VS to index the ControlPoints. The instance_IDs are stored in an IndexBuffer and the the control points are stored in the VertexBuffer. And when you are drawing by call the InstanceDraw()function, the GPU will draw the patch repeatedly by instance_num times, in which case, a patch is considered to be an element, so as in the normal cases when we are drawing the point, each "patch" was given a index value in the Index Buffer, so that the VS can locate its control points in the VB, and each group of the control points is stored as a pair together with the index value. Be aware, the order we store the controlPoints[16] and controlNormals[16] and controlTangents[16] and also textureCoordinate[16] together with the index value pair is not a matter, as long as we are keeping the group of them in group and when we are using them, they are used by group. Because we are drawing the pre-tessellated patch as an element.And each of them are processed independently. Saying,the two types below are the same thing.

Type1, the italic word "index" are used to hint the order we store the groups in.
Type2, the italic word "index" are used to hint the order we store the groups in.
Here, all the values are called "conrolValues", because they will be used to evaluate the final value we take for the PixelShader rendering, instead of being used directly.
2. What a role does a Geometry Shader play in a tessellation task?
In fact, GS play no role in the tessellation, but if we need to do the adaptively tessellation by the curvature of the surface or by the distance of the surface or the distance of a patch in the screen size (these are the research parts), we need the GS, as we are applying the same computation to each patch, why not use the parallel processing ability of GPU? And in GPU, only the GS part can do this job, which can take line-adjacency as input and based on some rules we take,computer and output the edge facts of a patch, which represent how much tessellation we should take for an edge.
After that, we got the edge fact, which describes how much the edge should be tessellated, but problems may happen if we chose different LODs for different patchs:
To solving this problem, we need only change the uv value of the point of a instance patch to suit for its edge facts:
Attention:
Here, we are not changing the vertex position or the connecting relationship between neigboring vertexs, we are just changing the uv value. Take the edge whose fact=2 as an example, there were 4 uv value in the edge, but as its fact=2, the midright uv value which once was (0,3) is modified to be (0,4), we keep the mid one as it was, and modify the midleft one to be (0,0), as a matter of fact, we drawed 4*4*2 triangles after VS processed this instance, but some of their vertexs are evaluated to be at the same point. I use "evaluated to be" here to remind you that we are modifying the uv value first and then evaluate the position by the evaluate function, as the control points are the same, then, the evaluating equation should be same, then, the same uv value will get the same position value.
Why not we first evaluate the position, then modify the position?
Surly we cannot do this, consider the VS's function, we can evaluate the position value, but how can we chang it to another one which the VS does not know? But when dealing with uv, we are sure "to what value it sould be modified", so that we can modify it.
3. Can GS take a line_strip_adjacency representing a patch as input, then compute and output the control mesh by some algorithsm?
I think the GS can do this, as long as the algorithm is a local algorithm, which need to only take one triangular information and out put a control mesh. Like PN triangle algorithm, is such an example. And maybe some of the approximated catmull-clark subdivision algorithm develoed by Loop.
After when you have read this note, you will Know the pipeline most of the CG researchers are using when building up a Instanced tessellation project. But you get nothing with the DX10's feature and how to implement that in a DX10, and nothing with how to apply surface techniques while evaluating, all of the topics requires more reading.
Reference
[1] Instanced Tesselation in DX10. Nv. Co. .
[2] Siggraph 2007 course Introduction to DirectX10. Microsoft Corp, Microsoft game stdio, Crytek, LucasArts, Relic Entertainment.
posted @
2008-08-27 10:17 Anything interesting? 阅读(1205) |
评论 (14) |
编辑