Aug 29, 2009

regular expression for real

'(\\b0[xX][0-9a-fA-F]+\\b)|(\\b[0-9]*\\.[0-9]+f?\\b)|(\\b[0-9]+\\b)'

Add this to syntax highlighter to high light "numbers" in 3 format :
  • 0x204080FF
  • 3.14159f
  • 7

Aug 28, 2009

下一站?

下個星期一(20090831)是這張名片有效的最後一天,下個星期二就要到新公司報到了,又是一個全新的開始:新的工作、新的同事和新的名片。轉移陣地不是因為遠大的目標,只是突然出現的機會加快了我的腳步。

感到遺憾的事:
  • 等級不到三!
  • 沒在p4上寫笑話!
  • 沒跟review team吵過架!
  • 沒有3d!
  • 沒有gf!
感到高興的事:
  • 轉team!
  • 好同事!
  • 沒了!
收護:
  • 進過大公司!
  • 進過軟體公司!
  • 比較懂3d了!
  • coding skill比較好了(原因同上)。
不爽的事:
  • .-.. . --. .- -.-. -.--
  • ..-. .. -..- -.-. --- -- .--. --- -. . -. -
  • .-- . .- -.- ... -.- .. .-.. .-..
該吃飯了,想到再寫。

syntax highlighter for HLSL10

After add a new brush js to SyntaxHighLighter :


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);
}
}

Aug 26, 2009

Trigonometric function explosion

這幾天寫HLSL碰到一個怪問題,存nomal的texture上總是會有多餘的碎片,原因大概是經過一連串三角函數的運算,不知道是三角函數還是浮點數出了問題,導致這段程式最後的the在應該接近π時變成非正數(小於等於0):

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));

Aug 22, 2009

不負責任單車遊記

公司單車社中社路前補胎。

Ryo + Ivan,我跟dynacolor的同事去北海岸湊熱鬧。

Aug 17, 2009

ui rendering optimization

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.)

Aug 14, 2009

塗鴉

跟同事e-mail 時的塗鴉: