A method for implementing viewport analysis in WebGL
By constructing a virtual camera and view frustum in WebGL, the technical challenge of view domain analysis in browsers is solved, enabling view domain analysis in browsers, which is applicable to maritime, aviation and military applications.
Patent Information
- Application Number
- CN202210290176.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-23
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-03-23
AI Technical Summary
Because end-to-end technical staff are unfamiliar with computer graphics and OpenGL, they are unable to implement certain functions using WebGL through simple operations, especially in performing viewport analysis in a browser.
By constructing a virtual camera, determining the world transformation matrix and perspective projection matrix, constructing a view frustum, and determining the positional relationship between the 3D model and the view frustum within the shader, the visible field of view is analyzed by combining depth map processing.
It enables visual domain analysis in a browser, leveraging the advantages of a B/S architecture, and is suitable for important applications in the maritime, aviation, and military fields, such as radar station deployment and flight path planning.
Smart Images

Figure CN114494561B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer graphics technology, specifically relating to a method for implementing viewport analysis in WebGL. Background Technology
[0002] WebGL (Web Graphics Library) is a 3D graphics protocol. This graphics technology standard allows JavaScript and OpenGL ES 2.0 to be combined. By adding a JavaScript binding to OpenGL ES 2.0, WebGL can provide hardware-accelerated 3D rendering for HTML5 Canvas. The WebGL 2.0 specification was released in January 2017. Since WebGL is not yet widely used in browser technology, front-end engineers who are not familiar with graphics and OpenGL cannot implement some functions by simply using the underlying API. Summary of the Invention
[0003] To overcome the shortcomings of the existing technology, the present invention provides a method for implementing viewport analysis in WebGL.
[0004] To achieve the above objectives, the present invention provides the following technical solution:
[0005] A method for implementing viewport analysis in WebGL includes the following steps:
[0006] Build a virtual camera;
[0007] The world transformation matrix of the virtual camera is determined by the position of the virtual camera, the rotation angle around the y-axis, and the rotation angle around the x-axis.
[0008] The perspective projection matrix of the virtual camera is determined based on the vertical opening angle, the horizontal opening angle, and the detection distance.
[0009] The virtual camera uses a point on the 3D model as the rendering point to render the 3D model and obtain a depth map;
[0010] The view frustum is constructed from the inverse of the world transformation matrix and the perspective projection matrix of the virtual camera;
[0011] From the perspective of the main camera, the positional relationship between the view frustum and the 3D model is determined within the shader. If the 3D model is located within the view frustum, the shader renders the 3D model; otherwise, the depth map is processed to obtain the final output depth value. Based on the relationship between the depth of the 3D model's rendered points and the final output depth value, it is determined whether the 3D model is visible.
[0012] Preferably, the world transformation matrix of the virtual camera is obtained according to the following formula:
[0013] M=R2(β)·R1(α)·T
[0014] In the formula, M is the world transformation matrix of the virtual camera;
[0015] R2(β) is the first rotation matrix determined by the angle β of the virtual camera's rotation around the x-axis.
[0016]
[0017] R1(α) is the second rotation matrix determined by the angle α of the virtual camera's rotation around the y-axis.
[0018]
[0019] T is the offset matrix determined by the coordinates (x, y, z) of the virtual camera.
[0020]
[0021] The specific expression of the world transformation matrix M of the virtual camera, calculated based on the first rotation matrix, the second rotation matrix, and the offset matrix, is as follows.
[0022]
[0023] Preferably, the perspective projection matrix P of the virtual camera is determined based on the following formula, according to the vertical opening angle A, the horizontal opening angle B, and the detection distance of the virtual camera.
[0024]
[0025] In the formula, near is the closest distance detected by the virtual camera, and far is the farthest distance detected by the virtual camera;
[0026] top = near * tan(A / 2)
[0027] bottom = top - height
[0028] Where,
[0029] height = 2 * top
[0030] left = -0.5 * width
[0031] right = left + width
[0032] Where,
[0033] width = aspect * height
[0034] Where,
[0035] aspect = tan(B) / tan(A)
[0036] The perspective projection matrix P is simplified as follows:
[0037]
[0038] Preferably, the step of using a point on the 3D model as the rendering point to render the 3D model and obtain a depth map includes:
[0039] Based on the following formula, a virtual camera is used to sequentially perform modeling changes, observation changes, projection changes, normalized coordinate transformations, and viewport changes on the 3D model;
[0040]
[0041] In the formula, P is the perspective projection matrix of the virtual camera, and V -1 Let (x, y, z) be the inverse of the world transformation matrix of the virtual camera, and (x, y, z) be the coordinates of the rendering point.
[0042] M1 is the world transformation matrix of the 3D model. The world transformation matrix M1 of the 3D model is obtained by performing matrix transformations of translation, rotation and scaling on the 3D model in sequence.
[0043] The final output depth value is calculated based on the changed 3D model parameters.
[0044]
[0045] The final output depth value is a floating-point number between 0 and 1.0;
[0046] The final output depth value is encoded and stored using four RGBA channels to obtain a depth map.
[0047] Preferably, the step of constructing the visual frustum from the inverse of the world transformation matrix and the perspective projection matrix of the virtual camera includes:
[0048] The observation projection transformation matrix is constructed based on the inverse of the virtual camera's world transformation matrix and the perspective projection matrix, according to the following formula:
[0049]
[0050] In the formula, P is the perspective projection matrix of the virtual camera, and M... -1 This is the inverse of the world transformation matrix of the virtual camera;
[0051] A six-sided frustum is constructed based on the observation projection transformation matrix. The six faces of the six-sided frustum are represented as: p1, p2, p3, p4, p5, p6, p7, p8, p9, p1, p1, p1, p1, p2, p1, p1, p2, p3 ...2, p1, p2, p3, p1, p1, p2, p1, p1 2, p3, p4, p5, p6
[0052] Where, the normal vector of p1 is the unit vector.
[0053] normalize(a 03 -a 00 a 13 -a 10 a 23 -a 20 );
[0054] The distance of p1 from the origin is,
[0055] (a 33 -a 30 ) / length(a 03 -a 00 a 13 -a 10 a 23 -a 20 );
[0056] The normal vector of p2 is the unit vector.
[0057] normalize(a 03 +a 00 a 13 +a 10, a 23 +a 20 );
[0058] The distance of p2 from the origin is,
[0059] (a 33 +a 30 ) / length(a 03 +a 00 a 13 +a 10 a 23 +a 20 );
[0060] The normal vector of p3 is the unit vector.
[0061] normalize(a 03 +a 01 a 13 +a 11 a 23 +a 21 );
[0062] The distance of p3 from the origin is,
[0063] (a 33 +a 31 ) / length(a 03 +a01 a 13 +a 11 a 23 +a 21 );
[0064] The normal vector of p4 is the unit vector.
[0065] normalize(a 03 -a 01 a 13 -a 11, a 23 -a 21 );
[0066] The distance of p4 from the origin is,
[0067] (a 33 -a 31 ) / length(a 03 -a 01 a 13 -a 11 a 23 -a 21 );
[0068] The normal vector of p5 is the unit vector.
[0069] normalize(a 03 -a 02 a 13 -a 12 a 23 -a 22 );
[0070] The distance of p5 from the origin is,
[0071] (a 33 -a 32 ) / length(a 03 -a 02 a 13 -a 12 a 23 -a 22 );
[0072] The normal vector of p6 is the unit vector.
[0073] normalize(a 03 +a 02 a 13 +a 12 a 23 +a 22 );
[0074] The distance of p6 from the origin is,
[0075] (a 33 +a 32 ) / length(a 03 +a 02 a 13 +a 12 a 23 +a 22 );
[0076] In the formula, the normalize() function is used to find the unit vector of a vector, and the length() function is used to find the Euclidean length of a vector.
[0077] Preferably, the step of determining the positional relationship between the view frustum and the 3D model within the shader includes:
[0078] Determine the positional relationship between the 3D model and the view frustum based on the distances from points on the 3D model to each plane of the view frustum; wherein, the distance from a point on the 3D model to a plane of the view frustum is calculated according to the following formula.
[0079]
[0080] In the formula, D is the distance from a point on the three-dimensional model to each plane of the view frustum. Let N be the coordinates of a point on the 3D model, N be the unit vector of the normal vector of a plane of the view frustum, and distance be the Euclidean distance between a plane of the view frustum and the origin.
[0081] Preferably, the steps for obtaining the depth of the rendering points of the 3D model include:
[0082] The UV coordinates of the rendering point are calculated using the following formula;
[0083]
[0084] In the formula, P is the perspective projection matrix of the virtual camera, and M1 -1 M1 is the inverse of the world transformation matrix of the 3D model. The 3D model is transformed by translation, rotation and scaling matrix transformations in sequence to obtain the world transformation matrix M1 of the 3D model. (x, y, z) are the coordinates of the rendering point, and (X1, Y1, Z1) are the UV coordinates of the rendering point.
[0085] The pixel coordinates of the rendering point on the screen are calculated using the UV coordinates of the rendering point as (X1 / W1, Y1 / W1, Z1 / W1).
[0086] Calculate the depth value of the rendering point of the 3D model using the pixel coordinates of the rendering point.
[0087]
[0088] Preferably, the step of determining whether the 3D model is visible includes:
[0089] Read the depth map based on the UV coordinates of the rendering point;
[0090] Collect the RGBA value at the rendering point, decode the RGBA value, and the decoded RGBA value is the final output depth value;
[0091] If the depth value of the rendered point of the 3D model is greater than the final output depth value, the 3D model is not visible; otherwise, the 3D model is visible.
[0092] The method for implementing viewport analysis in WebGL provided by this invention has the following beneficial effects: 1. Viewport analysis is no longer limited to certain specialized software; it can be implemented using a browser, possessing all the advantages of a B / S architecture. 2. It has significant application value in navigation, aviation, and military fields, such as setting up radar stations, television broadcasting stations, road selection, and maritime navigation. In military applications, it can be used for deploying positions, setting up observation posts, and laying communication lines. Sometimes, it may also be necessary to analyze invisible areas, such as when low-altitude reconnaissance aircraft are flying, they need to avoid being detected by enemy radar as much as possible, and the aircraft should choose to fly in radar blind zones. Attached Figure Description
[0093] To more clearly illustrate the embodiments and design schemes of the present invention, the accompanying drawings required for this embodiment will be briefly described below. The drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0094] Figure 1 This is a flowchart of the method for implementing viewport analysis in WebGL according to Embodiment 1 of the present invention;
[0095] Figure 2 The image shows the result of the shader rendering the 3D model from the main camera angle in Embodiment 1 of the present invention.
[0096] Figure 3 This is a depth map of the three-dimensional model rendered by the shader in Embodiment 1 of the present invention;
[0097] Figure 4 This is a rendering result of a three-dimensional model by a virtual camera according to Embodiment 1 of the present invention;
[0098] Figure 5 This is a depth map of a 3D model rendered by the virtual camera in Embodiment 1 of the present invention. Detailed Implementation
[0099] To enable those skilled in the art to better understand and implement the technical solutions of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. The following embodiments are only used to more clearly illustrate the technical solutions of the present invention and should not be construed as limiting the scope of protection of the present invention.
[0100] Example 1
[0101] See Figure 1 A method for implementing viewport analysis in WebGL includes the following steps: constructing a virtual camera; determining the world transformation matrix of the virtual camera based on its position, rotation angle around the y-axis, and rotation angle around the x-axis; determining the perspective projection matrix of the virtual camera based on its vertical opening angle, horizontal opening angle, and detection distance; rendering the 3D model using a point on the virtual camera as the rendering point to obtain a depth map; constructing a view frustum using the inverse of the virtual camera's world transformation matrix and the perspective projection matrix; determining the positional relationship between the view frustum and the 3D model within the shader from the main camera's perspective; if the 3D model is located within the view frustum, rendering the 3D model; otherwise, processing the depth map to obtain the final output depth value, and determining whether the 3D model is visible based on the relationship between the depth of the rendered point of the 3D model and the final output depth value.
[0102] In this embodiment, the world transformation matrix of the virtual camera is obtained according to the following formula:
[0103] M=R2(β)·R1(α)·T
[0104] In the formula, M is the world transformation matrix of the virtual camera.
[0105] R2(β) is the first rotation matrix determined by the angle β of the virtual camera's rotation around the x-axis.
[0106]
[0107] R1(α) is the second rotation matrix determined by the angle α of the virtual camera's rotation around the y-axis.
[0108]
[0109] T is the offset matrix determined by the coordinates (x, y, z) of the virtual camera.
[0110]
[0111] The specific expression of the world transformation matrix M of the virtual camera, calculated based on the first rotation matrix, the second rotation matrix, and the offset matrix, is as follows.
[0112]
[0113] In this embodiment, the perspective projection matrix P of the virtual camera is determined based on the following formula, according to the vertical opening angle A, the horizontal opening angle B, and the detection distance of the virtual camera.
[0114]
[0115] In the formula, near is the closest distance detected by the virtual camera, and far is the farthest distance detected by the virtual camera;
[0116] top = near * tan(A / 2),
[0117] bottom = top - height
[0118] In the formula,
[0119] height = 2 * top,
[0120] left = -0.5 * width
[0121] right = left + width
[0122] In the formula,
[0123] width = aspect * height
[0124] In the formula,
[0125] aspect = tan(B) / tan(A),
[0126] The perspective projection matrix P is simplified as follows:
[0127]
[0128] Figure 3 In this embodiment, the depth map obtained by the virtual camera rendering the 3D model includes the following steps: The virtual camera uses a point on the 3D model as the rendering point to render the 3D model and obtain the depth map.
[0129] Based on the following formula, a virtual camera is used to sequentially perform modeling changes, observation changes, projection changes, normalized coordinate transformations, and viewport changes on the 3D model.
[0130]
[0131] In the formula, P is the perspective projection matrix of the virtual camera, and V -1M1 is the inverse of the virtual camera's world transformation matrix, where (x, y, z) are the coordinates of the rendering point. M2 is the world transformation matrix of the 3D model, obtained by sequentially performing translation, rotation, and scaling matrix transformations on the 3D model. The final output depth value is calculated based on the transformed 3D model parameters.
[0132] Because the viewport transformation matrix needs to be applied during viewport transformation. Normalize the transformed coordinates to the screen area.
[0133]
[0134] The final output depth value is a floating-point number between 0 and 1.0. This final output depth value is encoded and stored using four RGBA channels to obtain the depth map. This is because using only one channel of an RGBA array to store depth information would result in longitude loss. Therefore, the depth value needs to be encoded and stored using all four RGBA channels to improve longitude accuracy. Finally, it can be decoded when needed. Figure 4 A depth map rendered for the camera inside the scene (the depth map with the smallest retained depth value after depth testing).
[0135] In this embodiment, the step of constructing the view frustum from the inverse of the world transformation matrix and the perspective projection matrix of the virtual camera includes: constructing the view projection transformation matrix based on the inverse of the world transformation matrix and the perspective projection matrix of the virtual camera according to the following formula:
[0136]
[0137] In the formula, P is the perspective projection matrix of the virtual camera, and M... -1 It is the inverse of the world transformation matrix of the virtual camera.
[0138] Figure 5 This is a schematic diagram of one of the six planes of the viewing frustum. In this embodiment, a six-faceted viewing frustum is constructed based on the observation projection transformation matrix. The six faces of the six-faceted viewing frustum are represented as: p1, p2, p3, p4, p5, p6, p7, p8, p9, p1, p1, p1, p1, p2, p1, p1, p2, p3, p1, p2 ...1, p2, p3, p1, p2, p1, p2, p3, p1, p2, p1, p2, p 2, p3, p4, p5, p6.
[0139] Where, the normal vector of p1 is the unit vector.
[0140] normalize(a 03 -a 00 a 13 -a 10 a 23 -a 20 ).
[0141] The distance of p1 from the origin is,
[0142] (a 33 -a 30 ) / length(a 03 -a 00 a 13 -a 10 a 23 -a 20 ).
[0143] The normal vector of p2 is the unit vector.
[0144] normalize(a 03 +a 00 a 13 +a 10 a 23 +a 20 ).
[0145] The distance of p2 from the origin is,
[0146] (a 33 +a 30 ) / length(a 03 +a 00 a 13 +a 10 a 23 +a 20 ).
[0147] The normal vector of p3 is the unit vector.
[0148] normalize(a 03 +a 01 a 13 +a 11 a 23 +a 21 ).
[0149] The distance of p3 from the origin is,
[0150] (a 33 +a 31 ) / length(a 03 +a 01 a 13 +a 11 a 23 +a 21 ).
[0151] The normal vector of p4 is the unit vector.
[0152] normalize(a 03 -a 01 a 13 -a 11 a23 -a 21 ).
[0153] The distance of p4 from the origin is,
[0154] (a 33 -a 31 ) / length(a 03 -a 01 a 13 -a 11 a 23 -a 21 ).
[0155] The normal vector of p5 is the unit vector.
[0156] normalize(a 03 -a 02 a 13 -a 12 a 23 -a 22 )
[0157] The distance of p5 from the origin is,
[0158] (a 33 -a 32 ) / length(a 03 -a 02 a 13 -a 12 a 23 -a 22 ).
[0159] The normal vector of p6 is the unit vector.
[0160] normalize(a 03 +a 02 a 13 +a 12 a 23 +a 22 ).
[0161] The distance of p6 from the origin is,
[0162] (a 33 +a 32 ) / length(a 03 +a 02 a 13 +a 12 a 23 +a 22 ).
[0163] In the formula, the normalize() function is used to find the unit vector of a vector, and the length() function is used to find the Euclidean length of a vector.
[0164] Specifically, the steps for determining the positional relationship between the view frustum and the 3D model within the shader include: determining the positional relationship between the 3D model and the view frustum based on the distances from points on the 3D model to each plane of the view frustum; wherein, the distance from a point on the 3D model to a plane of the view frustum is calculated according to the following formula.
[0165]
[0166] In the formula, D is the distance from a point on the three-dimensional model to each plane of the view frustum. Let N be the coordinates of a point on the 3D model, N be the unit vector of the normal vector of a plane of the view frustum, and distance be the Euclidean distance between a plane of the view frustum and the origin.
[0167] In this embodiment, the step of obtaining the depth of the rendering point of the 3D model includes: calculating the UV coordinates of the rendering point according to the following formula.
[0168]
[0169] In the formula, P is the perspective projection matrix of the virtual camera, and M1 -1 Let (x, y, z) be the inverse of the world transformation matrix of the 3D model, (x, y, z) be the coordinates of the rendering point, and (X1, Y1, Z1) be the UV coordinates of the rendering point.
[0170] The pixel coordinates of the rendering point are calculated using the UV coordinates of the rendering point as (X1 / W1, Y1 / W1, Z1 / W1).
[0171] The depth value of the 3D model is calculated using the pixel coordinates of the rendering points.
[0172]
[0173] Specifically, the steps to determine whether a 3D model is visible include: reading the depth map based on the UV coordinates of the rendering point; collecting the RGBA value at the rendering point, decoding the RGBA value, and the decoded RGBA value is the final output depth value; if the depth value of the 3D model rendering point is greater than the final output depth value, then the 3D model is not visible; otherwise, the 3D model is visible.
[0174] The above embodiments are merely preferred embodiments of the present invention, and the scope of protection of the present invention is not limited thereto. Any simple changes or equivalent substitutions of the technical solutions that can be obviously obtained by those skilled in the art within the scope of the technology disclosed in the present invention shall fall within the scope of protection of the present invention.
Claims
1. A method for implementing viewport analysis in WebGL, characterized in that, The following steps are involved: Build a virtual camera; The world transformation matrix of the virtual camera is determined by the position of the virtual camera, the rotation angle around the y-axis, and the rotation angle around the x-axis; The perspective projection matrix of the virtual camera is determined based on the vertical opening angle, the horizontal opening angle, and the detection distance. The virtual camera uses a point on the 3D model as the rendering point to render the 3D model and obtain a depth map; The view frustum is constructed from the inverse of the world transformation matrix and the perspective projection matrix of the virtual camera; From the perspective of the main camera, the positional relationship between the view frustum and the 3D model is determined within the shader. If the 3D model is located within the view frustum, the shader renders the 3D model; otherwise, the depth map is processed to obtain the final output depth value. Based on the relationship between the depth of the 3D model's rendered points and the final output depth value, it is determined whether the 3D model is visible. The virtual camera uses a point on the 3D model as the rendering point, and the steps for rendering the 3D model to obtain a depth map include: Based on the following formula, a virtual camera is used to sequentially perform modeling changes, observation changes, projection changes, normalized coordinate transformations, and viewport changes on the 3D model; In the formula, P is the perspective projection matrix of the virtual camera, and V -1 Let (x, y, z) be the inverse of the world transformation matrix of the virtual camera, and (x, y, z) be the coordinates of the rendering point. M1 is the world transformation matrix of the 3D model. The world transformation matrix M1 of the 3D model is obtained by performing matrix transformations of translation, rotation and scaling on the 3D model in sequence. The final output depth value is calculated based on the changed 3D model parameters. The final output depth value is a floating-point number between 0 and 1.0; The final output depth value is encoded and stored using four RGBA channels to obtain a depth map; The steps to obtain the depth of the rendering points of a 3D model include: The UV coordinates of the rendering point are calculated using the following formula; In the formula, P is the perspective projection matrix of the virtual camera, and M1 -1 M1 is the inverse of the world transformation matrix of the 3D model. The 3D model is transformed by translation, rotation and scaling in sequence to obtain the world transformation matrix M1 of the 3D model. (x,y,z) are the coordinates of the rendering point and (X1,Y1,Z1) are the UV coordinates of the rendering point. The pixel coordinates of the rendering point on the screen are calculated using the UV coordinates of the rendering point as (X1 / W1, Y1 / W1, Z1 / W1). Calculate the depth value of the rendering point of the 3D model using the pixel coordinates of the rendering point. The steps for determining whether a 3D model is visible include: Read the depth map based on the UV coordinates of the rendering point; Collect the RGBA value at the rendering point, decode the RGBA value, and the decoded RGBA value is the final output depth value; If the depth value of the rendered point of the 3D model is greater than the final output depth value, the 3D model is not visible; otherwise, the 3D model is visible.
2. The method for implementing viewport analysis in WebGL according to claim 1, characterized in that, The world transformation matrix of the virtual camera can be obtained using the following formula. M=R2(β)·R1(α)·T In the formula, M is the world transformation matrix of the virtual camera; R2(β) is the first rotation matrix determined by the angle β of the virtual camera's rotation around the x-axis. R1(α) is the second rotation matrix determined by the angle α of the virtual camera's rotation around the y-axis. T is the offset matrix determined by the coordinates (x, y, z) of the virtual camera. The specific expression of the world transformation matrix M of the virtual camera, calculated based on the first rotation matrix, the second rotation matrix, and the offset matrix, is as follows.
3. The method for implementing viewport analysis in WebGL according to claim 1, characterized in that, The perspective projection matrix P of the virtual camera is determined based on the following formula, which includes the vertical opening angle A, the horizontal opening angle B, and the detection distance. In the formula, near is the closest distance detected by the virtual camera, and far is the farthest distance detected by the virtual camera; top = near * tan(A / 2) bottom = top - height In the formula, height = 2 * top left = -0.5 * width right = left + width In the formula, width = aspect * height In the formula, aspect = tan(B) / tan(A) The perspective projection matrix P is simplified as follows:
4. The method for implementing viewport analysis in WebGL according to claim 1, characterized in that, The steps of constructing the visual frustum from the inverse of the virtual camera's world transformation matrix and the perspective projection matrix include: The observation projection transformation matrix is constructed based on the inverse of the virtual camera's world transformation matrix and the perspective projection matrix, according to the following formula: In the formula, P is the perspective projection matrix of the virtual camera, and M... -1 This is the inverse of the world transformation matrix of the virtual camera; A six-faceted frustum is constructed based on the observation projection transformation matrix. The six faces of the six-faceted frustum are represented as: p1, p2, p3, p4, p5, p6. Where, the normal vector of p1 is the unit vector. normalize(a 03 -a 00 ,a 13 -a 10 ,a 23 -a 20 ); The distance of p1 from the origin is, (a 33 -a 30 ) / length(a 03 -a 00 ,a 13 -a 10 ,a 23 -a 20 ); The normal vector of p2 is the unit vector. normalize(a 03 +a 00 ,a 13 +a 10 ,a 23 +a 20 ); The distance of p2 from the origin is, (a 33 +a 30 ) / length(a 03 +a 00 ,a 13 +a 10 ,a 23 +a 20 ); The normal vector of p3 is the unit vector. normalize(a 03 +a 01 ,a 13 +a 11 ,a 23 +a 21 ); The distance of p3 from the origin is, (a 33 +a 31 ) / length(a 03 +a 01 ,a 13 +a 11 ,a 23 +a 21 ); The normal vector of p4 is the unit vector. normalize(a 03 -a 01 ,a 13 -a 11 ,a 23 -a 21 ); The distance of p4 from the origin is, (a 33 -a 31 ) / length(a 03 -a 01 ,a 13 -a 11 ,a 23 -a 21 ); The normal vector of p5 is the unit vector. normalize(a 03 -a 02 ,a 13 -a 12 ,a 23 -a 22 ); The distance of p5 from the origin is, (a 33 -a 32 ) / length(a 03 -a 02 ,a 13 -a 12 ,a 23 -a 22 ); The normal vector of p6 is the unit vector. normalize(a 03 +a 02 ,a 13 +a 12 ,a 23 +a 22 ); The distance of p6 from the origin is, (a 33 +a 32 ) / length(a 03 +a 02 ,a 13 +a 12 ,a 23 +a 22 ); In the formula, the normalize() function is used to find the unit vector of a vector, and the length() function is used to find the Euclidean length of a vector.
5. The method for implementing viewport analysis in WebGL according to claim 1, characterized in that, The steps for determining the positional relationship between the view frustum and the 3D model within the shader include: Determine the positional relationship between the 3D model and the view frustum based on the distances from points on the 3D model to each plane of the view frustum; specifically, the distance from a point on the 3D model to a plane of the view frustum is calculated using the following formula: In the formula, D is the distance from a point on the three-dimensional model to each plane of the view frustum. Let be the coordinates of a point on the 3D model. is the unit vector of the normal vector of a plane of the view frustum, and distance is the Euclidean distance between a plane of the view frustum and the origin.
Citation Information
Patent Citations
Model rendering method and device
CN105894566A