战魂小筑

:: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
 252 随笔 :: 0 文章 :: 506 评论 :: 0 Trackbacks

`   1:  float4x4 view_proj_matrix: register(c0);`
`   2:  float4x4 view_matrix: register(c4);`
`   3:  float time_0_X: register(c8);`
`   4:  float4 particleSystemPosition: register(c9);`
`   5:  float particleSystemShape: register(c10);`
`   6:  float particleSpread: register(c11);`
`   7:  float particleSpeed: register(c12);`
`   8:  float particleSystemHeight: register(c13);`
`   9:  float particleSize: register(c14);`
`  10:  // The model for the particle system consists of a hundred quads.`
`  11:  // These quads are simple (-1,-1) to (1,1) quads where each quad`
`  12:  // has a z ranging from 0 to 1. The z will be used to differenciate`
`  13:  // between different particles`
`  14:   `
`  15:  struct VS_OUTPUT {`
`  16:     float4 Pos: POSITION;`
`  17:     float2 texCoord: TEXCOORD0;`
`  18:     float color: TEXCOORD1;`
`  19:  };`
`  20:   `
`  21:  VS_OUTPUT main(float4 Pos: POSITION){`
`  22:     VS_OUTPUT Out;`
`  23:   `
`  24:     // Loop particles`
`  25:     float t = frac(Pos.z + particleSpeed * time_0_X);`
`  26:     // Determine the shape of the system`
`  27:     float s = pow(t, particleSystemShape);`
`  28:   `
`  29:     float3 pos;`
`  30:     // Spread particles in a semi-random fashion`
`  31:     pos.x = particleSpread * s * cos(62 * Pos.z);`
`  32:     pos.z = particleSpread * s * sin(163 * Pos.z);`
`  33:     // Particles goes up`
`  34:     pos.y = particleSystemHeight * t;`
`  35:   `
`  36:     // Billboard the quads.`
`  37:     // The view matrix gives us our right and up vectors.`
`  38:     pos += particleSize * (Pos.x * view_matrix[0] + Pos.y * view_matrix[1]);`
`  39:     // And put the system into place`
`  40:     pos += particleSystemPosition;`
`  41:   `
`  42:     Out.Pos = mul(view_proj_matrix, float4(pos, 1));`
`  43:     Out.texCoord = Pos.xy;`
`  44:     Out.color = 1 - t;`
`  45:   `
`  46:     return Out;`
`  47:  }`

2008年时，我曾经根据这个原理，设计了一套粒子系统，原理与这个差不多，只不过VB是由Constant设置进来，在DX10/11以上就叫ConstantBuffer。测试了下，传统的粒子系统，在我的本子上大约只能跑60多帧，但是这个不锁定VB的粒子系统却可以跑300多帧。

`#define VERTEX_COUNT 80`
` `
`float4 PositionBuffer[VERTEX_COUNT];`
`float2 UVBuffer[VERTEX_COUNT];`
`float4 ColorBuffer[VERTEX_COUNT];`
` `
`float4x4 Transform;`
` `
`void Main(`
`    in float InIndex : TEXCOORD0,`
`    out float4 OutPosition : POSITION,`
`    out float2 OutTexCoord : TEXCOORD1,`
`    out float4 OutColor : COLOR0`
`    )`
`{`
`    OutPosition = mul( PositionBuffer[ InIndex ] , Transform );`
`    OutColor = ColorBuffer[ InIndex ];`
`    OutTexCoord = UVBuffer[ InIndex ];`
`}`

DX9因为不开源，我们并不了解下面3种绘制方式的性能差异：

1. Constant发送

2. 锁定VB发送

3. DrawPrimitiveUP系列使用系统内建缓冲渲染

posted on 2010-07-27 14:46 战魂小筑 阅读(2009) 评论(1)  编辑 收藏 引用 所属分类: 渲染 Shader 引擎

评论

# re: DirectX 9高效渲染之利用Constant构建渲染数据 2012-10-24 22:46 王月
Constant怎么发送?  回复  更多评论