Some time ago, the implementation of dynamic surface inversion and refraction was done. In this case, the camera needs to be set up at different locations on the surface of the water, and the scene texture under the refraction or reflection needs to be generated for the cropping plane on the water surface. You can use the cropping plane method provided by d3d or the custom shader method. Another method is to directly modify the projection matrix to change the original near plane to a specified plane, this is actually equivalent to constructing and obtaining an irregular view cone (oblique view frustum). Aside from the applicability of this method, at least the derivation of the relationship between the projection matrix and the cone is of great significance, so here is a brief summary.
1. Basic Relationship Between transformation matrix and cone planeFor spatial points, the transformation from the view space to the cropping space can be directly completed by the projection matrix transformation:
For spatial vectors and planes, the transformation from the view space to the cropped space requires the reverse transpose of the projection matrix:
SubscriptC, V
Used to identify the space system in, suchCCilp-space,VView-sapce. Most reversible projection matrices have the following features:
Therefore, the above formula can be converted:
Using the preceding formula and the equations of each cropping plane of the cone in the projection space, we can obtain the equation representation of these cropping planes in the view space, the corresponding relationship is as follows (convert the above formula to the originalM:
The preceding formula also provides a method to obtain the six constrained plane equations of the view cone in the view space from the projection matrix.MCIProjection MatrixMTheI
Column. Of course, if you want to obtain the equations of the cone plane in other spaces, you can use the same reasoning method: for example, you can use viewprojection matrix instead of projection matrix to obtain the equations in these plane world spaces.
Next, we can use the above basic relationship to derive the irregular cone projection matrix.
2. Calculation of Oblique distance plane
In a view space, the near plane in a cone is represented (for a point on it), and the element in the projection matrix corresponding to its pair is representedN
= MC3In this case, if you want to change the near shear plane, you need to modify the corresponding projection matrix component.MC3. Assuming that the new near plane after modification is, the corresponding far plane will also be affected by the change of the projection matrix element.
If there are no other conditions, the modification of the distance plane cannot be started. However, the modification of the distance plane can be constrained from the following two aspects:
- The angle between the modified distance plane must be as small as possible to ensure thatZThe value ratio is as similar as possible (the original distance cropping plane is parallel to each other, so the final projection obtainedZThe value is even, and the modified distance plane is no longer parallel, so the obtained attempt value is not even.ZThis constraint is required for value consideration)
- The modified far plane must contain vertices on the original cone's far plane. The strabismus cone is mainly used to perform irregular cropping on the near plane. Therefore, it is necessary to avoid improper removal of objects in the original cone as much as possible. Therefore, it is required that the far plane contain the original cone as much as possible.
The preceding constraints also apply to the far and near plane.F' = Mc4-C'Adjust the reasonable position and direction, which mainly includes three factorsMC3, mc4, C';Mc4
It cannot be changed directly, because it contains the corresponding elements for normalization after the projection transformation; for the planeC'All modifications do not affect the original flat attribute, but only the numeric value. Therefore, the change to C' is restricted to adding and adjusting a scaling factor.MC3The changes are relatively free. In this way, the modified near plane can beN'AndMC3The relationship is changed. In this caseF'Is:
The final constraint obtained in this way is to include the modified far plane just several points on the far plane of the original cone, and the point on the far from the modified near planeQMust be in the far plane (in the cropping space and view space to meet these features ). If the modified distance plane isN', f', AndN'The farthest point on the corresponding cone isQV. PointQVThe corresponding vertex in the cropping space isQC
= Qv m, QCYou can also crop the orientation of the near plane in the spaceZThe offset in the axis direction is determined, which can be expressed:
Sort out the aboveF', QC, QVThe relationship between them can be:
In this way, the modified part of the projection matrix can be obtained.MC3The new statement is:
And there are:
3. Effects of the strabismus cone on the Z value
We can see that the modifications to the custom irregular cropping cone can be found throughM'c3. The relationship between the projection matrix and the distance plane in d3d is as follows:
The corresponding inverse matrix is:
The simplifiedM'c3It can be expressed:
At the same time, it can be simplified.QVExpression:
Then:
Here, we can use the near-plane equation in the original view space to verify the above transformation formula.
In this case, the original projection matrix is also obtained. However, we need to analyze the final transformation of the projection matrix obtained by these operations.ZImpact of values: Because the irregular cropping cone produces two non-parallel near-distant planes, different resolutions are obtained in different directions of the line of sight.ZValue (the greater the degree of inequality,Z
The larger the value is, the worse the algorithm is .)ZValue rendering operations may have adverse effects (for example, ssao needs to be used ).ZThe value is used as the pseudo space information for occlusion calculation.ZValues correspond to different visual effects ). The angle between the distance and the plane (that is, the degree of parallelism) DeterminesZThe uniformity of the value is also the advantage and disadvantage of this method, and the angle between the distance and the plane is affected by two aspects:
- The degree to which the modified near-Plane Method deviates from the line of sight. The larger the deflection, the closer the distance, the more parallel the plane.
- The distance from the original far plane to the viewpoint. The greater the distance, the greater the degree of parallelism.
Therefore, these restrictions may limit the scope of use of this method.
For more information, refer to this article: oblique view frustum depth projection and clipping.