Image rendering method, device and electronic device
By adding a three-dimensional model of virtual glass objects to the background image, determining its virtual thickness and calculating the rendering color, the problem of complex and inefficient rendering glass in the prior art is solved, and an efficient and realistic glass rendering effect is achieved.
Patent Information
- Application Number
- CN202111452005.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2041-11-30
AI Technical Summary
In the prior art, the rendering glass effect is complex and inefficient, the texture sampling direction is fixed, making it difficult to maintain a good visual effect when objects move, and the designers have high requirements, so the texture production is complicated.
By obtaining the three-dimensional model of the object to be rendered in the background image, determining its virtual thickness, and calculating the rendering color after the light exits according to the virtual thickness, real rendering effect of the glass material is achieved without additional maps, and manual operations are simplified.
It improves the authenticity and efficiency of the rendering effect, reduces manpower and time consumption, simplifies the rendering process of glass materials, and is suitable for mobile devices.
Smart Images

Figure CN114155338B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to an image rendering method, device and electronic device. Background Art
[0002] Glass is a common material in daily life, widely used in the production of various daily necessities and decorations. In virtual 3D scenes, glass is also a high-frequency material used to simulate the refraction and reflection effects of glass on objects.
[0003] In the related art, the glass effect is usually achieved by using texture simulation. For example, the Material Capture (MatCap) texture uses the normal to sample the MatCap texture to obtain an effect similar to the glass highlight reflection, and appropriately changes the texture coordinates when sampling the background image to achieve the effect of simulating the refraction and distortion of the background image, and part of the background image is revealed through transparency to simulate the transparent texture of glass. However, when the glass effect is obtained through the above scheme, the direction of the texture sampling is relatively fixed, and the visual effect is poor when the object moves; and the texture has high requirements on the designer, and the production of the texture is also relatively complicated. Summary of the invention
[0004] The present disclosure provides an image rendering method, device and electronic device to at least solve the problem that the operation of rendering glass effects in the related art is too complicated. The technical solution of the present disclosure is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, there is provided an image rendering method, comprising obtaining an object to be rendered of a glass material corresponding to a background image; wherein the object to be rendered is a virtual object to be added on the background image; determining a virtual thickness of the object to be rendered according to a three-dimensional model of the object to be rendered; wherein the virtual thickness is used to characterize the thickness of the object to be rendered from the incidence to the emission of light; determining a rendering color of the object to be rendered when the light irradiates the background image through the three-dimensional model having the virtual thickness; the rendering color is the color of the background image presented on the object to be rendered; rendering the object to be rendered according to the rendering color, and displaying the rendered object to be rendered on the background image.
[0006] This solution can determine the virtual thickness of the object to be rendered, and the virtual thickness can be used to truly calculate the color of the background image on the object to be rendered when the light is emitted from the object to be rendered and illuminates the background image, so that the rendering effect of the object to be rendered is more in line with the actual situation. In addition, there is no need to make additional maps for the glass material, which can save manpower and time and improve rendering efficiency.
[0007] In a possible implementation, determining the virtual thickness of the object to be rendered based on the three-dimensional model of the object to be rendered includes: when the three-dimensional model is a hollow model, obtaining a back surface contour map of the three-dimensional model; extracting the back surface normal of the three-dimensional model based on the back surface contour map of the three-dimensional model; determining the mixed normal of each vertex of the three-dimensional model based on the vertex normal and the back surface normal of each vertex; and determining the virtual thickness of each vertex through the mixed normal of each vertex and the viewing direction of the human eye.
[0008] In a possible implementation, determining the virtual thickness of the object to be rendered based on the three-dimensional model of the object to be rendered includes: when the object to be rendered is solid, calculating the dot product of the vertex normal at the vertex of the three-dimensional model and the direction of human eye observation, and using the calculated result as the virtual thickness at the vertex of the object to be rendered.
[0009] In a possible implementation, determining the rendering color of the object to be rendered when the light passes through the three-dimensional model with the virtual thickness and illuminates the background image includes: calculating the refraction color of the background image and the edge color of the light passing through the object to be rendered according to the virtual thickness of the three-dimensional model; wherein the refraction color is the color of the background image presented on the object to be rendered when the light is refracted by the object to be rendered and illuminates the background image, and the edge color is the color presented at the edge of the object to be rendered when the light is illuminated on the object to be rendered; determining the reflection color of the background image when the light passes through the object to be rendered through the reflection map of the three-dimensional model; the reflection color is the color presented by the object to be rendered when the light reflects the light when the light is illuminated on the object to be rendered; and determining the rendering color of the object to be rendered in combination with the refraction color, the reflection color and the edge color.
[0010] In a possible implementation, determining the rendering color of the object to be rendered when the light passes through the three-dimensional model with the virtual thickness and illuminates the background image includes: acquiring the refractive index of the object to be rendered; calculating the travel length of the light when passing through the three-dimensional model according to the incident angle when the light enters the three-dimensional model, the refractive index and the virtual thickness of the three-dimensional model; calculating the exit point of the light when passing through the three-dimensional model according to the travel length; and acquiring the color of the first target pixel in the background image corresponding to the exit point as the rendering color.
[0011] In a possible implementation, obtaining the color of a first target pixel in the background image corresponding to the exit point includes: determining the normal direction at the exit point; determining the exit direction of light when it enters a first medium from the exit point according to the normal direction at the exit point; determining the first target pixel on the background image that the light passes through the exit point and is irradiated according to the exit direction, the exit point, and the refractive index of the first medium, and obtaining the color of the first target pixel.
[0012] In a possible implementation, the surface of the three-dimensional model is a curved surface, and determining the normal direction at the exit point includes: obtaining the incident point of the light on the three-dimensional model; determining the center position of the circle corresponding to the surface of the three-dimensional model according to the normal at the incident point; and obtaining the normal direction at the exit point using the center position of the circle and the exit point.
[0013] In a possible implementation, the calculation of the exit point of the light when it passes through the three-dimensional model based on the travel length includes: when the three-dimensional model is a hollow model, determining a first exit point when the light passes through the convex surface of the hollow model and a second exit point when the light passes through the concave surface of the hollow model based on the travel length, and using the second exit point as the exit point when the light passes through the hollow three-dimensional model.
[0014] According to a second aspect of an embodiment of the present disclosure, there is provided an image rendering device, comprising: a scene determination module, a model determination module, a color determination module and a rendering module.
[0015] Specifically, the scene determination module is used to obtain an object to be rendered of glass material corresponding to the background image. The object to be rendered is a virtual object to be added to the background image. The model determination module is used to determine the virtual thickness of the object to be rendered based on the three-dimensional model of the object to be rendered. The virtual thickness is used to characterize the thickness of the object to be rendered from the incidence to the emission of the light. The color determination module is used to determine the rendering color of the object to be rendered when the light passes through the three-dimensional model with the virtual thickness and shines on the background image. The rendering color is the color of the background image presented on the object to be rendered. The rendering module is used to render the object to be rendered according to the rendering color, and display the rendered object to be rendered on the background image.
[0016] In some embodiments, the model determination module can be used to calculate the dot product of the vertex normal at the vertex of the three-dimensional model and the human eye observation direction when the object to be rendered is solid, and use the calculated result as the virtual thickness at the vertex of the object to be rendered.
[0017] In some embodiments, the model determination module further includes a back surface contour acquisition module, a back surface normal acquisition module, a normal blending module, and a thickness determination module.
[0018] Among them, the back contour acquisition module is used to obtain the back contour map of the three-dimensional model when the three-dimensional model is a hollow model. The back normal acquisition module is used to extract the back normal of the three-dimensional model according to the back contour map of the three-dimensional model. The normal blending module is used to determine the blended normal of each vertex of the three-dimensional model according to the vertex normal and the back normal of each vertex. The thickness determination module is used to determine the virtual thickness of each vertex according to the blended normal of each vertex and the human eye observation direction.
[0019] In some implementations, the color determination module may include a refraction color determination module, a reflection color determination module, and a rendering color determination module.
[0020] The refraction color determination module is used to calculate the refraction color of the background image when the light passes through the object to be rendered, and the edge color according to the virtual thickness of the three-dimensional model. The refraction color is the color of the background image presented on the object to be rendered when the light is refracted by the object to be rendered and then shines on the background image. The edge color is the color presented at the edge of the object to be rendered when the light shines on the object to be rendered. The reflection color determination module is used to determine the reflection color of the background image when the light passes through the object to be rendered through the reflection map of the three-dimensional model. The reflection color is the color presented when the light shines on the object to be rendered and the object to be rendered reflects the light. The rendering color determination module is used to determine the rendering color of the object to be rendered by combining the refraction color, the reflection color and the edge color.
[0021] In some embodiments, the color determination module further includes a refractive index acquisition module, a light travel length calculation module, an exit point determination module, and an exit point color determination module. The refractive index acquisition module is used to acquire the refractive index of the object to be rendered.
[0022] A light travel length calculation module is used to calculate the travel length of the light when passing through the three-dimensional model according to the incident angle when the light enters the three-dimensional model, the refractive index and the virtual thickness of the three-dimensional model. An exit point determination module is used to calculate the exit point when the light passes through the three-dimensional model according to the travel length. An exit point color determination module is used to obtain the color of the first target pixel point in the background image corresponding to the exit point as the rendering color.
[0023] In some embodiments, the exit point color determination module is also used to determine the normal direction at the exit point; determine the exit direction of the light when it enters the first medium from the exit point based on the normal direction at the exit point; determine the first target pixel point on the background image that the light passes through the exit point and is irradiated by based on the exit direction, the exit point, and the refractive index of the first medium, and obtain the color of the first target pixel point.
[0024] In some embodiments, the surface of the three-dimensional model is a curved surface, and the exit point color determination module is used to obtain the incident point of the light on the three-dimensional model; determine the center position of the circle corresponding to the surface of the three-dimensional model according to the normal at the incident point; and use the center position of the circle and the exit point to obtain the normal direction at the exit point.
[0025] In some embodiments, the exit point color determination module is used to determine, when the three-dimensional model is a hollow model, a first exit point where the light passes through the convex surface of the hollow model and a second exit point where the light passes through the concave surface of the hollow model based on the travel length, and use the second exit point as the exit point when the light passes through the hollow three-dimensional model.
[0026] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor executable instructions; wherein the processor is configured to execute instructions to implement the image rendering method of the above-mentioned first aspect and any possible implementation manner thereof.
[0027] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the image rendering method in the above-mentioned first aspect and any possible implementation manner thereof.
[0028] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided. The computer program product includes a computer program. When the computer program runs on an electronic device, the electronic device executes the image rendering method of the first aspect and any possible implementation manner thereof.
[0029] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0030] In the technical solution of this embodiment, on the one hand, by determining a virtual thickness for the three-dimensional model of the glass material object to be rendered, and using the physical principle of light passing through the three-dimensional model with thickness to determine the rendering color, the authenticity of the rendering can be enhanced. On the other hand, there is no need to make additional maps for the glass material, which can save manpower and time and improve rendering efficiency.
[0031] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0033] Figure 1 is a flowchart of an image rendering method according to an exemplary embodiment;
[0034] Figure 2 is a schematic diagram of light refraction in an image rendering method according to an exemplary embodiment;
[0035] Figure 3A is a schematic diagram showing the effect of an image rendering method according to an exemplary embodiment;
[0036] Figure 3B is another effect schematic diagram of an image rendering method according to an exemplary embodiment;
[0037] Figure 4 is a block diagram of an image rendering device according to an exemplary embodiment;
[0038] Figure 5 The diagram is a structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0039] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0040] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0041] The image rendering method in the disclosed embodiment can be applied to various electronic devices, such as computers, tablet computers, mobile phones, smart wearable devices, etc., which are not particularly limited in this embodiment. For the convenience of description, the following embodiments are described by taking the electronic device as a mobile phone as an example.
[0042] Figure 1 is a flowchart of an image rendering method according to an exemplary embodiment. Figure 1 As shown, the method may include the following steps.
[0043] In step S11, an object to be rendered of a glass material corresponding to the background image is obtained, wherein the object to be rendered is a virtual object to be added to the background image.
[0044] Camera applications on electronic devices such as mobile phones can render images, for example, by adding filters, photo frames, emoticons, etc. Magic emoticons are a rendering effect provided by camera applications, which are used to add virtual decorations to images.
[0045] In this embodiment, the image captured by the camera is the background image. The object to be rendered is a virtual object that needs to be added to the background image, such as virtual clothes, virtual accessories, etc. For example, when the user needs to add virtual decorations to the currently captured image (i.e., the background image), the user can select various magic expressions provided in the application, such as virtual clothes, virtual hats, etc. When the user chooses to add a magic expression of glass material, for example, the magic expression is a virtual glass ornament, then the magic expression is the object to be rendered.
[0046] In step S12, a virtual thickness of the object to be rendered is determined according to the three-dimensional model of the object to be rendered. The virtual thickness is used to characterize the thickness of the object to be rendered from the time when the light enters the object to the time when the light exits the object.
[0047] The object to be rendered can be established by the designer, and the attribute information of its glass material can be set, such as the refractive index of the glass, the intensity of the change in glass thickness, etc. The three-dimensional model of the object to be rendered is a mathematical model established for the object to be rendered. Exemplarily, the three-dimensional model may include the vertex position, texture coordinates, vertex normal direction, and screen space texture coordinates of the object to be rendered. Among them, the vertex position refers to the coordinates of the vertex of the object to be rendered. Texture coordinates refer to the coordinates of each pixel in the texture map. Each vertex of the three-dimensional model can correspond to a texture coordinate, which is used to indicate the position of the vertex in the texture map. The vertex normal direction refers to the normal direction at the vertex. The screen space texture coordinates refer to the coordinates corresponding to the vertex on the screen. In addition, the object to be rendered may also include other parameters, such as lighting information, etc., which are not particularly limited in this embodiment.
[0048] The image has information of four channels: RGBA. The three channels of RGB store red, green, and blue respectively, and the A channel stores the transparency of the image.
[0049] The edge of the other side of the model, that is, the thickness of the model, can be determined by the product of the line of sight and the normal. The virtual thickness of the three-dimensional model of the object to be rendered can be determined by the line of sight and the normal. The line of sight is the direction of human eye observation, that is, the direction from the human eye to the vertex of the three-dimensional model, marked as -V, and the vertex normal is N. The virtual thickness of the three-dimensional model can be simulated by the direction of human eye observation and the normal direction of the three-dimensional model itself (that is, the vertex normal), which is simple and efficient. Exemplarily, the dot function can simulate the thickness of the model, and the dot function can calculate the dot product of two vectors. The virtual thickness of the three-dimensional model can be calculated by dot(V,N). Among them, V is the opposite direction of -V. Substituting the vertex normal of each vertex of the three-dimensional model into the dot function, the virtual thickness of each vertex of the three-dimensional model can be obtained. Alternatively, the thickness calculated by dot(V,N) is used as the first thickness, and a more reasonable virtual thickness is obtained by adjusting on the basis of the first thickness. For example, the absolute value of the first thickness can be calculated first to avoid errors in the result when the first thickness is negative. Then the absolute value of the first thickness is increased by an exponential function, and the final result is used as the virtual thickness of the three-dimensional model. The above process can be summarized as the following formula: thickness = pow(abs(dot(V,N)), ThicknessStrength), where the abs function is a function for calculating absolute values, and abs(dot(V,N)) is the absolute value of the first thickness. The pow function is used to calculate the ThicknessStrength power of the above absolute value. ThicknessStrength is the strength of glass thickness change. This parameter can be preset manually. The greater the strength of glass thickness change, the more obvious the glass thickness change. The thickness calculated by the above formula can be used as the virtual thickness of the three-dimensional model.
[0050] The object to be rendered can be a hollow shape, such as a water cup; or a solid shape, such as a glass ball. If the object to be rendered is solid, the light only needs to go through the incident and exit processes once when passing through the object to be rendered. Then the dot product of the human eye observation direction and the vertex normal calculated by the dot function can be the virtual thickness of the solid object to be rendered. If the object to be rendered is hollow, the light must go through the incident and exit processes at least twice when passing through the object to be rendered. The surface where the light first exits is regarded as the front face of the object to be rendered, and the surface where the light exits for the second time is regarded as the back face of the object to be rendered. For the hollow object to be rendered, the virtual thickness needs to mix the thickness of the front and back faces of the three-dimensional model. Exemplarily, when the three-dimensional model is a hollow model, a background contour map of the three-dimensional model is obtained; the back contour map of the three-dimensional model is sampled to obtain the back normal of the three-dimensional model; for each vertex on the three-dimensional model, the mixed normal of each vertex of the hollow three-dimensional model is determined according to the vertex normal at each vertex and the back normal corresponding to each vertex; and the virtual thickness of each vertex of the hollow three-dimensional model is calculated in combination with the mixed normal of the hollow three-dimensional model and the observation direction of the human eye.
[0051] In the above implementation, the calculation of the virtual thickness is combined with the back contour of the three-dimensional model, and the back normal is mixed with the front normal (i.e., vertex normal), so that the calculated equivalent normal has the characteristics of both the front and back sides, thereby simulating the effect of seeing the back contour of a hollow model through the front side, so that the virtual thickness covers the scene of the hollow model, which can enrich the rendering effect.
[0052] Specifically, the back normal of the three-dimensional model is required to calculate the thickness of the back side, and the back normal can be sampled from the back contour map of the three-dimensional model. The back contour map is the data preset by the designer when constructing the three-dimensional model, and is used to record the image information of the back side of the three-dimensional model, such as the color of each pixel on the back side. Exemplarily, the back contour map can be sampled by the TEXTURE2D function, and the specific formula is: back = TEXTURE2D (inside_color_tex, screen_uv), and the TEXTURE2D function includes two input parameters, where inside_color_tex represents the back contour map, and screen_uv is the screen space texture coordinate of a vertex. The information of the point screen_uv in the back contour map can be obtained by this formula, which is represented by back. The back normal is the information recorded by the RGB channel in the back contour information, that is, the information of the RGB channel in back is the back normal. Exemplarily, the difference in the value of the back normal can be increased by the formula back_n = back.rgb*2-1, and the adjusted back normal can be obtained, which is represented by back_n. Wherein back.rgb is the back normal before adjustment.
[0053] After obtaining the back normal, the back normal back_n and the front normal (i.e., the vertex normal N of the solid three-dimensional model) of each vertex are mixed through a mixing function to obtain the mixed normal of each vertex of the hollow model. The mixing function is mix(x, y, a), which can linearly mix x and y and return the result of x(1-a)+y*a. Where a is the mixing coefficient, which can be set according to actual conditions, for example, a can be 0, 0.5, etc. Exemplarily, when mixing the back normal and the front normal, a can be the transparency of the back contour map, that is, the information of the a channel: back.a. The normal of the entire hollow model can be calculated by the formula N=normalize(mix(back_n,N,back.a)), where the mix function is used to mix back_n, N, back.a, and normalize is used to normalize the value obtained by mix, that is, convert the value range of the normal to 0 to 1, which can ensure that the value range of the normal vector is correct. The blended normal combines the contours of the front and back faces, which can make the rendering appear as if the contours of the back face are seen through the front face, thus simulating the effect of hollow glass more realistically.
[0054] After obtaining the mixed normal of the hollow model, the thickness of the hollow model is calculated by the above-mentioned method of calculating thickness. Specifically, the virtual thickness of the hollow model is calculated by the formula thick_back=pow(inside_info.w,ThicknessStrength), which is represented by thick_back. Among them, inside_info.w is the absolute value of the dot product of the mixed normal N of the hollow model and the human eye observation direction V. In addition, after calculating the virtual thickness of the hollow model, it can also be mixed with the virtual thickness of the solid three-dimensional model to further improve the authenticity of the virtual thickness of the hollow model. For example, the virtual thickness think1 of the mixed hollow module is calculated by the formula thick1=mix(thick,thick+thick_back,thick_back). Among them, thick is the virtual thickness of the solid three-dimensional model, and thick_back is the virtual thickness of the hollow model.
[0055] In step S13, the rendering color of the object to be rendered when the light passes through the three-dimensional model with virtual thickness and irradiates the background image is determined. The rendering color is the color of the background image presented on the object to be rendered.
[0056] When light passes through a three-dimensional model made of glass, it will produce effects such as refraction and reflection, and the intensity of light reflection will also be different when the thickness of the glass edge changes. In this embodiment, the refraction color and edge color of the three-dimensional model to the light can be calculated according to the physical principle based on the virtual thickness of the three-dimensional model; the reflection color of the background image when the light passes through the object to be rendered is determined by the reflection map of the three-dimensional model; thereby obtaining the refraction color, edge color, and reflection color of the three-dimensional model, and combining these three color effects to determine the final rendering color. The refraction color is the color of the background image presented on the object to be rendered when the light is refracted by the object to be rendered and shines on the background image. The edge color is the color presented by the edge of the object to be rendered when the light shines on the object to be rendered. The reflection color is the color presented by the object to be rendered when the light reflects the light when it shines on the object to be rendered. The rendering color combines the effects of refraction, reflection, and edge, which can make the rendering of the object to be rendered more consistent with the effect of real glass and improve the visual experience.
[0057] Next, the above process of determining the refraction color based on the virtual thickness is explained. When the three-dimensional model is a solid model, the light is refracted only once when passing through the three-dimensional model. Specifically, the travel length of the light when passing through the three-dimensional model can be calculated through the refractive index of the three-dimensional model, the incident angle when the light enters the three-dimensional model, and the virtual thickness of the three-dimensional model; the exit point when the light exits the three-dimensional model can be determined based on the travel length; the intersection of the three-dimensional model light passing through the exit point and the background image can be determined based on the exit point, which is called the first target pixel point; the color of the first target pixel point is the refracted color of the light on the three-dimensional model.
[0058] The travel length of a ray refers to the length of a ray that is calculated by the ray technology when it passes through a surface with virtual thickness of a three-mode model. Ray Marching is a method of implementing ray tracing, which is used to intersect a ray with an object. Each time a ray advances a certain step length, it detects whether the current ray is on the surface of an object, and adjusts the ray's advance amplitude accordingly until it reaches the surface of the object.
[0059] When the light reaches a surface of the three-dimensional model, the intersection with the surface is taken as the incident point. When the light exits a surface of the three-dimensional model, the intersection with the surface is taken as the exit point. The travel length can be the length that the light travels between the incident point and the exit point.
[0060] The incident point is the point where the light preset by ray tracing technology reaches the 3D model. Ray tracing is a special rendering algorithm in 3D computer graphics. It tracks the light emitted from the eye instead of the light source, and displays the mathematical model of the arranged scene, presenting a more realistic rendering effect that conforms to the principles of physics.
[0061] For example, refer to Figure 2 As shown, the human eye observation direction -V for the three-dimensional model 200 is the incident light; the intersection of the incident light and the three-dimensional model 200 is the incident point P0. The angle θ between the incident light and the normal line 0 is the angle of incidence, the angle θ between the refracted light ray V1 and the normal 1 is the refraction angle.
[0062] According to the law of light refraction, the incident angle θ 0 , refraction angle θ 1 , the refractive index n0 of medium 0 through which the incident light passes and the refractive index n1 of medium 1 through which the incident light passes have the following relationship:
[0063] n0×sinθ 0 =n1×sinθ 1
[0064] For example, medium 0 can be air, and medium 1 is the object to be rendered made of glass in this embodiment. When light enters the object to be rendered from air, the incident angle θ can be determined according to the human eye observation direction -V and the normal line N. 0 , substituting the incident angle, the refractive index of air, and the refractive index of glass into the above refraction law, we can determine the refraction angle θ 1 The refraction angle θ 1 The cosine value of is the ratio of the thickness of the glass material thick to the travel length of the light in the glass travel_path, then according to cosθ 1 The travel length travel_path of the light through the glass can be calculated.
[0065] Specifically, the refraction direction can be obtained by the following formula: ray_out0 = normalize(refract(-V,N,n01)). Where n01 is the ratio of the refractive index n0 of medium 0 to the refractive index n1 of medium 1 when the light enters medium 1 from medium 0. The refract function is a refraction function, which is used to calculate the outgoing direction based on the incident direction, normal, and refractive index ratio. The normalize function is used for normalization processing, normalizing the outgoing direction to a unit vector to ensure that the direction is calculated correctly. The refraction angle θ can be calculated by the formula: theta1 = asin(sin(acos(nohv))*n01). 1 , where nohv is the ratio of the normal to the human eye's viewing direction -V, i.e., the cosine value corresponding to the incident angle; the acos function is used to calculate the angle corresponding to the cosine value, i.e., the incident angle; sin(acos(nohv))*n01 can calculate the sine value of the refraction angle, and the asin function can calculate the angle corresponding to the sine value, i.e., the refraction angle θ1 . Calculate the refraction angle θ 1 Then, the unit distance of the light in the 3D model can be calculated by the formula: travel_dis0 = RefrStretch / cos(theta1). Among them, RefrStretch is the light step length, that is, the length of the light when passing through the unit thickness of glass. The formula: travel_path = ray_out0*travel_dis0*thick can be used to calculate the travel length of the light when passing through the virtual thickness of glass. The travel length is the product of the direction of the refracted light, the length of the refracted light, and the virtual thickness.
[0066] The position of the exit point when the light exits the three-dimensional model can be determined based on the travel length of the light inside the three-dimensional model and the position of the incident point. Exemplarily, the position out_p0 of the exit point P1 can be calculated by the formula: out_p0=worldpos+travel_path. Among them, worldpos is the coordinate of the incident point P0, and travel_path is the above-mentioned travel length. After calculating the exit point of the light through the three-dimensional model, the intersection of the exit point and the background image can be determined as the first target pixel point. The first target pixel point is the first target pixel point that the human eye can observe from the incident point when the light enters the three-dimensional model, and the color of the first target pixel point can be rendered to the incident point P0 in the three-dimensional model.
[0067] After the light is emitted from the inside of the 3D model, it can enter another medium, such as air. The medium that the light enters after emitting from the 3D model is regarded as the first medium. Figure 2 , after the light enters the three-dimensional model from point P0 of the three-dimensional model, it enters the first medium from the exit point P1, and the exit point P1 can be used as the incident point of the light in the first medium. Similarly, the travel length of the light in the first medium can be calculated by the above method of calculating the travel length of the light in the three-dimensional model. Specifically, first calculate the normal of the light at the exit point where the light exits the three-dimensional model; then determine the exit direction based on the normal of the exit point; and then calculate the travel distance of the light in the second medium based on the exit direction and the refractive index of the first medium, and the end point of the travel distance is the intersection point where the light passes through the exit point and the background image. By performing ray tracing in the first medium with a certain thickness and the three-dimensional model, the refraction effect of the light on the background image after passing through the three-dimensional model and the first medium can be simulated, thereby improving the authenticity of the refraction effect.
[0068] Exemplarily, the surface of the three-dimensional model can be a curved surface, and the normal direction at the exit point P1 can be the direction from the center of the circle at the exit point to the exit point. When the surface of the three-dimensional model is a curved surface, the refraction of the light is stronger, which can make the visual experience have a more obvious refraction effect. Specifically, first obtain the incident point of the light in the three-dimensional model, and then determine the center position of the curved surface corresponding to the exit point P1 according to the normal at the incident point. The normal direction at the exit point P1 can be obtained using the center position and the exit point P1. The center position origin of the exit point can be calculated by the formula: origin = worldpos + N * RefrStepCount * RefrStretch. Among them, worldpos is the coordinate of the incident point, RefrStretch is the light step length, RefrStepCount is the number of light steps, and N is the normal direction of the three-dimensional model. After determining the center position, the direction from the center to the exit point P1 can be used as the normal direction of the exit point P1. The normal direction at the exit point P1 is obtained by the formula: N0 = normalize (origin - out_p0), where origin is the center of the circle; out_p0 is the exit point; and the normalize function is used for normalization.
[0069] The emission direction can be determined according to the normal direction of the emission point P1. Similarly, the method for determining the refraction direction is the same as the above method. By substituting the human eye observation direction -V into the refract function, the above calculated normal direction N0 and the refractive index ratio of the three-dimensional model and the first medium, the emission direction of the light can be obtained. For example, the emission direction ray_out1 can be calculated by the formula: ray_out1 = normalize(refract(ray_ou.t0, N0, n12)); wherein n12 is the ratio of the refractive index of the three-dimensional model to the refractive index of the first medium. The emission direction can be further used to calculate the emission angle θ 2 For example, the exit angle can be obtained by the formula: theta2=asin(sin(acos(dot(-ray_out0,N0)))*n12), where -ray_out0 is the reverse vector of the exit direction; and the dot function is used to calculate the thickness of the first medium.
[0070] After calculating the exit angle, the distance traveled by the light in the first medium is calculated using the formula: travel_dis1 = RefrStretch / cos(theta1). Then, based on the distance of the light in the first medium, the intersection point P2 of the light passing through the exit direction and the background image, that is, the first target pixel point, is determined. Exemplarily, the coordinates of the first target pixel point P2, intersect_uv1, are determined using the formula: intersect_uv1 = GetIntersectPointUV(ray_out1, travel_dis1*thick, out_p0). Among them, ray_out1 is the exit direction; travel_dis1*thick is the distance of the light in the first medium after the thickness is added; out_p0 is the coordinate of the exit point. The GetIntersectPointUV function can calculate the coordinates of the first target pixel point P2 on the background image that the light reaches after passing through the exit point P1 and the first medium in the exit direction.
[0071] After determining the first target pixel, sampling the background image can obtain the color of the first target pixel on the background image. For example, the color of the first target pixel, that is, the RGB value, can be obtained through the formula: refr_clr1 = TEXTURE2D (photo_tex, intersect_uv1).rgb. Among them, photo_tex represents the background image; intersect_uv1 is the coordinate of the first target pixel; the calculated refr_clr is the color of the first target pixel, that is, the RGB value. The color of the first target pixel P2 can be used as the refraction color of the incident point P0 on the three-dimensional model. Similarly, by taking each pixel on the three-dimensional model as an incident point, the refraction color of each pixel on the three-dimensional model can be obtained, thereby rendering the three-dimensional model. The refraction color calculated in the above manner integrates the back contour of the three-dimensional model, so that the refraction effect of the three-dimensional model on light can be truly simulated.
[0072] Usually, when realizing the refraction effect of real glass, every time the real light undergoes incidence and reflection, the reflected light will become an incident light again, and the light emitted after refraction will also become the next incident light. Therefore, the calculation method based on the real physical principle involves complex parameters and a large number of parameters, which requires repeated iterative calculations, a large amount of calculations, and too high requirements on device performance. In this embodiment, the virtual thickness integrates the contour of the back of the model. When calculating the refracted color through the virtual thickness, only a single calculation is needed to obtain the refraction effect of the hollow model. It is simple and efficient, and does not require multiple iterations, and the complexity is greatly reduced. In addition, it can improve efficiency, reduce the requirements for device performance, and can meet the use of mobile terminals.
[0073] In the above embodiment, when the three-dimensional model is a solid model, the intersection point of the light with the background image after one refraction when passing through the three-dimensional model is calculated, that is, the first target pixel point. In order to simulate the refraction effect of the hollow model on the light, it is assumed that the above three-dimensional model is a hollow model. The light must be refracted at least twice in the hollow three-dimensional model. The refraction colors corresponding to the two refractions can be calculated, and the refraction colors of the two refractions can be combined to determine the final refraction color of the three-dimensional model. The hollow model includes a convex surface and a concave surface. If the convex surface is the front surface and the concave surface is the back surface, the light is refracted once on the front surface and once on the back surface. The color of the above first target pixel point can be used as the refraction color corresponding to the convex refraction. Then, the second target pixel point is determined according to the above method for determining the first pixel point, and the color of the second target pixel point is used as the refraction color corresponding to the concave refraction, that is, the exit point when the light finally exits the hollow three-dimensional model.
[0074] Specifically, when the three-dimensional model is a hollow model, the first exit point of the light on the convex surface, that is, the exit point P1 mentioned above, and the second exit point of the light on the concave surface can be determined respectively according to the travel length of the light in the three-dimensional model. As shown in the formula: out_p0=worldpos+travel_path, the first exit point is the sum of the incident point and the travel length. The second exit point can be the difference between the incident point and the travel length, such as: the second exit point out_p1=worldpos-travel_path, where worldpos is the coordinate of the incident point P0, and travel_path is the above travel length. That is to say, in a hollow three-dimensional model, the exit point of the convex surface is the sum of the incident point and the travel length, and the exit point of the concave surface is the difference between the incident point and the travel length. This embodiment can simulate the refraction effect of the hollow model, thereby enriching the rendering effect. Moreover, in the case of a hollow model, the accuracy of the refracted color can be improved by combining the refractions of two different planes.
[0075] According to the second emission point, the second target pixel corresponding to the second emission point can be determined, and the color of the first target pixel is mixed with the color of the second target pixel, and the result is used as the refraction color of the three-dimensional model. Exemplarily, the color of the first target pixel and the color of the second pixel can be mixed by the mixing function mix, such as: the mixed color refr_clr = mix (refr_clr1, refr_clr2, DoubleRefrMix), where refr_clr1 is the color of the first target pixel; refr_clr2 is the color of the second target pixel; DoubleRefrMix is the double refraction mixing coefficient, which can be predetermined by the designer. The mixed color is used as the refraction color of the three-dimensional model.
[0076] The convex surface of the hollow three-dimensional model can magnify the background image, and the concave surface can reduce the background image. The refraction color of the three-dimensional model determined in this embodiment mixes the refraction effects of the concave and convex surfaces, can simulate the refraction effect of the hollow model, and enhance the richness and authenticity of the rendering.
[0077] The surface of glass material is usually very smooth, and the reflection of ambient light is specular reflection, which is relatively strong. The reflection color can be expressed by reflection map. Reflection map can include panorama map or matcap map, which can be designed in advance by the designer. When rendering the object to be rendered, the reflection map can be sampled to obtain the color stored in the reflection map as the reflection color of the object to be rendered.
[0078] In some embodiments, the color of the edge of the three-dimensional model of the object to be rendered can be adjusted to enhance or weaken the color of the edge, simulating the effect of sudden enhancement of refraction and reflection at the edge of the glass material, so that the rendering is more realistic. Exemplarily, the edge of the three-dimensional model is first determined, and then the color at the edge is adjusted. The edge of the three-dimensional model can be determined by the dot function, such as: dot(N, V), and the normal of the three-dimensional model and the direction of human eye observation are used as input parameters to obtain the calculation result of the dot function, that is, the edge of the three-dimensional model. Then, the light intensity of the color at the edge is enhanced within a certain range, for example, an enhancement coefficient is set, and the light intensity at the edge is adjusted to the result multiplied by the enhancement coefficient, thereby obtaining the edge color.
[0079] The final rendering color of the three-dimensional model can be obtained by combining the above determined refraction color, reflection color and edge color. Exemplarily, the sum of the refraction color, reflection color and edge color can be used as the final rendering color.
[0080] In step S14, the object to be rendered is rendered according to the rendering color, and the rendered object to be rendered is displayed on the background image.
[0081] The shader in the mobile phone can render the object to be rendered layer by layer. For example, the shader can obtain the edge color determined above and render the rendering color onto the object to be rendered. In addition, the object to be rendered can also be rendered in other ways, for example, the material of the object to be rendered can be captured, the material information and light source information of the object to be rendered can be obtained from the texture map of the object to be rendered, and then the light source and material can be rendered onto the object to be rendered.
[0082] The rendered object to be rendered can be displayed at the corresponding position of the background image, simulating the effect of adding a virtual object to be rendered to the background image. Figure 3AAs shown, a virtual object 301 to be rendered may be displayed in the background image 300 captured by the camera. The object 301 to be rendered may be a virtual glass. Figure 3A In the example, when light passes through the glass 301, the glass 301 refracts and reflects the light, so that the background image observed by the human eye through the glass 301 presents real refraction and reflection effects. As the direction of human eye observation (i.e., the direction of the camera) changes, the effect presented on the virtual glass 301 in the background image also changes accordingly. When light passes through the glass 301 and shines on the cartoon toy 302 in the background image, the effect presented by the cartoon toy 302 is as follows: Figure 3B As shown. It can be seen that when rendering the glass material object to be rendered, the above method provided by this embodiment can render a more realistic glass refraction and reflection effect, making the rendering of the glass material more realistic and accurate. In addition, this embodiment does not need to perform multiple complex physical calculations. Through virtual thickness, the effect of multiple refractions of light can be achieved in one calculation, which can reduce the requirements for device performance and reduce energy consumption.
[0083] Exemplarily, the object to be rendered can be at a specific position of the background image, or the position can be flexibly updated according to the content of the background image. Taking the object to be rendered as a magic expression as an example, the magic expression can be fixedly displayed at a specific position such as the left, right or top of the background image; or, the position of a specific object such as a face in the background image can be detected, and the magic expression can be displayed around the face, etc. This embodiment does not specifically limit this.
[0084] In the above implementation, for the object to be rendered made of glass material, its refraction color can be determined based on physical principles, and the refraction color, reflection color and edge color can be combined to determine the final rendering color, which can make the rendering effect more consistent with the refraction and reflection effects of real glass on light, making the rendering effect more realistic and improving the user's visual experience.
[0085] Figure 4 is a block diagram of an image rendering device according to an exemplary embodiment. Figure 4 The image rendering device 400 includes: a scene determination module 410, a model determination module 420, a color determination module 430 and a rendering module 440. The image rendering device 400 can be used to perform the above-mentioned image rendering method, for example, the scene determination module 410 can be used to perform the above-mentioned step S11, the model determination module 420 can be used to perform the above-mentioned step S12, the color determination module 430 can be used to perform the above-mentioned step S13, and the rendering module 440 can be used to perform the above-mentioned step S14.
[0086] Specifically, the scene determination module 410 is used to obtain the object to be rendered of glass material corresponding to the background image. The object to be rendered is a virtual object to be added to the background image. The model determination module 420 is used to determine the virtual thickness of the object to be rendered based on the three-dimensional model of the object to be rendered. The virtual thickness is used to characterize the thickness of the object to be rendered from the incidence to the emission of the light. The color determination module is used to determine the rendering color of the object to be rendered when the light is irradiated on the background image through the three-dimensional model with virtual thickness. The rendering color is the color of the background image presented on the object to be rendered. The rendering module 440 is used to render the object to be rendered according to the rendering color, and display the rendered object to be rendered on the background image.
[0087] In some embodiments, the model determination module 420 can be used to calculate the dot product of the vertex normal at the vertex of the three-dimensional model and the human eye observation direction when the object to be rendered is solid, and use the calculated result as the virtual thickness at the vertex of the object to be rendered.
[0088] In some implementations, the model determination module 420 further includes a back surface contour acquisition module, a back surface normal acquisition module, a normal blending module, and a thickness determination module.
[0089] The back contour acquisition module is used to obtain the back contour map of the 3D model when the 3D model is a hollow model. The back normal acquisition module is used to extract the back normal of the 3D model based on the back contour map of the 3D model. The normal blending module is used to determine the blended normal of each vertex of the 3D model based on the vertex normal and the back normal of each vertex. The thickness determination module is used to determine the virtual thickness of each vertex through the blended normal of each vertex and the viewing direction of the human eye.
[0090] In some implementations, the color determination module 430 may include a refraction color determination module, a reflection color determination module, and a rendering color determination module.
[0091] The refraction color determination module is used to calculate the refraction color of the background image and the edge color when the light passes through the object to be rendered according to the virtual thickness of the three-dimensional model. Among them, the refraction color is the color of the background image presented on the object to be rendered when the light is refracted by the object to be rendered and shines on the background image. The edge color is the color presented at the edge of the object to be rendered when the light shines on the object to be rendered. The reflection color determination module is used to determine the reflection color of the background image when the light passes through the object to be rendered through the reflection map of the three-dimensional model. The reflection color is the color presented by the object to be rendered when the light reflects the light when it shines on the object to be rendered. The rendering color determination module is used to determine the rendering color of the object to be rendered by combining the refraction color, the reflection color and the edge color.
[0092] In some embodiments, the color determination module 430 further includes a refractive index acquisition module, a light travel length calculation module, an exit point determination module, and an exit point color determination module. The refractive index acquisition module is used to acquire the refractive index of the object to be rendered.
[0093] The light travel length calculation module is used to calculate the travel length of the light when passing through the three-dimensional model according to the incident angle, refractive index and virtual thickness of the three-dimensional model when the light enters the three-dimensional model. The exit point determination module is used to calculate the exit point of the light when passing through the three-dimensional model according to the travel length. The exit point color determination module is used to obtain the color of the first target pixel in the background image corresponding to the exit point as the rendering color.
[0094] In some embodiments, the exit point color determination module is also used to determine the normal direction at the exit point; determine the exit direction of the light when it enters the first medium from the exit point based on the normal direction at the exit point; determine the first target pixel point on the background image that the light passes through the exit point and is irradiated by based on the exit direction, the exit point, and the refractive index of the first medium, and obtain the color of the first target pixel point.
[0095] In some embodiments, the surface of the three-dimensional model is a curved surface, and the exit point color determination module is used to obtain the incident point of the light in the three-dimensional model; determine the center position of the circle corresponding to the surface of the three-dimensional model according to the normal at the incident point; and use the center position and the exit point to obtain the normal direction at the exit point.
[0096] In some embodiments, when the three-dimensional model is a hollow model, the exit point color determination module is used to determine the first exit point where the light passes through the convex surface of the hollow model and the second exit point where the light passes through the concave surface of the hollow model based on the travel length, and use the second exit point as the exit point when the light passes through the hollow three-dimensional model.
[0097] Regarding the image rendering device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0098] The specific manner in which each module performs operations has been described in detail in the embodiment of the image rendering method, and will not be elaborated here.
[0099] The present disclosure also provides an electronic device, which can be applied to execute the above-mentioned image rendering method. Figure 5 is a schematic diagram of the structure of an electronic device 500 provided by the present disclosure. Figure 5The electronic device 500 may include at least one processor 501 and a memory 503 for storing instructions executable by the processor 501. The processor 501 is configured to execute the instructions in the memory 503 to implement the image rendering method in the above embodiment.
[0100] In addition, the electronic device 500 may further include a communication bus 502 and at least one communication interface 504 .
[0101] The processor 501 may be a GPU, a microprocessing unit, an ASIC, or one or more integrated circuits for controlling the execution of the program of the disclosed solution.
[0102] Communication bus 502 may include a pathway for transmitting information between the above-mentioned components.
[0103] The communication interface 504 uses any transceiver or other device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.
[0104] The memory 503 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory may be independent and connected to the processing unit via a bus. The memory may also be integrated with the processing unit and be a volatile storage medium in the GPU.
[0105] The memory 503 is used to store instructions for executing the solution of the present disclosure, and the execution is controlled by the processor 501. The processor 501 is used to execute the instructions stored in the memory 503, thereby realizing the functions of the image rendering method of the present disclosure.
[0106] In a specific implementation, as an embodiment, the processor 501 may include one or more GPUs, such as Figure 5 GPU0 and GPU1 in .
[0107] In a specific implementation, as an embodiment, the electronic device 500 may include multiple processors, such as Figure 5 501 and processor 507 in FIG. Each of these processors may be a single-core (single-CPU) processor or a multi-core (multi-GPU) processor. A processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0108] In a specific implementation, as an embodiment, the electronic device 500 may further include an output device 505 and an input device 506. The output device 505 communicates with the processor 501 and may display information in a variety of ways. For example, the output device 505 may be a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector. The input device 506 communicates with the processor 501 and may receive user input in a variety of ways. For example, the input device 506 may be a mouse, a keyboard, a touch screen device, or a sensor device.
[0109] Those skilled in the art will understand that Figure 5 The structure shown in the figure does not constitute a limitation on the electronic device 500, and may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.
[0110] The present disclosure also provides a computer-readable storage medium having instructions stored thereon. When the instructions in the storage medium are executed by a processor of a server, the server is enabled to execute the image rendering method provided by the above-mentioned embodiment of the present disclosure.
[0111] The embodiment of the present disclosure also provides a computer program product including instructions, which, when executed on a server, enables the server to execute the image rendering method provided by the embodiment of the present disclosure.
[0112] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0113] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An image rendering method, characterized in that: include: Acquire an object to be rendered of glass material corresponding to the background image, wherein the object to be rendered is a virtual object to be added to the background image; Determining the virtual thickness of the object to be rendered according to the three-dimensional model of the object to be rendered, including: when the three-dimensional model is a hollow model, obtaining a back surface contour map of the three-dimensional model, and extracting the back surface normal of the three-dimensional model according to the back surface contour map of the three-dimensional model; determining the mixed normal of each vertex of the three-dimensional model according to the vertex normal of each vertex and the back surface normal, and determining the virtual thickness of each vertex according to the mixed normal of each vertex and the human eye observation direction; the mixed normal is a normal obtained by mixing the vertex normal with the back surface normal according to a mixing function; or, when the object to be rendered is solid, calculating the dot product of the vertex normal at the vertex of the three-dimensional model and the human eye observation direction, and using the calculated result as the virtual thickness at the vertex of the object to be rendered; wherein the virtual thickness is used to represent the thickness equivalently simulated based on the route experienced by the light from entering the object to be rendered to emitting; Determining the rendering color of the object to be rendered when the light passes through the three-dimensional model with the virtual thickness and irradiates the background image, includes: calculating the refraction color and the edge color according to the virtual thickness of the object to be rendered, and determining the reflection color of the background image when the light passes through the object to be rendered through the reflection map of the three-dimensional model; the refraction color is the color of the background image presented on the object to be rendered when the light is refracted through the object to be rendered and irradiates the background image; the edge color is the color presented at the edge of the object to be rendered when the light is irradiated on the object to be rendered; the reflection color is the color of the background image presented on the object to be rendered when the light is irradiated on the object to be rendered; When the object to be rendered is on the three-dimensional model, the color presented by the object to be rendered when reflecting the light; the rendering color of the object to be rendered is determined by combining the refraction color, the reflection color and the edge color; or, the refractive index of the object to be rendered is obtained, and the travel length of the light when passing through the three-dimensional model is calculated according to the incident angle when the light enters the three-dimensional model, the refractive index and the virtual thickness of the three-dimensional model; the exit point when the light passes through the three-dimensional model is calculated according to the travel length, and the color of the first target pixel point in the background image corresponding to the exit point is obtained as the rendering color; the rendering color is the color presented by the background image on the object to be rendered; The object to be rendered is rendered according to the rendering color, and the rendered object to be rendered is displayed on the background image.
2. The method according to claim 1, characterized in that The obtaining the color of the first target pixel in the background image corresponding to the emission point includes: Determining the normal direction at the emission point; Determining the exit direction of the light when it enters the first medium from the exit point according to the normal direction at the exit point; According to the emission direction, the emission point, and the refractive index of the first medium, determine that the light passes through the emission point and irradiates a first target pixel on the background image, and obtain the color of the first target pixel.
3. The method according to claim 2, characterized in that The surface of the three-dimensional model is a curved surface, and determining the normal direction at the emission point includes: Obtaining the incident point of the light on the three-dimensional model; Determine the center position of the circle corresponding to the surface of the three-dimensional model according to the normal line at the incident point; The normal direction at the exit point is obtained by using the center position of the circle and the exit point.
4. The method according to claim 3, characterized in that The step of calculating the exit point of the light when the light passes through the three-dimensional model according to the travel length includes: When the three-dimensional model is a hollow model, determining a first exit point of the light through the convex surface of the hollow model according to the travel length, and The light passes through the second exit point of the concave surface of the hollow model, and the second exit point is used as the exit point when the light passes through the hollow three-dimensional model.
5. An image rendering device, characterized in that: include: A scene determination module, used to obtain an object to be rendered of a glass material corresponding to a background image; wherein the object to be rendered is a virtual object to be added to the background image; A model determination module, used to determine the virtual thickness of the object to be rendered according to the three-dimensional model of the object to be rendered, including: when the three-dimensional model is a hollow model, obtaining the back contour map of the three-dimensional model, and extracting the back normal of the three-dimensional model according to the back contour map of the three-dimensional model; determining the mixed normal of each vertex of the three-dimensional model according to the vertex normal of each vertex and the back normal, and determining the virtual thickness of each vertex through the mixed normal of each vertex and the human eye observation direction; the mixed normal is a normal obtained by mixing the vertex normal with the back normal according to a mixing function; or, when the object to be rendered is solid, calculating the dot product of the vertex normal at the vertex of the three-dimensional model and the human eye observation direction, and using the calculated result as the virtual thickness at the vertex of the object to be rendered; wherein the virtual thickness is used to characterize the thickness of the object to be rendered from the incidence to the emission of light; The color determination module is used to determine the rendering color of the object to be rendered when the light passes through the three-dimensional model with the virtual thickness and irradiates the background image, including: calculating the refraction color and the edge color according to the virtual thickness of the object to be rendered, and determining the reflection color of the background image when the light passes through the object to be rendered through the reflection map of the three-dimensional model; the refraction color is the color of the background image presented on the object to be rendered when the light is refracted through the object to be rendered and irradiates the background image, the edge color is the color presented at the edge of the object to be rendered when the light irradiates the object to be rendered; the reflection color is the color of the light The color presented by the object to be rendered when the light is reflected by the object to be rendered when irradiated on the object to be rendered; the rendering color of the object to be rendered is determined in combination with the refraction color, the reflection color and the edge color; or, the refractive index of the object to be rendered is obtained, and the travel length of the light when passing through the three-dimensional model is calculated according to the incident angle when the light enters the three-dimensional model, the refractive index and the virtual thickness of the three-dimensional model; the exit point of the light when passing through the three-dimensional model is calculated according to the travel length, and the color of the first target pixel point in the background image corresponding to the exit point is obtained as the rendering color; the rendering color is the color presented by the background image on the object to be rendered; A rendering module is used to render the object to be rendered according to the rendering color, and display the rendered object to be rendered on the background image.
6. The device according to claim 5, characterized in that The emission point color determination module is used for: Determining the normal direction at the emission point; Determining the exit direction of the light when it enters the first medium from the exit point according to the normal direction at the exit point; According to the emission direction, the emission point, and the refractive index of the first medium, determine that the light passes through the emission point and irradiates a first target pixel on the background image, and obtain the color of the first target pixel.
7. The device according to claim 6, characterized in that The surface of the three-dimensional model is a curved surface, and the emission point color determination module is used for: Obtaining the incident point of the light on the three-dimensional model; Determine the center position of the circle corresponding to the surface of the three-dimensional model according to the normal line at the incident point; The normal direction at the exit point is obtained by using the center position of the circle and the exit point.
8. The device according to claim 7, characterized in that The emission point determination module is used for: When the three-dimensional model is a hollow model, the first exit point where the light passes through the convex surface of the hollow model and the second exit point where the light passes through the concave surface of the hollow model are determined according to the travel length, and the second exit point is used as the exit point when the light passes through the hollow three-dimensional model.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the image rendering method according to any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the image rendering method according to any one of claims 1 to 4.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the image rendering method according to any one of claims 1 to 4 is implemented.
