Model rendering method, device and electronic device
By dynamically adjusting the resolution of texture sampling, the target distance and resolution with the virtual camera are determined for each vertex according to the model and texture map to be rendered, the problem of mismatch between the texture resolution and the screen display resolution in the prior art is solved, and smooth transition and efficient rendering are achieved.
Patent Information
- Application Number
- CN202411544966.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-04-08
AI Technical Summary
When existing game engines render game screens, fixed texture resolution causes the texture resolution to mismatch the screen display resolution, causing blur or flickering, especially when the camera moves quickly.
By obtaining the model and texture map to be rendered, the target distance from the virtual camera is determined for each vertex, and the target resolution is determined based on the preset distance range and resolution range, dynamic adjustment of texture sampling is achieved.
It avoids transition blur, flicker or texture mutation during camera movement, and achieves smooth transitions at different distances and resolution ranges, improving rendering effect.
Smart Images

Figure CN119784921A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of data rendering, and in particular to a model rendering method, device and electronic device. Background Art
[0002] In the related art, in order to save performance and other considerations, the game engine sets the texture resolution within different partition distances from the camera to a fixed value when rendering the game screen. This method will cause the texture resolution to be inconsistent with the screen display resolution occupied during rendering, resulting in low-resolution textures being applied to high-resolution displays and being too blurry, or high-resolution textures covering low-resolution displays and causing flickering when the camera moves. At the same time, this method is prone to causing texture mutations, transition blur or flickering when the camera moves quickly. Summary of the invention
[0003] The purpose of the present disclosure is to provide a model rendering method, device and electronic device, which can be flexibly applied to different distance ranges and resolution ranges for texture sampling for different object models, thereby avoiding transition blur, flickering or mutation caused by camera movement.
[0004] In a first aspect, the present disclosure provides a model rendering method, the method comprising: obtaining a model to be rendered and assigning a texture map to the model to be rendered; wherein the model to be rendered comprises a plurality of vertices, and the texture map is used to render the texture of the surface of the model to be rendered; for each vertex in the model to be rendered, determining a target distance between the vertex and a virtual camera, determining a target distance range to which the target distance belongs from a plurality of preset distance ranges, and determining a target resolution of the vertex corresponding to the target distance based on a target resolution range corresponding to the target distance range; wherein the plurality of preset distance ranges are respectively configured with corresponding resolution ranges; based on the target resolution corresponding to each vertex in the model to be rendered, texture sampling is performed on the texture map to obtain the model to be rendered after texture rendering.
[0005] In a second aspect, the present disclosure provides a model rendering device, which includes: a model acquisition module, used to acquire a model to be rendered and a texture map assigned to the model to be rendered; wherein the model to be rendered includes multiple vertices, and the texture map is used to render the texture of the surface of the model to be rendered; a resolution determination module, used to determine, for each vertex in the model to be rendered, a target distance between the vertex and a virtual camera, determine a target distance range to which the target distance belongs from multiple preset distance ranges, and determine a target resolution of the vertex corresponding to the target distance based on a target resolution range corresponding to the target distance range; wherein the multiple preset distance ranges are respectively configured with corresponding resolution ranges; a texture rendering module, used to perform texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered, to obtain the model to be rendered after texture rendering.
[0006] In a third aspect, the present disclosure provides an electronic device, which includes 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-mentioned model rendering method.
[0007] In a fourth aspect, the present disclosure provides a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned model rendering method.
[0008] The embodiments of the present disclosure bring the following beneficial effects:
[0009] The present disclosure provides a model rendering method, device and electronic device, which first obtains a model to be rendered and a texture map assigned to the model to be rendered; wherein the model to be rendered includes multiple vertices, and the texture map is used to render the texture of the surface of the model to be rendered; for each vertex in the model to be rendered, the target distance between the vertex and the virtual camera is determined, the target distance range to which the target distance belongs is determined from multiple preset distance ranges, and based on the target resolution range corresponding to the target distance range, the target resolution of the vertex corresponding to the target distance is determined; wherein the multiple preset distance ranges are respectively configured with corresponding resolution ranges; then, based on the target resolution corresponding to each vertex in the model to be rendered, texture sampling is performed on the texture map to obtain the model to be rendered after texture rendering. This method can determine the resolution corresponding to the vertex at a certain distance from the virtual camera in real time according to the preset distance range and the resolution range corresponding to the preset distance range, and realize a smooth transition of resolutions corresponding to different distances, thereby avoiding the phenomenon of sudden changes in model texture caused by the movement of the virtual camera.
[0010] Other features and advantages of the present disclosure will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present disclosure.
[0011] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, the following specifically cites preferred implementation modes and describes them in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0013] Figure 1 A flowchart of a model rendering method provided by an embodiment of the present disclosure;
[0014] Figure 2 A schematic diagram of the structure of a model rendering device provided in an embodiment of the present disclosure;
[0015] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0016] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all the embodiments. The components of the embodiments of the present disclosure described and shown in the drawings here can be arranged and designed in various different configurations.
[0017] Therefore, the following detailed description of the embodiments of the present disclosure provided in the accompanying drawings is not intended to limit the scope of the present disclosure claimed for protection, but merely represents selected embodiments of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present disclosure.
[0018] Currently, in the game engine, you can turn on TextureLOD by controlling the Boolean parameter in the configuration file to achieve global texture hierarchical rendering, and the textures closer to the camera are clearer and have higher resolutions, while the farther away, the lower the resolution and the blurrier. Among them, TextureLOD is a function used to explicitly control the level of detail (LOD) of the texture in the shader. LOD control can be used to control the level of detail of the texture to improve performance or render realistic textures at different distances. Lower levels of detail usually cause the texture to look blurry, while higher levels of detail will show more details.
[0019] However, in order to save performance and other considerations, most of the solutions in game engines in related technologies set the texture resolution within different partition distances from the camera to a fixed value. When the camera moves, obvious texture mutations will be felt, and often the texture's color channel (also called RGB channel) and transparency channel (Alpha channel) are uniformly graded and partitioned, which has low flexibility and poor effect.
[0020] The intervals of texture grading in the game engine in the related technology cannot be customized, resulting in the resolution of the texture not being consistent with the rendering and occupied screen display resolution, resulting in low-resolution textures being too blurry when applied to high-resolution displays, or high-resolution textures covering low-resolution displays and causing flickering when the camera moves. And because there is no transition in the current partition grading, it is easy to feel texture mutations when the camera moves quickly. At the same time, in the current LOD grading scheme, the color channel and transparency channel of the texture are often uniformly graded and partitioned, which cannot meet the needs of some texture applications where the transparency edges are complex and the color is simple. Better visual effects can be achieved by distinguishing channel grading.
[0021] Based on the above problems, the embodiments of the present disclosure provide a model rendering method, device and electronic device. The technology can be applied to texture rendering and model rendering scenarios.
[0022] In order to facilitate understanding of the embodiments of the present disclosure, a model rendering method provided by the embodiments of the present disclosure is first described in detail. Figure 1 As shown, the method comprises the following specific steps:
[0023] Step S102, obtaining a model to be rendered and a texture map assigned to the model to be rendered; wherein the model to be rendered includes a plurality of vertices, and the texture map is used to render the texture of the surface of the model to be rendered.
[0024] In specific implementation, the model to be rendered can be any three-dimensional model, which can be drawn by the user in the game engine, or drawn in three-dimensional drawing software and then transferred to the game engine. The texture map can be an image with any pattern or color. The texture map can map the texture pixels in the texture space to the three-dimensional model in the model space, that is, a texture map is pasted on the surface of the three-dimensional model to enhance the sense of reality. It can be combined with lighting calculation, image mixing and other technologies to form many very beautiful effects.
[0025] In a specific embodiment, the above-mentioned model to be rendered is usually composed of a plurality of triangular facets, each of which is composed of three vertices and three edges. By combining these triangular facets, a complex geometric shape can be constructed. These triangular facets are connected together by adjacent edges to form the surface of the three-dimensional model. In another specific embodiment, the above-mentioned model to be rendered can also be composed of facets of other shapes, each of which contains multiple vertices, for example, other shapes can be squares or hexagons.
[0026] Step S104, for each vertex in the model to be rendered, determine the target distance between the vertex and the virtual camera, determine the target distance range to which the target distance belongs from multiple preset distance ranges, and determine the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range; wherein the multiple preset distance ranges are respectively configured with corresponding resolution ranges.
[0027] After the game engine obtains the model to be rendered and the texture map, it needs to determine the corresponding resolution according to the distance between the model to be rendered and the virtual camera, so that users can configure different resolutions for different distances to meet their personalized needs. Among them, the virtual camera is used in the game engine to shoot the 3D model to form the model screen. Usually, the texture of the 3D model that is close to the virtual camera is clearer and has a higher resolution. On the contrary, the farther away it is, the lower the resolution and the more blurred it is.
[0028] When determining the resolution corresponding to the vertices in the model to be rendered, it is first necessary to calculate the target distance between each vertex in the model to be rendered and the virtual camera, and then determine the target distance range to which the target distance corresponding to each vertex belongs from multiple preset distance ranges, and then determine the target resolution corresponding to each vertex in the target resolution range corresponding to the target distance range. Since the distance between each vertex in the model to be rendered and the virtual camera is different, the target resolution corresponding to each vertex is also different, but the target resolution corresponding to some vertices may be the same, which can be determined according to the divided preset distance range and resolution range.
[0029] In actual applications, users can divide multiple preset distance ranges according to needs, and the minimum distance value and the maximum distance value corresponding to each preset distance range can be determined according to user settings or research and development needs. For example, it can be divided into three preset distance ranges, namely (0, a], (a, b], (b, ∞); wherein a and b both represent distance values, and a is less than b, and ∞ represents infinite distance. Users can set multiple resolution ranges according to needs, and the number of resolution ranges is the same as the number of preset distance ranges; for example, it can be divided into three resolution ranges, namely (e, f], (f, g] and (g, h], wherein e, f, g and h are all used to indicate specific resolution values, and e is less than f, f is less than g, and g is less than h. Based on the above description, the resolution range corresponding to the preset distance range (0, a] is (e, f], the resolution range corresponding to the preset distance range (a, b] is (f, g], and the resolution corresponding to the preset distance range (b, ∞) is (g, h]. This method can more flexibly set the distance range and the resolution range corresponding to each distance range.
[0030] In an optional embodiment, a specific method for determining the target resolution corresponding to each vertex in the target resolution range corresponding to the target distance range may be: randomly determining a resolution from the target resolution range as the target resolution corresponding to the vertex; interpolating the minimum and maximum values of the target resolution range according to the target distance to obtain the target resolution corresponding to the vertex; the target resolution may also be determined by other methods, which may be determined specifically according to research and development needs.
[0031] Step S106, based on the target resolution corresponding to each vertex in the model to be rendered, texture sampling is performed on the texture map to obtain the model to be rendered after texture rendering.
[0032] When the target resolution corresponding to each vertex in the model to be rendered is obtained, the pixel at the texture coordinate position corresponding to each vertex in the texture map can be sampled based on the target resolution corresponding to each vertex to obtain the sampling value corresponding to each vertex, which is also the color value. Then, based on the sampling value corresponding to each vertex in the model to be rendered, the model to be rendered is texture rendered to obtain the model to be rendered after texture rendering.
[0033] A model rendering method provided by an embodiment of the present disclosure can determine in real time the resolution corresponding to vertices at a certain distance from a virtual camera according to a set preset distance range and a resolution range corresponding to the preset distance range, and achieve a smooth transition of resolutions corresponding to different distances, thereby avoiding sudden changes in model texture caused by the movement of the virtual camera.
[0034] The following embodiments are used to describe the method of determining the resolution corresponding to the vertices.
[0035] Specifically, the specific process of determining the target distance between the vertex and the virtual camera may include: obtaining vertex coordinates corresponding to the vertex and camera coordinates of the virtual camera; and determining the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates.
[0036] In the specific implementation, the distance between each vertex in the model to be rendered and the virtual camera can be calculated in the vertex shader, which can be used as the basis for TextureLOD partitioning, that is, as the basis for dividing the resolutions corresponding to vertices at different distances from the virtual camera. First, it is necessary to determine the vertex coordinates corresponding to each vertex in the model to be rendered in the world coordinate system, as well as the camera coordinates corresponding to the virtual camera in the world coordinate system; then calculate the distance between each vertex coordinate and the camera coordinate, and obtain the target distance corresponding to each vertex and the virtual camera.
[0037] In an optional embodiment, the target distance between the vertex and the virtual camera may be a straight-line distance between the vertex and the virtual camera, or a straight-line distance from the vertex to a certain plane where the virtual camera is located. Since the vertex coordinates and the camera coordinates are both three-dimensional coordinates, the certain plane where the virtual camera is located may be an XZ-axis plane, an XY-axis plane, or a YZ-axis plane where the virtual camera is located.
[0038] In a specific embodiment, the specific process of determining the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates may include: determining a first coordinate value corresponding to a first axis in the vertex coordinates, a first coordinate value corresponding to the first axis in the camera coordinates, a second coordinate value corresponding to a second axis in the vertex coordinates, and a second coordinate value corresponding to the second axis in the camera coordinates; subtracting the first coordinate value corresponding to the vertex coordinates from the first coordinate value corresponding to the camera coordinates to obtain a first subtraction result; subtracting the second coordinate value corresponding to the vertex coordinates from the second coordinate value corresponding to the camera coordinates to obtain a second subtraction result; adding the square of the first subtraction result to the square of the second subtraction result to obtain an addition result; and taking the square root of the addition result to obtain the target distance between the vertex and the virtual camera.
[0039] In a specific implementation, the first axis and the second axis are different axes in the world coordinate system, and the first axis and the second axis can be determined according to research and development requirements. For example, the first axis can be the X axis, and the second axis can be the Y axis; the first axis can be the X axis, and the second axis can be the Z axis, etc.
[0040] In a specific embodiment, since the change of the Y-axis distance of the virtual camera in the game is not obvious, it is not desirable for the resolution grading to be sensitive to the Y-axis. Therefore, the first axis can be determined as the X-axis and the second axis can be determined as the Z-axis. Based on this, assuming that the vertex coordinates corresponding to a vertex are (x1, y1, z1) and the camera coordinates are (x2, y2, z2), then the target distance between the vertex and the virtual camera is Among them, x1 is the coordinate value corresponding to the X axis in the vertex coordinates, and x2 is the coordinate value corresponding to the X axis in the camera coordinates; z1 is the coordinate value corresponding to the Z axis in the vertex coordinates, and z2 is the coordinate value corresponding to the Z axis in the camera coordinates. The above target distance is the straight-line distance from the vertex to the XZ plane of the virtual camera, which is independent of the Y axis coordinates.
[0041] In an optional embodiment, since the coordinate position in the world coordinate system is too large in the open world, the target distance between the obtained vertex and the virtual camera can be divided by a preset value to reduce the target distance to a limited range. The updated target distance can be obtained by dividing the target distance by the preset value, and the updated target distance is subsequently used to determine the resolution. The above preset value can be determined according to research and development requirements, for example, the preset value can be 300 or 200, etc.
[0042] Furthermore, the specific process of determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range may include: normalizing the target distance to obtain a normalized distance value; and performing linear interpolation between the minimum value and the maximum value corresponding to the target resolution range through the normalized distance value to obtain the target resolution. This method allows the resolution to smoothly transition to adapt to the movement of the virtual camera and avoid screen flickering.
[0043] In the specific implementation, if the target distance between a vertex in the model to be rendered and the virtual camera belongs to the target distance range, the target resolution range corresponding to the target distance range is (g, f]. First, the target distance corresponding to the vertex is mapped to the range [0, 1] according to the upper and lower limits of the target distance range to obtain a value x. The closer the x value is to 0, the closer it is to the lower limit of the target distance range and the closer it is to the virtual camera. The larger the x value is, the closer it is to the upper limit of the target distance range and the farther it is from the virtual camera. This value is used to blend the f and g values through a linear interpolation function to obtain the sampling resolution corresponding to the vertex. In this way, when the model vertex moves from the virtual camera position, the sampling resolution will gradually transition without sudden changes.
[0044] In a specific embodiment, linear interpolation processing can be performed by the smoothstep function, which is an interpolation function commonly used in computer graphics and other fields for smooth transition data. Its main purpose is to generate smooth interpolation within a given range, smoothstep (edge0, edge1, x), where edge0 and edge1 are the minimum and maximum values corresponding to the target resolution range, respectively, and the x value (equivalent to the normalized distance value) is the input value to be interpolated. It is mainly implemented in three steps. The first step is normalization, which normalizes the input x value to the range of [0, 1], float t = (x-edge0) / (edge1-edge0); the second step is clipping to limit t to the range of [0, 1] to ensure that the output value does not exceed this range, t = clamp (t, 0.0, 1.0); the third step is to apply the cubic interpolation polynomial t*t* (3.0-2.0*t) to obtain the target resolution corresponding to the x value. The result is a smooth transition from 0 to 1 between edge0 and edge1.
[0045] Furthermore, the specific process of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering may include: inputting the target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader; performing texture sampling on the texture map based on the target resolution through the preset fragment shader to obtain a sampling result; rendering the texture of the surface of the model to be rendered based on the sampling result to obtain the model to be rendered after texture rendering.
[0046] In the specific implementation, the calculation of the target resolution corresponding to each vertex in the model to be rendered is performed in the vertex shader. After the target resolution corresponding to each vertex is calculated in the vertex shader, the target resolution corresponding to each vertex calculated by the vertex shader is passed to the fragment shader, so that the fragment shader performs the final texture sampling on the texture map through the SampleLevel sampling function, thereby obtaining the sampling result corresponding to each vertex, and the sampling result corresponding to each vertex is fused on the surface of the model to be rendered, and the model to be rendered after texture rendering can be obtained. Before the fragment shader performs sampling, it is necessary to determine the relationship between each vertex in the model to be rendered and the texture coordinates (that is, UV coordinates) corresponding to each pixel in the texture map, so as to determine the texture coordinates corresponding to each vertex in the texture map, so as to subsequently perform texture sampling on the corresponding texture coordinates in the sampling map according to the target sampling rate corresponding to a certain vertex.
[0047] It should be noted that the above-mentioned vertex shader is a program executed for each vertex in the graphics. Its main function is to transform, project and perform other operations on the vertex according to the input vertex information (such as the position, normal, color, texture coordinates, etc. of the vertex), and finally pass the transformed vertex position to the next stage (usually the primitive assembly or geometry shader). In the vertex shader, developers can implement various operations such as transformation, deformation, lighting calculation, and perform some vertex-level calculations and processing. The fragment shader is a program executed for each pixel (or fragment) in the graphics. Its main function is to calculate the final color value of each pixel, usually including operations such as color, normal, texture sampling, lighting calculation, etc. Fragment shaders can be used to implement various visual effects, such as lighting models, texture mapping, shadow calculations, transparent effects, post-processing, etc.
[0048] The following embodiments are used to describe the method of determining the preset distance range and resolution range.
[0049] Specifically, the above-mentioned multiple preset distance ranges are determined based on the distance parameter, and the resolution range corresponding to the preset distance range is determined based on the resolution parameter; wherein the distance parameter and the resolution parameter are custom parameters. The user can customize multiple preset distance ranges and multiple resolution ranges according to the distance parameter and the resolution parameter, thereby improving the flexibility of resolution grading.
[0050] In a specific implementation, the above-mentioned distance parameter may include multiple sub-distance values, so that multiple preset distance ranges are determined according to the multiple sub-distance values. For example, the distance parameter may be (a, b), where a is greater than b. Then, three preset distance ranges can be obtained according to the distance parameter, namely (0, a], (a, b] and (b, ∞). The above-mentioned resolution parameter also includes multiple sub-resolution levels, so that multiple resolution ranges are determined according to the multiple sub-resolution levels. For example, the resolution parameter may be (e, f, g, h). Then, three resolution ranges can be obtained according to the resolution parameter, namely (e, f], (f, g] and (g, h]. Therefore, the resolution range corresponding to the preset distance range (0, a] is (e, f], the resolution range corresponding to the preset distance range (a, b] is (f, g], and the resolution corresponding to the preset distance range (b, ∞) is (g, h].
[0051] In an optional embodiment, the above-mentioned texture map is determined based on the color value corresponding to the color channel and the transparency value corresponding to the transparent channel; the color channel is configured with a first distance parameter and a first resolution parameter, and the transparent channel is configured with a second distance parameter and a second resolution parameter; that is, this method separates the Alpha channel (equivalent to the above-mentioned transparency channel) from the RGB channel (equivalent to the above-mentioned color channel), and controls the area and transition of texture resolution grading through two different parameters.
[0052] Among them, RGB in the RGB channel stands for red (R), green (G), and blue (B), which are the basic color components used to describe the color of a pixel. In most color images, each pixel is composed of the values of the three channels of red, green, and blue, which are used to mix to form a specific color. The alpha channel is usually used to describe the transparency or opacity of a pixel. It is an additional color channel in an image, and usually represents the transparency of the pixel with a value between 0 and 1, where 0 means completely transparent and 1 means completely opaque.
[0053] In a specific embodiment, four parameters need to be created in the preset file to control the interval interpolation of the texture partition, that is, to determine the resolution of the texture sampling. These four parameters include a first distance parameter, a second distance parameter, a first resolution parameter and a second resolution parameter. These four parameters are user-defined parameters and can be set by the user as required. Among them, the first distance parameter and the second distance parameter respectively divide the intervals of the color channel and transparency channel texture partitions according to the distance from the virtual camera (the area here is equivalent to the above-mentioned preset distance range). For example, the first distance parameter is a float4 value set to float4 (a, b, c, d), mainly using the first two parameters a and b, the distance from the virtual camera to the model vertex is t, which can be divided into three intervals according to this, interval 1, from 0 to a from the virtual camera; interval 2, from a to b from the virtual camera; interval 3, from b to infinity from the virtual camera.
[0054] Among them, the first resolution parameter and the second resolution parameter are used to control the MipMap level of the color channel and the transparency channel corresponding to different intervals, respectively. The MipMap level here is equivalent to the above-mentioned resolution range. For example, the first resolution parameter is a float4 value set to float4(e,f,g,h), e and f control the resolution range of the image sampling of interval 1; f and g control the resolution range of the image sampling of interval 2; g and h control the resolution range of the image sampling of interval 3. In this way, the LOD interval range and the resolution range of each interval can be adjusted according to different texture map configurations.
[0055] It should be noted that MipMap Level is one of the multi-resolution levels used to describe textures. Mipmap is a technique for optimizing texture mapping that improves rendering performance and image quality by storing multiple versions of texture images at different resolution levels of the texture. Mipmap level refers to one of the layers in these different resolution versions. In Mipmapping, the original texture is scaled down to different resolution levels, and each level of texture is half the size of the original texture. This allows lower resolution textures to be used when rendering distant objects, thereby improving performance, while higher resolution textures can be used when rendering nearby objects, maintaining image quality. Mipmap levels usually start with 0, indicating the highest resolution level (original texture), and then gradually increase to represent the corresponding scaled-down version.
[0056] The following embodiments are used to describe the manner of processing the color channel and the transparency channel separately.
[0057] Specifically, the specific process of determining the target distance range to which the target distance belongs from multiple preset distance ranges, and determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range, may include: determining a first target distance range to which the target distance belongs from multiple first preset distance ranges through a preset vertex shader, and determining a first target resolution corresponding to the vertex corresponding to the target distance in the color channel based on a first target resolution range corresponding to the first target distance range; wherein the multiple first preset distance ranges are determined based on a first distance parameter, and the resolution range corresponding to the first preset distance range is determined based on the first resolution parameter; determining a second target distance range to which the target distance belongs from multiple second preset distance ranges through a preset vertex shader, and determining a second target resolution corresponding to the vertex corresponding to the target distance in the transparent channel based on a second target resolution range corresponding to the second target distance range.
[0058] In the specific implementation, it is necessary to determine the resolution corresponding to each vertex in the model to be rendered for the color channel and the transparency channel respectively, so that different resolutions can be used for sampling for different channels later, thereby meeting the user's personalized needs and making the sampling results more natural.
[0059] In practical applications, color and transparency are separated and partitioned, and the texture is divided into RGB color and Alpha opacity to create a first distance parameter, a second distance parameter, a first resolution parameter, and a second resolution parameter, respectively, so as to obtain multiple first preset distance ranges corresponding to the RGB channel and a resolution range corresponding to each first preset distance range, and multiple second preset distance ranges corresponding to the Alpha channel and a resolution range corresponding to each second preset distance range. Then, the target distance between each vertex in the model to be rendered and the virtual camera is calculated, and it is determined which preset distance range of the multiple first preset distance ranges corresponding to the RGB channel the target virtual is located in, and which preset distance range of the multiple second preset distance ranges corresponding to the Alpha channel. After determining which preset distance range it is located in, according to the smooth interpolation algorithm, the resolution range corresponding to the preset distance range corresponding to the RGB channel of the vertex is interpolated and mixed, and the resolution range corresponding to the preset distance range corresponding to the Alpha channel of the vertex is interpolated and mixed, so as to achieve a smooth transition to adapt to the movement of the camera.
[0060] For example, if a vertex of the model to be rendered is located in interval 2 through RGB calculation, the corresponding resolution is determined by the f and g controls of the first resolution parameter float4(e,f,g,h). First, the target distance between the vertex and the virtual camera is mapped to the value x between [0,1] according to the upper and lower limits of interval 2 through smoothstep. This x value is used to blend the f and g values through the lerp linear interpolation function to obtain the sampling resolution. In this way, when the model vertex moves away from the camera position, the sampling resolution will gradually transition without sudden changes.
[0061] Based on the above description, the specific process of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering may include: inputting the first target resolution and the second target resolution corresponding to each vertex in the model to be rendered into the preset fragment shader respectively; performing texture sampling on the color channel in the texture map based on the first target resolution through the preset fragment shader to obtain a first sampling result, and performing texture sampling on the transparent channel in the texture map based on the second target resolution to obtain a second sampling result; integrating the first sampling result and the second sampling result to obtain a final sampling result; rendering the texture of the surface of the model to be rendered based on the final sampling result to obtain the model to be rendered after texture rendering.
[0062] In the specific implementation, the vertex shader calculates the texture partition level of each vertex (equivalent to the target sampling rate), passes the structure from the vertex shader to the fragment shader to obtain sampleBiasX and sampleBiasY, and performs the final texture sampling through the SampleLevel sampling function. The LOD level of the texture sampling can be controlled by the input of the last value. SampleBiasX controls the LOD level of the RGB channel, and sampleBiasY controls the LOD level of the Alpha channel. The LOD level here is used to control the level of detail of the texture. Generally, the higher the sampling rate, the higher the corresponding LOD level. Among them, sampleBiasX and sampleBiasY are parameters applied in the fragment shader, which are used to pass the target resolution of each vertex corresponding to the RGB channel calculated in the vertex shader, and the target resolution of each vertex corresponding to the Alpha channel.
[0063] Through this solution, different model textures can customize different distance parameters and resolution parameters according to their own characteristics. At the same time, all algorithm calculations are mainly performed in the vertex shader, which has better performance than the pixel shader. In addition, the RGB and Alpha channels are separated and graded separately, which can more flexibly adapt to different scenes to achieve better picture effects.
[0064] Corresponding to the above method embodiment, the present disclosure embodiment also provides a model rendering device, such as Figure 2 As shown, the device comprises:
[0065] The model acquisition module 20 is used to acquire the model to be rendered and assign a texture map to the model to be rendered; wherein the model to be rendered includes a plurality of vertices, and the texture map is used to render the texture of the surface of the model to be rendered.
[0066] The resolution determination module 21 is used to determine the target distance between each vertex in the model to be rendered and the virtual camera, determine the target distance range to which the target distance belongs from multiple preset distance ranges, and determine the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range; wherein the multiple preset distance ranges are respectively configured with corresponding resolution ranges.
[0067] The texture rendering module 22 is used to perform texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered, so as to obtain the model to be rendered after texture rendering.
[0068] The above-mentioned model rendering device can determine the resolution corresponding to vertices at a certain distance from the virtual camera in real time according to the set preset distance range and the resolution range corresponding to the preset distance range, and realize a smooth transition of resolutions corresponding to different distances, thereby avoiding the sudden change of model texture caused by the movement of the virtual camera.
[0069] Specifically, a plurality of preset distance ranges are determined based on a distance parameter, and a resolution range corresponding to the preset distance range is determined based on a resolution parameter; wherein the distance parameter and the resolution parameter are custom parameters.
[0070] Further, the above-mentioned texture map is determined based on the color value corresponding to the color channel and the transparency value corresponding to the transparent channel; the color channel is configured with a first distance parameter and a first resolution parameter, and the transparent channel is configured with a second distance parameter and a second resolution parameter; based on this, the above-mentioned resolution determination module 21 is used to: determine the first target distance range to which the target distance belongs from multiple first preset distance ranges through a preset vertex shader, and determine the first target resolution corresponding to the color channel of the vertex corresponding to the target distance based on the first target resolution range corresponding to the first target distance range; wherein the multiple first preset distance ranges are determined based on the first distance parameter, and the resolution range corresponding to the first preset distance range is determined based on the first resolution parameter; determine the second target distance range to which the target distance belongs from multiple second preset distance ranges through a preset vertex shader, and determine the second target resolution corresponding to the transparent channel of the vertex corresponding to the target distance based on the second target resolution range corresponding to the second target distance range.
[0071] Furthermore, the above-mentioned texture rendering module 22 is used to: input the first target resolution and the second target resolution corresponding to each vertex in the model to be rendered into the preset fragment shader respectively; through the preset fragment shader, texture sampling is performed on the color channel in the texture map based on the first target resolution to obtain a first sampling result, and texture sampling is performed on the transparent channel in the texture map based on the second target resolution to obtain a second sampling result; integrate the first sampling result and the second sampling result to obtain a final sampling result; render the texture of the surface of the model to be rendered based on the final sampling result to obtain the model to be rendered after texture rendering.
[0072] In a specific implementation, the resolution determination module 21 is used to: obtain the vertex coordinates corresponding to the vertex and the camera coordinates of the virtual camera; and determine the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates.
[0073] Furthermore, the above-mentioned resolution determination module 21 is also used to: determine the first coordinate value corresponding to the first axis in the vertex coordinates, the first coordinate value corresponding to the first axis in the camera coordinates, the second coordinate value corresponding to the second axis in the vertex coordinates, and the second coordinate value corresponding to the second axis in the camera coordinates; subtract the first coordinate value corresponding to the vertex coordinates from the first coordinate value corresponding to the camera coordinates to obtain a first subtraction result; subtract the second coordinate value corresponding to the vertex coordinates from the second coordinate value corresponding to the camera coordinates to obtain a second subtraction result; add the square of the first subtraction result to the square of the second subtraction result to obtain an addition result; and take the square root of the addition result to obtain the target distance between the vertex and the virtual camera.
[0074] Furthermore, the above-mentioned resolution determination module 21 is also used to: normalize the target distance to obtain a normalized distance value; and perform linear interpolation between the minimum value and the maximum value corresponding to the target resolution range through the normalized distance value to obtain the target resolution.
[0075] Furthermore, the above-mentioned texture rendering module 22 is used to: input the target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader; through the preset fragment shader, perform texture sampling on the texture map based on the target resolution to obtain a sampling result; render the texture of the surface of the model to be rendered based on the sampling result to obtain the model to be rendered after texture rendering.
[0076] The model rendering device provided in the embodiment of the present disclosure has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.
[0077] The present disclosure also provides an electronic device, such as Figure 3 As shown, the electronic device includes 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 above-mentioned model rendering method.
[0078] Specifically, the above-mentioned model rendering method includes: obtaining a model to be rendered and assigning a texture map to the model to be rendered; wherein the model to be rendered includes multiple vertices, and the texture map is used to render the texture of the surface of the model to be rendered; for each vertex in the model to be rendered, determining the target distance between the vertex and the virtual camera, determining the target distance range to which the target distance belongs from multiple preset distance ranges, and determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range; wherein the multiple preset distance ranges are respectively configured with corresponding resolution ranges; based on the target resolution corresponding to each vertex in the model to be rendered, texture sampling is performed on the texture map to obtain the model to be rendered after texture rendering.
[0079] The above-mentioned model rendering method can determine the resolution corresponding to vertices at a certain distance from the virtual camera in real time according to the set preset distance range and the resolution range corresponding to the preset distance range, and realize a smooth transition of resolutions corresponding to different distances, thereby avoiding the sudden change of model texture caused by the movement of the virtual camera.
[0080] In an optional embodiment, the above-mentioned multiple preset distance ranges are determined based on distance parameters, and the resolution ranges corresponding to the preset distance ranges are determined based on resolution parameters; wherein the distance parameter and the resolution parameter are custom parameters.
[0081] In an optional embodiment, the texture map is determined based on a color value corresponding to a color channel and a transparency value corresponding to a transparent channel; the color channel is configured with a first distance parameter and a first resolution parameter, and the transparent channel is configured with a second distance parameter and a second resolution parameter; based on this, the step of determining a target distance range to which a target distance belongs from a plurality of preset distance ranges, and determining a target resolution of a vertex corresponding to the target distance based on a target resolution range corresponding to the target distance range, comprises: determining a first target distance range to which a target distance belongs from a plurality of first preset distance ranges through a preset vertex shader, and determining a first target resolution corresponding to a color channel for a vertex corresponding to the target distance based on a first target resolution range corresponding to the first target distance range; wherein the plurality of first preset distance ranges are determined based on the first distance parameter, and the resolution range corresponding to the first preset distance range is determined based on the first resolution parameter; determining a second target distance range to which a target distance belongs from a plurality of second preset distance ranges through a preset vertex shader, and determining a second target resolution corresponding to a transparent channel for a vertex corresponding to the target distance based on a second target resolution range corresponding to the second target distance range.
[0082] In an optional embodiment, the above-mentioned step of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering includes: inputting the first target resolution and the second target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader respectively; through the preset fragment shader, performing texture sampling on the color channel in the texture map based on the first target resolution to obtain a first sampling result, and performing texture sampling on the transparent channel in the texture map based on the second target resolution to obtain a second sampling result; integrating the first sampling result and the second sampling result to obtain a final sampling result; rendering the texture of the surface of the model to be rendered based on the final sampling result to obtain the model to be rendered after texture rendering.
[0083] In an optional embodiment, the step of determining the target distance between the vertex and the virtual camera includes: obtaining vertex coordinates corresponding to the vertex and camera coordinates of the virtual camera; and determining the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates.
[0084] In an optional embodiment, the step of determining the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates includes: determining a first coordinate value corresponding to a first axis in the vertex coordinates, a first coordinate value corresponding to the first axis in the camera coordinates, a second coordinate value corresponding to a second axis in the vertex coordinates, and a second coordinate value corresponding to the second axis in the camera coordinates; subtracting the first coordinate value corresponding to the vertex coordinates from the first coordinate value corresponding to the camera coordinates to obtain a first subtraction result; subtracting the second coordinate value corresponding to the vertex coordinates from the second coordinate value corresponding to the camera coordinates to obtain a second subtraction result; adding the square of the first subtraction result to the square of the second subtraction result to obtain an addition result; and taking the square root of the addition result to obtain the target distance between the vertex and the virtual camera.
[0085] In an optional embodiment, the step of determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range includes: normalizing the target distance to obtain a normalized distance value; and performing linear interpolation between the minimum value and the maximum value corresponding to the target resolution range through the normalized distance value to obtain the target resolution.
[0086] In an optional embodiment, the above-mentioned step of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering includes: inputting the target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader; performing texture sampling on the texture map based on the target resolution through the preset fragment shader to obtain a sampling result; rendering the texture of the surface of the model to be rendered based on the sampling result to obtain the model to be rendered after texture rendering.
[0087] Further, Figure 3 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 101 , the communication interface 103 and the memory 100 are connected via the bus 102 .
[0088] The memory 100 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0089] The processor 101 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 101. The above processor 101 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can 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 gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 100, and the processor 101 reads the information in the memory 100 and completes the steps of the method of the above embodiment in combination with its hardware.
[0090] The embodiment of the present disclosure also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned model rendering method. The specific implementation can be found in the method embodiment, which will not be repeated here.
[0091] Specifically, the above-mentioned model rendering method includes: obtaining a model to be rendered and assigning a texture map to the model to be rendered; wherein the model to be rendered includes multiple vertices, and the texture map is used to render the texture of the surface of the model to be rendered; for each vertex in the model to be rendered, determining the target distance between the vertex and the virtual camera, determining the target distance range to which the target distance belongs from multiple preset distance ranges, and determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range; wherein the multiple preset distance ranges are respectively configured with corresponding resolution ranges; based on the target resolution corresponding to each vertex in the model to be rendered, texture sampling is performed on the texture map to obtain the model to be rendered after texture rendering.
[0092] The above-mentioned model rendering method can determine the resolution corresponding to vertices at a certain distance from the virtual camera in real time according to the set preset distance range and the resolution range corresponding to the preset distance range, and realize a smooth transition of resolutions corresponding to different distances, thereby avoiding the sudden change of model texture caused by the movement of the virtual camera.
[0093] In an optional embodiment, the above-mentioned multiple preset distance ranges are determined based on distance parameters, and the resolution ranges corresponding to the preset distance ranges are determined based on resolution parameters; wherein the distance parameter and the resolution parameter are custom parameters.
[0094] In an optional embodiment, the texture map is determined based on a color value corresponding to a color channel and a transparency value corresponding to a transparent channel; the color channel is configured with a first distance parameter and a first resolution parameter, and the transparent channel is configured with a second distance parameter and a second resolution parameter; based on this, the step of determining a target distance range to which a target distance belongs from a plurality of preset distance ranges, and determining a target resolution of a vertex corresponding to the target distance based on a target resolution range corresponding to the target distance range, comprises: determining a first target distance range to which a target distance belongs from a plurality of first preset distance ranges through a preset vertex shader, and determining a first target resolution corresponding to a color channel for a vertex corresponding to the target distance based on a first target resolution range corresponding to the first target distance range; wherein the plurality of first preset distance ranges are determined based on the first distance parameter, and the resolution range corresponding to the first preset distance range is determined based on the first resolution parameter; determining a second target distance range to which a target distance belongs from a plurality of second preset distance ranges through a preset vertex shader, and determining a second target resolution corresponding to a transparent channel for a vertex corresponding to the target distance based on a second target resolution range corresponding to the second target distance range.
[0095] In an optional embodiment, the above-mentioned step of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering includes: inputting the first target resolution and the second target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader respectively; through the preset fragment shader, performing texture sampling on the color channel in the texture map based on the first target resolution to obtain a first sampling result, and performing texture sampling on the transparent channel in the texture map based on the second target resolution to obtain a second sampling result; integrating the first sampling result and the second sampling result to obtain a final sampling result; rendering the texture of the surface of the model to be rendered based on the final sampling result to obtain the model to be rendered after texture rendering.
[0096] In an optional embodiment, the step of determining the target distance between the vertex and the virtual camera includes: obtaining vertex coordinates corresponding to the vertex and camera coordinates of the virtual camera; and determining the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates.
[0097] In an optional embodiment, the step of determining the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates includes: determining a first coordinate value corresponding to a first axis in the vertex coordinates, a first coordinate value corresponding to the first axis in the camera coordinates, a second coordinate value corresponding to a second axis in the vertex coordinates, and a second coordinate value corresponding to the second axis in the camera coordinates; subtracting the first coordinate value corresponding to the vertex coordinates from the first coordinate value corresponding to the camera coordinates to obtain a first subtraction result; subtracting the second coordinate value corresponding to the vertex coordinates from the second coordinate value corresponding to the camera coordinates to obtain a second subtraction result; adding the square of the first subtraction result to the square of the second subtraction result to obtain an addition result; and taking the square root of the addition result to obtain the target distance between the vertex and the virtual camera.
[0098] In an optional embodiment, the step of determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range includes: normalizing the target distance to obtain a normalized distance value; and performing linear interpolation between the minimum value and the maximum value corresponding to the target resolution range through the normalized distance value to obtain the target resolution.
[0099] In an optional embodiment, the above-mentioned step of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering includes: inputting the target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader; performing texture sampling on the texture map based on the target resolution through the preset fragment shader to obtain a sampling result; rendering the texture of the surface of the model to be rendered based on the sampling result to obtain the model to be rendered after texture rendering.
[0100] If the functions are implemented in the form of 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 disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a terminal device, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0101] In the description of the present disclosure, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present disclosure and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present disclosure. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0102] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A model rendering method, characterized in that: The method comprises: Acquire a model to be rendered and a texture map assigned to the model to be rendered; wherein the model to be rendered includes a plurality of vertices, and the texture map is used to render the texture of the surface of the model to be rendered; For each vertex in the model to be rendered, determine a target distance between the vertex and the virtual camera, determine a target distance range to which the target distance belongs from a plurality of preset distance ranges, and determine a target resolution of the vertex corresponding to the target distance based on a target resolution range corresponding to the target distance range; wherein the plurality of preset distance ranges are respectively configured with corresponding resolution ranges; Based on the target resolution corresponding to each vertex in the model to be rendered, texture sampling is performed on the texture map to obtain the model to be rendered after texture rendering.
2. The method according to claim 1, characterized in that: The multiple preset distance ranges are determined based on a distance parameter, and the resolution range corresponding to the preset distance range is determined based on a resolution parameter; wherein the distance parameter and the resolution parameter are custom parameters.
3. The method according to claim 2, characterized in that The texture map is determined based on a color value corresponding to a color channel and a transparency value corresponding to a transparent channel; the color channel is configured with a first distance parameter and a first resolution parameter, and the transparent channel is configured with a second distance parameter and a second resolution parameter; The step of determining the target distance range to which the target distance belongs from a plurality of preset distance ranges, and determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range, comprises: By presetting a vertex shader, a first target distance range to which the target distance belongs is determined from a plurality of first preset distance ranges, and based on a first target resolution range corresponding to the first target distance range, a first target resolution corresponding to the vertex corresponding to the target distance in the color channel is determined; wherein the plurality of first preset distance ranges are determined based on the first distance parameter, and the resolution range corresponding to the first preset distance range is determined based on the first resolution parameter; The preset vertex shader is used to determine a second target distance range to which the target distance belongs from a plurality of second preset distance ranges, and based on a second target resolution range corresponding to the second target distance range, a second target resolution corresponding to the vertex corresponding to the target distance in the transparent channel is determined.
4. The method according to claim 3, characterized in that The step of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering comprises: Inputting the first target resolution and the second target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader respectively; By using the preset fragment shader, texture sampling is performed on the color channel in the texture map based on the first target resolution to obtain a first sampling result, and texture sampling is performed on the transparent channel in the texture map based on the second target resolution to obtain a second sampling result; Integrate the first sampling result and the second sampling result to obtain a final sampling result; The texture of the surface of the model to be rendered is rendered based on the final sampling result to obtain the model to be rendered after the texture is rendered.
5. The method according to claim 1, characterized in that The step of determining the target distance between the vertex and the virtual camera comprises: Obtaining vertex coordinates corresponding to the vertex and camera coordinates of the virtual camera; Based on the vertex coordinates and the camera coordinates, a target distance between the vertex and the virtual camera is determined.
6. The method according to claim 5, characterized in that The step of determining the target distance between the vertex and the virtual camera based on the vertex coordinates and the camera coordinates comprises: Determine a first coordinate value corresponding to a first axis in the vertex coordinates, a first coordinate value corresponding to the first axis in the camera coordinates, a second coordinate value corresponding to a second axis in the vertex coordinates, and a second coordinate value corresponding to the second axis in the camera coordinates; Subtracting the first coordinate value corresponding to the vertex coordinates from the first coordinate value corresponding to the camera coordinates to obtain a first subtraction result; subtracting the second coordinate value corresponding to the vertex coordinates from the second coordinate value corresponding to the camera coordinates to obtain a second subtraction result; Adding the square of the first subtraction result to the square of the second subtraction result to obtain an addition result; The square root of the addition result is taken to obtain the target distance between the vertex and the virtual camera.
7. The method according to claim 1, characterized in that The step of determining the target resolution of the vertex corresponding to the target distance based on the target resolution range corresponding to the target distance range includes: Normalizing the target distance to obtain a normalized distance value; The target resolution is obtained by performing linear interpolation between the minimum value and the maximum value corresponding to the target resolution range through the normalized distance value.
8. The method according to claim 1, characterized in that The step of performing texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered to obtain the model to be rendered after texture rendering comprises: Inputting the target resolution corresponding to each vertex in the model to be rendered into a preset fragment shader; By using the preset fragment shader, the texture map is texture sampled based on the target resolution to obtain a sampling result; The texture of the surface of the model to be rendered is rendered based on the sampling result to obtain the model to be rendered after the texture is rendered.
9. A model rendering device, characterized in that: The device comprises: A model acquisition module, used to acquire a model to be rendered and a texture map assigned to the model to be rendered; wherein the model to be rendered includes a plurality of vertices, and the texture map is used to render the texture of the surface of the model to be rendered; a resolution determination module, for determining, for each vertex in the model to be rendered, a target distance between the vertex and the virtual camera, determining a target distance range to which the target distance belongs from a plurality of preset distance ranges, and determining a target resolution of the vertex corresponding to the target distance based on a target resolution range corresponding to the target distance range; wherein the plurality of preset distance ranges are respectively configured with corresponding resolution ranges; The texture rendering module is used to perform texture sampling on the texture map based on the target resolution corresponding to each vertex in the model to be rendered, so as to obtain the model to be rendered after texture rendering.
10. An electronic device, characterized in that: The electronic device includes 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 model rendering method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the model rendering method according to any one of claims 1 to 8.
Citation Information
Cited By
GPU texture filling rate testing method based on textuLod multi-level sampling
CN120450941A