Jul 30, 2009

screen space motion blur

I don`t know how to implement motion blur in general method. In the sample of d3d9, the document said that it renders each object many times before one present call. And d3d10 implement them by geometry shader. I`m lazy and wanna try GLSL in my Mac. So I made a simple demo to show motion blur in screen space. The general scene with 16 ugly water mellon :

Blurred in screen space :
You need 2 new render targets, let`s call them A & B. Blend your scene on A, then alpha blend B on A. After that, blend A to back buffer then switch A & B. It`s pretty simple since you don`t even need GLSL (if you can alpha blend in fix function pipeline). The alpha value used in the screen shot is 0.9. But there are some troubles in this method when the moving object overlapped in screen space......I guess you can image it, so there is no screenshot here :)

Jul 26, 2009

Anything wrong in glShaderSourceARB ?

It cost me many hours to find what was wrong with glShaderSourceARB. When I wrote this :

char v[128] =
"void main(void)\n"
"{\n"
" gl_Position = ftransform();\n"
"}\n";

glShaderSourceARB(shaderVtx, 1, (const GLcharARB**)&v, 0);

My application always crashed in "strlen". But if I change the code to :

char v[128] =
"void main(void)\n"
"{\n"
" gl_Position = ftransform();\n"
"}\n";

const GLcharARB* ppV[1] = {(GLcharARB*)v};

glShaderSourceARB(shaderVtx, 1, ppV, 0);

Everything is fine. Do I forget how to write C ? (Although I insert them in objective-c.) It looks like due to compiler setting since the first one works in sample of xcode.

20090802
Ok, nothing wrong except my careless style. This is a very basic pointer usage problem. "v" in the code does mean the start address of a string, but not a pointer to a string (althought the type is a pointer). That means "&v" is not in the memory. But why the sample works ? Because the sample pass "v" to another function which would generate a new local pointer to v, so we can find this pointer in memory. Luckily, no one would read this article. XD

Jul 21, 2009

Hello Watermelon !


Hello ! Watermelon ! You are so sweet in this summer. Actually, it`s "Hello world" of OpenGL. It`s my first OpenGL program (except the other one with OpenGL ES which is pretty simple). I wanna make something with OpenGL & GLSL & my Mac, that`s the reason why I start to swallow OpenGL.

Jul 17, 2009

在玩 WPF 3D 之前

也許WPF根本不打算支援3D,但是在確定這些項目前,WPF 3D 對我沒什麼吸引力:
  1. 有些時候不需要 face culling,這些時候不做會有比較好的效能。WPF一定做 face culling,當你不需要時,只能用兩組三角形來解決。
  2. 有越來越多的特效需要多個pass來完成,WPF似乎不管這件事。
  3. 有越來越多的特效需要換 render target,但是因為WPF的redering被完整封裝,沒辦法讓我胡搞。
  4. geometry 的 member 有缺,只有 vertex、index、texture coordinate、normal,在寫San Angels 的時候,我想在頂點上填色卻不知道怎麼辦。
  5. 光源必然影響整個scene tree。
  6. 想到再加。

Jul 16, 2009

Hello SyntaxHightlighter !


#include

int main()
{
printf("Hello SyntaxHightlighter !");
}


終於弄出來了,有興趣的話原始專案在這。當初在彩富還特別寫了個轉檔程式,沒想到有更漂亮的方法!幾點注意事項如下(參照本頁的原始碼):

  1. java script 的 source 可以放在blogspot提供的元件上(本頁最下面那條槓)。

  2. css 的 link 得直接放到head上。

  3. 放在blog上得在HightLightAll前加上dp.SyntaxHighlighter.BloggerMode();


現在比較頭痛的是script放在google page上,而google準備把google page移掉,雖然說會轉移,不過google site禁止上傳js檔,不知道到時會不會失效啊!

Jul 13, 2009

San Angeles in WPF


最近看 WPF 3D,可能是對SDK不夠熟,覺得WPF在3D的表現非常貧乏。上面是用WPF+C#,仿 San Angeles 寫了個小程式,看起來還很單調。不過這東西最吸引我的是super shape,所有的模型都是用super fomula算出來的。因為WPF的限制,加進去的光源會影響整個場景,但是我希望倒影是比較暗的,像這樣:
由於我懶得細想,所以直接疊了兩層viewport,一層畫倒影,一層畫實景,這樣變成分開的兩個場景,可以設不同的光源,最後得到比較接近原程式的結果。