Model rendering method, device and electronic equipment
By setting vertex color information for model vertices and adjusting fragment colors, the problem of high computational cost of lighting occlusion is solved, achieving efficient lighting occlusion rendering, reducing GPU computation, and minimizing game stuttering and frame rate drops.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2022-01-12
- Publication Date
- 2026-05-15
AI Technical Summary
Existing technologies involve a large amount of computation when rendering the lighting occlusion of virtual models, which leads to game stuttering and frame rate failures, making it difficult to reduce the amount of GPU computation while ensuring the visual effect of lighting occlusion.
By setting vertex color information for the model's vertices and adjusting the fragment color information in the primitives based on the vertex color information, the computational cost of lighting occlusion is reduced, and fragment colors are optimized using interpolation and brightness adjustment parameters.
While ensuring the visual effect of light occlusion, it reduces the amount of computation, reduces game lag and frame rate issues, and saves computing resources.
Smart Images

Figure CN114549732B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of model rendering technology, and more specifically, to a model rendering method, apparatus, and electronic device. Background Technology
[0002] To simulate lighting effects in real-world scenes, the issue of lighting occlusion is typically considered when rendering virtual models. In related technologies, when rendering lighting occlusion on a virtual model, it's necessary to determine whether each pixel is located on a convex or concave surface of the model, and then determine the lighting occlusion intensity based on the pixel's position. This method of rendering lighting occlusion is computationally intensive, requires significant resources, and can easily lead to game stuttering or substandard frame rates. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a model rendering method, apparatus and electronic device that significantly reduces GPU computation and improves model rendering efficiency while ensuring good lighting occlusion visual effects.
[0004] In a first aspect, embodiments of the present invention provide a method for rendering a model, the method comprising: acquiring a target model; wherein the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; fragments within the primitives are pre-set with basic color information; setting vertex color information for the vertices according to their positions in the target model; the vertex color information is used to indicate the illumination occlusion intensity at each position in the target model; adjusting the basic color information of the fragments in the primitives based on the vertex color information of the vertices included in the primitives to obtain the adjusted color information of the fragments; and rendering the pixels corresponding to the fragments based on the color information of the fragments.
[0005] The steps of setting vertex color information for the positions of the aforementioned vertices in the aforementioned target model include: for a first primitive whose distance from the edge of the target model is less than a first distance threshold, setting the vertex color information of the vertices in the first primitive to be greater than a first color threshold; for a second primitive whose distance from the edge of the target model is greater than a second distance threshold, setting the vertex color information of the vertices in the second primitive to be less than a second color threshold.
[0006] The steps described above, which adjust the base color information of fragments in a primitive based on the vertex color information of the vertices included in the primitive, to obtain the adjusted color information of the fragments, include: for each fragment in the primitive, determining the color adjustment parameters corresponding to the fragment based on the position of the fragment in the primitive and the vertex color information of each vertex in the primitive; adjusting the base color information of the fragment based on the color adjustment parameters to obtain the adjusted color information of each fragment.
[0007] The steps described above for determining the color adjustment parameters corresponding to each fragment in the primitive, based on the fragment's position in the primitive and the vertex color information of each vertex in the primitive, include: for each fragment in the primitive, performing interpolation processing on the vertex color information of each vertex in the primitive based on the distance between the fragment and each vertex in the primitive to obtain the interpolation result; and determining the interpolation result as the color adjustment parameters corresponding to the fragment.
[0008] The steps described above, for each fragment in a primitive, interpolate the vertex color information of each vertex in the primitive based on the distance between the fragment and each vertex in the primitive to obtain the interpolation result, include: for each fragment in the primitive, determining the interpolation weight corresponding to each vertex based on the distance between the fragment and each vertex in the primitive; and interpolating the vertex color information of multiple vertices in the primitive based on the interpolation weight corresponding to each vertex to obtain the interpolation result.
[0009] The steps described above, which adjust the base color information of the fragments based on the color adjustment parameters to obtain the adjusted color information of each fragment, include: multiplying the base color information of the fragments by the color adjustment parameters to obtain the adjusted color information of the fragments.
[0010] After the steps described above, which involve adjusting the base color information of fragments in a primitive based on the vertex color information of the vertices included in the primitive to obtain the adjusted color information of the fragments, the method further includes: obtaining a pre-set brightness adjustment parameter; and adjusting the color information of each of the above fragments based on the brightness adjustment parameter to obtain the final color information of each fragment.
[0011] The steps described above, which adjust the color information of each of the above fragments based on the brightness adjustment parameters to obtain the final color information of each fragment, include: multiplying the color information of each fragment by the brightness adjustment parameters to obtain the final color information of each fragment.
[0012] Secondly, embodiments of the present invention provide a rendering apparatus for a model, the apparatus comprising: a model acquisition module for acquiring a target model, wherein the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; fragments within each primitive are pre-set with basic color information; a vertex color information acquisition module for setting vertex color information for vertices based on their positions in the target model; the vertex color information is used to indicate the occlusion intensity at each position in the target model; a color information adjustment module for adjusting the basic color information of fragments in the primitive based on the vertex color information of the vertices included in the primitive, thereby obtaining the adjusted color information of the fragments; and a rendering module for rendering the pixels corresponding to the fragments based on the color information of the fragments.
[0013] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-described model rendering method.
[0014] Fourthly, embodiments of the present invention provide a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are invoked and executed by a processor, the machine-executable instructions cause the processor to implement the above-described model rendering method.
[0015] The embodiments of the present invention bring the following beneficial effects:
[0016] The above provides a rendering method, apparatus, and electronic device for a model. The method involves acquiring a target model; the target model's surface includes multiple primitives; each primitive includes multiple vertices; fragments within each primitive have pre-set basic color information; vertex color information is set based on the vertex's position in the target model; the vertex color information indicates the lighting occlusion intensity at various locations in the target model; the basic color information of the fragments within the primitives is adjusted based on the vertex color information of the vertices included in the primitives to obtain the adjusted fragment color information; and the pixels corresponding to the fragments are rendered based on the fragment color information. In this method, the colors of each fragment in the model are adjusted using vertex color information, thereby rendering a visual effect where different locations of the model have different lighting occlusion intensities. This lighting occlusion rendering method, while ensuring good rendering visual effects, reduces computational load, saves computing resources, and reduces game stuttering and frame rate issues.
[0017] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0018] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0019] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0020] Figure 1A schematic diagram illustrating a light shading processing method provided in an embodiment of the present invention;
[0021] Figure 2 A flowchart illustrating a model rendering method provided in an embodiment of the present invention;
[0022] Figure 3 A flowchart of another model rendering method provided in an embodiment of the present invention;
[0023] Figure 4 A schematic diagram of the structure of a model rendering device provided in an embodiment of the present invention;
[0024] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0026] To simulate lighting effects in real-world scenes, the issue of lighting occlusion is typically considered when rendering virtual models. Areas not illuminated by light appear darker in the rendered image, mimicking lighting occlusion in reality. In related technologies, when rendering lighting occlusion on a virtual model, it's necessary to determine whether each pixel is located on a convex or concave surface of the model, and then determine the intensity of the lighting occlusion based on the pixel's position. Stronger lighting occlusion results in lower pixel brightness, while weaker lighting occlusion results in higher pixel brightness.
[0027] like Figure 1 As shown, the process first requires collecting a series of points around the pixel, then calculating whether each point is inside or outside the model. If more points are outside the model, the pixel is considered to be on a convex surface. If more points are inside the model, the pixel is considered to be on a concave surface. Pixels on convex surfaces are considered to have weaker occlusion, while pixels on concave surfaces are considered to have stronger occlusion. Calculating whether a point is inside or outside the model is itself a computationally intensive algorithm. By sampling the depth values of the target point and calculating the degree of primitive occlusion, ambient occlusion is applied based on the degree of occlusion. This method of rendering lighting occlusion is computationally intensive, requires significant resources, and can easily lead to game stuttering or substandard frame rates.
[0028] In computer graphics, the effect of global illumination directly affects the realism of the image. Traditional physically based lighting algorithms (such as ray tracing) can achieve good results, but they are computationally complex and difficult to implement. Therefore, in real-time applications such as games, ambient occlusion techniques are generally used to simulate global illumination effects, achieving a balance between image quality and rendering speed. In related technologies, when rendering lighting occlusion on virtual models, it is necessary to determine whether each pixel on the virtual model is located on the convex or concave surface of the model, and then determine the lighting occlusion intensity of the pixel based on its position. This method of rendering lighting occlusion is computationally intensive, consumes a lot of resources, overloads the GPU, and affects the stability of the operation. In the game world, it is usually not necessary to represent such realistic lighting occlusion, so it is not necessary to consume such high-performance occlusion algorithms. Based on this, the present invention provides a model rendering method, device, and electronic device, which can be applied to the rendering of virtual models in game models or other virtual scenes.
[0029] To facilitate understanding of this embodiment, a rendering method for a model disclosed in this embodiment will first be described in detail, such as... Figure 2 As shown, the method includes the following steps:
[0030] Step 202: Obtain the target model; wherein, the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; and the fragments within each primitive have pre-set basic color information.
[0031] Game models are objects designed and manufactured to scale for scenes, characters, and props within a game. They are often situated within a 3D graphical scene, a virtual environment composed of various types of 3D graphics, such as map scenes and game scenes. Models are crucial elements in constructing 3D graphical scenes, including terrain, vegetation, buildings, characters, mountains, and rivers. When processing a target model, its surface is divided into many basic components called "primitives" to facilitate graphics processing operations. Primitives are typically in the form of simple polygons, such as triangles and rectangles. A primitive contains one or more vertices, and each vertex is associated with specific data values representing the primitive at that vertex's location, such as the vertex's X and Y positions, depth (Z) value, color, and transparency values. Fragments refer to elements of a primitive at a sampling location; rasterization can convert a clipped primitive into multiple fragments. In the system, color can be defined as a fixed number or variable. Color is obtained by varying the three color channels (Red (R), Green (G), and Blue (B) and superimposing them. Each color channel has a value ranging from 0 to 255. The corresponding color value is obtained by superimposing the color channels. The target model fragments obtained in this step have pre-set basic color information, which represents the basic color value of the fragments. This color value can be set by engineers when designing the target model.
[0032] Step 204: Set vertex color information for the vertex according to its position in the target model; vertex color information is used to indicate the light occlusion intensity at each position in the target model.
[0033] Each vertex of a primitive on the model surface can contain various information data, including: position coordinates, color, texture coordinates, vertex color, and boundary markers. Vertex color information indicates the degree of occlusion of each vertex by other vertices or other models within the target model under lighting conditions. In this step, the vertex color information can be a floating-point number, the magnitude of which indicates the intensity of lighting occlusion. In game scenes, to simulate realistic lighting effects, lighting occlusion is typically considered when rendering virtual models. This refers to the changes in brightness caused by the occlusion relationship of the model itself under ambient lighting. Specifically, recessed areas have higher lighting occlusion intensity and appear darker, while protruding areas have lower lighting occlusion intensity and appear brighter. This results in a more layered and higher-contrast rendering. In this step, vertex color information is set for the rendered model vertices based on their positions within the target model, indicating the intensity of lighting occlusion at each location. In practice, engineers can set vertex color information by coloring the vertices.
[0034] Step 206: Based on the vertex color information of the vertices included in the primitive, adjust the basic color information of the fragments in the primitive to obtain the adjusted color information of the fragments;
[0035] Specifically, for each fragment in the primitive, color adjustment parameters are determined based on the fragment's position within the primitive and the vertex color information of each vertex in the primitive. These color adjustment parameters can be understood as weighted color information specific to the fragment; that is, the color intensity of the fragment is controlled by weighting the illumination occlusion intensity values of different vertices. The data can be obtained through GPU (Graphics Processing Unit) interpolation, and the numerical value of the color adjustment parameters represents the intensity of the fragment's color. The color adjustment parameters are then loaded onto the fragment's base color information to obtain the adjusted color information for each fragment. By utilizing the vertex color information of the primitives in the model to control the intensity of fragment colors, and thus controlling the overall color intensity of the model surface, this method is simple, efficient, and reduces the computational load on the GPU for occlusion algorithms in related technologies.
[0036] Step 208: Render the pixels corresponding to the fragments based on the fragment color information;
[0037] Rendering is the process by which a computer uses a program to generate an image from a model. The smallest unit of an image is a pixel. A fragment is a basic unit of pixel size that a primitive is divided into after the rasterization stage. During the rendering stage, fragments undergo coloring and shading operations to finally generate an image on the display. Each fragment (data element) may correspond to a single pixel (picture element), or there may not be a one-to-one correspondence between fragments and display pixels. For example, before displaying the final image, specific forms of post-processing, such as resizing, may be performed on the blended image.
[0038] In this step, the fragment data of the model contains color information used for rendering. Based on the color information of the fragments, the rendering operation is performed on the pixels corresponding to the fragments.
[0039] The rendering method described above involves obtaining a target model. The target model's surface includes multiple primitives; each primitive includes multiple vertices; fragments within each primitive have pre-set basic color information; vertex color information is set for each vertex based on its position within the target model; the vertex color information indicates the occlusion intensity at various locations within the target model; based on the vertex color information of the vertices included in the primitives, the basic color information of the fragments within the primitives is adjusted to obtain the adjusted fragment color information; and the pixels corresponding to the fragments are rendered based on the fragment color information. This method adjusts the color of each fragment in the model using vertex color information, thereby rendering a visual effect where different locations on the model have different occlusion intensities. This occlusion rendering method, while ensuring good visual rendering effects, reduces computational load, saves computing resources, and reduces game stuttering and frame rate issues.
[0040] The following embodiments provide a specific implementation method for obtaining vertex color information.
[0041] Each vertex color information can be a floating-point value that controls the intensity of the color, and its magnitude indicates the intensity of light occlusion. In the real world, the outer edges of trees are affected by light and appear brighter with higher saturation, while the interior of trees appears darker because they are not illuminated. Therefore, vertex color information is set for vertices based on their position in the target model. For the first primitive whose distance from the edge of the target model is less than a first distance threshold, the vertex color information of the vertices in the first primitive is set to be greater than the first color threshold. In this case, the first primitive whose distance from the edge of the target model is less than the first distance threshold can be understood as a primitive close to the edge of the target model, receiving more light. In this case, setting the vertex color information of the vertices in the first primitive to be greater than the first color threshold results in a larger vertex color information value in the subsequent fragments in the first primitive, leading to a larger color information value and a smaller light occlusion intensity.
[0042] For a second primitive whose distance from the edge of the target model is greater than a second distance threshold, the vertex color information of the vertices in the second primitive is set to be less than the second color threshold. In this case, the second primitive whose distance from the edge of the target model is greater than the first distance threshold can be understood as a primitive far from the edge of the target model, receiving less illumination. Therefore, setting the vertex color information of the vertices in the second primitive to be less than the second color threshold results in a smaller vertex color information value in the second primitive, leading to a smaller color information value for the adjusted fragments in the subsequent second primitive, and stronger illumination occlusion intensity. The first and second distance thresholds can be the same or different; the first and second color thresholds can also be the same or different.
[0043] Specifically, taking a tree model as an example, the vertices inside the tree model need to be set to a smaller vertex color value, while the vertices on the outer edge of the tree model need to be set to a larger vertex color value. The outer edge of the tree, affected by lighting, will appear brighter and more saturated, while the inner edge of the tree, because it receives less light, will appear darker. This can be achieved using tools in commercial game engines or 3D graphics software.
[0044] The following embodiments provide a specific implementation method for obtaining color adjustment parameters.
[0045] For each fragment in a primitive, the color adjustment parameters corresponding to the fragment are determined based on its position within the primitive and the vertex color information of each vertex in the primitive. A primitive can be divided into multiple fragments, which are then concatenated to form a primitive; therefore, each fragment has a different position within the primitive. In practical implementation, a position reference can be set, and the position of the fragment within the primitive can be determined by its relative position to this reference. This reference can be a vertex or an edge of the primitive. Using this position reference, the position of each fragment within the primitive can be expressed by a specific position parameter. Then, a preset algorithm processes this position parameter and the vertex color information of each vertex in the primitive to obtain the color adjustment parameters corresponding to the fragment.
[0046] In one specific approach, for each fragment in a primitive, the vertex color information of each vertex in the primitive is interpolated based on the distance between the fragment and each vertex in the primitive to obtain an interpolation result. This interpolation result is then used as the color adjustment parameter corresponding to the fragment. In this approach, the position of a fragment in the primitive is determined by the distance between the fragment and each vertex in the primitive. The closer a vertex is to the fragment, the greater the color adjustment parameter of that vertex for the fragment. Based on this, the interpolation weight corresponding to each vertex can be determined, and the vertex color information of each vertex is interpolated based on this interpolation weight. Specific interpolation methods can be implemented using various interpolation algorithms, such as bilinear interpolation and nearest neighbor interpolation.
[0047] Based on the above, in specific implementation, for each fragment in the primitive, the interpolation weight corresponding to each vertex can be determined based on the distance between the fragment and each vertex in the primitive; according to the interpolation weight corresponding to each vertex, the vertex color information of multiple vertices in the primitive is interpolated to obtain the interpolation result, which is the color adjustment parameter corresponding to the fragment.
[0048] The aforementioned color adjustment parameters are weighted color information parameters for fragments, obtained through GPU interpolation, and their values control the intensity of the color. During rendering, input primitive information data, including vertex color information, position, color, and texture coordinates, is transformed into a series of fragments during the rasterization stage. These fragments undergo a series of operations to imbue each fragment with attribute information such as position, color, and texture coordinates. This attribute information is obtained through GPU interpolation of vertex feature attributes. In this method, based on the distance between the fragment and each vertex in the primitive, weights are applied to the vertex color information data from the primitive using weighted attributes, and then interpolation is performed on the information of multiple vertices in the primitive. The resulting interpolation is the color adjustment parameter corresponding to that fragment.
[0049] Another embodiment provides a specific implementation method for color adjustment parameters and brightness adjustment parameters to participate in model rendering. For ease of understanding, Figure 3 Another method for rendering a model is shown, which includes the following steps:
[0050] Step S302: Obtain the target model; wherein, the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; and the fragments inside the primitives have pre-set basic color information.
[0051] This step is the same as step S202, and will not be repeated here.
[0052] Step S304: Set vertex color information for the vertex according to its position in the target model; vertex color information is used to indicate the light occlusion intensity at each position in the target model.
[0053] This step is the same as step S204. Specifically, based on the vertex's position in the target model, vertex color information is set for the vertex. For a first primitive whose distance from the edge of the target model is less than a first distance threshold, the vertex color information of the vertices in the first primitive is set to be greater than the first color threshold. For a second primitive whose distance from the edge of the target model is greater than a second distance threshold, the vertex color information of the vertices in the second primitive is set to be less than the second color threshold. Taking a tree as an example, the vertices inside the tree need to be set to a vertex color with a smaller value, while the vertices on the outer edge of the tree need to be set to a vertex color with a larger value. Of course, this operation can be achieved using tools in commercial game engines or 3D drawing software.
[0054] Step S306: For each fragment in the primitive, determine the color adjustment parameters corresponding to the fragment based on the position of the fragment in the primitive and the vertex color information of each vertex in the primitive.
[0055] As mentioned earlier, in this step, weights are applied to the color information data of each vertex from the primitive by using distance-weighted attributes, and then interpolation is performed on the information of multiple vertices in the primitive to obtain the interpolation result, which is the color adjustment parameter corresponding to the primitive. This stage is processed by the GPU.
[0056] Step S308: Adjust the basic color information of the fragments based on the color adjustment parameters to obtain the adjusted color information of each fragment;
[0057] In this implementation example, the adjusted color information of each fragment is obtained by multiplying the base color information of each surface fragment with its corresponding color adjustment parameters. This allows the vertex color to control the intensity of the surface color. This approach eliminates the high-consumption lighting occlusion algorithms found in related technologies, relying solely on vertex color to control lighting occlusion significantly reduces GPU computation and effectively alleviates the pressure on game performance.
[0058] Step S310: Obtain the preset brightness adjustment parameters, and adjust the color information of each fragment based on the brightness adjustment parameters to obtain the final color information of each fragment.
[0059] For example, the color information of a fragment can be added to the brightness adjustment parameter to obtain the final color information. Alternatively, the color information of each fragment can be multiplied by the brightness adjustment parameter to obtain the final color information of each fragment. Among these methods, multiplying the color information by the brightness adjustment parameter can achieve linear control and adjust the color information of the fragments over a wider range, thereby meeting more brightness adjustment needs.
[0060] In this embodiment, the brightness adjustment parameter is set to facilitate secondary adjustments by game developers. It is calculated by multiplying the brightness parameter with the color information of each fragment to adjust different effect details. The brightness adjustment parameter is typically set to 1.0, but other values can also be used. This step is mainly used to fine-tune the final effect to achieve the desired visual results for the developers.
[0061] In one specific implementation, this embodiment can provide a rendering formula, namely, FinalColor = Color * VertexColor * K; where FinalColor is the final color information of each fragment; Color is the basic color information of the fragment; VertexColor is the color adjustment parameter; and K is the brightness adjustment parameter.
[0062] Step S312: Render the pixels corresponding to the fragments based on the fragment color information;
[0063] Rendering is the process by which a computer uses a program to generate an image from a model. Specifically, in the computer graphics rendering process, vertex color information data is transformed by GPU weight interpolation. The resulting color adjustment parameters are then passed to the fragments corresponding to each pixel and obtained during the pixel processing stage. Based on the color adjustment parameters, the color intensity of the pixels can be processed, and the final result can be fine-tuned using brightness adjustment parameters to achieve the desired rendering effect.
[0064] The above-mentioned method of using vertex color information to control fragment color for pixel rendering only uses the vertex color information of primitives in the model to control the intensity of fragment color, and renders pixels based on fragment color to achieve the rendering effect. It is simple and efficient, realizes the light occlusion effect in the game, and greatly reduces the amount of computation of the GPU for occlusion algorithm, effectively alleviating the problem of low rendering efficiency in the existing technology.
[0065] For the corresponding method embodiments described above, see [link to relevant documentation]. Figure 4 The diagram shows a rendering apparatus for a model, which includes the following steps:
[0066] The model acquisition module 402 is used to acquire the target model, wherein the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; and the fragments inside the primitives have pre-set basic color information.
[0067] The vertex color information acquisition module 404 is used to set vertex color information for vertices according to their positions in the target model; the vertex color information is used to indicate the light occlusion intensity at each position in the target model.
[0068] The color information adjustment module 406 is used to adjust the basic color information of fragments in the primitive based on the vertex color information of the vertices included in the primitive, so as to obtain the adjusted color information of the fragments.
[0069] The rendering module 408 is used to render the pixels corresponding to the fragments based on the color information of the fragments mentioned above.
[0070] In the rendering device of the above model, a target model is acquired, wherein the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; fragments within the primitives have pre-set basic color information; vertex color information is acquired based on the position of the vertices in the target model; the vertex color information is used to indicate the lighting occlusion intensity at each position in the target model; color information of the acquired fragments is used; based on the vertex color information of the vertices included in the primitives, the basic color information of the fragments in the primitives is adjusted to obtain the adjusted color information of the fragments; and in response to the color information of the fragments, the pixels corresponding to the fragments are rendered. In this method, the color of each fragment in the model is adjusted by the vertex color information, thereby rendering a visual effect in which different positions of the model have different lighting occlusion intensities. This lighting occlusion rendering method, while ensuring good rendering visual effects, reduces the amount of computation, saves computing resources, and reduces the problems of game lag and frame rate failure.
[0071] The vertex color information acquisition module described above is further configured to: for a first primitive whose distance from the edge of the target model is less than a first distance threshold, set the vertex color information of the vertices in the first primitive to be greater than a first color threshold; and for a second primitive whose distance from the edge of the target model is greater than a second distance threshold, set the vertex color information of the vertices in the second primitive to be less than a second color threshold.
[0072] The aforementioned color information adjustment module is also used to: for each fragment in the primitive, determine the color adjustment parameters corresponding to the fragment based on the position of the fragment in the primitive and the vertex color information of each vertex in the primitive; adjust the basic color information of the fragment based on the color adjustment parameters to obtain the adjusted color information of each fragment.
[0073] The aforementioned color information adjustment module is further configured to: for each fragment in the primitive, perform interpolation processing on the vertex color information of each vertex in the primitive based on the distance between the fragment and each vertex in the primitive, and obtain the interpolation result; and determine the interpolation result as the color adjustment parameter corresponding to the fragment.
[0074] The aforementioned color information adjustment module is also used to: determine the interpolation weight corresponding to each vertex for each fragment in the primitive based on the distance between the fragment and each vertex in the primitive; and perform interpolation processing on the vertex color information of multiple vertices in the primitive based on the interpolation weight corresponding to each vertex to obtain the interpolation result.
[0075] The aforementioned color information adjustment module is also used for: adjusting the basic color information of the aforementioned fragments using the aforementioned color adjustment parameters to obtain the adjusted color information of each fragment, including: multiplying the basic color information of the fragments by the color adjustment parameters to obtain the adjusted color information of the fragments.
[0076] The aforementioned device further includes a brightness adjustment module, used to: acquire preset brightness adjustment parameters; and adjust the color information of each of the aforementioned fragments based on the brightness adjustment parameters to obtain the final color information of each fragment.
[0077] The brightness adjustment module described above is also used to: multiply the color information of each fragment by the brightness adjustment parameter to obtain the final color information of each fragment.
[0078] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the rendering method of the above-described model.
[0079] See Figure 5 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine-executable instructions that can be executed by the processor 100. The processor 100 executes the machine-executable instructions to implement the rendering method of the above-described model.
[0080] Furthermore, Figure 5 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 100, the communication interface 103 and the memory 101 connected via the bus 102.
[0081] The memory 101 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0082] Processor 100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 100 or by instructions in software form. Processor 100 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 101, and the processor 100 reads the information from memory 101 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0083] This embodiment also provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by the processor, the machine-executable instructions cause the processor to implement the rendering method of the above model.
[0084] The present invention provides a model rendering method, apparatus, and electronic device, including a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation details, please refer to the method embodiments, which will not be repeated here.
[0085] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0086] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0087] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0088] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0089] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for rendering a model, characterized in that, The method includes: Obtain the target model; wherein, the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; and the fragments within each primitive are pre-set with basic color information. Based on the position of the vertex in the target model, vertex color information is set for the vertex; the vertex color information is used to indicate the light occlusion intensity at each position in the target model. Based on the vertex color information of the vertices included in the primitive, the base color information of the fragments in the primitive is adjusted to obtain the adjusted color information of the fragments; Based on the color information of the fragment, the pixels corresponding to the fragment are rendered; The step of setting vertex color information for a vertex based on its position in the target model includes: For a first primitive whose distance from the edge of the target model is less than a first distance threshold, the vertex color information of the vertices in the first primitive is set to be greater than a first color threshold. For a second primitive whose distance from the edge of the target model is greater than a second distance threshold, the vertex color information of the vertices in the second primitive is set to be less than a second color threshold; The step of adjusting the base color information of fragments in the primitive based on the vertex color information of the vertices included in the primitive to obtain the adjusted color information of the fragments includes: For each fragment in the primitive, the color adjustment parameters corresponding to the fragment are determined based on the position of the fragment in the primitive and the vertex color information of each vertex in the primitive. The base color information of the fragment is adjusted based on the color adjustment parameters to obtain the adjusted color information of each fragment.
2. The method according to claim 1, characterized in that, For each fragment in the primitive, the step of determining the color adjustment parameters corresponding to the fragment based on the fragment's position in the primitive and the vertex color information of each vertex in the primitive includes: For each fragment in the primitive, based on the distance between the fragment and each vertex in the primitive, the vertex color information of each vertex in the primitive is interpolated to obtain the interpolation result; The interpolation result is determined as the color adjustment parameter corresponding to the fragment.
3. The method according to claim 2, characterized in that, For each fragment in the primitive, the step of interpolating the vertex color information of each vertex in the primitive based on the distance between the fragment and each vertex in the primitive to obtain the interpolation result includes: For each fragment in the primitive, the interpolation weight corresponding to each vertex is determined based on the distance between the fragment and each vertex in the primitive; Based on the interpolation weight corresponding to each vertex, the vertex color information of multiple vertices in the primitive is interpolated to obtain the interpolation result.
4. The method according to claim 1, characterized in that, The step of adjusting the base color information of the fragments based on the color adjustment parameters to obtain the adjusted color information of each fragment includes: multiplying the base color information of the fragments by the color adjustment parameters to obtain the adjusted color information of the fragments.
5. The method according to claim 1, characterized in that, After adjusting the base color information of fragments in the primitive based on the vertex color information of the vertices included in the primitive to obtain the adjusted color information of the fragments, the method further includes: Obtain the preset brightness adjustment parameters; Based on the brightness adjustment parameters, the color information of each fragment is adjusted to obtain the final color information of each fragment.
6. The method according to claim 5, characterized in that, The step of adjusting the color information of each fragment based on the brightness adjustment parameter to obtain the final color information of each fragment includes: multiplying the color information of each fragment by the brightness adjustment parameter to obtain the final color information of each fragment.
7. A rendering apparatus for a model, characterized in that, The device includes: The model acquisition module is used to acquire a target model, wherein the model surface of the target model includes multiple primitives; each primitive includes multiple vertices; and fragments within each primitive are pre-set with basic color information. A vertex color information acquisition module is used to set vertex color information for a vertex based on its position in the target model; the vertex color information is used to indicate the light occlusion intensity at each position in the target model; The color information adjustment module is used to adjust the basic color information of fragments in the primitive based on the vertex color information of the vertices included in the primitive, so as to obtain the adjusted color information of the fragments. The rendering module is used to render the pixels corresponding to the fragments based on the color information of the fragments; The vertex color information acquisition module is further configured to, for a first primitive whose distance from the edge of the target model is less than a first distance threshold, set the vertex color information of the vertices in the first primitive to be greater than a first color threshold; and for a second primitive whose distance from the edge of the target model is greater than a second distance threshold, set the vertex color information of the vertices in the second primitive to be less than a second color threshold. The color information adjustment module is further configured to determine the color adjustment parameters corresponding to each fragment in the primitive based on the position of the fragment in the primitive and the vertex color information of each vertex in the primitive; and adjust the basic color information of the fragment based on the color adjustment parameters to obtain the adjusted color information of each fragment.
8. An electronic device, characterized in that, It includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the rendering method of the model according to any one of claims 1-6.
9. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores machine-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the rendering method of the model according to any one of claims 1-6.