Add this to syntax highlighter to high light "numbers" in 3 format :
- 0x204080FF
- 3.14159f
- 7
Texture2D g_NSZTexture;
Texture2D g_LitTexture;
float4x4 g_mWorld;
float4x4 g_mWorldViewProjection;
VtxNormalPass VSNormalPass(
float4 pos : POSITION,
float3 nor : NORMAL,
float2 tex : TEXCOORD0)
{
VtxNormalPass output;
output.spos = mul(pos, g_mWorldViewProjection);
output.wpos = mul(pos, g_mWorld);
output.wnor = mul(nor, g_mWorld);
return output;
}
PixOutput PSNormalPass(VtxNormalPass input)
{
float3 nor = normalize(input.wnor);
float phi = acos(nor.y);
float len = sin(phi);
float the = acos(clamp(nor.x / len, -1.0f, 1.0f));
if (nor.z <= 0.0f)
the = 6.283125f - the;
float z = length((input.wpos - g_vEyePos).xyz);
PixOutput output;
output.color = float4(the, phi, z, 4.0);
return output;
}
technique10 NormalPass
{
pass P0
{
SetVertexShader(CompileShader(vs_4_0, VSNormalPass()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PSNormalPass()));
SetRasterizerState(CullBack);
SetDepthStencilState(EnableDepth, 1);
SetBlendState(BSOverWrite, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
float3 nor = normalize(input.wnor);
float phi = acos(nor.y);
float len = sin(phi);
float the = acos(nor.x / len);
float the = acos(clamp(nor.x / len, -1.0f, 1.0f));
Forget everything, the geometry instancing is your best friend ! In the picture, I rendered 4800 2d rectangles in 1024x768 resolution. If each rectangle is rendered with one draw call, there are only 78 frames per second on my G1S. But if all of them are rendered by geometry instancing (which rendering 512 rectangles in one draw call), the fps jump to 662. (Of course, this is not exciting since you can do more complicated things with geometry instancing.)