compute_density.cg

来自「游戏编程精粹6第中关于粒子的实时流体仿真系统,对入门的游戏开发者很有帮助.」· CG 代码 · 共 24 行

CG
24
字号
#include "sph.cg"
void main(float2 tc0 : TEXCOORD0, // pair index
		  uniform samplerRECT attr_rect      : TEXUNIT0,  // attributes of particles
		  uniform samplerRECT neighbour_rect : TEXUNIT1,  // neighbour list
		  out float result : COLOR // density
		  )
{
	float m = MASS;
	float h = SMOOTHING_LENGTH;
	float mu = VISCOSITY;
	float2 texel = unpack_2ushort(f1texRECT(neighbour_rect, tc0))*65536;
	float index = texel.x;
	float nindex = texel.y;

	float3 pos_i = f3texRECT(attr_rect, float2(index, GPU_ATTR_POS));
	float3 pos_j = f3texRECT(attr_rect, float2(nindex, GPU_ATTR_POS));

	float3 dp = pos_i - pos_j;
	float r2 = dot(dp, dp);
	float h2_r2 = h*h - r2;
	if (h2_r2 > 0.0)
		result = h2_r2*h2_r2*h2_r2;
	else result = 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?