Showing posts with label cg. Show all posts
Showing posts with label cg. Show all posts

Mar 18, 2012

disparity


for computer vision: disparity
for computer graphic: light map

Dec 19, 2010

SIGGRAPH ASIA 2010

第一次參加 conference,


paper 好多!


動畫好棒!


韓國好冷!

Mar 10, 2010

Line Rasterization

Dec 2, 2009

No distortion !

Fixed ! Direction of reflection is incorrect !

Dec 1, 2009

Nov 30, 2009

Better, but ...


Better, but there are some bugs.
1> Don`t know the root cause of distortion (back surface).
2> Some refraction are disappeared.
3> Both bottom-right & bottom-left corners are rendered with incorrect lighting.

Nov 25, 2009

Tired~

I feel tired today, and still don`t have better idea how to implement some details. So adding several lines to get this (hard code) only.

Sep 1, 2009

粗糙的lit pre pass


大概知道 lit pre pass 是怎麼一回事了,然後很嗨的用了一堆super shape 想做個太空都市,結果根本是個廢墟……試了一些東西,大致上可行,點光源還是用球做的,這次加上geometry instancing,應該可以用告示板來代替。之前沒仔細看wolf的blog,結果用兩個角度來表示法向量,但是如果法向量是在view space 裡的話,就可以直接存xy,因為對鏡頭來說,所有可見點的法向量 z都是負的!

現在又有別的問題了(MSAA),但是我想寫個炫點的小程式啊!

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

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 13, 2009

San Angeles in WPF


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

Jun 30, 2009

projection in vertex shader

一般的perspective projection :


在 vertex shader 動手腳的 projection:


不知道為什麼下圖有點走樣,不過似乎可以靠vertex shader 讓 z 值變成線性的,這樣的話應該可以避掉z fighting,效能差多少就不清楚了。

deferred lighting


In the beginning, I wanted to know how "light pre-pass" works. But I couldn`t catch that idea easily. Then I started to study defered lighting. Finally, I make a sample after wasting whole GPU powers. (yes, I implement it without any optimazation !) Here is a screenshot, 128 point lights rotate around each balls. It looks like the reflection of wave can be implemented by the same way.

Jun 29, 2009

UNORM v.s. UNORM_SRGB

DXGI_FORMAT_R8G8B8A8_UNORM_SRGB :



DXGI_FORMAT_R8G8B8A8_UNORM :


DXGI_FORMAT_R8G8B8A8_UNORM 才是我要的結果!dx 10 DXUT 的back buffer format 預設只選DXGI_FORMAT_R8G8B8A8_UNORM_SRGB!

p.s. 材質是這裡來的

Jun 1, 2009

some methods to optimized gui rendering.

I thought about gui rendering today and got some ideas. Here is a brief note (but this should be useless since ui rendering is an old topic).

Sometimes we have to render ui with 3d API such as d3d. For example, it`s hard to rendering ui with video without d3d on windows. The generic method to rendering gui is to render many "rectangle", like buttons, checkbox, combobox, etc. Each rectangle need one draw call. When there are too many controls (include text), it may call draw primitive too much times and start to affect the performance. There are some points we can try :

[1]. Sort entire gui rendering by texture. The first issue make us render rectangle one by one is : all images may not on the same texture. For controls that share the same texture we have a chance to draw many "triangle list" to reduce the draw call.

[2]. Separate gui to dynamic & static part. All controls share the same "dynamic" vertex buffer. For dynamic controls, changing vertex position to move their position. For static controls, their position is fixed. So all vertices in the buffer can sort by their state to 2 part, too. Then there is a chance to minimize the vertex update method.

[3]. All controls share the same "dynamic" index buffer. For those hided control, we can just ignore them by not applying index. Sort the index could get better performance, too.

[4]. If there is alpha controls, separate them to another pass......or everything is gone.

[5]. So now you can :
  1. get a single texture with all images of controls.
  2. update position of dynamic controls by update vertex buffer.
  3. update visibility of controls by update index buffer.
  4. collect all characters in the same texture (or less textures)
  5. pray.
[6]. I am kidding... please inform me if you tried it. 

May 4, 2009

thinking about depth buffer


我的 software rendering 用的 view matrix 跟 d3d 一樣,但是會有問題,這個問題也許是整個pipeline 最大的瓶頸。

主要的問題是這樣,為了讓 z 可以 mapping 到 near 跟 far plane,view matrix 裡會做些手腳,讓最後的 z 變成 (f / (f - n)) * (1 - n / z),如此一來,當 z 是n 時,深度為0,z 是 f 時深度為 1。上圖是 depth - z 的關係。問題出在 z 小於 0 的時候,depth是正的,如果在這時才作 z 方向上的 culling,那整個三角形的方向就錯了!如果這一塊是無法解決的,那整塊 mesh 就得在 normaliz 之前先跟 view frustum clip,結果則是產生更多的小三角形。讓我慶幸的是……我可以懶得管這件事,讓dx去解決。