- Home /
Does the projection matrix calculation affect the shader?
I'm working on a portal game with Unity. For the portal camera to see the world correctly, I do a matrix calculation like the one I see in github. I also tried the matrix calculation used in the water script of unity and the MirrorReflection4 script in the unity wiki. The result has not changed.
The portal camera calculates the projection matrix correctly, but does not render certain materials correctly.
If I don't change the projection matrix of the camera, there is no problem.
I need to use a projection matrix for the portal camera. Otherwise, the camera displaying the portal can see the walls behind the portal and similar objects. But when I use the projection matrix, I encounter the problem mentioned above. Does anyone have an idea for the cause and solution of this problem?
I've uploaded a video to better understand my problem.
I still haven't found a solution :(
Sorry but your images do not work. Your text isn't really clear what materials are not rendered correctly. There shouldn't be any issues. However If you try to make the mirror reflection script working with your portal script, that wouldn't be so simple because both scripts do replace the projection matrix and calculate a custom oblique near clipping plane, but a totally different one. The mirror script sets the mirror plane as clipping plane and the portal script the portal plane.
You can not have two different near clipping planes. However you can add a manual clipping plane to a shader (requires just two vectors, a position and a normal) to additionally clip the scene at the specified plane. To test if a fragment is before or behind the clipping plane, just subtract the clipping plane position from the fragment worldspace position and calculate the dot product between the resulting vector and the plane normal. If the result is below 0, discard the fragment.
ps: Before someone tries to correct me: Yes it's possible to define the clipping plane just with a single Vector4 by using the usual normal form of a plane. This is probably a bit cheaper in the fragment shader.
Sorry. I updated the images. The projection matrix calculation in the reflection script was an example. I made a calculation like the github link I specified for the portal. I didn't use the reflection script for the portal.
I would like to explain the problem again: The shader that works correctly on the main camera does not work correctly on a camera where I calculate the projection matrix. $$anonymous$$y problem is not the miscalculation of the portal projection matrix (water reflection, etc.). I calculate the projection matrix correctly with the portal's clipping plane. But the camera doesn't render the shaders correctly. These shaders are unity's standard shaders (Glass refraction and Toon shaders).
I guess I don't know much about the Shaders. I don't understand what you're talking about in the second paragraph. I think you thought I wanted to cut the mesh according to the clipping plane.
Answer by hknylt · Jul 06, 2019 at 10:15 PM
Also, the projection matrix is reset when I use a post processing stack. I have learned that there is no solution yet. So my question is: how can I set up the F***ing portal camera with these restrictions? How will the portal camera work without using a projection matrix? :((