Shielding detection method and system based on mobile platform shader
By using the occlusion detection method based on mobile platform shaders on mobile devices, the problem that traditional methods cannot accurately capture the object occlusion relationship is solved, efficient object occlusion detection is achieved, and the realism and interactivity of image rendering is enhanced.
Patent Information
- Application Number
- CN202311136602.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-05
- Publication Date
- 2025-03-07
AI Technical Summary
Traditional object occlusion calculation methods may not accurately capture the real occlusion relationship between objects on mobile devices, resulting in the occlusion effect being not realistic enough, affecting the realism and interactivity of image rendering.
The occlusion detection method based on the mobile platform shader is adopted, and the sampling points are predefined, the depth sampling points are calculated, the occlusion situation is judged, and the color value in the rendering effect is adjusted according to the occlusion degree.
Efficiently realize object occlusion detection on mobile devices, enhance the realism and interactivity of image rendering, and enhance the dazzling and vividness of mobile game pictures.
Smart Images

Figure CN119579878A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer communication technology, and in particular to an occlusion detection method and system based on a mobile platform shader. Background Art
[0002] In the field of image rendering and mobile applications, object occlusion effect is one of the key factors to enhance scene realism and interactivity. However, traditional object occlusion calculation methods may face performance challenges on mobile devices. Since some existing technologies use screen space approximation methods, they may not accurately capture the true occlusion relationship between objects, resulting in unrealistic occlusion effects. Summary of the invention
[0003] In order to solve the above technical problems, the present invention provides an occlusion detection method and system based on a mobile platform shader, which can efficiently implement object occlusion detection on a mobile device, thereby enhancing the realism and interactivity of image rendering.
[0004] The present invention is implemented by the following technical solution: an occlusion detection method based on a mobile platform shader, the method comprising the following steps:
[0005] Step S1, pre-define a set of sampling points for obtaining depth information values from different positions, and obtain parameters of each sampling point;
[0006] Step S2, using a loop to traverse the sampling points and calculate the corresponding depth sampling points;
[0007] Step S3, normalize and map the depth sampling points, map their coordinates to the range of 0-1, and then sample them in the depth texture to obtain the depth information value;
[0008] Step S4: compare the sampled depth information value with the threshold to determine whether the depth sampling point is blocked by other objects;
[0009] Step S5: if the depth sampling point is blocked by other objects, a set value is added to the original blocking degree value of the depth sampling point, and then the blocking degree values of all blocked points are added to obtain a final blocking degree value;
[0010] Step S6: adjusting the color value in the rendering effect according to the final occlusion degree value.
[0011] Preferably, the step S1 is further specifically as follows: after predefining a set of sampling points, the screen scale and the sampling xy direction distance (distancex, distancey) are calculated; the calculation formula is as follows:
[0012] scale = 1 / (width / height);
[0013] distancey=0.05;
[0014] distancex=distancey*scale;
[0015] in,
[0016] width is the screen width,
[0017] height is the screen height,
[0018] distancex is the sampling distance in the x direction,
[0019] distancey is the sampling distance in the y direction.
[0020] Preferably, the step S2 is further specifically as follows: in each loop iteration, according to the offset of the current sampling point in the screen space, the corresponding depth sampling point depthUv is calculated; the calculation formula is as follows:
[0021] depthUv=(distancex,distancey)*samplePoint[i]+center;
[0022] in,
[0023] Center is the position coordinate of the center point of the object on the screen.
[0024] depthUv is the coordinate of the depth sampling point,
[0025] samplePoint[i] is the sampling point, i represents the index, which is the sampling point.
[0026] Preferably, the step S3 is further specifically as follows: mapping the coordinates of the depth sampling point to a range of 0-1 by the following calculation formula:
[0027] depthUvClamp=depthUv*0.5+0.5;
[0028] in,
[0029] depthUvClamp is the coordinate of the depth sampling point mapped to the 0-1 range.
[0030] Preferably, the step S4 is further specified as follows: the threshold is 0.99, if the depth value is greater than 0 and less than 0.99, it indicates that the point is blocked by other objects, and if the depth value is greater than 0.99, it indicates that the point is not blocked by other objects.
[0031] Preferably, the step S5 is further specifically as follows: obtaining the set value by the following calculation formula:
[0032] Setting value = 1 / A,
[0033] Where A is the number of sampling points.
[0034] Preferably, the step S6 is further specifically as follows: according to the final occlusion degree value, adjusting the color value in the rendering effect to adjust and control the display, hiding, and semi-transparent effects; adjusting the color value in the rendering effect by the following calculation formula:
[0035] Final color value = original color value * occlusion degree value.
[0036] An occlusion detection system based on a mobile platform shader, the system comprising a pre-definition module, a traversal module, a mapping module, a judgment module, a calculation module and an adjustment module;
[0037] A predefined module predefines a set of sampling points for obtaining depth information values from different positions and obtaining parameters of each sampling point;
[0038] Traverse the module, use a loop to traverse the sampling points and calculate the corresponding depth sampling points;
[0039] The mapping module normalizes the depth sampling points, maps their coordinates to the range of 0-1, and then samples them in the depth texture to obtain the depth information value;
[0040] The judgment module compares the sampled depth information value with the threshold to determine whether the depth sampling point is blocked by other objects;
[0041] Calculation module: If the depth sampling point is blocked by other objects, a set value is added to the original occlusion degree value of the depth sampling point, and then the occlusion degree values of all blocked points are added to obtain the final occlusion degree value;
[0042] Adjust the module and adjust the color value in the rendering effect according to the final occlusion value.
[0043] Preferably, the predefined module is further specifically as follows: after predefining a set of sampling points, the screen scale and the sampling xy direction distance (distancex, distancey) are calculated; the calculation formula is as follows:
[0044] scale = 1 / (width / height);
[0045] distancey=0.05;
[0046] distancex=distancey*scale;
[0047] in,
[0048] width is the screen width,
[0049] height is the screen height,
[0050] distancex is the sampling distance in the x direction,
[0051] distancey is the sampling distance in the y direction.
[0052] Preferably, the traversal module is further specifically as follows: in each loop iteration, according to the offset of the current sampling point in the screen space, the corresponding depth sampling point depthUv is calculated; the calculation formula is as follows:
[0053] depthUv=(distancex,distancey)*samplePoint[i]+center;
[0054] in,
[0055] Center is the position coordinate of the center point of the object on the screen.
[0056] depthUv is the coordinate of the depth sampling point,
[0057] samplePoint[i] is the sampling point, i represents the index, which is the sampling point.
[0058] Preferably, the mapping module is further specifically configured to map the coordinates of the depth sampling points to a range of 0-1 by the following calculation formula:
[0059] depthUvClamp=depthUv*0.5+0.5;
[0060] in,
[0061] depthUvClamp is the coordinate of the depth sampling point mapped to the 0-1 range.
[0062] Preferably, the judgment module is further specified as follows: the threshold is 0.99, if the depth value is greater than 0 and less than 0.99, it means that the point is blocked by other objects, and if the depth value is greater than 0.99, it means that the point is not blocked by other objects.
[0063] Preferably, the calculation module is further specifically: obtaining the set value through the following calculation formula:
[0064] Setting value = 1 / A,
[0065] Where A is the number of sampling points.
[0066] Preferably, the adjustment module is further specifically: adjusting the color value in the rendering effect according to the final occlusion degree value to adjust and control the display, hiding, and semi-transparent effects; adjusting the color value in the rendering effect by the following calculation formula:
[0067] Final color value = original color value * occlusion degree value.
[0068] Beneficial effects of the present invention:
[0069] The present invention provides an occlusion detection method and system based on a mobile platform shader, which can efficiently realize object occlusion detection on a mobile device, thereby enhancing the realism and interactivity of image rendering; and can solve the occlusion problem of the halo effect in mobile games, making the game screen more dazzling and vivid. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] Figure 1 It is a schematic flow chart of the method of the present invention.
[0071] Figure 2 It is a system principle block diagram of the present invention. DETAILED DESCRIPTION
[0072] The present invention will be further described below in conjunction with the accompanying drawings.
[0073] See also Figure 1 The present invention provides an occlusion detection method based on a mobile platform shader, the method comprising the following steps:
[0074] Step S1, pre-define a set of sampling points for obtaining depth information values from different positions, and obtain parameters of each sampling point;
[0075] Step S2: use a loop to traverse the sampling points and calculate the corresponding depth sampling points, i.e., the uv value of the depth map, sample the depth map to obtain the depth information and perform normalized mapping;
[0076] Step S3, normalize and map the depth sampling points, map their coordinates to the range of 0-1, and then sample them in the depth texture to obtain the depth information value;
[0077] Step S4: compare the sampled depth information value with the threshold to determine whether the depth sampling point is blocked by other objects;
[0078] Step S5: if the depth sampling point is blocked by other objects, a set value is added to the original blocking degree value of the depth sampling point, and then the blocking degree values of all blocked points are added to obtain a final blocking degree value;
[0079] Step S6: adjusting the color value in the rendering effect according to the final occlusion degree value.
[0080] The present invention will be further described below in conjunction with a specific embodiment:
[0081] 1. Predefine a set of sampling points to obtain depth information from different positions and obtain the parameters of each sampling point;
[0082] 1.1. After defining a set of sampling points in advance, calculate the screen scale and the sampling xy direction distance (distancex, distancey); the calculation formula is as follows:
[0083] scale = 1 / (width / height);
[0084] distancey=0.05;
[0085] distancex=distancey*scale;
[0086] in,
[0087] width is the screen width,
[0088] height is the screen height,
[0089] distancex is the sampling distance in the x direction,
[0090] distancey is the sampling distance in the y direction.
[0091] For example:
[0092] const float2 samplePoint
[32] =
[0093] {float2(0.658752441,-0.0977704078),
[0094] float2(-0.678673446,0.120453641),
[0095] float2(-0.239791021,0.577527523),
[0096] float2(0.14785859,-0.304675519),
[0097] float2(-0.16471009,-0.170767933),
[0098] float2(0.109557107,-0.993980527),
[0099] float2(0.80428493,0.594243884),
[0100] float2(-0.313934922,0.949444473),
[0101] float2(0.979771316,-0.200120285),
[0102] float2(0.617167234,0.247610524),
[0103] float2(-0.305256099,-0.952270269),
[0104] float2(0.0982239097,0.995164275),
[0105] float2(-0.308868766,0.150203511),
[0106] float2(-0.912466347,-0.409151614),
[0107] float2(0.813257217,-0.581904233),
[0108] float2(-0.542099535,0.432246923),
[0109] float2(0.505380452,-0.862896621),
[0110] float2(-0.429447204,-0.501827657),
[0111] float2(-0.66682452,-0.74521476),
[0112] float2(0.0334240831,0.263438135),
[0113] float2(0.289210409,0.0226817727),
[0114] float2(-0.999996424,-0.00266989553),
[0115] float2(0.240315378,-0.653567195),
[0116] float2(0.386928111,0.480902404),
[0117] float2(0.50587368,-0.407543361),
[0118] float2(-0.672138274,0.740425646),
[0119] float2(0.493631095,0.869671345),
[0120] float2(0.97640425,0.215950698),
[0121] float2(-0.586166859,-0.196715489),
[0122] float2(0.0959918648,0.666364193),
[0123] float2(-0.914829493,0.403840065),
[0124] float2(-0.106764615,-0.618209302)};
[0125] scale = 1 / (width / height)
[0126] distancey=0.05;
[0127] distancex=distancey*scale;
[0128] in:
[0129] width screen width,
[0130] heightScreen height.
[0131] 2. Use a loop to traverse the sampling points and calculate the corresponding depth sampling points;
[0132] 2.1. In each loop iteration, the corresponding depth sampling point depthUv is calculated according to the offset of the current sampling point in screen space; the calculation formula is as follows:
[0133] depthUv=(distancex,distancey)*samplePoint[i]+center;
[0134] in,
[0135] Center is the position coordinate of the center point of the object on the screen.
[0136] depthUv is the coordinate of the depth sampling point,
[0137] samplePoint[i] is the sampling point, i represents the index, which is the sampling point.
[0138] 3. Normalize and map the depth sampling points, map their coordinates to the range of 0-1, so that they can be sampled in the depth texture; use the normalized depth coordinates obtained by sampling to sample in the depth texture to obtain the depth information of the object, and then convert the depth information to a value in the range of 0-1 for comparison;
[0139] The coordinates of the depth sampling point are mapped to the range of 0-1 using the following calculation formula:
[0140] depthUvClamp=depthUv*0.5+0.5;
[0141] in,
[0142] depthUvClamp is the coordinate of the depth sampling point mapped to the 0-1 range.
[0143] 4. Compare the sampled depth information with the threshold to determine whether the depth sampling point is blocked by other objects;
[0144] 4.1. The threshold is 0.99. If the depth value is greater than 0 and less than 0.99, it means that the point is blocked by other objects. If the depth value is greater than 0.99, it means that the point is not blocked by other objects.
[0145] 5. If the depth sampling point is blocked by other objects, a set value is added to the original occlusion value of the depth sampling point, and then the occlusion values of all blocked points are added together to obtain the final occlusion value;
[0146] 5.1. The set value is obtained by the following calculation formula:
[0147] Setting value = 1 / A,
[0148] Where A is the number of sampling points.
[0149] For example, there are 32 points in step 1, so the set value = 1 / 32 = 0.03125.
[0150] 6. Adjust the color value in the rendering effect according to the final occlusion value;
[0151] 6.1. According to the final occlusion value, adjust the color value in the rendering effect to adjust the display, hiding, semi-transparency and other effects; adjust the color value in the rendering effect through the following calculation formula:
[0152] Final color value = original color value * occlusion degree value.
[0153] Please continue reading Figure 2 , the present invention also provides an occlusion detection system based on a mobile platform shader, the system comprising a pre-definition module, a traversal module, a mapping module, a judgment module, a calculation module and an adjustment module;
[0154] A predefined module predefines a set of sampling points for obtaining depth information values from different positions and obtaining parameters of each sampling point;
[0155] Traverse the module, use a loop to traverse the sampling points and calculate the corresponding depth sampling points;
[0156] The mapping module normalizes the depth sampling points, maps their coordinates to the range of 0-1, and then samples them in the depth texture to obtain the depth information value;
[0157] The judgment module compares the sampled depth information value with the threshold to determine whether the depth sampling point is blocked by other objects;
[0158] Calculation module: If the depth sampling point is blocked by other objects, a set value is added to the original occlusion degree value of the depth sampling point, and then the occlusion degree values of all blocked points are added to obtain the final occlusion degree value;
[0159] Adjust the module and adjust the color value in the rendering effect according to the final occlusion value.
[0160] The predefined module is further specifically as follows: after predefining a set of sampling points, the screen scale and the sampling xy direction distance (distancex, distancey) are calculated; the calculation formula is as follows:
[0161] scale = 1 / (width / height);
[0162] distancey=0.05;
[0163] distancex=distancey*scale;
[0164] in,
[0165] width is the screen width,
[0166] height is the screen height,
[0167] distancex is the sampling distance in the x direction,
[0168] distancey is the sampling distance in the y direction.
[0169] The traversal module is further specifically as follows: in each loop iteration, according to the offset of the current sampling point in the screen space, the corresponding depth sampling point depthUv is calculated; the calculation formula is as follows:
[0170] depthUv=(distancex,distancey)*samplePoint[i]+center;
[0171] in,
[0172] Center is the position coordinate of the center point of the object on the screen.
[0173] depthUv is the coordinate of the depth sampling point,
[0174] samplePoint[i] is the sampling point, i represents the index, which is the sampling point.
[0175] The mapping module is further specifically configured to map the coordinates of the depth sampling points to a range of 0-1 using the following calculation formula:
[0176] depthUvClamp=depthUv*0.5+0.5;
[0177] in,
[0178] depthUvClamp is the coordinate of the depth sampling point mapped to the 0-1 range.
[0179] The judgment module is further specified as follows: the threshold is 0.99, if the depth value is greater than 0 and less than 0.99, it means that the point is blocked by other objects, if the depth value is greater than 0.99, it means that the point is not blocked by other objects.
[0180] The calculation module is further specifically: obtaining the set value through the following calculation formula:
[0181] Setting value = 1 / A,
[0182] Where A is the number of sampling points.
[0183] The adjustment module is further specifically configured to: adjust the color value in the rendering effect according to the final occlusion degree value to adjust and control the display, hiding, and semi-transparent effects; and adjust the color value in the rendering effect by the following calculation formula:
[0184] Final color value = original color value * occlusion degree value.
[0185] In summary, the present invention can efficiently implement object occlusion detection on mobile devices, thereby enhancing the realism and interactivity of image rendering; it can solve the occlusion problem of halo effects in mobile games, making the game screen more dazzling and vivid.
[0186] The above description is only a preferred embodiment of the present invention and should not be construed as limiting the present application. All equivalent changes and modifications made within the scope of the patent application of the present invention should fall within the scope of the present invention.
Claims
1. An occlusion detection method based on a mobile platform shader, characterized in that: The method comprises the following steps: Step S1, pre-define a set of sampling points for obtaining depth information values from different positions, and obtain parameters of each sampling point; Step S2, using a loop to traverse the sampling points and calculate the corresponding depth sampling points; Step S3, normalize and map the depth sampling points, map their coordinates to the range of 0-1, and then sample them in the depth texture to obtain the depth information value; Step S4: compare the sampled depth information value with the threshold to determine whether the depth sampling point is blocked by other objects; Step S5: if the depth sampling point is blocked by other objects, a set value is added to the original blocking degree value of the depth sampling point, and then the blocking degree values of all blocked points are added to obtain a final blocking degree value; Step S6: adjusting the color value in the rendering effect according to the final occlusion degree value.
2. The occlusion detection method based on mobile platform shader according to claim 1, characterized in that: The step S1 is further specifically as follows: after predefining a set of sampling points, the screen scale and the sampling xy direction distance (distancex, distancey) are calculated; the calculation formula is as follows: scale = 1 / (width / height); distancey=0.05; distancex=distancey*scale; in, width is the screen width, height is the screen height, distancex is the sampling distance in the x direction, distancey is the sampling distance in the y direction.
3. The occlusion detection method based on mobile platform shader according to claim 2, characterized in that: The step S2 is further specifically as follows: in each loop iteration, according to the offset of the current sampling point in the screen space, the corresponding depth sampling point depthUv is calculated; the calculation formula is as follows: depthUv=(distancex,distancey)*samplePoint[i]+center; in, Center is the position coordinate of the center point of the object on the screen. depthUv is the coordinate of the depth sampling point, samplePoint[i] is the sampling point, i represents the index, which is the sampling point.
4. The occlusion detection method based on mobile platform shader according to claim 3, characterized in that: The step S3 is further specifically as follows: mapping the coordinates of the depth sampling point to a range of 0-1 by the following calculation formula: depthUvClamp=depthUv*0.5+0.5; in, depthUvClamp is the coordinate of the depth sampling point mapped to the 0-1 range.
5. The occlusion detection method based on mobile platform shader according to claim 4, characterized in that: The step S4 is further specified as follows: the threshold is 0.99, if the depth value is greater than 0 and less than 0.99, it means that the point is blocked by other objects, and if the depth value is greater than 0.99, it means that the point is not blocked by other objects.
6. The occlusion detection method based on mobile platform shader according to claim 1, characterized in that: The step S5 is further specifically as follows: obtaining the set value by the following calculation formula: Setting value = 1 / A, Where A is the number of sampling points.
7. The occlusion detection method based on mobile platform shader according to claim 1, characterized in that: The step S6 is further specifically as follows: according to the final occlusion degree value, adjusting the color value in the rendering effect to adjust and control the display, hiding, and semi-transparent effects; adjusting the color value in the rendering effect by the following calculation formula: Final color value = original color value * occlusion degree value.
8. An occlusion detection system based on a mobile platform shader, characterized in that: The system includes a pre-definition module, a traversal module, a mapping module, a judgment module, a calculation module and an adjustment module; A predefined module predefines a set of sampling points for obtaining depth information values from different positions and obtaining parameters of each sampling point; Traverse the module, use a loop to traverse the sampling points and calculate the corresponding depth sampling points; The mapping module normalizes the depth sampling points, maps their coordinates to the range of 0-1, and then samples them in the depth texture to obtain the depth information value; The judgment module compares the sampled depth information value with the threshold to determine whether the depth sampling point is blocked by other objects; Calculation module: If the depth sampling point is blocked by other objects, a set value is added to the original occlusion degree value of the depth sampling point, and then the occlusion degree values of all blocked points are added to obtain the final occlusion degree value; Adjust the module and adjust the color value in the rendering effect according to the final occlusion value.
9. The mobile platform shader-based occlusion detection system according to claim 8, characterized in that: The predefined module is further specifically as follows: after predefining a set of sampling points, the screen scale and the sampling xy direction distance (distancex, distancey) are calculated; the calculation formula is as follows: scale = 1 / (width / height); distancey=0.05; distancex=distancey*scale; in, width is the screen width, height is the screen height, distancex is the sampling distance in the x direction, distancey is the sampling distance in the y direction.
10. The mobile platform shader-based occlusion detection system according to claim 9, characterized in that: The traversal module is further specifically as follows: in each loop iteration, according to the offset of the current sampling point in the screen space, the corresponding depth sampling point depthUv is calculated; the calculation formula is as follows: depthUv=(distancex,distancey)*samplePoint[i]+center; in, Center is the position coordinate of the center point of the object on the screen. depthUv is the coordinate of the depth sampling point, samplePoint[i] is the sampling point, i represents the index, which is the sampling point.
11. The mobile platform shader-based occlusion detection system according to claim 10, characterized in that: The mapping module is further specifically configured to map the coordinates of the depth sampling points to a range of 0-1 using the following calculation formula: depthUvClamp=depthUv*0.5+0.5; in, depthUvClamp is the coordinate of the depth sampling point mapped to the 0-1 range.
12. The mobile platform shader-based occlusion detection system according to claim 11, characterized in that: The judgment module is further specified as follows: the threshold is 0.99, if the depth value is greater than 0 and less than 0.99, it means that the point is blocked by other objects, if the depth value is greater than 0.99, it means that the point is not blocked by other objects.
13. The mobile platform shader-based occlusion detection system according to claim 8, characterized in that: The calculation module is further specifically: obtaining the set value through the following calculation formula: Setting value = 1 / A, Where A is the number of sampling points.
14. The mobile platform shader-based occlusion detection system according to claim 8, characterized in that: The adjustment module is further specifically configured to: adjust the color value in the rendering effect according to the final occlusion degree value to adjust and control the display, hiding, and semi-transparent effects; and adjust the color value in the rendering effect by the following calculation formula: Final color value = original color value * occlusion degree value.