Model rendering method, apparatus, and electronic device
Patent Information
- Application Number
- CN202211431376.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-14
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2042-11-14
AI Technical Summary
但是,上述两种方式中透明材质对性能消耗非常大,无法在手游上实现;同时,卡通水晶效果过于卡通化,无法表现出钻石的高光效果
[0009]本发明提供的一种模型渲染方法、装置和电子设备,首先获取待渲染模型,该待渲染模型的表面包括多个面片;进而基于待渲染模型中的面片对应的法线方向、预设折射率和相机视角方向,确定待渲染模型的折射方向参数;再根据待渲染模型的纹理信息和相机视角方向,确定待渲染模型的视差偏移参数;然后基于折射方向参数和视差偏移参数,对预设三角形图进行采样,得到采样结果,将采样结果映射到待渲染模型上,得到具有三角割裂效果的第一模型;最后将预设光照图与第一模型叠加,得到具有高光效果的最终模型;其中,预设光照图用于指示待渲染模型所处环境的光照信息。该方式中,通过待渲染模型的折射方向和视差偏移的结合,对预设三角形图采样,使得采样结果更加随机,从而将采样结果映射到待渲染模型上得到的三角割裂效果更加自然;且通过光照图模拟光源与三角割裂效果叠加,可模拟模型高光效果,该高光效果可更好的表现水晶类模型的物理效果。
Smart Images

Figure CN115761087B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of model processing technology, and in particular to a model rendering method, apparatus, and electronic device. Background Technology
[0002] Two rendering methods for diamond models are provided in the relevant technologies. The first method uses ray tracing in advanced rendering to render a transparent diamond model, obtaining the crystal reflection and refraction effect. The second method uses images with triangles sampling the light reflection direction on the diamond model's surface, so that the reflection direction changes with each facet of the diamond model as it moves, thus creating a cartoon crystal effect where the triangles on the diamond model are constantly moving. However, the transparent materials in both methods are very performance-intensive and cannot be implemented in mobile games; at the same time, the cartoon crystal effect is too cartoonish and cannot show the highlights of the diamond. Summary of the Invention
[0003] The purpose of this invention is to provide a model rendering method, apparatus, and electronic device to reduce the performance consumption of model rendering while rendering the specular effect of the model.
[0004] In a first aspect, the present invention provides a model rendering method, the method comprising: acquiring a model to be rendered; wherein the surface of the model to be rendered comprises multiple facets; determining refraction direction parameters of the model to be rendered based on the normal direction corresponding to the facets, a preset refractive index, and a camera viewing angle; determining parallax offset parameters of the model to be rendered based on the texture information of the model to be rendered and the camera viewing angle; sampling a preset triangle map based on the refraction direction parameters and the parallax offset parameters to obtain a sampling result; mapping the sampling result onto the model to be rendered to obtain a first model with a triangular segmentation effect; and superimposing a preset lighting map onto the first model to obtain a final model with a specular highlight effect; wherein the preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located.
[0005] Secondly, the present invention provides a model rendering apparatus, comprising: a model acquisition module for acquiring a model to be rendered; wherein the surface of the model to be rendered includes multiple facets; a refraction direction determination module for determining the refraction direction parameters of the model to be rendered based on the normal direction corresponding to the facets in the model to be rendered, a preset refractive index, and a camera viewing angle; a parallax offset determination module for determining the parallax offset parameters of the model to be rendered based on the texture information of the model to be rendered and the camera viewing angle; a sampling module for sampling a preset triangle map based on the refraction direction parameters and the parallax offset parameters to obtain a sampling result; mapping the sampling result onto the model to be rendered to obtain a first model with a triangular segmentation effect; and a lighting overlay module for overlaying a preset lighting map with the first model to obtain a final model with a specular highlight effect; wherein the preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located.
[0006] Thirdly, the present invention provides an electronic device including 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 above-described model rendering method.
[0007] Fourthly, the present invention provides a computer-readable storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the above-described model rendering method.
[0008] The embodiments of the present invention bring the following beneficial effects:
[0009] This invention provides a model rendering method, apparatus, and electronic device. First, a model to be rendered is acquired, the surface of which includes multiple facets. Then, based on the normal direction corresponding to the facets, a preset refractive index, and the camera's viewing angle, the refraction direction parameters of the model to be rendered are determined. Next, based on the texture information of the model to be rendered and the camera's viewing angle, the parallax offset parameters of the model to be rendered are determined. Then, based on the refraction direction parameters and the parallax offset parameters, a preset triangle map is sampled to obtain the sampling results. These sampling results are mapped onto the model to be rendered to obtain a first model with a triangular segmentation effect. Finally, a preset lighting map is superimposed on the first model to obtain a final model with a specular highlight effect. The preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located. In this method, by combining the refraction direction and parallax offset of the model to be rendered, the sampling of the preset triangle map is made more random, resulting in a more natural triangular segmentation effect when the sampling results are mapped onto the model to be rendered. Furthermore, by simulating a light source using the lighting map and superimposing it with the triangular segmentation effect, a specular highlight effect can be simulated, which can better represent the physical effects of crystal-like models.
[0010] Other features and advantages of the invention will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the techniques described above.
[0011] 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
[0012] 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.
[0013] Figure 1 A flowchart of a model rendering method provided in an embodiment of the present invention;
[0014] Figure 2 A schematic diagram of a preset triangle diagram provided in an embodiment of the present invention;
[0015] Figure 3 A schematic diagram illustrating the triangular splitting effect of a model provided in an embodiment of the present invention;
[0016] Figure 4 A schematic diagram illustrating the specular effect of a model provided in an embodiment of the present invention;
[0017] Figure 5 A flowchart of another model rendering method provided in an embodiment of the present invention;
[0018] Figure 6 A schematic diagram of a material mapping map provided in an embodiment of the present invention;
[0019] Figure 7 A schematic diagram of a circular easing diagram provided in an embodiment of the present invention;
[0020] Figure 8 A flowchart of another model processing method provided in an embodiment of the present invention;
[0021] Figure 9 This is a schematic diagram of the structure of a model rendering device provided in an embodiment of the present invention;
[0022] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments 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, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0024] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0025] The related technologies provide various rendering methods for diamond models, including:
[0026] The first method uses cube maps to simulate light refraction, rendering the color of the transparent diamond material within the refraction environment to create a diamond model with a crystal effect. This method produces extremely poor rendering results, failing to meet the artists' expectations. Even with better textures, the use of transparent materials in this rendering method results in significant performance overhead.
[0027] The second method uses ray tracing in advanced rendering (ray tracing is a technique that gives graphics a realistic look; a high-quality graphics card can use ray tracing to immerse the user, and this technique attempts to display light in the same way as the real world) to render a diamond model with transparent materials, obtaining the crystal reflection and refraction effect of the diamond model; however, this rendering effect cannot be achieved on mobile games at present, and can only be achieved on PC, and transparent materials consume a lot of performance.
[0028] The third method uses images with triangles sampling the direction of light reflection from the diamond model's surface. This causes the reflection direction to change as each facet of the diamond model moves, creating a cartoonish crystal effect where the triangles on the diamond model are constantly moving. However, this cartoonish effect is too realistic and fails to capture the highlights and brilliance of a diamond.
[0029] To address the aforementioned problems, embodiments of the present invention provide a model rendering method, apparatus, and electronic device. This technology can be applied to rendering scenarios for various models, specifically diamond models. To facilitate understanding of these embodiments, a model rendering method disclosed in these embodiments will first be described in detail, such as... Figure 1 As shown, the method includes the following specific steps:
[0030] Step S102: Obtain the model to be rendered; wherein the surface of the model to be rendered includes multiple facets.
[0031] In its specific implementation, this invention is implemented on a game engine, that is, by obtaining the model to be rendered through the game engine and rendering the model. A game engine typically refers to the core component of some pre-written, editable computer game systems or interactive real-time graphics applications. These systems provide game designers with various tools needed to write games, with the aim of enabling game designers to easily and quickly create game programs without starting from scratch.
[0032] The model to be rendered can be any model drawn using model-making software, or it can be a model transferred from a preset model storage file. This model is typically a three-dimensional solid model, and its color and material can be set according to development needs. In practical applications, to save performance and ensure that the model rendering method can be implemented on mobile devices, the model can be set to a self-illuminating material model. This self-illuminating material model is usually a lighting model that only displays images and does not contain any lighting or shadow effects; it is the most performance-efficient basic material model. Specifically, the surface of the model to be rendered usually consists of multiple facets, each with a different orientation.
[0033] Step S104: Determine the refraction direction parameters of the model to be rendered based on the normal direction, preset refractive index, and camera viewpoint direction corresponding to the facets in the model to be rendered.
[0034] After obtaining the model to be rendered, the normal direction corresponding to each facet of the model's surface can be determined. The normal direction is a straight line that is always perpendicular to the plane corresponding to a particular facet. In geometry, a normal is a line on a plane that is perpendicular to the tangent to a curve at a point. The normal vector is a vector that records the direction of the normal. The camera viewpoint direction mentioned above is determined based on the current orientation of the camera. The preset refractive index is any value input according to user requirements, or it can be the refractive index input based on the model's material, etc.
[0035] In practical implementation, the formula for calculating the refraction direction parameter is refract(Ray,Normal,Index). In the refract function, Ray represents the camera's viewing angle (also known as the incident angle), Normal represents the normal direction parameter, and Index represents the preset refractive index. This preset refractive index is the ratio of the refractive index of the source material to the refractive index of the target material. For example, if the refractive index of air is 1 and the refractive index of water is 1.33, then the preset refractive index transmitted from air to water is 1 / 1.33. Therefore, we can know that the source material is air and the target material is water.
[0036] Step S106: Determine the parallax offset parameters of the model to be rendered based on the texture information of the model to be rendered and the camera viewpoint direction.
[0037] In practice, two color directions are first output based on the camera's viewpoint. These two color directions are then multiplied or divided to obtain the parallax effect. This parallax effect is then superimposed on the texture information (UV information) of the model to be rendered, resulting in the parallax offset parameter of the model. This parallax offset parameter indicates the rendering offset in the model, thus making the rendering result more natural.
[0038] It's important to note that UVs are commonly represented by TexCoord in game engines. Texture coordinates typically have two axes, U and V, hence the name UV coordinates. U represents the distribution on the horizontal axis, and V represents the distribution on the vertical axis. In 3D modeling, "UV" can be understood as the "skin" of a 3D model. This "skin" is unfolded and then drawn on a 2D plane to be applied to the object. A color image can be divided into RGB (Red, Green, Blue), and a colored image can also be divided into three channels: RGB, representing the percentage of red, blue, and green colors. In game engines, UVs only have two channels: red and green. U is the R channel of the UV image, and V is the G channel.
[0039] Step S108: Based on the above refraction direction parameters and parallax offset parameters, sample the preset triangle diagram to obtain the sampling results; map the sampling results onto the model to be rendered to obtain the first model with triangular segmentation effect.
[0040] The aforementioned preset triangle image refers to an image containing triangular shapes. The shape and size of the triangles contained in the preset triangle image can be set according to research and development needs, such as... Figure 2 The diagram shows a preset triangle image. In practice, sampling the preset triangle image based on preset refraction direction parameters ensures that the triangles in the sampling results are obtained from the preset triangle image according to the refraction direction of the surface of the model to be rendered, giving the model the effect of refraction to various triangles. Simultaneously, adding a parallax offset parameter during sampling increases the randomness of the sampling, thereby enhancing the randomness of the triangles' movement on the model after rendering, resulting in a more natural triangular fragmentation effect in the rendered model. Figure 3 The image shown is a schematic diagram of the triangular splitting effect of the model. Figure 3 The model to be rendered is a diamond-shaped model (referred to as the diamond model), which is rendered with a triangular splitting effect.
[0041] Step S110: Overlay the preset lighting map onto the first model to obtain the final model with a specular highlight effect; wherein, the preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located.
[0042] The aforementioned preset lighting map can also be called an HDR (High-Dynamic Range) map. This HDR map is typically an image containing lighting information, preserving ambient lighting details. Specifically, the preset lighting map can be set according to user requirements or determined based on the environment of the model to be rendered; no specific limitation is made here. In practical applications, overlaying the preset lighting map with the triangular slicing effect in the first model can simulate the specular highlight effect of the model to be rendered. This specular highlight effect is a fake highlight, resulting in a more natural effect. For example... Figure 4 This is a schematic diagram of the highlight effect of a model provided in an embodiment of the present invention.
[0043] This invention provides a model rendering method. First, a model to be rendered is acquired, the surface of which includes multiple facets. Then, based on the normal direction corresponding to the facets, a preset refractive index, and the camera's viewing angle, the refraction direction parameters of the model to be rendered are determined. Next, based on the texture information of the model to be rendered and the camera's viewing angle, the parallax offset parameters of the model to be rendered are determined. Then, based on the refraction direction parameters and the parallax offset parameters, a preset triangle map is sampled to obtain the sampling results. These sampling results are mapped onto the model to be rendered to obtain a first model with a triangular segmentation effect. Finally, a preset lighting map is superimposed on the first model to obtain a final model with a specular highlight effect. The preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located. In this method, by combining the refraction direction and parallax offset of the model to be rendered, the sampling of the preset triangle map is made more random, resulting in a more natural triangular segmentation effect when the sampling results are mapped onto the model to be rendered. Furthermore, by simulating a light source with the lighting map and superimposing it with the triangular segmentation effect, the specular highlight effect of the model can be simulated, which can better represent the physical effects of crystal-like models.
[0044] This invention also provides another model rendering method, which is implemented based on the above embodiments. This method focuses on describing the specific process of determining the refraction direction parameters of the model to be rendered based on the normal direction, preset refractive index, and camera viewpoint direction of the facets in the model (implemented through steps S504-S508 below), and the specific process of determining the parallax offset parameters of the model to be rendered based on the texture information and camera viewpoint direction (implemented through steps S510-S512 below); as follows; Figure 5 As shown, the method includes the following specific steps:
[0045] Step S502: Obtain the model to be rendered; wherein the surface of the model to be rendered includes multiple facets.
[0046] Step S504: Obtain the normal direction corresponding to each facet in the model to be rendered, and obtain the normal map.
[0047] The above normal map is used to represent the normal direction corresponding to each facet in the model to be rendered.
[0048] Step S506: Preprocess the normal map to obtain the normal direction parameters.
[0049] In a practical implementation, step S506 above can be achieved through the following steps 10-11:
[0050] Step 10: Convert the normal information in the normal map from tangent space to world scene space to obtain the converted normal information.
[0051] The tangent space mentioned above, also known as texture space, is a Cartesian coordinate system established along the tangent lines of the model. World scene space typically refers to the space within the world coordinate system. In practical applications, the TransformVector node in a game engine can be used to transform the input normal map from tangent space to world scene space, outputting the transformed normal information.
[0052] Step 11: Perform direction normalization on the converted normal information to obtain the normal direction parameters.
[0053] In practical applications, the converted normal information can be input into the Normalize node in the game engine. The Normalize node then normalizes the converted normal information to obtain normalized normal information, which is the normal direction parameter mentioned above. Normalization means converting it to a unit vector of 1, meaning only the normal direction is retained, not its length.
[0054] The above method of determining the normal refraction direction parameters can unify the normal refraction direction for some models with indistinct edges and corners, which is beneficial for the unification of subsequent specular effects and triangular refraction directions, making the specular effects in the model more natural and not limited by the number of faces or smoothness of the model.
[0055] Step S508: Obtain the camera viewpoint direction and preset refractive index, and input the camera viewpoint direction, preset refractive index and normal direction parameters into the preset refraction formula to obtain the refraction direction parameters of the model to be rendered.
[0056] In the specific implementation, the camera viewpoint direction, preset refractive index, and normal direction parameters of the model to be rendered are all imported into the preset refractive index formula refract(Ray,Normal,Index), which outputs the refractive direction parameters of the model to be rendered. Here, Ray represents the camera viewpoint direction, Normal represents the normal direction parameter, and Index represents the preset refractive index.
[0057] Step S510: Convert the camera viewpoint direction to tangent space to obtain the first texture corresponding to the first direction and the second texture corresponding to the second direction.
[0058] The camera viewpoint is located in the world scene space. The camera viewpoint is transformed from the world scene space to the tangent space. Then, the RGB texture corresponding to the camera viewpoint is split and the texture corresponding to two directions is output. These two directions are called the first direction and the second direction. The specific direction can be set according to the development needs. For example, the first direction can be the RG direction and the second direction can be the B direction.
[0059] It should be noted that since the UV values in the image contain two directions, the index needs to divide the three RGB channels in the RGB map into two directions to facilitate better subsequent UV sampling.
[0060] Step S512: Obtain the texture information of the model to be rendered, and determine the disparity offset parameters of the model to be rendered based on the first texture, the second texture, and the texture information.
[0061] The texture information of the model to be rendered, also known as the UV information, contains only information in the U and V directions. In practice, step S212 can be implemented using steps 20-21 below:
[0062] Step 20: Multiply or divide the first texture and the second texture to obtain the processing result.
[0063] By multiplying or dividing the first texture and the second texture, a parallax effect can be obtained, which is represented by the result of the multiplication or division.
[0064] Step 21: Overlay the above processing results with the texture information to obtain the disparity offset parameters.
[0065] The above processing result is added to the texture information of the model to be rendered to obtain the disparity offset parameter. Here, the texture information of the model to be rendered is the second UV of the selected model. The first UV reads the base texture of the model to be rendered, and the second UV reads the processed texture of the model to be rendered.
[0066] Step S514: Based on the above refraction direction parameters and parallax offset parameters, sample the preset triangle diagram to obtain the sampling results; map the sampling results onto the model to be rendered to obtain the first model with triangular segmentation effect.
[0067] Step S516: Overlay the preset lighting map onto the first model to obtain the final model with a highlight effect.
[0068] Step S518: Set the glow effect and / or internal light transmission effect of the final model.
[0069] In practical implementation, to make the final model's rendering effect more consistent with the model's characteristics, a glow effect or an inner light effect can be set for the final model. Specifically, a glow effect can be set only for the final model, an inner light effect can be set only for the final model, or both a glow effect and an inner light effect can be set for the final model.
[0070] In practical applications, the following steps 30-32 can be used to set the highlight effect for the final model:
[0071] Step 30: Determine the sampling matrix based on the preset human eye direction and camera viewing angle direction.
[0072] The preset human eye direction can be set according to research and development needs. For example, the preset human eye direction can be set to the direction of (0,1,0) in world coordinate space. Then, according to the Matcap formula, a sampling matrix is obtained by reconstructing the matrix based on the preset human eye direction and the camera view direction. Matcap stands for materialCapture, which is a well-established theorem method in computer graphics.
[0073] Step 31: Sample the preset material mapping map using the sampling matrix to obtain the sampled texture.
[0074] The material map described above can be set by the user according to their needs. This material map is used to set the glow effect of the model. For example... Figure 6 The image shown is a schematic diagram of a material mapping diagram provided in an embodiment of the present invention.
[0075] Step 32: Map the above sampled texture onto the final model to obtain the final model with a glow effect.
[0076] In practical applications, adding a glow effect to the final model helps to make the overall crystal effect of the crystal model softer and more in line with the high-quality glow effect of cartoon crystals. It also helps to characterize the physical properties of crystal models.
[0077] In practical applications, the following steps 40-42 can be used to set the internal light transmission effect for the final model:
[0078] Step 40: Calculate the texture information of the surface of the model to be rendered, and obtain a texture effect map that matches the surface size of the model to be rendered.
[0079] In practice, the appearance of the model to be rendered can be automatically calculated through the BoundingBoxBased_0-1_UVW node in the game engine, thereby creating a fake model appearance UV, which is a texture effect map that matches the length, width and height of the model to be rendered.
[0080] Step 41: Perform texture sampling on the texture effect map to obtain a circular gradation map; wherein, the circular gradation map is used to simulate the gradation effect from the pivot center of the model to be rendered to the outside.
[0081] like Figure 7 The image shown is a schematic diagram of a circular gradient. Figure 7 The circular gradient image shown is a white image that gradually changes color from the inside out. This circular gradient image can simulate the easing effect from the center of the model's pivot to the outside, that is, it can simulate the internal light effect.
[0082] Step 42: Overlay the circular gradient image onto the final model to obtain the final model with an internal light transmission effect.
[0083] By overlaying a circular gradient onto the final model, you can create a model with an internal light transmission effect that allows light to shine outwards, thereby enhancing the model's natural glow.
[0084] The above-mentioned model rendering method can produce a model with a sparkling, anime-like feel while ensuring performance; at the same time, it can also represent the specular and glow effects in the physical properties of crystals while maintaining the crystal effect of crystal-like models.
[0085] This invention also provides another model rendering method, which is implemented based on the above embodiments. This method focuses on describing the specific process of sampling a preset triangle image based on the refraction direction parameter and the parallax offset parameter to obtain the sampling result (implemented through steps S808-S812 below), and the specific process of superimposing the preset lighting map with the first model to obtain a final model with a specular effect (implemented through steps S816-S818 below); Figure 8 As shown, the method includes the following specific steps:
[0086] Step S802: Obtain the model to be rendered; wherein the surface of the model to be rendered includes multiple facets.
[0087] Step S804: Determine the refraction direction parameters of the model to be rendered based on the normal direction, preset refractive index, and camera viewpoint direction corresponding to the facets in the model to be rendered.
[0088] Step S806: Determine the parallax offset parameters of the model to be rendered based on the texture information of the model to be rendered and the camera viewpoint direction.
[0089] Step S808: Convert the refraction direction parameters to obtain the third texture corresponding to the third direction and the fourth texture corresponding to the fourth direction.
[0090] The refraction direction parameter is a three-dimensional vector (including the R-channel direction, G-channel direction, and B-channel direction). To sample a two-dimensional texture (including the U-direction and V-direction) based on this refraction direction parameter, it needs to be split into textures corresponding to two directions. Which of these two directions corresponds to can be set according to development needs; for example, the third direction could be the RG-channel direction, and the fourth direction could be the RB-channel direction.
[0091] Step S810: The third texture is superimposed with the disparity offset parameter to obtain the first superimposed result; the fourth texture is superimposed with the disparity offset parameter to obtain the second superimposed result.
[0092] Step S812: Based on the first superposition result and the second superposition result, sample the preset triangle diagram to obtain the sampling result.
[0093] In a practical implementation, step S812 can be achieved through the following steps 50-52:
[0094] Step 50: Sample the preset triangle diagram using the first superposition result to obtain the first result.
[0095] Step 51: Sample the preset triangle diagram using the second superposition result to obtain the second result.
[0096] The triangles in the first and second results above may be the same or different.
[0097] Step 52: Superimpose the first result and the second result to obtain the sampling result.
[0098] Step S814: Map the sampling results onto the model to be rendered to obtain the first model with a triangular segmentation effect.
[0099] Step S816: Multiply the preset illumination map by the preset brightness value to obtain the multiplication result.
[0100] The specific value of the preset brightness can be set according to the research and development needs. For example, the preset brightness value can be 1.5 or 2. Multiplying the preset lighting map by the preset brightness value can increase the brightness of the preset lighting map, resulting in a preset lighting map with relatively high brightness (equivalent to the multiplication result above).
[0101] In practical applications, before multiplying the preset lighting map with the preset brightness value to obtain the multiplication result, it is necessary to obtain the normal direction corresponding to each facet in the model to be rendered, thus obtaining a normal map; convert the normal information in the normal map from tangent space to world scene space to obtain the converted normal information; perform direction normalization processing on the converted normal information to obtain normal direction parameters; select the normal direction parameters, vertex normal directions of the model to be rendered, and Boolean parameters through preset instructions to obtain the selection result; link the selection result and the preset engine reflection direction to the preset lighting map to obtain the final preset lighting map.
[0102] The aforementioned preset commands can be set by the user according to their needs. These preset commands are typically input to the Switch node of the game engine. The input data of the Switch node consists of normal direction parameters, vertex normal directions of the model to be rendered, and Boolean parameters. The node can output the selection results of these three parameters through preset commands. The Switch node (selection node) can be used as a selection switch. This node is also a group node, also known as a selection group node. Different child nodes can be created in this node, but only one child node can be selected at a time (one child node corresponds to one input data).
[0103] Step S818: The multiplication result is superimposed on the first model to obtain the final model with a highlight effect.
[0104] The first model is added to the result of the multiplication above to obtain an initial specular map. The value of the R channel, 0, and 1 in the initial specular map are input to the linear interpolation node for linear interpolation to obtain the specular effect of the final model. The A port of the linear interpolation node is 0, the B port is 1, and the Alpha input is the value of the R channel. If the Alpha input is black, the output is 0; if the input is white, the output is 1. This process combines the extreme brightness of the preset lighting map into a black-and-white image.
[0105] The aforementioned model rendering method, applied to the rendering of diamond models within crystal models, is a complete diamond effect rendering scheme. It enhances the crystal's expressive capabilities, with the specular highlight effect achieved through a combination of triangular parallax and refraction direction, along with masking to correct the normal direction of the specular highlight. The specular highlight effect of the model rendered by this invention is very natural and practical, while also enhancing the physical effects of the crystal.
[0106] In addition to the above-described method embodiments, this invention also provides a model rendering apparatus, such as... Figure 9 As shown, the device includes:
[0107] The model acquisition module 90 is used to acquire the model to be rendered; wherein the surface of the model to be rendered includes multiple facets.
[0108] The refraction direction determination module 91 is used to determine the refraction direction parameters of the model to be rendered based on the normal direction corresponding to the surface in the model to be rendered, the preset refractive index, and the camera view direction.
[0109] The parallax offset determination module 92 is used to determine the parallax offset parameters of the model to be rendered based on the texture information of the model to be rendered and the camera viewpoint direction.
[0110] The sampling module 92 is used to sample the preset triangle diagram based on the refraction direction parameter and the parallax offset parameter to obtain the sampling result; the sampling result is mapped onto the model to be rendered to obtain the first model with the triangle segmentation effect.
[0111] The lighting overlay module 93 is used to overlay a preset lighting map with the first model to obtain a final model with a highlight effect; wherein, the preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located.
[0112] The aforementioned model rendering device first acquires the model to be rendered, whose surface comprises multiple facets. Then, based on the normal direction corresponding to the facets, the preset refractive index, and the camera's viewing angle, it determines the refraction direction parameters of the model. Next, based on the texture information and the camera's viewing angle, it determines the parallax offset parameters. Then, based on the refraction direction parameters and the parallax offset parameters, it samples a preset triangle map to obtain the sampling results. These sampling results are then mapped onto the model to be rendered, resulting in a first model with a triangular segmentation effect. Finally, a preset lighting map is superimposed on the first model to obtain a final model with a specular highlight effect. The preset lighting map indicates the lighting information of the environment in which the model is located. In this method, by combining the refraction direction and parallax offset of the model to be rendered, the sampling of the preset triangle map becomes more random, resulting in a more natural triangular segmentation effect when mapped onto the model. Furthermore, by simulating the light source with the lighting map and superimposing it with the triangular segmentation effect, the specular highlight effect of the model can be simulated, which better represents the physical effects of crystal-like models.
[0113] Specifically, the aforementioned refraction direction determination module 91 is used to: obtain the normal direction corresponding to each facet in the model to be rendered, and obtain a normal map; preprocess the normal map to obtain normal direction parameters; obtain the camera view direction and preset refractive index, and input the camera view direction, preset refractive index and normal direction parameters into a preset refraction formula to obtain the refraction direction parameters of the model to be rendered.
[0114] Furthermore, the aforementioned refraction direction determination module 91 is also used to: convert the normal information in the normal map from tangent space to world scene space to obtain the converted normal information; and perform direction normalization processing on the converted normal information to obtain normal direction parameters.
[0115] In a specific implementation, the disparity offset determination module 92 is used to: convert the camera viewpoint direction to tangent space to obtain a first texture corresponding to the first direction and a second texture corresponding to the second direction; obtain the texture information of the model to be rendered, and determine the disparity offset parameters of the model to be rendered based on the first texture, the second texture and the texture information.
[0116] Furthermore, the aforementioned disparity offset determination module 92 is also used to: multiply or divide the first texture and the second texture to obtain a processing result; and to overlay the processing result with the texture information to obtain the disparity offset parameter.
[0117] In practical applications, the above-mentioned sampling module 92 is also used to: convert the refraction direction parameters to obtain a third texture corresponding to the third direction and a fourth texture corresponding to the fourth direction; superimpose the third texture with the disparity offset parameters to obtain a first superposition result; superimpose the fourth texture with the disparity offset parameters to obtain a second superposition result; and sample a preset triangle image based on the first superposition result and the second superposition result to obtain a sampling result.
[0118] Furthermore, the sampling module 92 is also used to: sample the preset triangle diagram using the first superposition result to obtain a first result; sample the preset triangle diagram using the second superposition result to obtain a second result; and superimpose the first result and the second result to obtain a sampling result.
[0119] In specific implementation, the above-mentioned lighting overlay module 93 is used to: multiply the preset lighting map with the preset brightness value to obtain the multiplication result; and overlay the multiplication result on the first model to obtain the final model with a highlight effect.
[0120] In practical applications, the aforementioned device also includes a lighting map processing module, used for: obtaining the normal direction corresponding to each facet in the model to be rendered before multiplying the preset lighting map with a preset brightness value to obtain the multiplication result, thus obtaining a normal map; converting the normal information in the normal map from tangent space to world scene space to obtain the converted normal information; performing direction normalization processing on the converted normal information to obtain normal direction parameters; selecting the normal direction parameters, vertex normal directions of the model to be rendered, and Boolean parameters through preset instructions to obtain a selection result; and linking the selection result and the preset engine reflection direction to the preset lighting map to obtain the final preset lighting map.
[0121] Furthermore, the aforementioned device also includes a glow setting module, used for: after superimposing a preset lighting map with a first model to obtain a final model with a highlight effect, determining a sampling matrix based on a preset human eye direction and camera viewing angle direction; sampling a preset material mapping map through the sampling matrix to obtain a sampled texture; and mapping the sampled texture onto the final model to obtain a final model with a glow effect.
[0122] Furthermore, the aforementioned device also includes an internal light transmission effect setting module, used for: after superimposing a preset lighting map onto the first model to obtain a final model with a specular highlight effect, calculating the texture information of the surface of the model to be rendered to obtain a texture effect map that matches the surface size of the model to be rendered; performing texture sampling on the texture effect map to obtain a circular gradation map; wherein, the circular gradation map is used to simulate the gradation effect from the pivot center of the model to be rendered to the outside; superimposing the circular gradation map onto the final model to obtain a final model with an internal light transmission effect.
[0123] The model rendering apparatus provided in this embodiment of the invention has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the apparatus embodiment can be referred to the corresponding content in the aforementioned method embodiment.
[0124] This invention also provides an electronic device, such as... Figure 10 As shown, the electronic device includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, which executes the machine-executable instructions to implement the above-described model rendering method.
[0125] Furthermore, Figure 10 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 101, the communication interface 103 and the memory 100 connected via the bus 102.
[0126] The memory 100 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 10 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.
[0127] Processor 101 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 101 or by instructions in software form. The 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 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 can 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 100, and processor 101 reads information from memory 100 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0128] This invention also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are called and executed by a processor, they cause the processor to implement the above-described model rendering method. For specific implementation details, please refer to the method embodiments, which will not be repeated here.
[0129] 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 this invention, essentially, or the part that contributes to the prior art, or a portion 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, a terminal device, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this 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.
[0130] 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.
[0131] Finally, it should be noted that the above-described 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 model rendering method, characterized in that, The method includes: Obtain the model to be rendered; wherein the surface of the model to be rendered includes multiple facets; Based on the normal direction, preset refractive index, and camera viewing angle of the facet in the model to be rendered, the refractive direction parameters of the model to be rendered are determined. Based on the texture information of the model to be rendered and the camera viewpoint direction, the disparity offset parameter of the model to be rendered is determined; wherein, the disparity offset parameter is used to indicate the rendering offset in the model to be rendered; Based on the refraction direction parameter and the parallax offset parameter, a preset triangle image is sampled to obtain a sampling result; the sampling result is mapped onto the model to be rendered to obtain a first model with a triangular segmentation effect; wherein, the preset triangle image refers to an image containing triangular shapes, and the sampling result includes a triangle image sampled from the preset triangle image according to the refraction direction of the surface of the model to be rendered; The preset lighting map is superimposed on the first model to obtain the final model with a highlight effect; wherein, the preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located.
2. The method according to claim 1, characterized in that, The step of determining the refraction direction parameters of the model to be rendered based on the normal direction, preset refractive index, and camera viewing angle of the facet in the model to be rendered includes: Obtain the normal direction corresponding to each facet in the model to be rendered to obtain a normal map; The normal map is preprocessed to obtain the normal direction parameters; The camera viewpoint direction and the preset refractive index are obtained, and the camera viewpoint direction, the preset refractive index and the normal direction parameters are input into the preset refraction formula to obtain the refraction direction parameters of the model to be rendered.
3. The method according to claim 2, characterized in that, The step of preprocessing the normal map to obtain the normal direction parameters includes: The normal information in the normal map is converted from tangent space to world scene space to obtain the converted normal information. The converted normal information is subjected to direction normalization processing to obtain the normal direction parameter.
4. The method according to claim 1, characterized in that, The step of determining the disparity offset parameter of the model to be rendered based on the texture information of the model to be rendered and the camera viewpoint direction includes: The camera viewpoint direction is converted to tangent space to obtain a first texture corresponding to the first direction and a second texture corresponding to the second direction. The texture information of the model to be rendered is obtained, and the disparity offset parameter of the model to be rendered is determined based on the first texture, the second texture and the texture information.
5. The method according to claim 4, characterized in that, The step of determining the disparity offset parameters of the model to be rendered based on the first texture, the second texture, and the texture information includes: Multiply or divide the first texture and the second texture to obtain the processing result; The processing result is superimposed on the texture information to obtain the disparity offset parameter.
6. The method according to claim 1, characterized in that, The step of sampling a preset triangle image based on the refraction direction parameter and the disparity offset parameter to obtain the sampling result includes: The refraction direction parameters are converted to obtain a third texture corresponding to the third direction and a fourth texture corresponding to the fourth direction. The third texture is superimposed with the disparity offset parameter to obtain a first superposition result; the fourth texture is superimposed with the disparity offset parameter to obtain a second superposition result. Based on the first superposition result and the second superposition result, the preset triangle diagram is sampled to obtain the sampling result.
7. The method according to claim 6, characterized in that, The step of sampling the preset triangle diagram based on the first superposition result and the second superposition result to obtain the sampling result includes: The preset triangle diagram is sampled using the first superposition result to obtain a first result; The preset triangle diagram is sampled using the second superposition result to obtain the second result; The sampling result is obtained by superimposing the first result and the second result.
8. The method according to claim 1, characterized in that, The step of overlaying a preset lighting map onto the first model to obtain a final model with a highlight effect includes: Multiply the preset illumination map by the preset brightness value to obtain the multiplication result; The multiplication result is superimposed on the first model to obtain the final model with a highlight effect.
9. The method according to claim 8, characterized in that, Before the step of multiplying the preset illumination map by the preset brightness value to obtain the multiplication result, the method further includes: Obtain the normal direction corresponding to each facet in the model to be rendered to obtain a normal map; The normal information in the normal map is converted from tangent space to world scene space to obtain the converted normal information. The converted normal information is subjected to direction normalization processing to obtain the normal direction parameter; By using preset instructions, the normal direction parameter, the vertex normal direction of the model to be rendered, and the Boolean parameter are selected to obtain the selection result; The selection result and the preset engine reflection direction are linked to the preset lighting map to obtain the final preset lighting map.
10. The method according to claim 1, characterized in that, After the step of superimposing the preset lighting map onto the first model to obtain a final model with a highlight effect, the method further includes: The sampling matrix is determined based on the preset human eye direction and the camera's viewing angle direction; The preset material mapping map is sampled using the sampling matrix to obtain a sampled texture. The sampled texture is mapped onto the final model to obtain the final model with a glow effect.
11. The method according to claim 1, characterized in that, After the step of superimposing the preset lighting map onto the first model to obtain a final model with a highlight effect, the method further includes: Calculate the texture information of the surface of the model to be rendered, and obtain a texture effect map that matches the surface size of the model to be rendered; Texture sampling is performed on the texture effect map to obtain a circular gradation map; wherein, the circular gradation map is used to simulate the gradation effect from the pivot center of the model to be rendered to the outside; The circular gradient image is superimposed on the final model to obtain the final model with an internal light transmission effect.
12. A model rendering apparatus, characterized in that, The device includes: The model acquisition module is used to acquire the model to be rendered; wherein the surface of the model to be rendered includes multiple facets; The refraction direction determination module is used to determine the refraction direction parameters of the model to be rendered based on the normal direction, preset refractive index and camera viewing angle direction corresponding to the facet in the model to be rendered. The disparity offset determination module is used to determine the disparity offset parameter of the model to be rendered based on the texture information of the model to be rendered and the camera view direction; wherein, the disparity offset parameter is used to indicate the rendering offset in the model to be rendered; A sampling module is used to sample a preset triangle image based on the refraction direction parameter and the parallax offset parameter to obtain a sampling result; and to map the sampling result onto the model to be rendered to obtain a first model with a triangular segmentation effect; wherein, the preset triangle image refers to an image containing triangular shapes, and the sampling result includes a triangle image sampled from the preset triangle image according to the refraction direction of the surface of the model to be rendered; The lighting overlay module is used to overlay a preset lighting map onto the first model to obtain a final model with a highlight effect; wherein, the preset lighting map is used to indicate the lighting information of the environment in which the model to be rendered is located.
13. 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 model rendering method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the model rendering method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Spar model rendering method, device, computer storage medium and electronic equipment
CN112785679A
