WO2016045298A1 - 阴影体的建立方法及装置 - Google Patents

阴影体的建立方法及装置 Download PDF

Info

Publication number
WO2016045298A1
WO2016045298A1 PCT/CN2015/072334 CN2015072334W WO2016045298A1 WO 2016045298 A1 WO2016045298 A1 WO 2016045298A1 CN 2015072334 W CN2015072334 W CN 2015072334W WO 2016045298 A1 WO2016045298 A1 WO 2016045298A1
Authority
WO
WIPO (PCT)
Prior art keywords
edge
hash table
value
data
depth map
Prior art date
Application number
PCT/CN2015/072334
Other languages
English (en)
French (fr)
Inventor
刘明
樊增智
贾霞
方晓鑫
董振江
盛斌
王睿
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016045298A1 publication Critical patent/WO2016045298A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/003D [Three Dimensional] image rendering
    • G06T15/50Lighting effects
    • G06T15/60Shadow generation

Definitions

  • the present invention relates to the field of computer graphics rendering, and more particularly to a method and apparatus for establishing a shadow body.
  • Shadow is a certain area where the light in the space is blocked. Shadow effects can help people better sense the distance and relative position between objects, while helping people to obtain information such as the shape of shadow masks and shadow receivers.
  • the efficiency of the shadow body algorithm is always limited by two key steps: one is the detection of the silhouette edges, and the other is the rendering of the shadow body. Since the previous step will greatly affect the workload of the latter step, improving the edge edge detection efficiency is a key to improving the efficiency of the overall algorithm.
  • the edge detection is usually not performed, but all the edges on the front side are used to construct the shadow body. This does reduce the burden on the CPU, but a large number of redundant edges are used to construct the shadow body, which greatly increases the burden on the GPU.
  • the present invention provides a method and apparatus for rendering a shadow to at least solve the above problems.
  • a method for establishing a shadow body comprising: culling a non-contour edge of the object in the depth map according to a hash algorithm in a depth map of an object to be shaded And finding all the silhouette edges of the object in the depth map; establishing a shadow body of the object according to the all silhouette edges;
  • the method further includes: creating a corresponding light source for saving the object An array of vertices for all edge data on the front of the object.
  • finding all the silhouette edges of the object in the depth map according to a hash algorithm comprises: traversing all edge data in the vertex array; calculating, for each side data of all the edge data Determining a key value of the edge data, and searching for a position corresponding to the edge data in a pre-established hash table according to the key value; determining that the edge corresponding to the edge data is a silhouette edge when no overlapping edge is found at the position
  • the first hash table value corresponding to the repeated edge is the same as the second hash table value, and the first hash table value and/or the second hash table value is determined according to the key value
  • the second hash table value is a hash table value of the edge indicated by the side data.
  • the non-contour edge of the object in the depth map is culled according to a hash algorithm, including: when the repeated edge is found at the position, determining whether the index values of the two vertices of the edge data are equal; if yes, The edge corresponding to the edge data is culled.
  • finding all the silhouette edges of the object in the depth map according to the hash algorithm includes: adding 2N to the key value of the edge data when the index values of the two vertices of the edge data are not equal -1, wherein the N is the number of collision cycles, and the position corresponding to the side data is searched in the pre-established hash table according to the value of the key value plus 2N-1.
  • the key value KEY of the side data is calculated according to the following formula: Wherein, V A and V B are index values respectively corresponding to the two vertices, and MAX is a size of the hash table.
  • a shadow body establishing apparatus comprising: a culling module, configured to: in a depth map of an object to be shaded, according to a hash algorithm a non-contour edge culling of the object; a search module for finding all the silhouette edges of the object in the depth map according to a hash algorithm; and establishing a module for establishing a shadow of the object according to the all contour edges body.
  • the apparatus further comprises: a creation module configured to create an array of vertices for storing all side data of the front side of the object corresponding to the light source of the object.
  • a creation module configured to create an array of vertices for storing all side data of the front side of the object corresponding to the light source of the object.
  • the searching module comprises: a traversing unit configured to traverse all side data in the vertex array; and a calculating unit configured to calculate a key of the side data for each side of the all side data a value; a search unit configured to search for a location corresponding to the edge data in a pre-established hash table according to the key value; and a determining unit configured to determine that the edge data corresponds to when no duplicate edge is found at the location
  • the edge of the edge is a silhouette edge, wherein the first hash table value corresponding to the repeated edge is the same as the value of the second hash table, the first hash table
  • the value and/or the second hash table value is determined according to the key value, wherein the second hash table value is a hash table value of the edge indicated by the side data.
  • the culling module comprises: a judging unit configured to determine whether an index value of two vertices of the side data is equal when the repeated edge is found at the position; and the culling unit is set to be at the two vertices When the index values are equal, the edges corresponding to the edge data are culled.
  • the technical solution for finding the contour edge based on the hash algorithm and determining the shadow body based on the contour edge is solved, and the technical solution for constructing the shadow body in the related art is greatly increased, and the burden of the GPU is greatly increased, and the implementation does not increase.
  • the contour edge is accurately detected, which greatly improves the efficiency.
  • FIG. 1 is a flow chart of a method of establishing a shadow body according to an embodiment of the present invention
  • FIG. 2 is a schematic diagram of adding a new edge to a hash table according to an embodiment of the present invention
  • FIG. 3 is a general flowchart of rendering a shadow according to an embodiment of the present invention.
  • FIG. 4 is a structural block diagram of a shadow body establishing apparatus according to an embodiment of the present invention.
  • FIG. 5 is a block diagram showing still another structure of a shadow body establishing apparatus according to an embodiment of the present invention.
  • FIG. 6 is a schematic diagram of a shadow algorithm according to an embodiment of the present invention.
  • FIG. 7 is a schematic diagram of a Z-pass detection method according to an embodiment of the invention.
  • FIG. 1 is a flowchart of a method for establishing a shadow body according to an embodiment of the present invention. As shown in FIG. 1, the method includes the following steps:
  • Step S102 In the depth map of the object to be shaded, the non-contour edge of the object in the depth map is removed according to a hash algorithm, and all the silhouette edges of the object in the depth map are found;
  • Step S104 The shadow body of the above object is established according to all the silhouette edges described above.
  • the hash algorithm is used to quickly find the contour edge used to establish the shadow body, and the technical solution for determining the shadow body based on the contour edge is solved, and the technical solution for constructing the shadow body in the related art is greatly increased.
  • the burden of the GPU achieves a fast and accurate detection of the silhouette edge without increasing the CPU load, which greatly improves the efficiency.
  • the method further includes: creating a front surface of the object for storing the corresponding light source of the object An array of vertices for all edge data.
  • searching for all the silhouette edges of the object in the depth map according to the hash algorithm includes: traversing all the edge data in the vertex array; and calculating the edge for each side data of all the edge data
  • the key value of the data and searching for the position corresponding to the edge data in the pre-established hash table according to the above key value; when no overlapping edge is found at the above position, determining that the edge corresponding to the edge data is a silhouette edge, wherein the repetition
  • the first hash table value corresponding to the edge is the same as the second hash table value, and the hash table value is determined according to the key value, wherein the second hash table value is a hash table of the edge indicated by the edge data. value.
  • the key value KEY of the above edge data is calculated according to the following formula: Wherein, V A and V B are index values respectively corresponding to the two vertices, and MAX is the size of the hash table.
  • the repeated edge when the repeated edge is found at the above location, it is determined whether the index values of the two vertices of the edge data are equal; if yes, the edge corresponding to the edge data is removed; And continuing to perform the above process of "finding all the silhouette edges of the above object in the depth map": that is, the key value of the above edge data is added by 2N-1, wherein the above N is the number of collision loops, and according to the above key value in advance Find the location of the edge data in the created hash table.
  • contour edge corresponding to the edge data is true, and the contour edge array is used to perform rendering processing on the shadow body.
  • a further improvement of the above technical solution in the embodiment of the present invention is to perform a template test on the shadow area of the shadow body according to the Z-pass algorithm, wherein the Z-pass algorithm is performed on the shadow area corresponding to the front surface of the object corresponding to the light source.
  • the Z-pass algorithm is performed on the shadow area corresponding to the front surface of the object corresponding to the light source.
  • the template buffer value of the shaded area is decremented by one. If not, the template buffer value is unchanged; and the shadow area corresponding to the back surface of the object corresponding to the light source is Z-
  • the depth test of the pass algorithm if the depth test passes, the template buffer value of the above shadow area is incremented by one, and if it is not passed, the template buffer value is unchanged.
  • FIG. 3 is a general flowchart of rendering a shadow according to an embodiment of the present invention. As shown in FIG. 3, the flow may include steps 1 to 3:
  • Step 1 Build a shadow body. This includes the reading of the scene file (that is, obtaining the depth map of the scene), the storage of the vertex data, the culling of the non-contour edges, and the preservation of the silhouette edge as a set of edges for creating the shadow body (you can use the hash algorithm to remove the silhouette edge, and extract the outline Side collection) and so on.
  • the shadow body edge array to be drawn is obtained, wherein the “non-contour edge culling” according to the hash algorithm is the main content of the embodiment of the present invention.
  • step 2 the shadow area is judged by the shadow body. Including rendering the shadow body, using the judgment algorithm to update the shadow area and so on. After this step, the shaded area marked with the stencil buffer is obtained.
  • Step 3 Draw the marked shaded area. This includes setting and drawing operations on the template buffer test method. After this step, the final shadow of the drawing is completed on the screen, and the rendered shadow layer is attached to the scene.
  • Step 1 specifically includes: first opening a depth buffer write operation (setting a command in openGL), reading the vertex information of the entire scene file, and then using the openGL command to load the vertex information for rendering, rendering Throughout the scene, the depth map of all objects is obtained after the first pass rendering, and the depth map is referenced by the user's real viewpoint. Then use the hash algorithm to process the outline edges of the object, excluding the edges of the outline. After culling, the silhouette edges are saved as an array. Then for each silhouette edge, project it to a distance, plus all the edges on the front side of the object to construct a shadow body. The edges of the entire shadow body are saved as an array, waiting for the rendering operation.
  • the following is a detailed description of the hash algorithm for the outline of the outline:
  • the hash-based non-contour edge culling technique is designed to improve the detection efficiency of the silhouette edges.
  • a point source and an indexed model file are used.
  • all of the patches on the occlusion model need to be tested to determine the front and back patches, ie, the patches facing the light source, either front or back, relative to the position of the light source.
  • the vector (the direction is directed to the light source) of the patch and the point vector of the patch's normal vector are used to determine the front and back.
  • the two vector points are multiplied by more than zero, it is the front patch, otherwise it is the back patch.
  • all edges need to be tested to determine the silhouette edges.
  • the Hash Table-based shadow body algorithm creates a shadow body for the entire object, that is, for finding the outline edge of the object, and using the silhouette edge to create a shadow body instead of creating a shadow body for all the triangular patches whose objects are on the front side. This greatly reduces the stress on the graphics hardware without adding a lot of computation.
  • the hash table is used to improve the contour edge search efficiency. By using the characteristics of the hash table, it is guaranteed that all non-contour edges can be eliminated after all the edges on the front side of the object have been traversed.
  • a hash table is used to improve the efficiency of detection.
  • a hash table is a data structure that is accessed directly based on key code values. It speeds up the lookup by mapping key values to a location in the table to access the stored data. This mapping function is called a hash function, and the array holding the records is called a hash table.
  • the hash algorithm can greatly increase the speed of the query.
  • the root of the hash algorithm lies in the setting of the hash function and the post-conflict processing method. In the setting of the hash function and the conflict processing method, the embodiment of the present invention designs the culling of the silhouette edge to ensure that the process is completed quickly and without error.
  • Hash tables provide a quick lookup feature. Each time you add a new edge, you can know if there are redundant edges in O(1) time. Because the same edge always maps to the same position in the hash table.
  • Each hash element in the hash table stores an unsigned integer for storing key values; two integers are used to store the index values of the endpoints; and a boolean value is used to store the placeholders.
  • MAX represents the size of the hash table
  • V A and V B represent the index values of the two endpoints, thus providing a fast and efficient way to calculate key values:
  • FIG. 2 is a schematic diagram of adding a new edge to a hash table in accordance with an embodiment of the present invention.
  • Figure 2 when you need to add a new edge, first calculate the key value, and then check the corresponding position in the hash table. Check the flag bit (placeholder). If the position is not occupied, the flag is false, store the index value of the endpoint, and change the flag to true. If it is already occupied, the flag is true, and the vertex values (index values) of the two endpoints of the two sides are compared exactly. If they are exactly equal, the proof finds a redundant edge and changes the placeholder to false (that is, resets the flag).
  • a conflict occurs if the endpoint's vertex values (index values) are not exactly equal (that is, partially equal). Add the new edge's key value to 2N-1, where N is the number of collision cycles. For example, if the conflict is encountered for the first time, the key value is incremented by 1, and the corresponding position is rechecked. If it still conflicts, add 3, and then loop until it finds the unoccupied position.
  • the Z-pass algorithm is used for template testing.
  • the Z-fail algorithm is used for template testing to get the correct result.
  • the following is a pseudo-code that uses a hash table to detect the silhouette edge algorithm:
  • Step 2 Turn off the write operation of the depth buffer, open the write operation of the template buffer, input the shadow body edge array, and render the shadow body.
  • Apply the Z-Pass algorithm to test: the front side of the shadow body, that is, the relative viewpoint point. If the depth test passes, the template buffer value corresponding to the corresponding pixel is incremented by one. If the depth test does not pass, the template buffer value is Invariant; for the back side of the shadow body, that is, the side far from the viewpoint, if the depth test does not pass, the stencil buffer value remains unchanged, and if the depth test passes, the stencil buffer value is decremented by one. After the shadow area is tested, the non-zero area of the stencil buffer is marked as a shaded area.
  • step 3 for the shadow area marked by the stencil buffer, set the pass condition of the template test to be non-zero, and then draw a shadow map covering the entire screen, the shadow map is only drawn in the area tested by the template, and the completion is completed. The final shadow is drawn.
  • the embodiment of the present invention since the idea of creating a shadow body for the entire object is adopted, that is, the shadow body is constructed according to each object, instead of each triangle, the number of triangular patches for constructing the shadow body is sharply reduced. At the same time, there is not a lot of calculations. Therefore, the number of triangular patches that the shadow body needs to render is greatly reduced, which greatly reduces the pressure on the graphics hardware and saves a lot of rendering time. The final rendering speed is much improved, and the fluency of the image is greatly improved when rendering complex scenes.
  • the algorithm of the embodiment of the present invention processes models of different complexity, the relationship between rendering efficiency and model complexity is close to linear.
  • the algorithm makes use of the fast search and delete capabilities provided by the hash table. It does not significantly increase the CPU usage when quickly finding the edges, which greatly improves the efficiency of shadow rendering.
  • a shadow body establishing device is further provided for implementing the above-mentioned embodiments and preferred embodiments.
  • the descriptions of the modules involved in the device will be described below.
  • the term "module” may implement a combination of software and/or hardware of a predetermined function.
  • the apparatus described in the following embodiments is preferably implemented in software, hardware, or a combination of software and hardware, is also Can and is conceived.
  • 4 is a block diagram showing the structure of a shading drawing apparatus according to an embodiment of the present invention. As shown in Figure 4, the device comprises:
  • the culling module 40 is configured to: in the depth map of the object to be shaded, the non-contour edge of the object in the depth map is removed according to a hash algorithm;
  • the searching module 42 is connected to the culling module 40 and configured to find all the silhouette edges of the object in the depth map according to the hash algorithm;
  • the building module 44 is coupled to the lookup module 42 and is configured to establish a shadow body of the object according to all of the contour edges described above.
  • the apparatus further includes: a creating module 46 configured to create an array of vertices for storing all side data of the front side of the object corresponding to the light source of the object.
  • the searching module 42 includes: a traversing unit 420 configured to traverse all edge data in the vertex array; and a calculating unit 422 connected to the traversing unit 420, configured to calculate the edge for each side of the data of all the edges
  • the key unit of the data is connected to the calculating unit 422, and configured to search for a position corresponding to the edge data in a pre-established hash table according to the key value;
  • the determining unit 426 is connected to the searching unit 424, and is set to be When the above position is not occupied, it is determined that the edge corresponding to the side data is a silhouette edge.
  • the culling module 40 includes: a determining unit 400, configured to determine whether the index values of the two vertices of the edge data are equal when the location is occupied;
  • the culling unit 402 is connected to the determining unit 400 and is configured to cull the side corresponding to the side data when the index values of the two top tops are equal.
  • the specific method of drawing a shadow is:
  • Step 1 After rendering the model under ambient light for the first time, a depth map of all objects is obtained. This depth map is based on the user's real viewpoint. Open the write operation switch of the depth buffer, render the entire scene, and get all the vertex information of the model according to the model. The vertex information will be saved in a vertex array. Correspondingly, there is an index array that holds the index information of the vertex. The so-called index array, that is, the content in the index array holds the number of indexes in the vertex array. The current position of the light source is also obtained.
  • Step 2 After all the information is obtained, create a shadow body. Traverse each triangle on the model. First check if it is on the front side relative to the light. If it is on the front side of the light, the triangle patch is added to the shaded array of vertices to be rendered. The three consecutive vertices in the vertex array represent a triangular patch. In the process of traversing each triangle, another vertex array is created to hold all the side data on the front side of the light source. Two consecutive vertices represent an edge. Then use the hash culling algorithm to remove the silhouette edges and save the silhouette edges as the set of edges that create the shadow body.
  • Step 3 After generating an array of silhouette edges, iterate through the array. Each edge consists of two vertices. Each vertex is projected to "infinity" to generate two additional vertices. These four vertices form a quad. Each edge is projected and a quadrangle is generated. These quadrilaterals are the sides of the shadow body. Together with the front and rear covers, the entire shadow body is formed. Each quad is divided into two triangles that are added to the shaded array of vertices to be rendered. In this way, all the vertex information about the shadow body is saved in the shaded array to be rendered. Find the silhouette edge of the object relative to the light source, that is, the edge separating the object from the front and back of the light source.
  • Figure 6 illustrates the principle of the shadow body. The purpose of drawing the shadow body is to test the shadow, so the shadow body will not end up on the screen, otherwise there will be extra shadow area.
  • Step 4 Set the type of the depth test to be less than or equal to the reference value. Turn off the depth buffer write operation. Set the type of template test to always pass. The test only depends on the results of the depth test. The buffer value of the template test is set to zero.
  • Step 5 Render the shadow body twice.
  • Template testing is used during rendering. Template testing can effectively utilize the GPU's hardware acceleration capabilities to quickly detect shadow areas.
  • the template test algorithm uses the Z-Pass algorithm to specifically test which areas are in the shadow. The basic principle of the Z-Pass algorithm is explained in Figure 7. A ray is drawn from the user's visual point to the object, called the line of sight. When the line of sight enters the shadow body, that is, from the outer surface of the shadow body to the inner surface, the template buffer value is increased by one, and when the line of sight passes through the shadow body, that is, from the inner surface of the shadow body to the outside. When the face is changed, the template buffer value is decremented by one.
  • the stencil buffer value of a certain area is zero, indicating that the number of entering and leaving the shadow body is equal, then the area The domain is not in the shadows.
  • the stencil buffer value is not zero, it means that the area is in the shadow.
  • the first rendering rejects the back side. If the depth test passes, the corresponding area template buffer value is incremented by one, otherwise it remains unchanged.
  • the corresponding area template buffer value is decremented by one, otherwise it remains unchanged. Then call the render command to render. In this step, you can also render the cull front for the first time and the second render cull. The corresponding operations should be exchanged in order, and the same effect can be obtained, which belongs to the same rendering process.
  • the depth buffer actually stores the depth value of the object that really needs to be displayed. Then, when the front side of the shadow body is first rendered, since the type of the depth test is set to be less than or equal to, that is, the depth value of the shadow body is smaller than the depth value of the actual object (indicating that the front side of the shadow body covers the object), At this time, the template buffer value of the corresponding area is increased by one. In the same situation, if the depth test is passed when the back of the shadow body is passed, the stencil buffer value is decremented by one. It should be noted that when rendering the shadow body, the color buffer write operation should be closed. Because you don't really need to draw the shadow body on the screen, just draw the shadow body to get the depth information to draw the shadow.
  • Step 6 In the previous step, you get a template buffer map for all areas. Then draw a shadow map that covers the entire screen, draw the color where the template buffer value is not zero, and complete the shadow drawing.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
  • the embodiments of the present invention achieve the following beneficial effects: the technical solution for constructing a shadow body in the related art is greatly increased, and the burden of the GPU is greatly increased, and the accurate detection is realized without increasing the CPU load. Contour edges greatly increase efficiency.
  • modules or steps of the present invention described above can be implemented by a general-purpose computing device that can be centralized on a single computing device or distributed across a network of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein.
  • the steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof are fabricated as a single integrated circuit module.
  • the invention is not limited to any specific combination of hardware and software.
  • a technical solution for finding a contour edge based on a hash algorithm and determining a shadow body based on the contour edge is used to solve the technical solution of constructing a shadow body in the related art, which greatly increases the burden of the GPU.
  • the problem is that the contour edge is accurately detected without increasing the CPU load, which greatly improves the efficiency.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Graphics (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Processing Or Creating Images (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Image Generation (AREA)

Abstract

一种阴影体的建立方法及装置,其中,上述建立方法包括:在待进行阴影绘制的物体的深度图中,根据哈希算法将所述深度图中所述物体的非轮廓边剔除,并查找到所述深度图中所述物体的所有轮廓边(S102);根据所述所有轮廓边来建立所述物体的阴影体(S104)。采用上述技术方案,解决了相关技术中构建阴影体的技术方案极大的增加了GPU的负担问题,实现了在不增加CPU负担的情况下,准确检测出了轮廓边,极大提高了效率。

Description

阴影体的建立方法及装置 技术领域
本发明涉及计算机图形渲染领域,更具体地说,涉及一种阴影体的建立方法及装置。
背景技术
阴影是指空间中的光线被遮挡了的一定区域。阴影效果可以帮助人们更好地感知物体之间的距离和相对位置,同时帮助人们获取阴影遮挡物及阴影接收体的几何形状等信息。
相关技术中,到目前为止还没有标准的动态阴影渲染技术。为了渲染出逼真的动态阴影效果,相关研究人员已经做出了很多尝试,也提出了不少真实感阴影渲染算法。在这些不同的算法中,阴影体算法是一种主流的高效动态阴影算法。
阴影体算法的效率始终被两个关键的步骤所限制着:一个是轮廓边的检测,另一个是阴影体的渲染。由于前一个步骤将很大程度上影响后一个步骤的工作量,因此提高轮廓边检测效率是提高整体算法效率的一个关键所在。现有算法中为了节省中央处理器(Central Processing Unit,简称为CPU)资源通常不进行轮廓边的检测,而是将所有处在正面的边用于构建阴影体。这样做确实减少了CPU的负担,然而大量冗余的边用于构造阴影体,极大增加了GPU的负担。
针对相关技术中构建阴影体的技术方案极大的增加了GPU的负担问题,目前尚未提出有效的解决方案。
发明内容
本发明提供了一种阴影的绘制方法及装置,以至少解决上述问题。
根据本发明的一个实施例,提供了一种阴影体的建立方法,包括:在待进行阴影绘制的物体的深度图中,根据哈希算法将所述深度图中所述物体的非轮廓边剔除,并查找到所述深度图中所述物体的所有轮廓边;根据所述所有轮廓边来建立所述物体的阴影体;
优选地,根据哈希算法将所述深度图中物体的非轮廓边剔除,并查找到所述深度图中所述物体的所有轮廓边之前,还包括:创建用来保存所述物体对应光源的物体正面的所有边数据的顶点数组。
优选地,根据哈希算法查找到所述深度图中所述物体的所有轮廓边,包括:遍历所述顶点数组中的所有边数据;对于所述所有边数据中的每一边数据,计算所述边数据的键值,并根据所述键值在预先建立的哈希表中查找所述边数据对应的位置;在所述位置未发现重复边时,确定所述边数据对应的边为轮廓边,其中,所述重复边所对应的第一哈希表值与第二哈希表值相同,所述第一哈希表值和/或所述第二哈希表值根据所述键值确定,其中,所述第二哈希表值为所述边数据所指示边的哈希表值。
优选地,根据哈希算法将所述深度图中物体的非轮廓边剔除,包括:在所述位置发现重复边时,判断所述边数据的两个顶点的索引值是否相等;如果是,则剔除所述边数据对应的边。
优选地,根据哈希算法查找到所述深度图中所述物体的所有轮廓边,包括:在所述边数据的两个顶点的索引值不相等时,将所述边数据的键值加2N-1,其中,所述N为冲突循环的次数,并根据所述键值加2N-1后的值在所述预先建立的哈希表中查找边数据对应的位置。
优选地,根据以下公式计算所述边数据的键值KEY:
Figure PCTCN2015072334-appb-000001
其中,VA和VB为所述两个顶点分别对应的索引值,MAX为所述哈希表的大小。
根据本发明的另一个实施例,还提供了一种阴影体的建立装置,包括:剔除模块,用于在待进行阴影绘制的物体的深度图中,根据哈希算法将所述深度图中所述物体的非轮廓边剔除;查找模块,用于根据哈希算法查找到所述深度图中所述物体的所有轮廓边;建立模块,用于根据所述所有轮廓边来建立所述物体的阴影体。
优选地,所述装置,还包括:创建模块,设置为创建用来保存所述物体对应光源的物体正面的所有边数据的顶点数组。
优选地,所述查找模块,包括:遍历单元,设置为遍历所述顶点数组中的所有边数据;计算单元,设置为对于所述所有边数据中的每一边数据,计算所述边数据的键值;查找单元,设置为根据所述键值在预先建立的哈希表中查找所述边数据对应的位置;确定单元,设置为在所述位置未发现重复边时,确定所述边数据对应的边为轮廓边,其中,所述重复边所对应的第一哈希表值与第二哈希表值相同,所述第一哈希表 值和/或所述第二哈希表值根据所述键值确定,其中,所述第二哈希表值为所述边数据所指示边的哈希表值。。
优选地,所述剔除模块,包括:判断单元,设置为在所述位置发现重复边时,判断所述边数据的两个顶点的索引值是否相等;剔除单元,设置为在所述两个顶点的索引值相等时,剔除所述边数据对应的边。
通过本发明,采用基于哈希算法查找轮廓边,并基于轮廓边确定阴影体的技术方案,解决了相关技术中构建阴影体的技术方案极大的增加了GPU的负担问题,实现了在不增加CPU负担的情况下,准确检测出了轮廓边,极大提高了效率。
附图说明
此处所说明的附图用来提供对本发明的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:
图1为根据本发明实施例的阴影体的建立方法的流程图;
图2为根据本发明实施例的在哈希表中加入新的边的示意图;
图3为根据本发明实施例的渲染阴影的总流程图;
图4为根据本发明实施例的阴影体的建立装置的结构框图;
图5为根据本发明实施例的阴影体的建立装置的再一结构框图;
图6为根据本发明实施例的阴影算法示意图;
图7为根据本发明实施例的Z-pass检测方法示意图。
具体实施方式
下文中将参考附图并结合实施例来详细说明本发明。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。
本发明的其它特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本发明而了解。本发明的目的和其他优点可通过在所写的说明书、权利要求书、以及附图中所特别指出的结构来实现和获得。
为了使本技术领域的人员更好地理解本发明方案,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分的实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本发明保护的范围。
为了解决上述技术问题,本发明实施例提供了一种阴影体的建立方法,图1为根据本发明实施例的阴影体的建立方法的流程图,如图1所示,该方法包括如下步骤:
步骤S102:在待进行阴影绘制的物体的深度图中,根据哈希算法将上述深度图中上述物体的非轮廓边剔除,并查找到上述深度图中上述物体的所有轮廓边;
步骤S104:根据上述所有轮廓边来建立上述物体的阴影体。
通过上述各个步骤,采用基于哈希算法能够快速的查找到建立阴影体所用的轮廓边,并基于轮廓边确定阴影体的技术方案,解决了相关技术中构建阴影体的技术方案极大的增加了GPU的负担问题,实现了在不增加CPU负担的情况下,快速准确检测出了轮廓边,极大提高了效率。
可选地,根据哈希算法将上述深度图中物体的非轮廓边剔除,并查找到上述深度图中上述物体的所有轮廓边之前,还包括:创建用来保存上述物体对应光源的物体正面的所有边数据的顶点数组。
在本发明实施例中,根据哈希算法查找到上述深度图中上述物体的所有轮廓边,包括:遍历上述顶点数组中的所有边数据;对于上述所有边数据中的每一边数据,计算上述边数据的键值,并根据上述键值在预先建立的哈希表中查找上述边数据对应的位置;在上述位置未发现重复边时,确定上述边数据对应的边为轮廓边,其中,上述重复边所对应的第一哈希表值与第二哈希表值相同,上述哈希表值根据上述键值确定,其中,上述第二哈希表值为上述边数据所指示边的哈希表值。在具体实施过程中,根据以下公式计算上述边数据的键值KEY:
Figure PCTCN2015072334-appb-000002
其中,VA和VB为上述两个顶点分别对应的索引值,MAX为上述哈希表的大小。
在本发明实施例的一个可选实施例中,在上述位置发现了重复边时,判断上述边数据的两个顶点的索引值是否相等;如果是,则剔除上述边数据对应的边;如果否,则继续执行上述“查找上述深度图中上述物体的所有轮廓边”的过程:即上述边数据的键值加2N-1,其中,上述N为冲突循环的次数,并根据上述键值在预先建立的哈希表中查找边数据对应的位置。
其中,将上述占位符为真的上述边数据对应的轮廓边建立轮廓边数组,其中,上述轮廓边数组用于对上述阴影体进行渲染处理。
本发明实施例对上述技术方案的进一步改进在于,根据Z-pass算法对上述阴影体的阴影区域进行模板测试,其中,在进行上述物体对应光源的物体正面所对应的阴影区域进行Z-pass算法深度测试时,如果上述深度测试通过,则上述阴影区域的模板缓冲值减一,如果没有通过,则上述模板缓冲值不变;在进行上述物体对应光源的物体背面所对应的阴影区域进行Z-pass算法深度测试时,如果上述深度测试通过,则上述阴影区域的模板缓冲值加一,如果没有通过,则上述模板缓冲值不变。
高效渲染实时阴影效果是比较困难的。已有的算法在健壮性和算法效率上都不足以满足需求。现有的阴影体算法由于需要耗费很多CPU资源,因此上难以得到流畅的实时阴影效果。加之特别是目前移动平台图形硬件对于底层标准支持不完善,导致依赖于硬件的算法难以发挥应有的效应。本发明实施例探索出了一种新的实时阴影渲染算法,在保持低CPU消耗的前提下,大大提高了阴影的渲染效率,同时减少了硬件依赖,使之能够在包括移动平台在内的各平台上广泛使用。
为了更好的理解上述阴影的绘制方法的流程,以下结合优选实施例进行说明,但不限定本发明。图3为根据本发明实施例的渲染阴影的总流程图,如图3所示,该流程可以包括步骤1至3:
步骤1,构建阴影体。其中包括场景文件的读入(即获得场景深度图),顶点数据的储存,非轮廓边的剔除并保存轮廓边作为创建阴影体的边集合(可以利用哈希算法剔除非轮廓边,以及提取轮廓边集合)等。该步骤后得到待绘制的阴影体边数组,其中,根据哈希算法进行“非轮廓边的剔除”为本发明实施例侧重的主要内容。
步骤2,利用阴影体对阴影区域进行判断。包括渲染阴影体,利用判断算法对阴影区域进行更新标记等。该步骤后得到用模板缓冲区标记好的阴影区域。
步骤3,对标记好的阴影区域进行绘制。包括对模板缓冲测试方法的设置和绘制操作等;该步骤后,在屏幕上得到最终的绘制完成的阴影,即将渲染后的阴影图层附加到场景中。
在一个优选实施过程中:
步骤1具体包括:首先打开深度缓冲的写操作(在openGL中为一句设置命令),读入整个场景文件的顶点信息,然后采用openGL命令载入顶点信息进行绘制,渲染 整个场景,第一遍渲染后得到所有物体的深度图,该深度图以用户的真实视点作为参照。然后运用哈希算法,对物体的轮廓边进行处理,剔除非轮廓边。剔除之后,轮廓边保存为一个数组。接着针对每一条轮廓边,将其投影到远处,加上所有在物体正面的边,构建阴影体。整个阴影体的边保存为一个数组,等待渲染操作。以下是对于哈希算法剔除非轮廓边的详细介绍:
基于哈希表的阴影体非轮廓边剔除技术,旨在提高轮廓边的检测效率,首先,假设使用点光源和带有索引的模型文件。根据光源和遮挡物的相对位置,遮挡物模型上的所有面片都需要测试以确定前部面片和背部面片,即相对光源位置来说,正面或背面对着光源的面片。在技术上,利用光源到面片的向量(方向指向光源)和面片的法向量的点乘来判断正反面。当两向量点乘大于零,即为前部面片,否则为背部面片。然后对于所有的前部面片,所有的边需要被检测以确定轮廓边。对所有的轮廓边,沿光源到每条边连线的方向延伸到无穷远处构建阴影体。用阴影多边形来指代形成的阴影体的侧面。查找轮廓边是一个很费时的过程,因此轮廓边的查找效率将很大程度上决定整个算法的效率。基于哈希表的阴影体算法是针对整个物体创建阴影体,即对查找物体的轮廓边,利用轮廓边建立阴影体,而不是对物体处在正面的所有三角面片建立阴影体。这会极大减小图形硬件的压力,同时并没有增加大量计算。在本方法中,哈希表用于提高轮廓边查找效率。通过利用哈希表的特性,保证当所有的位于物体正面的边被遍历完一遍后,所有的非轮廓边都能够被剔除。
传统的算法中,从光源角度看到的遮挡物的正面面片都会用于产生阴影体。这种算法耗时很严重,在实际应用中对于硬件的要求很高。更重要的是,随着遮挡物模型复杂度的提高,轮廓边检测算法的效率下降得非常明显。对每一条边S的算法复杂度为O(n)。算法总复杂度达到了O(n2)。
为了减少轮廓边检测的算法复杂度,使用哈希表来提高检测的效率。哈希表是根据关键码值而直接进行访问的数据结构。它通过把关键码值映射到表中一个位置来访问储存的数据,可以加快查找的速度。这个映射函数叫做哈希函数,存放记录的数组叫做哈希表。在实践中,哈希算法可以极大增加查询速度。哈希算法的根本在于哈希函数的设定,以及冲突后的处理方法。在哈希函数的设定和冲突处理方法上,本发明实施例针对轮廓边的剔除进行了设计,保证快速无误地完成该过程。
假设使用带有索引值的模型文件,每个顶点都带有一个索引值。对于待选轮廓边数组,实际上只储存每一个端点的索引值。每当增加一条边时,不再需要遍历整个数组查找是否有冗余的边存在。哈希表提供了快速查找的特性。每次加入新的边,可以在O(1)时间内知道是否有冗余边的存在。因为相同的边总会映射到哈希表中的相同位 置。哈希表中的每个哈希元素储存着一个无符号整数用于储存键值;两个整数用于储存端点的索引值;一个布尔值用于储存占位符。假设MAX表示哈希表的大小,VA,VB表示两个端点的索引值,那么提供了一种快速且有效计算键值的方法:
Figure PCTCN2015072334-appb-000003
利用这种计算方法,可以保证有相同端点的边始终会映射到哈希表中的相同位置。图2为根据本发明实施例的在哈希表中加入新的边的示意图。如图2所示,当需要加入一条新的边时,首先计算键值,然后在哈希表中检查相应位置。检查标志位(占位符),如果该位置没有被占用,则标志位为假,储存端点的索引值,并更改标志位为真。如果已经被占用,则标志位为真,比较两条边的两个端点的顶点值(索引值)是否完全相等。如果完全相等,证明找到了冗余边,更改占位符为假(即重设标志位)。如果端点的顶点值(索引值)不是完全相等(即部分相等),则发生了冲突。将新的边的键值加2N-1,其中N代表冲突循环的次数。比如第一次遇到冲突,键值加1,重新检查相应位置,如果仍然冲突,则加3,如此循环直到找到未占用的位置。
当所有的边都加入到哈希表中以后,所有占位符为真的位置储存了轮廓边。遍历整个哈希表一次,生成最终的轮廓边数组,用于渲染阴影体。
在实现中,运用Z-pass算法进行模板测试,当摄像机位于阴影体内部时,Z-fail算法用于模板测试以得到正确结果。以下是利用哈希表检测轮廓边算法的伪代码:
Figure PCTCN2015072334-appb-000004
Figure PCTCN2015072334-appb-000005
步骤2中:关闭深度缓冲的写操作,打开模板缓冲的写操作,输入阴影体边数组,渲染阴影体。应用Z-Pass算法进行测试:对阴影体的正面,即相对视点来说的这一面,如果深度测试通过,那么和相应像素对应的模板缓冲值加一,如果深度测试没有通过,则模板缓冲值不变;对于阴影体的背面,即远离视点的那一面,如果深度测试不通过,则模板缓冲值保持不变,如果深度测试通过,则模板缓冲值减一。阴影区域测试完毕后,模板缓冲区非零区域标记为阴影区域。
步骤3中:针对模板缓冲区标记好的阴影区域,设置模板测试的通过条件为非零,再画一张覆盖整个屏幕的阴影图,该阴影图仅仅在通过模板测试的区域被绘制出,完成最终的阴影绘制。
采用本发明实施例提供的上述技术方案,由于采用了针对整个物体创建阴影体的思想,即根据每个物体来构建阴影体,而不是针对每个三角形,构建阴影体的三角面片数量锐减,同时没有增加大量运算。因而阴影体需要渲染的三角面片数量大量降低,极大地缓解了图形硬件的压力,同时节省了大量渲染时间。最终渲染速度提高了很多,在渲染复杂场景时,画面流畅度大幅提高了。而本发明实施例的算法在处理不同复杂度的模型时,渲染效率跟模型复杂度的关系接近了线性。这让该算法能够处理不同的复杂度情况,提升了算法的鲁棒性。同时,算法利用了哈希表所能够提供的快速查找和删除的能力,在快速查找剔除非轮廓边时并没有显著增加CPU的使用率,极大地提升了阴影渲染的效率。
在本实施例中还提供了一种阴影体的建立装置,用于实现上述实施例及优选实施方式,已经进行过说明的不再赘述,下面对该装置中涉及到的模块进行说明。如以下所使用的,术语“模块”可以实现预定功能的软件和/或硬件的组合。尽管以下实施例所描述的装置较佳地以软件来实现,但是硬件,或者软件和硬件的组合的实现也是可 能并被构想的。图4为根据本发明实施例的阴影的绘制装置的结构框图。如图4所示,该装置包括:
剔除模块40,设置为在待进行阴影绘制的物体的深度图中,根据哈希算法将上述深度图中上述物体的非轮廓边剔除;
查找模块42,与剔除模块40连接,设置为根据哈希算法查找到上述深度图中上述物体的所有轮廓边;
建立模块44,与查找模块42连接,设置为根据上述所有轮廓边来建立上述物体的阴影体。
通过上述各个模块的综合作用,采用基于哈希算法快速查找轮廓边,并基于轮廓边确定阴影体的技术方案,解决了相关技术中构建阴影体的技术方案极大的增加了GPU的负担问题,实现了在不增加CPU负担的情况下,准确检测出了轮廓边,极大提高了效率。
可选地,如图5所示,上述装置还包括:创建模块46,设置为创建用来保存上述物体对应光源的物体正面的所有边数据的顶点数组。
其中,查找模块42,包括:遍历单元420,设置为遍历上述顶点数组中的所有边数据;计算单元422,与遍历单元420连接,设置为对于上述所有边数据中的每一边数据,计算上述边数据的键值;查找单元424,与计算单元422连接,设置为根据上述键值在预先建立的哈希表中查找上述边数据对应的位置;确定单元426,与查找单元424连接,设置为在上述位置未被占用时,确定上述边数据对应的边为轮廓边。
在本发明实施例中,剔除模块40,包括:判断单元400,设置为在上述位置被占用时,判断上述边数据的两个顶点的索引值是否相等;
剔除单元402,与判断单元400连接,设置为在上述两个顶顶的索引值相等时,剔除上述边数据对应的边。在具体实施过程中,绘制一次阴影的具体方法为:
步骤1,第一遍渲染环境光下的模型后得到所有物体的深度图,这个深度图以用户的真实视点作为参照。打开深度缓冲区的写操作开关,渲染整个场景,根据模型,得到模型的所有顶点信息,这些顶点信息会保存在一个顶点数组中。而相对应的,还有一个索引数组保存顶点的索引信息。所谓索引数组,就是索引数组里的内容保存的是顶点数组中的索引数。同时也会获得光源的当前位置。
步骤2,所有信息获取好以后,创建阴影体。遍历模型上的每一个三角面片。首先检测它是否在相对于光线的正面。如果在光线的正面,则将该三角面片加入到阴影体的待渲染的顶点数组中。顶点数组中连续的三个顶点表示一个三角面片。在遍历每个三角形的过程中,创建了另一个顶点数组,用来保存在光源正面的所有边数据。连续的两个顶点表示一条边。然后利用哈希剔除算法,剔除非轮廓边,保存轮廓边作为创建阴影体的边集合。遍历每一条处在正面的边,加入哈希表,首先计算键值,然后在哈希表中检查相应位置。如果该位置没有被占用,那么储存端点的索引值,并更改占位符为真。如果已经被占用,检查两条边的两个端点的索引值是否完全相等。如果完全相等,证明找到了冗余边,更改占位符为假。如果端点的索引值不完全完全相等,则发生了冲突。将新的边的键值加2N-1,其中N代表冲突循环的次数。比如第一次遇到冲突,键值加1,重新检查相应位置,如果仍然冲突,则加3,如此循环直到找到未占用的位置。当所有的边都加入到哈希表中以后,所有占位符为真的位置储存了轮廓边。我们遍历整个哈希表一次,生成最终的轮廓边数组,用于渲染阴影体。
步骤3,生成了轮廓边的数组之后,遍历该数组。每一条边由两个顶点构成。而每个顶点投射到“无限远”处生成另外两个顶点。这四个顶点构成了一个四边形。每一条边投射出去,都会生成一个四边形。这些四边形就是阴影体的侧面。与前后盖一起就形成了整个阴影体。每个四边形划分为两个三角形,加入到阴影体的待渲染的顶点数组中。这样子,阴影体的待渲染数组中保存了有关阴影体的所有顶点信息。找到物体相对光源的轮廓边,也就是将物体相对于光源前方和后方隔开的边。图6解释了阴影体的原理。绘制阴影体的目的是作为绘制阴影的测试,因此该阴影体不会最终出现在屏幕上,否则就会出现多余的阴影体区域。
步骤4,设置深度测试的类型为小于等于参考值。而关掉深度缓冲的写操作。将模板测试的类型设置为总是通过。测试的时候只取决于深度测试的结果。模板测试的缓冲值被设为0。
步骤5,分两次渲染阴影体。渲染过程中利用模板测试。模板测试能有效利用GPU的硬件加速能力,快速检测阴影区域。在本专利中,模板测试的算法采用的是Z-Pass算法,用于具体测试哪些区域在阴影当中。在图7中解释了Z-Pass算法的基本原理。从用户的视觉点向物体引出一条射线,称为视线。当视线进入阴影体的时候,也就是从阴影体的外部面穿越到内部面的时候,模板缓冲值加一,而当视线穿出阴影体的时候,也就是从阴影体的内部面穿越到外部面的时候,模板缓冲值减一。根据Z-Pass算法,当某个区域的模板缓冲值为零时,表示进入和离开阴影体的次数相等,那么该区 域就不在阴影当中。而当模板缓冲值不为零时,就表示该区域在阴影当中。第一次渲染剔除背面,如果深度测试通过,则相应区域模板缓冲值加一,否则保持不变。
在openGL中用glCullFace(GL_BACK)命定设置剔除背面,然后运用命令glStencilOp(GL_KEEP,GL_KEEP,incr)设置深度测试如果通过则相应区域模板缓冲值加一,否则保持不变。然后调用渲染命令进行渲染。第二次渲染剔除正面,如果深度测试通过,则相应区域模板缓冲值减一,否则不变。在openGL中用glCullFace(GL_FRONT)命定设置剔除正面面,然后运用命令glStencilOp(GL_KEEP,GL_KEEP,decr)设置深度测试如果通过则相应区域模板缓冲值减一,否则保持不变。然后调用渲染命令进行渲染。该步骤中,也可以第一次渲染剔除正面,第二次渲染剔除背面。相应操作应交换顺序,能得到相同效果,同属于相同渲染流程。
这样做的原因是,在绘制阴影体之前,已经绘制了其他的模型。因此深度缓冲区里面实际保存着真正需要显示的物体的深度值。那么在第一次渲染阴影体正面的时候,由于将深度测试的类型设为小于等于,也就是说,阴影体的深度值小于实际物体的深度值(说明阴影体的正面遮住了物体),这时相应区域的模板缓冲值加一。同样的情况,如果阴影体的背面的时候,深度测试通过了的话,模板缓冲值减一。需要注意的是,在渲染阴影体的时候,要把颜色缓冲区的写操作关上。因为不需要真正的把阴影体绘制在屏幕上,只是通过绘制阴影体来获得深度信息,以绘制阴影。
步骤6,上一步中得到了一张关于所有区域的模板缓冲图。然后直接画一张覆盖整个屏幕的阴影图,在模板缓冲值不为零的地方绘上颜色,完成了阴影的绘制。
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
需要说明的是,本发明的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的对象在适当情况下可以互换,以便这里描述的本发明的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
综上上述,本发明实施例实现了以下有益效果:解决了相关技术中构建阴影体的技术方案极大的增加了GPU的负担问题,实现了在不增加CPU负担的情况下,准确检测出了轮廓边,极大提高了效率。
显然,本领域的技术人员应该明白,上述的本发明的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。
以上仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
工业实用性
基于本发明实施例提供的上述技术方案,采用基于哈希算法查找轮廓边,并基于轮廓边确定阴影体的技术方案,解决了相关技术中构建阴影体的技术方案极大的增加了GPU的负担问题,实现了在不增加CPU负担的情况下,准确检测出了轮廓边,极大提高了效率。

Claims (10)

  1. 一种阴影体的建立方法,包括:
    在待进行阴影绘制的物体的深度图中,根据哈希算法将所述深度图中所述物体的非轮廓边剔除,并查找到所述深度图中所述物体的所有轮廓边;
    根据所述所有轮廓边来建立所述物体的阴影体。
  2. 根据权利要求1所述的方法,其中,根据哈希算法将所述深度图中物体的非轮廓边剔除,并查找到所述深度图中所述物体的所有轮廓边之前,还包括:
    创建用来保存所述物体对应光源的物体正面的所有边数据的顶点数组。
  3. 根据权利要求2所述的方法,其中,根据哈希算法查找到所述深度图中所述物体的所有轮廓边,包括:
    遍历所述顶点数组中的所有边数据;
    对于所述所有边数据中的每一边数据,计算所述边数据的键值,并根据所述键值在预先建立的哈希表中查找所述边数据对应的位置;
    在所述位置未发现重复边时,确定所述边数据对应的边为轮廓边,其中,所述重复边所对应的第一哈希表值与第二哈希表值相同,所述第一哈希表和/或所述第二哈希表值根据所述键值确定,其中,所述第二哈希表值为所述边数据所指示边的哈希表值。
  4. 根据权利要求3所述的方法,其中,根据哈希算法将所述深度图中物体的非轮廓边剔除,包括:
    在所述位置发现重复边时,判断所述边数据的两个顶点的索引值是否相等;
    如果是,则剔除所述边数据对应的边。
  5. 根据权利要求4所述的方法,其中,根据哈希算法查找到所述深度图中所述物体的所有轮廓边,包括:
    在所述边数据的两个顶点的索引值不相等时,将所述边数据的键值加2N-1,其中,所述N为冲突循环的次数,并根据所述键值加2N-1后的值在所述预先建立的哈希表中查找边数据对应的位置。
  6. 根据权利要求3至5中任一项所述的方法,其中,根据以下公式计算所述边数据的键值KEY:
    Figure PCTCN2015072334-appb-100001
    其中,VA和VB为所述两个顶点分别对应的索引值,MAX为所述哈希表的大小。
  7. 一种阴影体的建立装置,包括:
    剔除模块,设置为在待进行阴影绘制的物体的深度图中,根据哈希算法将所述深度图中所述物体的非轮廓边剔除;
    查找模块,设置为根据哈希算法查找到所述深度图中所述物体的所有轮廓边;
    建立模块,设置为根据所述所有轮廓边来建立所述物体的阴影体。
  8. 根据权利要求7所述的装置,其中,所述装置,还包括:
    创建模块,设置为创建用来保存所述物体对应光源的物体正面的所有边数据的顶点数组。
  9. 根据权利要求8所述的装置,其中,所述查找模块,包括:
    遍历单元,设置为遍历所述顶点数组中的所有边数据;
    计算单元,设置为对于所述所有边数据中的每一边数据,计算所述边数据的键值;
    查找单元,设置为根据所述键值在预先建立的哈希表中查找所述边数据对应的位置;
    确定单元,设置为在所述位置未发现重复边时,确定所述边数据对应的边为轮廓边,所述重复边所对应的第一哈希表值与第二哈希表值相同,所述第一哈希表和/或所述第二哈希表值根据所述键值确定,其中,所述第二哈希表值为所述边数据所指示边的哈希表值。
  10. 根据权利要求9所述的装置,其中,所述剔除模块,包括:
    判断单元,设置为在所述位置发现重复边时,判断所述边数据的两个顶点的索引值是否相等;
    剔除单元,设置为在所述两个顶点的索引值相等时,剔除所述边数据对应的边。
PCT/CN2015/072334 2014-09-24 2015-02-05 阴影体的建立方法及装置 WO2016045298A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410495842.9 2014-09-24
CN201410495842.9A CN105513122B (zh) 2014-09-24 2014-09-24 阴影体的建立方法及装置

Publications (1)

Publication Number Publication Date
WO2016045298A1 true WO2016045298A1 (zh) 2016-03-31

Family

ID=55580209

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/072334 WO2016045298A1 (zh) 2014-09-24 2015-02-05 阴影体的建立方法及装置

Country Status (2)

Country Link
CN (1) CN105513122B (zh)
WO (1) WO2016045298A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107481314B (zh) * 2017-06-30 2020-10-27 浙江科澜信息技术有限公司 一种基于kd树的阴影体优化方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020018063A1 (en) * 2000-05-31 2002-02-14 Donovan Walter E. System, method and article of manufacture for shadow mapping
US20040179009A1 (en) * 2003-03-10 2004-09-16 Sharp Kabushiki Kaisha Graphic processing apparatus, graphic processing method, graphic processing program, and program storage medium
CN102135417A (zh) * 2010-12-26 2011-07-27 北京航空航天大学 一种全自动三维特征提取方法
CN102968814A (zh) * 2012-11-22 2013-03-13 华为技术有限公司 一种图像渲染的方法及设备

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101299965B (zh) * 2005-11-02 2012-08-01 皇家飞利浦电子股份有限公司 用于在介入操作期间进行轮廓绘制和图像显示的图像处理系统和方法
CN100476880C (zh) * 2006-09-14 2009-04-08 腾讯科技(深圳)有限公司 一种产生体积阴影的方法及系统
DE102006050379A1 (de) * 2006-10-25 2008-05-08 Norbert Prof. Dr. Link Verfahren und Vorrichtung zur Überwachung eines Raumvolumens sowie Kalibrierverfahren
CN101127127B (zh) * 2007-09-29 2011-07-27 腾讯科技(深圳)有限公司 阴影绘制方法及渲染装置
CN101799937B (zh) * 2010-03-23 2011-08-31 南京大学 一种采用草图创建三维模型的方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020018063A1 (en) * 2000-05-31 2002-02-14 Donovan Walter E. System, method and article of manufacture for shadow mapping
US20040179009A1 (en) * 2003-03-10 2004-09-16 Sharp Kabushiki Kaisha Graphic processing apparatus, graphic processing method, graphic processing program, and program storage medium
CN102135417A (zh) * 2010-12-26 2011-07-27 北京航空航天大学 一种全自动三维特征提取方法
CN102968814A (zh) * 2012-11-22 2013-03-13 华为技术有限公司 一种图像渲染的方法及设备

Also Published As

Publication number Publication date
CN105513122B (zh) 2019-01-25
CN105513122A (zh) 2016-04-20

Similar Documents

Publication Publication Date Title
US8711143B2 (en) System and method for interactive image-based modeling of curved surfaces using single-view and multi-view feature curves
WO2022042436A1 (zh) 图像渲染方法、装置、电子设备及存储介质
KR101482578B1 (ko) 에지 검출 및 셰이더 재사용을 이용한 멀티­뷰 광선 추적
US7561156B2 (en) Adaptive quadtree-based scalable surface rendering
CN104616286B (zh) 快速的半自动多视图深度修复方法
US8390618B2 (en) Technique for improving ray tracing performance
CN106447768B (zh) 一种适用于三维场景中三维模型并行绘制的方法
CN110838129A (zh) 基于倾斜摄影测量的三维建筑物模型轮廓特征线提取方法
Chrysanthou Shadow computation for 3D interaction and animation
CN110648363A (zh) 相机姿态确定方法、装置、存储介质及电子设备
WO2023066121A1 (zh) 三维模型的渲染
JP2002531905A (ja) ボクセル空間から透視描画を形成する方法
WO2022048468A1 (zh) 平面轮廓识别方法、装置、计算机设备和存储介质
US6978230B1 (en) Apparatus, system, and method for draping annotations on to a geometric surface
CN102831634B (zh) 一种高效精确的通用软阴影生成方法
JP2022509329A (ja) 点群融合方法及び装置、電子機器、コンピュータ記憶媒体並びにプログラム
CN107392990A (zh) 渲染3d场景的全局照明
WO2018227950A1 (zh) 一种基于屏幕块对的双目渲染流水线流程与方法
WO2022048414A1 (zh) 一种图像生成方法、装置、设备及存储介质
CN114283244A (zh) 一种基于gpu的八叉树布尔运算加速求交方法
CN101937577A (zh) 生成具有边界像素超采样效果的阴影的方法
CN112200906B (zh) 一种面向倾斜三维模型的实体提取方法及其系统
WO2016045298A1 (zh) 阴影体的建立方法及装置
CN107689076A (zh) 一种用于虚拟手术系统切割时的高效渲染方法
CN106709977A (zh) 一种基于场景夜景图的光源自动排列方法

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15844576

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15844576

Country of ref document: EP

Kind code of ref document: A1