最近使用clipplane的時(shí)候,當(dāng)渲染物在固定管線的時(shí)候,一切正常,但當(dāng)渲染物用了vertexshader的時(shí)候,完全看不到了,找了很久也不知道問(wèn)題的所在。后來(lái)再看DX的SDK時(shí)才發(fā)現(xiàn)用錯(cuò)了。
SDK里是這樣描述的:
When the fixed function pipeline is used the plane equations are assumed to be in world space. When the programmable pipeline is used the plane equations are assumed to be in the clipping space (the same space as output vertices).
假如用了可編程管線,那么必須把截面變換回clip space里,clip space即攝像機(jī)的frusturm的空間。下面是代碼(OGRE的):
D3DXMATRIX xform;
D3DXMatrixMultiply(&xform, &mDxViewMat, &mDxProjMat);
D3DXMatrixInverse(&xform, NULL, &xform);
D3DXMatrixTranspose(&xform, &xform);
D3DXPlaneTransform(&dx9ClipPlane, &dx9ClipPlane, &xform);
這樣就沒(méi)問(wèn)題了!