2007-01-08

今日も休出。昼過ぎまで寝てた。起きたくなくなるくらいに布団の中が暖かくて心地良い。会社は相変わらず少し寒かったけれど、昨日買ってきたお茶で温まりながら作業。

[]ポイントスプライト使用時の注意点 ポイントスプライト使用時の注意点 - Nao_uの日記 を含むブックマーク はてなブックマーク - ポイントスプライト使用時の注意点 - Nao_uの日記 ポイントスプライト使用時の注意点 - Nao_uの日記 のブックマークコメント

帰宅後に少し思うところがあって、ポイントスプライトの実験を始めてみた。作成時に2点ほどハマったポイントがあったのでメモ。

1.XNAはシェーダーの使用が必須で固定機能のポイントサイズ指定が使えないため、頂点シェーダー内で明示的にPSIZE0を指定する必要がある。

To draw point sprites, you need to set the PointSpriteEnable renderstate, and output a value with the PSIZE0 semantic from your vertex shader to control the point size.

Because XNA is a shader platform, the point size must be calculated in your vertex shader: the old fixed function falloff renderstates are gone.

BasicEffect doesn't compute or output a point size, so you can't use that for drawing point sprites.

Point sprites are also not 100% consistent between Windows and Xbox. You can still make them work on Xbox, but you have to do some things a little differently in your pixel shader.


2.Xbox360の実機では、Pixel Shader内でのポイントスプライトのUV指定に、"SPRITETEXCOORD"を使う必要がある。

struct PS_INPUT

{

#ifdef XBOX

float4 TexCoord : SPRITETEXCOORD;

#else

float2 TexCoord : TEXCOORD0;

#endif

float4 Color : COLOR0;

};

float4 PixelShader(PS_INPUT input) : COLOR0

{

float2 texCoord;

#ifdef XBOX

texCoord = abs(input.TexCoord.zw);

#else

texCoord = input.TexCoord.xy;

#endif

return tex2D(Sampler, texCoord) * input.Color;

}


以上の2点に引っかかって少し時間がかかってしまったけれど、とりあえず動いた。

f:id:Nao_u:20070109001300j:image

Xbox360GPUだと、パーティクルのサイズが十分に小さければ4万個程度なら平気で60fps動作する模様。これだけの数を出しても滑らかに動くのは気持ちいい。結局、この世代のハードウェアの性能を生かすには、いかにバッチ数を減らすのかが一番のポイントになりそうか。

今日はもう眠いので、詳細なテストはまた後日。