- Home /
Inverse projection vertex shader
Hello , i'm working on some piece of code to create some volumetric 3dtexture mapped to the frustum of a camera. To create that volumetric texture i multiply some position vector with the inverse projection matrix. So my frustum and geometry inside become a normalized cube. This work so far if the model is inside frustum , but if vertices are far outisdes the frustum and cross the "eye view plane" my model got distorted. here is my code to transform position.
float4 Local = mul(mul(Projection,View),float4(WorldPos,1.0));
Local.xyz /=Local.w;
I believe the Local.w become 0 / negative or infinite at the point where vertices cross the eye view plane and then the model is not correct anymore. i tried a few things by checking if Local.w is equal 0 or smaller than 0 ... but nothing really worked for me atm. I would like to find a solution to keep the mesh inside my normalized frustum always correct. How to deal with this vertices crossing the eye view plane ? Here is a litle drawing of my problem , after applying inverse projection transform to my vector A and C are always correct , but i can't find a way to preserve B position after it cross the eye plane. I'm working with shader/compute shader .