Model processing method and apparatus, storage medium, and electronic device
By acquiring virtual scenes with non-uniform normal directions of mirror models, using a mirror camera to capture images of the virtual scene as rendering textures, determining sampling coordinates based on normal direction information, and sampling the rendering textures, the problem of difficulty in realistically simulating the distortion effect of funhouse mirrors in existing technologies is solved, thus improving the efficiency of model processing.
Patent Information
- Application Number
- CN202411967836.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2044-12-30
AI Technical Summary
Existing model processing methods struggle to realistically simulate the distortion and deformation effects of funhouse mirrors, resulting in poor model processing efficiency.
By acquiring virtual scenes with non-uniform normal directions of mirror models, the virtual scene images are captured by a mirror camera and used as rendering textures. Based on the normal direction information, the sampling coordinates are determined, and the rendering texture is sampled to obtain the target color value. Finally, a mirror image with deformation effect is displayed on the mirror model.
It achieves a realistic and accurate simulation of the mirror distortion effect of a funhouse mirror in a virtual scene, improving the model's processing efficiency.
Smart Images

Figure CN119850845B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a model processing method and device, storage medium and electronic equipment. BACKGROUND
[0002] With the rapid development of life and technology, people often entertain through game applications. In some games, it is often necessary to make some special effects, for example, to realize the special effect of a funhouse mirror in the game. How to realistically restore the distortion effect of a funhouse mirror in the game is a big problem. In the existing model processing method, the imaging is often disturbed by directly superimposing the disturbance map on the imaging, or the imaging is changed by controlling the local enlargement or reduction of the model UV, to realize the distortion effect of the funhouse mirror.
[0003] However, the existing model processing method is difficult to control the distortion effect of the model imaging, and cannot realistically simulate the display of the funhouse mirror effect, resulting in poor model processing efficiency. SUMMARY
[0004] The embodiments of the present application provide a model processing method and device, storage medium and electronic equipment, which can flexibly control the distortion effect of the mirror model imaging, realistically and accurately simulate the mirror deformation effect of the funhouse mirror in the virtual scene, and effectively improve the processing efficiency of the model.
[0005] The embodiments of the present application provide a model processing method, comprising:
[0006] Obtain a mirror model in a virtual scene, the surface of the mirror model is uneven, and the normal directions of different vertices of the mirror model are not completely the same;
[0007] Capture a virtual scene picture that needs to be reflected by the mirror model by a mirror camera corresponding to the mirror model, as a rendering texture of the mirror model;
[0008] Determine the sampling coordinates of each vertex of the mirror model in the rendering texture based on the normal direction information of the vertex;
[0009] Sample the rendering texture based on the sampling coordinates to obtain the target color value corresponding to the vertex;
[0010] Render the mirror model based on the target color value of each vertex to display a mirror image with deformation effect on the mirror model.
[0011] Correspondingly, the embodiments of the present application provide a model processing device, comprising:
[0012] The acquisition unit is configured to acquire a mirror model in a virtual scene, wherein a surface of the mirror model is uneven, and normal directions of different vertices of the mirror model are not completely same;
[0013] The shooting unit is configured to shoot a virtual scene picture needed to be reflected by the mirror model by a mirror camera corresponding to the mirror model, as a rendering texture of the mirror model.
[0014] The determination unit is configured to determine a sampling coordinate of each vertex of the mirror model in the rendering texture based on normal direction information of the vertex.
[0015] The sampling unit is configured to sample the rendering texture based on the sampling coordinate to obtain a target color value corresponding to the vertex.
[0016] The rendering unit is configured to render the mirror model based on the target color value of each vertex to display a mirror image with a deformation effect on the mirror model.
[0017] In addition, an embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is adapted to be loaded by a processor to execute steps in any model processing method provided by the embodiment of the present application.
[0018] In addition, an embodiment of the present application further provides an electronic device, which comprises a processor and a memory, the memory stores an application program, and the processor is configured to run the application program in the memory to implement the model processing method provided by the embodiment of the present application.
[0019] An embodiment of the present application further provides a computer program product, which comprises a computer program stored in a computer readable storage medium; when a processor of an electronic device reads the computer program from the computer readable storage medium, the processor executes the computer program, so that the electronic device executes steps in the model processing method provided by the embodiment of the present application.
[0020] The embodiment of the application obtains a mirror surface model in a virtual scene, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely same; a mirror camera corresponding to the mirror surface model shoots a virtual scene picture needed to be reflected by the mirror surface model as a rendering texture of the mirror surface model; based on the normal direction information of each vertex of the mirror surface model, a sampling coordinate of the vertex in the rendering texture is determined; based on the sampling coordinate, the rendering texture is sampled to obtain a target color value corresponding to the vertex; and based on the target color value of each vertex, the mirror surface model is rendered to display a mirror image with a deformation effect on the mirror surface model. In this way, by adjusting the curvature and the normal direction of the mirror surface model based on the required deformation effect, the sampling coordinate of the vertex in the rendering texture is determined according to the normal direction information of the vertex of the mirror surface model, the rendering texture is sampled based on the sampling coordinate, and the mirror surface model is rendered based on the target color value of each vertex sampled, so that the mirror image with the deformation effect can be displayed on the mirror surface model, the distortion deformation effect of model imaging can be flexibly controlled, the mirror surface deformation effect of a funhouse mirror can be simulated in the virtual scene, and the processing efficiency of the model is further improved. BRIEF DESCRIPTION OF DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.
[0022] Figure 1 is a model processing method provided by an embodiment of the present application.
[0023] Figure 2 is a flowchart of a model processing method provided by an embodiment of the present application.
[0024] Figure 3a is a model processing diagram of a model processing method provided by an embodiment of the present application.
[0025] Figure 3b is another model processing diagram of a model processing method provided by an embodiment of the present application.
[0026] Figure 3c is still another model processing diagram of a model processing method provided by an embodiment of the present application.
[0027] Figure 3d is still another model processing diagram of a model processing method provided by an embodiment of the present application.
[0028] Figure 4ais a mirror image schematic diagram of a model processing method provided by an embodiment of the present application;
[0029] Figure 4b is another mirror image schematic diagram of a model processing method provided by an embodiment of the present application;
[0030] Figure 4c is a mirror surface imaging schematic diagram of a model processing method provided by an embodiment of the present application;
[0031] Figure 5 is a structural schematic diagram of a model processing apparatus provided by an embodiment of the present application;
[0032] Figure 6 is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0033] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0034] The present application provides a model processing method, apparatus, storage medium and electronic device. The model processing apparatus can be integrated in an electronic device, which can be a server or a terminal device.
[0035] The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network (CDN), and basic cloud computing services such as big data and artificial intelligence platforms. The terminal can include but is not limited to mobile phones, computers, smart voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, etc. The terminal and the server can be connected directly or indirectly through wired or wireless communication, which is not limited in the present application.
[0036] Please refer to Figure 1 For example, the model processing apparatus is integrated in an electronic device, Figure 1An implementation scenario diagram of a model processing method provided by an embodiment of the present application is shown in FIG. 1. The electronic device can be a terminal or a server. The electronic device can obtain a mirror surface model in a virtual scene. The surface of the mirror surface model is uneven. The normal directions of different vertices of the mirror surface model are not completely the same. A mirror camera corresponding to the mirror surface model is used to shoot a virtual scene picture that needs to be reflected by the mirror surface model, as a rendering texture of the mirror surface model. Based on the normal direction information of each vertex of the mirror surface model, the sampling coordinates of the vertex in the rendering texture are determined. The rendering texture is sampled based on the sampling coordinates, to obtain a target color value corresponding to the vertex. The mirror surface model is rendered based on the target color value of each vertex, to display a mirror image with a deformation effect on the mirror surface model.
[0037] It should be noted that Figure 1 The implementation environment scenario diagram of the model processing method shown in FIG. 1 is only an example. The implementation environment scenario of the model processing method described in the embodiments of the present application is used to more clearly illustrate the technical solutions of the embodiments of the present application, and does not constitute a limitation on the technical solutions provided by the embodiments of the present application. It can be known by those skilled in the art that, with the evolution of data processing and the appearance of new business scenarios, the technical solutions provided by the present application are also applicable to similar technical problems.
[0038] The solutions provided by the embodiments of the present application are described in detail through the following embodiments. It should be noted that the description order of the following embodiments does not constitute a limitation on the preferred order of the embodiments.
[0039] This embodiment will be described from the perspective of a model processing device. The model processing device can be integrated in an electronic device, which can be a terminal and / or a server. The present application does not make any limitation here.
[0040] Please refer to Figure 2 , Figure 2 FIG. 2 is a flowchart of a model processing method provided by an embodiment of the present application. The model processing method includes the following steps.
[0041] In step 101, a mirror surface model in a virtual scene is obtained.
[0042] The surface of the mirror surface model is uneven. The normal directions of different vertices of the mirror surface model can not be completely the same.
[0043] The virtual scene can be a scene composed of virtual elements, and can be a simulation environment of the real world, or a semi-simulation and semi-fictional virtual environment, or a purely fictional virtual environment, etc. For example, the virtual scene can be a game scene. The mirror model can be a model for realizing the mirror effect of a mirror, and the surface of the mirror model can be curved according to the deformation effect to be realized, so as to obtain a mirror model with a concave-convex surface. Meanwhile, the normal direction of the vertex of the mirror model can be adjusted according to the deformation effect to be realized, so that the normal directions of different vertices of the mirror model can not be completely the same.
[0044] The mirror model in the virtual scene can be obtained in various ways. For example, a single-sided sheet model can be prepared in advance, for example, various three-dimensional modeling software can be used to prepare a single-sided sheet model for simulating a flat mirror surface, and then the distorted shape of the mirror surface of a funhouse mirror with various deformation effects in reality can be referred to, and the surface curvature and normal direction of the single-sided sheet model can be changed in the three-dimensional modeling software according to the required deformation effect (convex surface shrinking, concave surface expanding), for example, the normal direction of the model can be adjusted by adding lines, subtracting lines, adjusting point lines and surfaces, expanding, free-form deformation (FFD), smoothing, etc., so as to prepare a mirror model realizing different deformation effect combinations.
[0045] For example, please refer to Figure 3a The model processing diagram is a model processing diagram of a model processing method provided by the embodiment of the present application, and the curvature of the mirror model can be changed according to the mirror imaging deformation effect to be realized, so as to obtain various concave-convex mirror models.
[0046] Optionally, the normal direction of the vertex of the mirror model can be adjusted in various ways. For example, the normal direction of the model surface of the model can be automatically changed by the three-dimensional modeling software when the curvature of the model is changed according to the deformation effect to be realized, and the normal direction of the mirror model can also be manually adjusted according to the deformation effect to be realized, so as to realize a more realistic mirror imaging deformation effect.
[0047] For example, please refer to Figure 3b , Figure 3bis another model processing schematic diagram of the model processing method provided in the embodiment of the present application, which can adjust the normal direction of the surface vertex of the mirror model according to the desired morphing effect, so as to realize a more realistic mirror imaging morphing effect. Specifically, the final imaging effect of the mirror model can be controlled by manually modifying the normal direction at a position where the display effect is not satisfactory, for example, the normal direction of the vertex of the mirror model is adjusted downward, which can make the color corresponding to the vertex higher in the final imaging display, the normal direction of the vertex of the mirror model is adjusted upward, which can make the color corresponding to the vertex lower in the final imaging display, the normal direction of the vertex of the mirror model is adjusted leftward, which can make the vertex offset to the right in the final imaging display, the normal direction of the vertex of the mirror model is adjusted rightward, which can make the vertex offset to the left in the final imaging display, and so on. In this way, the mirror imaging effect of the mirror model can be corrected or changed by adjusting the normal direction of different vertices of the mirror model, so that various desired mirror imaging morphing effects can be realized, and the twist morphing effect of the imaging of the mirror model can be flexibly controlled.
[0048] In an embodiment, refer to Figure 3c , Figure 3c is still another model processing schematic diagram of the model processing method provided in the embodiment of the present application, which can synthesize the mirror model adjusted based on the desired mirror imaging morphing effect with the mirror model, so that a model in the shape of a mirror can be constructed in the virtual scene, for realizing the mirror effect in the virtual scene.
[0049] In step 102, the virtual scene picture that needs to be reflected by the mirror model is shot by the mirror camera corresponding to the mirror model, as the rendering texture of the mirror model.
[0050] The mirror camera can be a virtual camera for realizing the mirror reflection effect, the virtual scene picture can be a picture shot by the mirror camera in the virtual scene, and the rendering texture can be a texture rendered by the mirror camera, which can be a RenderTexture (RT) picture of the virtual scene picture and can be used as the mirror reflection effect of the mirror model.
[0051] Optionally, the position of the mirror camera in the virtual scene can be the position of the mirror model or the position around the mirror model, and the position setting can be set according to actual needs, which is not limited in the embodiment of the present application.
[0052] The mirror camera corresponding to the mirror model can capture a virtual scene picture of the virtual object to be displayed in the mirror image of the mirror model in the virtual scene as a rendering texture of the mirror model in various ways. For example, a virtual object to be displayed in the mirror image of the mirror model in the virtual scene can be determined; a target distance between the virtual object and the mirror model is obtained; the virtual object is captured by the mirror camera corresponding to the mirror model based on the target distance, and a virtual scene picture containing the virtual object is obtained as a rendering texture of the mirror model.
[0053] The virtual object can be an object in the virtual scene, which can be reflected on the mirror model. For example, the virtual object can include a game character, an animal, a tree, a flower, a stone, and the like in the virtual scene. The target distance can be a distance between the virtual object and the mirror model.
[0054] The way of determining the virtual object to be displayed in the mirror image of the mirror model in the virtual scene can be various. For example, object information of the virtual object that can be displayed in the mirror image of the mirror model can be obtained; a position of a candidate virtual object matching the object information in the virtual scene is obtained; when the position of the candidate virtual object is within an imaging range of the mirror model, the candidate virtual object is determined as the virtual object to be displayed in the mirror image of the mirror model.
[0055] The object information can be information indicating the virtual object that can be displayed in the mirror image of the mirror model, for example, can include information such as the name, the identity number (ID), the material, the object type, the label, and the like of the virtual object. The candidate virtual object can be a virtual object in the virtual scene matching the object information, for example, when the object information is the name “smart dog” and “big tree model”, the candidate virtual object can be a virtual object with the name “smart dog” and “big tree model”. The imaging range can refer to a region formed by positions that can be reflected by the mirror model, that is, objects within the imaging range can be reflected in the mirror imaging of the mirror model.
[0056] In an embodiment, a mirror component can be set by a game engine according to the position and orientation of the mirror model in the virtual scene. The function of the mirror component can be to create a mirror camera, through which a virtual scene picture in the virtual scene can be captured in real time based on the position and the configured orientation, so that the captured virtual scene picture can be stored on an RT map to obtain a rendering texture corresponding to the mirror model. Then, the RT map, that is, the rendering texture corresponding to the mirror model, can be obtained through a corresponding keyword variable (uniform) semantic in a shader.
[0057] In step 103, the sampling coordinates of the vertices in the rendering texture are determined based on the normal direction information of each vertex of the mirror model.
[0058] The normal direction information can be information indicating a normal direction of a vertex of the mirror model, and the sampling coordinate can be a UV coordinate used for texture sampling, which can be used to sample a rendering texture of the mirror model, so as to map a mirror image corresponding to the virtual scene picture with the deformation effect.
[0059] The UV coordinate can be a coordinate in a two-dimensional coordinate system, which is used to map a texture map to the surface of a three-dimensional model, and U and V can represent horizontal and vertical coordinate axes respectively. The UV coordinate can define information of the position of each point on the texture map, which is related to the three-dimensional model, so as to correspond each point on the texture map to the surface of the model. In this way, the texture map can be sampled according to the UV coordinate, and the corresponding position on the model surface can be mapped according to the pixel value sampled, so as to realize the tiling of the texture map on the surface of the three-dimensional model.
[0060] The manner of determining the sampling coordinate of the vertex in the rendering texture based on the normal direction information of each vertex of the mirror model can be various. For example, the screen space coordinate corresponding to the vertex in the mirror model can be calculated; the initial sampling coordinate corresponding to the vertex in the rendering texture is calculated based on the screen space coordinate; the first sampling offset value corresponding to the vertex is determined based on the normal direction information of the vertex on the mirror model; and the initial sampling coordinate of the vertex is offset based on the first sampling offset value to obtain the sampling coordinate corresponding to the vertex in the rendering texture.
[0061] The screen space coordinate can be a coordinate of the vertex of the mirror model in the screen space, and the initial sampling coordinate can be a UV coordinate used for sampling the rendering texture without considering the deformation effect. In this case, if the rendering texture is sampled and mapped according to the initial sampling coordinate, the mirror effect obtained is a plane reflection effect, that is, the virtual scene picture does not have the deformation. The first sampling offset value can be an offset value used for offsetting the initial sampling coordinate. If the rendering texture is sampled and mapped based on the sampling coordinate offset based on the first sampling offset value, the mirror effect corresponding to the virtual scene picture with the deformation based on the normal direction of each vertex in the mirror model can be obtained.
[0062] The manner of calculating the initial sampling coordinate corresponding to the vertex in the rendering texture based on the screen space coordinate can be various. For example, the screen space coordinate of the vertex of the mirror model can be converted into a texture coordinate (UV) to obtain the initial sampling coordinate corresponding to the vertex in the rendering texture. Since the range of the screen space coordinate is [-1, 1], and the range of the texture coordinate is [0, 1], scaling and offsetting are needed to convert the screen space coordinate of the vertex of the mirror model into the initial sampling coordinate corresponding to the rendering texture.
[0063] Optionally, the screen space coordinates of the vertex of the mirror model can be converted into the initial sampling coordinates corresponding to the rendering texture by using the following formula:
[0064] screen_uv = pscreen.xy * 0.5f + float2(0.5f)
[0065] screen_uv can represent the initial sampling coordinates, and pscreen.xy can represent the screen space coordinates of the vertex of the mirror model. The formula is used to convert the screen space coordinates of the vertex into the texture coordinates. The screen space coordinates are usually the normalized device coordinates (NDC) obtained by performing perspective division on the clipping space coordinates of the vertex. Since the x and y coordinates of the screen space coordinates are both in the range of [-1, 1], and in the NDC, [-1, -1] represents the lower left corner of the screen, and [1, 1] represents the upper right corner of the screen. pscreen.xy * 0.5f can represent scaling the screen space coordinates of the vertex from [-1, 1] to [-0.5, 0.5]. Then, adding float2(0.5f) can shift the [-0.5, 0.5] range to [0, 1]. Thus, the screen space coordinates of the vertex of the mirror model can be converted into the initial sampling coordinates corresponding to the rendering texture.
[0066] The manner of determining the first sampling offset value corresponding to the vertex based on the normal direction information of the vertex on the mirror model can be various, for example, the projection component of the normal vector of the vertex on the xy plane in the virtual scene can be calculated as the first sampling offset value corresponding to the vertex based on the normal direction information of the vertex on the mirror model.
[0067] The manner of offsetting the initial sampling coordinates of the vertex based on the first sampling offset value to obtain the sampling coordinates of the vertex corresponding to the rendering texture can be various, for example, the initial sampling coordinates of the vertex can be added with the projection component of the normal vector of the vertex on the xy plane in the virtual scene to obtain the sampling coordinates of the vertex corresponding to the rendering texture.
[0068] Optionally, a first twist parameter (turb_slide) can also be set to further adjust the twist degree of the deformation effect controlled based on the normal direction of the mirror model. The first twist parameter can be an open parameter of the shader, which can be used to change the twist degree of the imaging caused by the model normal direction. The twist degree is the size of the sampling offset of the rendering texture. The greater the twist degree, the greater the sampling offset value, and the more exaggerated the deformation effect of the imaging of the mirror model. The smaller the twist degree, the smaller the sampling offset value of the rendering texture, and thus the imaging of the mirror model is closer to the ordinary plane mirror.
[0069] Optionally, the first distortion parameter corresponding to the mirror model can be determined before the first sampling offset value corresponding to the vertex is determined based on the normal direction information of the vertex on the mirror model.
[0070] Correspondingly, the step of determining the first sampling offset value corresponding to the vertex based on the normal direction information of the vertex on the mirror model can include: determining a basic sampling offset value based on the normal direction information of the vertex on the mirror model; and calculating the product of the first distortion parameter and the basic sampling offset value of the vertex to obtain the first sampling offset value corresponding to the vertex.
[0071] The basic sampling offset value can be a sampling offset value determined according to the normal direction information of the vertex on the mirror model.
[0072] The manner of determining the basic sampling offset value based on the normal direction information of the vertex on the mirror model can be various, for example, the projection component of the normal vector of the vertex on a plane parallel to the orientation of the mirror model in the virtual scene can be calculated according to the orientation of the mirror model to obtain the basic sampling offset value, for example, assuming that the mirror model is vertically placed in the virtual scene and the orientation of the mirror model is the horizontal direction, the projection component of the normal vector of the vertex on the xy plane in the virtual scene can be calculated based on the normal direction information of the vertex on the mirror model to obtain the basic sampling offset value of the vertex.
[0073] In an embodiment, the following pseudo code can be used to calculate the screen space coordinate corresponding to the vertex in the mirror model, to calculate the initial sampling coordinate of the vertex corresponding to the rendering texture based on the screen space coordinate, to determine the first distortion parameter corresponding to the mirror model, to determine the basic sampling offset value based on the normal direction information of the vertex on the mirror model, to calculate the product of the first distortion parameter and the basic sampling offset value of the vertex to obtain the first sampling offset value corresponding to the vertex, and to offset the initial sampling coordinate of the vertex based on the first sampling offset value to obtain the sampling coordinate of the vertex corresponding to the rendering texture:
[0074]
[0075] Optionally, in order to obtain a mirror image with deformation effect more accurately based on the normal direction and the concave-convex shape of the mirror model, another sampling offset value can be determined according to the concave-convex shape of the mirror model, so that more accurate sampling coordinates can be obtained to obtain a mirror image that more closely fits the deformation effect caused by the curvature of the mirror model.
[0076] The model processing method provided by the embodiments of the present application offsets the sampling coordinates of the rendering texture captured by the camera according to the concave-convex shape and normal direction of the mirror model, thereby distorting the rendering texture based on the offset sampling coordinates, so as to generate a mirror deformation effect such as a funhouse mirror. In order to more accurately offset the sampling coordinates of the rendering texture captured by the camera according to the concave-convex shape of the mirror model, it is necessary to calculate how much and how to distort the rendering texture according to the concave-convex shape of the mirror model. Specifically, a basis for judging the distortion degree of the rendering texture can be generated according to the concave-convex shape of the model, the distance from each vertex (or pixel) of the mirror model to the observation camera, and the distance between the position of the object in the mirror image on the mirror model and the observation camera when the mirror model is assumed to be a plane. According to the laws of the physical world, a funhouse mirror will only produce horizontal distortion (e.g. a person is stretched) or vertical distortion (e.g. a person becomes taller), so the calculation can be performed in the horizontal direction and the vertical direction to obtain the sampling offset value in the corresponding direction, so as to more accurately distort the rendering texture according to the concave-convex shape of the mirror model, thereby generating a more realistic mirror deformation effect of the funhouse mirror.
[0077] Specifically, the virtual scene picture can include a virtual object, so that the first distance of the vertex of the mirror model and the observation camera corresponding to the mirror model in the target direction can be obtained; the corresponding position of the virtual object on the plane in the mirror model is determined, and the second distance of the virtual object and the observation camera in the target direction is calculated based on the position; the second distortion parameter of the vertex in the target direction is determined based on the first distance and the second distance of the vertex in the target direction; and the second sampling offset value of the vertex is determined based on the second distortion parameter of the vertex in each target direction and the first distance.
[0078] Correspondingly, for the normal direction information of each vertex of the mirror model, the step of determining the sampling coordinates of the vertex in the rendering texture can include: determining the sampling coordinates of the vertex in the rendering texture based on the normal direction information of each vertex of the mirror model and the second sampling offset value.
[0079] The observation camera can be a camera corresponding to a player view, for example, a main camera. The target direction can include a horizontal direction and a vertical direction, and the first distance can be a distance between a vertex of the mirror model and the observation camera in the target direction, or a distance between a pixel on the mirror model and the observation camera in the target direction. The position of the virtual object on the plane in the mirror model can be a position of the virtual object horizontally mapped to the plane of the mirror model, that is, a plane in the mirror model when the mirror model is a plane. The second distance can be a distance between the virtual object and the observation camera in the target direction. The second distortion parameter can be a parameter indicating a mirror distortion degree of the mirror model, and the second sampling offset value can be an offset value for offsetting the sampling coordinates based on the second distortion parameter.
[0080] For example, refer to Figure 3d , Figure 3d is another model processing diagram of a model processing method provided by the embodiment of the present application. Taking the target direction as the horizontal direction and the first distance as a horizontal distance between the position C of the observation camera and the vertex P of the mirror model in the horizontal direction, that is, the first distance Dis=(C-P).rg, the second distance is a horizontal distance between the position of the virtual object on the plane of the mirror model and the observation camera in the horizontal direction, that is, the second distance Dis2=(C-Obj).rg. For the first distance and the second distance in the vertical direction, similar methods can be used for calculation to obtain the first distance Disb=(C-P).b between the position C of the observation camera and the vertex P of the mirror model in the vertical direction, and the second distance Dis2b=(C-Obj).b between the position of the virtual object on the plane of the mirror model and the observation camera in the vertical direction. Wherein, r, g, b can be three channels in the RGB color channel, which can be used to store the second sampling offset value corresponding to the vertex, r can correspond to the x-axis, g can correspond to the y-axis, and b can correspond to the z-axis.
[0081] Wherein, based on the first distance and the second distance of the vertex in the target direction, the second distortion parameter corresponding to the vertex in the target direction can be determined in multiple ways, for example, the difference between the first distance and the second distance in the same target direction can be calculated, and the absolute value of the difference is normalized to obtain the second distortion parameter corresponding to the vertex in the target direction.
[0082] For example, taking the target direction as the horizontal direction, the second distortion parameter corresponding to the vertex in the horizontal direction can be calculated by the following formula:
[0083] Normalize(Abs(Dis-Dis2))=Mh
[0084] wherein, Mh is the second warping parameter of the vertex in the horizontal direction, Abs is an absolute value, and Normalize is a normalization function. Specifically, the absolute value of the difference between the two distances corresponding to the vertex is calculated, the concave-convex condition of the mirror model at the vertex position is obtained, and the influence of the camera distance is not considered. Then, through normalization, the width of the funhouse mirror is changed from 1 to 0. For example, please refer to Figure 3d The second warping parameter of the vertex corresponding to the more convex place in the mirror model is closer to 1, which is closer to white, and the more concave place is closer to 0, which corresponds to black. In this way, the concave-convex information of the mirror model in the horizontal direction is obtained, which can be understood in the refraction environment. The whiter part is farther away in the final imaging, so the warping is greater. The darker part is closer, so the warping degree is small. In this way, the absolute distance of each vertex relative to the observation camera can be obtained, which can exclude the influence of the distance between the observation camera and the mirror model, so that the camera distance interference can be excluded first, and the warping of the mirror itself can be calculated.
[0085] Correspondingly, taking the target direction as the vertical direction as an example, the second warping parameter of the vertex in the vertical direction can be calculated by the following formula:
[0086] Normalize(Abs(disb-dis2b))=Mv
[0087] wherein, Mv is the second warping parameter of the vertex in the vertical direction.
[0088] wherein, the way of determining the second sampling offset value of the vertex based on the second warping parameter of the vertex in each target direction and the first distance can be various, for example, the second warping parameter of each target direction can be mapped to a preset numerical range to obtain a mapped warping parameter; a warping adjustment coefficient corresponding to each target direction is obtained; based on the mapped warping parameter of the vertex in each target direction, the first distance and the warping adjustment coefficient, the second sampling offset value of the vertex corresponding to each target direction is calculated.
[0089] wherein, the preset numerical range can be a numerical range of -1 to 1. The warping adjustment coefficient can be a parameter for controlling the warping degree based on the first distance. Since the first distance will affect the warping of the mirror, a warping adjustment coefficient (warp_factor) can be added to adjust the warping effect of the mirror, which is used to improve the presentation of the artistic effect. Physically, the closer the distance corresponding to the first distance, the more distorted the mirror effect should be, and the farther the distance, the smoother the mirror effect should be. Therefore, the warping adjustment coefficient can be set in a linear decreasing manner.
[0090] In a specific embodiment, the following formula can be used to map the second warping parameters corresponding to each target direction to a preset numerical range, to obtain the mapped warping parameters:
[0091] UVraw = ({Mh, Mv} * 2) - 1
[0092] wherein UVraw can be the mapped warping parameters corresponding to each target direction. In order to obtain different warping modes in the horizontal direction and the vertical direction, the calculation is performed in two channels, the channel R corresponds to the information of the horizontal direction, and the channel G corresponds to the information of the vertical direction. Here, 2 is multiplied and then -1 is subtracted, because the range of the normalized second warping parameters is 0-1, in order to let the offset adopt the standard normal coordinates, i.e. the range from -1 to 1, because the mirror can have positive warping or negative warping, i.e. fattening or thinning, and 0 must be unchanged, so the coordinates are changed to -1 to 1. In this way, the mapped warping parameters in the horizontal direction can be put into the R channel, and the mapped warping parameters in the vertical direction can be put into the G channel, so that the offset information for warping the UV coordinates can be obtained. In order to bring in the UV information, here the RG channel can be sampled, and the B channel is not needed.
[0093] Correspondingly, the following formula can be used to calculate the second sampling offset value corresponding to each target direction of the vertex based on the mapped warping parameters of the vertex in each target direction, the first distance, and the warping adjustment coefficient:
[0094] UVwarp = {UVraw.r * (Dis / warp_factor), UVraw.g * (Disb / warp_factor)}
[0095] wherein UVwarp can represent the sampling offset values in the horizontal direction and the vertical direction, i.e. the second sampling offset values in the U and V directions, warp_factor is the warping adjustment coefficient, UVraw.r is the mapped warping parameter in the horizontal direction, and UVraw.g is the mapped warping parameter in the vertical direction. Since the distance between the observation camera and the mirror model will affect the warping of the mirror, a adjustable warping adjustment coefficient warp_factor can be added to improve the presentation of the artistic effect, because even if it is physically correct, it may actually not look good. Physically speaking, the closer the distance, the more distorted the mirror image should be, and the farther the distance, the smoother the mirror image should be, so the specific value of the warping adjustment coefficient warp_factor can be directly set by linearly decreasing. In this way, based on the influence of the distance on the warping, the distance between the camera and the vertex on the mirror model is considered back into the mirror warping information that has been obtained, so that the accurate warping of the virtual object can be obtained.
[0096] The manner of determining the sampling coordinate of the vertex in the rendering texture based on the normal direction information of each vertex of the mirror model and the second sampling offset value can be various, for example, the first sampling offset value and the second sampling offset value corresponding to the normal direction information of each vertex of the mirror model and the initial sampling coordinate can be added to obtain the sampling coordinate of the vertex in the rendering texture.
[0097] For example, the following formula can be used to determine the sampling coordinate of the vertex in the rendering texture based on the normal direction information of each vertex of the mirror model and the second sampling offset value:
[0098] Output=RT sample(t_RT,UV.rg+texcoord.uv0+Normal.rg)
[0099] The Output can be a target color value corresponding to the vertex sampled based on the final sampling coordinate, the RTsample() can be a texture sampling function, the t_RT can represent a rendering texture, the UV.rg can be a second sampling offset value corresponding to the vertex, the texcoord.uv0 can represent an initial sampling coordinate, and the Normal.rg can represent a first sampling offset value. Optionally, the texcoord.uv0+Normal.rg can also be the mirror_uv described above, so that the initial sampling coordinate can be offset according to the first sampling offset value and the second sampling offset value to obtain the final sampling coordinate of the vertex in the rendering texture.
[0100] In step 104, the rendering texture is sampled based on the sampling coordinate to obtain a target color value corresponding to the vertex.
[0101] The target color value can be a pixel value sampled in the rendering texture based on the sampling coordinate.
[0102] Optionally, the color value corresponding to the vertex of the mirror model can be further processed in an artistic manner using a smoothness parameter or the like to improve the display effect of the mirror image corresponding to the mirror model.
[0103] In step 105, the mirror model is rendered based on the target color value of each vertex to display a mirror image with a deformation effect on the mirror model.
[0104] The deformation effect can include stretching, compression, twisting, enlargement, and reduction, and the like. The mirror image can be an image obtained by texture mapping based on the sampling coordinate and the rendering texture, that is, an image displaying the mirror effect corresponding to the mirror model.
[0105] For example, please refer to Figure 4a , Figure 4ais a mirror image schematic diagram of a model processing method provided by an embodiment of the present application. When a game character in a virtual scene is located in the imaging range of the mirror model, a mirror image based on the reflection of the game character can be displayed in the mirror model. Meanwhile, the mirror image based on the reflection of the game character has a distorted mirror deformation effect based on the curvature and normal line of the mirror model, thereby simulating a funhouse effect in the virtual scene.
[0106] For another example, refer to Figure 4b , Figure 4b is another mirror image schematic diagram of a model processing method provided by an embodiment of the present application. Different imaging deformation effects of a game character can be reflected on a mirror model by adjusting the curvature and normal line direction of the mirror model based on different deformation effects to be achieved. In this way, a funhouse display effect can be achieved based on a physical algorithm, the effect observed from different angles is different, the playability is high, the mirror deformation effect is controllable and realistic, and the model processing efficiency is effectively improved.
[0107] In an embodiment, refer to Figure 4c , Figure 4c is a mirror imaging schematic diagram of a model processing method provided by an embodiment of the present application. A corresponding sampling offset value can be calculated according to the normal line direction of the mirror model, so as to offset the sampling coordinates of a rendering texture according to the sampling offset value, thereby performing texture mapping based on the offset sampling coordinates, obtaining a mirror image of a game character after stretching deformation, and achieving a funhouse effect in a virtual scene. The camera position is the position of an observation camera, and a virtual object "little girl" can stand in front of the mirror model, so that a distorted mirror image corresponding to the little girl can be displayed in the mirror model. For example, the normal line direction of the lower vertex of the mirror model is adjusted downward, so that the mirror image of the foot area of the little girl realizes a downward stretching effect. The normal line direction of the upper vertex of the mirror model is adjusted upward, so that the mirror image corresponding to the head area of the little girl realizes an upward stretching effect, thereby displaying the stretched and deformed mirror image of the little girl in the mirror model.
[0108] In some games, it is necessary to realize the funhouse effect in a virtual scene to improve the game experience of players. How to truly restore the distortion effect of a real funhouse in a game is a big problem. In existing model processing methods, a disturbance map is often directly superimposed on an image to disturb the image, or the local enlargement or reduction of a model UV is controlled to change the image, so as to realize the distortion effect of the funhouse. However, in the method of directly superimposing a disturbance map on an image to disturb the image, the image is disturbed uniformly when a virtual object is stationary, the effect is uncontrollable, and the performance is inconsistent with that of a real funhouse. The image stretching is not well controlled, and the effect of the complex funhouse performance is not satisfactory. The real funhouse performance cannot be simulated, and the presented effect is relatively fixed and lacks dynamic changes. It can be seen that the existing model processing method is difficult to control the distortion effect of the model image, and cannot truly simulate the displayed funhouse effect, so that the model processing efficiency is poor.
[0109] Therefore, an embodiment of the present application proposes a model processing method based on the implementation principle of a funhouse. The normal direction of a mirror surface model is controlled to represent different funhouse performance effects, so as to realize the distortion effect of the funhouse in a physical manner, and the effect of all funhouses can be basically realized. The implementation principle of the funhouse mainly depends on the irregular light reflection and focusing of a curved mirror. The mirror surface of the funhouse is not flat, some parts are convex mirrors, and some parts are concave mirrors. Therefore, some images are enlarged, and some images are reduced. When light passes through a curved surface, different light will be dispersed or focused due to different curvatures. The image is enlarged and distorted at a place that is equal in distance to the object and the mirror surface in the opposite direction of the mirror surface, so that the mirror image of the object reflected by the curved mirror is deformed or distorted. Based on the imaging principle of the funhouse simulated in a physical manner, the curvature and the normal direction of the mirror surface model are adjusted based on the required deformation effect, so as to determine the sampling coordinates of the vertices in the rendering texture according to the normal direction information of the vertices of the mirror surface model, sample the rendering texture based on the sampling coordinates, and render the mirror surface model based on the target color values of the sampled vertices. The mirror image with the deformation effect can be displayed on the mirror surface model. Compared with the existing model processing method, the embodiment of the present application realizes the simulation of the funhouse imaging performance based on physics, does not need to use a disturbance map or change the UV stretching, and the effect is controllable, the performance method is strong, and the playability is strong. The different mirror deformation effects seen by the human eye at different positions can be simulated according to the camera view angle. In this way, the distortion effect of the model image can be flexibly controlled, and the mirror surface deformation effect of the funhouse can be truly and accurately simulated in a virtual scene.
[0110] From the above, the embodiment of the application obtains a mirror surface model in a virtual scene, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same; a mirror camera corresponding to the mirror surface model is used to shoot a virtual scene picture that needs to be reflected by the mirror surface model, as a rendering texture of the mirror surface model; based on the normal direction information of each vertex of the mirror surface model, the sampling coordinates of the vertex in the rendering texture are determined; the rendering texture is sampled based on the sampling coordinates, to obtain a target color value corresponding to the vertex; and the mirror surface model is rendered based on the target color values of the vertices, to display a mirror image with a deformation effect on the mirror surface model. In this way, by adjusting the curvature and the normal direction of the mirror surface model based on the required deformation effect, the sampling coordinates of the vertex in the rendering texture are determined according to the normal direction information of the vertex of the mirror surface model, the rendering texture is sampled based on the sampling coordinates, and the mirror surface model is rendered based on the target color values of the sampled vertices, so that the mirror image with the deformation effect can be displayed on the mirror surface model, the distortion deformation effect of model imaging can be flexibly controlled, the mirror surface deformation effect of a funhouse mirror can be simulated in the virtual scene, and the processing efficiency of the model is further improved.
[0111] In order to better implement the above method, the embodiment of the application further provides a model processing device, which can be integrated in an electronic device, which can be a terminal or a server.
[0112] For example, as shown in Figure 5 Fig. 1 is a structural schematic diagram of a model processing device provided by the embodiment of the application, which can include an obtaining unit 201, a shooting unit 202, a determining unit 203, a sampling unit 204, and a rendering unit 205, as follows:
[0113] The obtaining unit 201 is configured to obtain a mirror surface model in a virtual scene, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same;
[0114] The shooting unit 202 is configured to shoot a virtual scene picture that needs to be reflected by the mirror surface model, as a rendering texture of the mirror surface model, by using a mirror camera corresponding to the mirror surface model;
[0115] The determining unit 203 is configured to determine the sampling coordinates of the vertex in the rendering texture based on the normal direction information of each vertex of the mirror surface model;
[0116] The sampling unit 204 is configured to sample the rendering texture based on the sampling coordinates, to obtain a target color value corresponding to the vertex;
[0117] The rendering unit 205 is configured to render the mirror surface model based on the target color values of the vertices, to display a mirror image with a deformation effect on the mirror surface model.
[0118] In some embodiments, the determining unit 203 includes:
[0119] a first calculating sub-unit, configured to calculate a screen space coordinate corresponding to a vertex in the mirror model;
[0120] a second calculating sub-unit, configured to calculate an initial sampling coordinate of the vertex corresponding to the rendering texture based on the screen space coordinate;
[0121] a first sampling offset value determining sub-unit, configured to determine a first sampling offset value corresponding to the vertex based on normal direction information of the vertex on the mirror model;
[0122] a coordinate offsetting sub-unit, configured to offset the initial sampling coordinate of the vertex based on the first sampling offset value to obtain a sampling coordinate of the vertex corresponding to the rendering texture.
[0123] In some embodiments, the model processing apparatus further includes:
[0124] a first twist parameter determining unit, configured to determine a first twist parameter corresponding to the mirror model;
[0125] a first offset value determining sub-unit, configured to:
[0126] determine a base sampling offset value based on the normal direction information of the vertex on the mirror model;
[0127] calculate a product of the first twist parameter and the base sampling offset value of the vertex to obtain the first sampling offset value corresponding to the vertex.
[0128] In some embodiments, the photographing unit 202 includes:
[0129] an object determining sub-unit, configured to determine a virtual object in a virtual scene to be displayed in a mirror image of the mirror model;
[0130] a distance obtaining sub-unit, configured to obtain a target distance between the virtual object and the mirror model;
[0131] a texture rendering sub-unit, configured to photograph the virtual object based on the target distance by using a mirror camera corresponding to the mirror model to obtain a virtual scene picture containing the virtual object as a rendering texture of the mirror model.
[0132] In some embodiments, the object determining sub-unit is configured to:
[0133] obtain object information of a virtual object that can be displayed in the mirror image of the mirror model;
[0134] obtain a position of a candidate virtual object in the virtual scene that matches the object information;
[0135] When the position of the candidate virtual object is within the imaging range of the mirror model, the candidate virtual object is determined as a virtual object to be displayed in the mirror image of the mirror model.
[0136] In some embodiments, the virtual scene picture includes a virtual object, and the model processing apparatus further includes a second warping parameter determination unit including:
[0137] The first distance obtaining sub-unit is configured to obtain a first distance of a vertex of the mirror model and an observation camera corresponding to the mirror model in a target direction, the target direction including a horizontal direction and a vertical direction.
[0138] The second distance obtaining sub-unit is configured to determine a corresponding position of the virtual object on a plane in the mirror model, and calculate a second distance of the virtual object and the observation camera in the target direction based on the position.
[0139] The second warping parameter determination sub-unit is configured to determine a second warping parameter of the vertex in the target direction based on the first distance and the second distance of the vertex in the target direction.
[0140] The second offset value determination sub-unit is configured to determine a second sampling offset value of the vertex based on the second warping parameter of the vertex in each target direction and the first distance.
[0141] The determination unit 203 is configured to:
[0142] Determine a sampling coordinate of the vertex in the rendering texture based on the normal direction information of each vertex of the mirror model and the second sampling offset value.
[0143] In some embodiments, the second warping parameter determination sub-unit is configured to:
[0144] Calculate a difference value between the first distance and the second distance in the same target direction,
[0145] Normalize an absolute value of the difference value to obtain the second warping parameter of the vertex in the target direction.
[0146] In some embodiments, the second offset value determination sub-unit is configured to:
[0147] Map the second warping parameter of each target direction into a preset numerical range to obtain a mapped warping parameter.
[0148] Obtain a warping adjustment coefficient corresponding to each target direction.
[0149] Calculate the second sampling offset value of the vertex in each target direction based on the mapped warping parameter of the vertex in each target direction, the first distance, and the warping adjustment coefficient.
[0150] In practice, the above units can be implemented as independent entities, or combined as the same or several entities, and the specific implementation of the above units can refer to the method embodiments above, which will not be repeated here.
[0151] As can be seen from the above, the mirror surface model in the virtual scene is acquired by the acquisition unit 201, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same; the virtual scene picture that needs to be reflected by the mirror surface model is shot by the mirror camera corresponding to the mirror surface model as the rendering texture of the mirror surface model by the shooting unit 202; the sampling coordinates of the vertices in the rendering texture are determined based on the normal direction information of the vertices of the mirror surface model by the determination unit 203; the target color value corresponding to the vertex is obtained by sampling the rendering texture based on the sampling coordinates by the sampling unit 204; and the mirror surface model is rendered based on the target color value of each vertex to display the mirror image with the deformation effect on the mirror surface model by the rendering unit 205. In this way, by adjusting the curvature and the normal direction of the mirror surface model based on the required deformation effect, the sampling coordinates of the vertices in the rendering texture are determined according to the normal direction information of the vertices of the mirror surface model, the rendering texture is sampled based on the sampling coordinates, and the mirror surface model is rendered based on the target color value of each vertex sampled, the mirror image with the deformation effect can be displayed on the mirror surface model, the distortion deformation effect of the model imaging can be flexibly controlled, the mirror surface deformation effect of the funhouse mirror can be simulated in the virtual scene, and the processing efficiency of the model is further improved.
[0152] The embodiment of the present application also provides an electronic device, such as Figure 6 As shown in the figure, a structure schematic diagram of an electronic device related to the embodiment of the present application is shown, which can be a terminal or a server, and specifically:
[0153] The electronic device 300 includes a processor 301 with one or more processing cores, a memory 302 with one or more computer readable storage media, and a computer program stored on the memory 302 and executable on the processor. The processor 301 is electrically connected to the memory 302. Those skilled in the art can understand that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and can include more or fewer components than shown, or combine certain components, or different component arrangements.
[0154] The processor 301 is the control center of the electronic device 300, which connects all parts of the electronic device 300 through various interfaces and lines, executes various functions of the electronic device 300 and processes data by running or loading software programs and / or modules stored in the memory 302, and calling data stored in the memory 302, thereby overall monitoring the electronic device 300.
[0155] In the embodiments of the present application, the processor 301 in the electronic device 300 loads the instructions corresponding to the processes of one or more application programs into the memory 302, and runs the application programs stored in the memory 302 by the processor 301, so as to realize various functions according to the following steps:
[0156] The mirror surface model in the virtual scene is obtained, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same;
[0157] A mirror camera corresponding to the mirror surface model is used to shoot a virtual scene picture needed to be reflected by the mirror surface model as a rendering texture of the mirror surface model;
[0158] Based on the normal direction information of each vertex of the mirror surface model, a sampling coordinate of the vertex in the rendering texture is determined;
[0159] Based on the sampling coordinate, the rendering texture is sampled to obtain a target color value corresponding to the vertex;
[0160] Based on the target color value of each vertex, the mirror surface model is rendered to display a mirror image with a deformation effect on the mirror surface model.
[0161] The present scheme can obtain a mirror surface model in a virtual scene, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same; a mirror camera corresponding to the mirror surface model is used to shoot a virtual scene picture needed to be reflected by the mirror surface model as a rendering texture of the mirror surface model; based on the normal direction information of each vertex of the mirror surface model, a sampling coordinate of the vertex in the rendering texture is determined; based on the sampling coordinate, the rendering texture is sampled to obtain a target color value corresponding to the vertex; and based on the target color value of each vertex, the mirror surface model is rendered to display a mirror image with a deformation effect on the mirror surface model. In this way, by adjusting the curvature and the normal direction of the mirror surface model based on the required deformation effect, the sampling coordinate of the vertex in the rendering texture is determined according to the normal direction information of the vertex of the mirror surface model, the rendering texture is sampled based on the sampling coordinate, and the mirror surface model is rendered based on the target color value of each vertex sampled, the mirror image with the deformation effect can be displayed on the mirror surface model, the distortion deformation effect of model imaging can be flexibly controlled, the mirror surface deformation effect of a funhouse mirror can be truly and accurately simulated in the virtual scene, and the processing efficiency of the model is further improved.
[0162] The specific implementation of each operation can be referred to the foregoing embodiments, which will not be described here.
[0163] Optionally, as Figure 6As shown, the electronic device 300 further includes a touch display screen 303, a radio frequency circuit 304, an audio circuit 305, an input unit 306, and a power supply 307. The processor 301 is electrically connected to the touch display screen 303, the radio frequency circuit 304, the audio circuit 305, the input unit 306, and the power supply 307, respectively. Those skilled in the art can understand that Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and can include more or fewer components than shown, or combine certain components, or different component arrangements.
[0164] The touch display screen 303 can be used to display a graphical user interface and receive operation instructions generated by a user acting on the graphical user interface. The touch display screen 303 can include a display panel and a touch panel. The display panel can be used to display information input by a user or information provided to a user and various graphical user interfaces of an electronic device, which can be composed of graphics, text, icons, videos, and any combination thereof. Optionally, the display panel can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. The touch panel can be used to collect touch operations (such as operations of a user using a finger, a stylus, or any suitable object or accessory on or near the touch panel) of a user thereon or therearound, and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Optionally, the touch panel can include two parts: a touch detection device and a touch controller. The touch detection device detects the touch position of a user and detects signals generated by touch operations, and transmits the signals to the touch controller; the touch controller receives touch information from the touch detection device, and converts it into touch coordinates, and then sends it to the processor 301, and can also receive commands from the processor 301 and execute them. The touch panel can cover the display panel, and when the touch panel detects a touch operation thereon or therearound, it transmits to the processor 301 to determine the type of the touch event, and then the processor 301 provides corresponding visual output on the display panel according to the type of the touch event. In the embodiments of the present application, the touch panel and the display panel can be integrated into the touch display screen 303 to realize input and output functions. However, in some embodiments, the touch panel and the touch panel can realize input and output functions as two independent components. That is, the touch display screen 303 can also realize input functions as part of the input unit 306.
[0165] The radio frequency circuit 304 can be used to transceive radio frequency signals to establish wireless communication with network devices or other electronic devices, and transceive signals between network devices or other electronic devices.
[0166] The audio circuit 305 can be used to provide an audio interface between the user and the electronic device through a speaker and a microphone. The audio circuit 305 can convert the received audio data into an electrical signal and transmit the electrical signal to the speaker for conversion into an audible signal output by the speaker. On the other hand, the microphone collects a sound signal and converts the sound signal into an electrical signal, which is received by the audio circuit 305 and converted into audio data. The audio data is output to the processor 301 for processing, and then transmitted to another electronic device via the radio frequency circuit 304, or output to the memory 302 for further processing. The audio circuit 305 can also include a headphone jack to provide communication between an external device and the electronic device.
[0167] The input unit 306 can be used to receive input digital, character information or user feature information (such as fingerprint, iris, face information, etc.), and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0168] The power supply 307 is used to supply power to various components of the electronic device 300. Optionally, the power supply 307 can be logically connected to the processor 301 through a power management system, so that the power management system can be used to manage charging, discharging and power consumption management. The power supply 307 can also include one or more DC or AC power sources, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and any other components.
[0169] Although Figure 6 The electronic device 300 can also include a camera, a sensor, a wireless fidelity module, a Bluetooth module, etc., which are not shown in the above embodiments and will not be described here.
[0170] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments. It should be noted that the electronic device provided by the embodiments of the present application and the model processing method suitable for the above embodiments belong to the same concept, and the specific implementation process is described in detail in the above method embodiments, which will not be described here.
[0171] It can be learned from the above that the electronic device provided in the embodiments of the present application can obtain a mirror surface model in a virtual scene, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same; a mirror camera corresponding to the mirror surface model is used to shoot a virtual scene picture that needs to be reflected by the mirror surface model, as a rendering texture of the mirror surface model; based on the normal direction information of each vertex of the mirror surface model, the sampling coordinates of the vertex in the rendering texture are determined; based on the sampling coordinates, the rendering texture is sampled to obtain a target color value corresponding to the vertex; and based on the target color values of the vertices, the mirror surface model is rendered to display a mirror image with a deformation effect on the mirror surface model. In this way, by adjusting the curvature and the normal direction of the mirror surface model based on the required deformation effect, the sampling coordinates of the vertex in the rendering texture are determined according to the normal direction information of the vertex of the mirror surface model, the rendering texture is sampled based on the sampling coordinates, and the mirror surface model is rendered based on the target color values of the sampled vertices, so that the mirror image with the deformation effect can be displayed on the mirror surface model, the distortion deformation effect of model imaging can be flexibly controlled, the mirror surface deformation effect of a funhouse mirror can be simulated in the virtual scene, and the processing efficiency of the model is further improved.
[0172] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by a computer program or by a computer program controlling related hardware, and the computer program can be stored in a computer readable storage medium and loaded and executed by a processor.
[0173] To this end, the embodiments of the present application provide a computer readable storage medium, which stores a computer program capable of being loaded by a processor to execute the steps in any model processing method provided by the embodiments of the present application. For example, the computer program can execute the following steps:
[0174] obtain a mirror surface model in a virtual scene, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same;
[0175] shoot a virtual scene picture that needs to be reflected by the mirror surface model by a mirror camera corresponding to the mirror surface model, as a rendering texture of the mirror surface model;
[0176] determine the sampling coordinates of the vertex in the rendering texture based on the normal direction information of each vertex of the mirror surface model;
[0177] sample the rendering texture based on the sampling coordinates to obtain a target color value corresponding to the vertex;
[0178] render the mirror surface model based on the target color values of the vertices to display a mirror image with a deformation effect on the mirror surface model.
[0179] The scheme can obtain a mirror surface model in a virtual scene, the surface of the mirror surface model is uneven, and the normal directions of different vertices of the mirror surface model are not completely the same; a mirror camera corresponding to the mirror surface model shoots a virtual scene picture that needs to be reflected by the mirror surface model, as a rendering texture of the mirror surface model; based on the normal direction information of each vertex of the mirror surface model, a sampling coordinate of the vertex in the rendering texture is determined; based on the sampling coordinate, the rendering texture is sampled to obtain a target color value corresponding to the vertex; and based on the target color value of each vertex, the mirror surface model is rendered to display a mirror image with a deformation effect on the mirror surface model. In this way, by adjusting the curvature and the normal direction of the mirror surface model based on the required deformation effect, the sampling coordinate of the vertex in the rendering texture is determined according to the normal direction information of the vertex of the mirror surface model, the rendering texture is sampled based on the sampling coordinate, and the mirror surface model is rendered based on the target color value of each vertex sampled, so that the mirror image with the deformation effect can be displayed on the mirror surface model, the distortion deformation effect of model imaging can be flexibly controlled, the mirror surface deformation effect of a funhouse mirror can be simulated in the virtual scene, and the processing efficiency of the model is further improved.
[0180] The specific implementation of each operation can refer to the foregoing embodiments, and will not be described here.
[0181] The computer readable storage medium can include a read-only memory (ROM), a random access memory (RAM), a magnetic disk, an optical disk, and the like.
[0182] Due to the computer program stored in the computer readable storage medium, the steps of any model processing method provided in the embodiments of the present application can be executed, and thus the beneficial effects of any model processing method provided in the embodiments of the present application can be achieved. Details are described in the foregoing embodiments, and will not be described here.
[0183] According to an aspect of the present application, a computer program product is provided, which includes a computer program stored in a computer readable storage medium; when a processor of an electronic device reads the computer program from the computer readable storage medium, the processor executes the computer program, so that the electronic device executes the method provided in any of the various optional implementation manners provided in the foregoing embodiments.
[0184] The model processing method and device provided by the embodiments of the present application, the storage medium and the electronic device are described in detail above, and the principles and implementation manners of the present application are described by applying specific examples. The above description of the embodiments is only used to help understand the method of the present application and its core idea; meanwhile, for those skilled in the art, according to the idea of the present application, the specific implementation manners and application ranges will be changed, and the above description should not be understood as a limitation of the present application.
Claims
1. A model processing method, characterized in that, include: Obtain a mirror model in a virtual scene. The surface of the mirror model is uneven, and the normal directions of different vertices of the mirror model are not exactly the same. The virtual scene includes virtual objects. The virtual scene that the mirror model needs to reflect is captured by the mirror camera corresponding to the mirror model, and used as the rendering texture of the mirror model; Obtain the first distance between the vertex of the mirror model and the observation camera corresponding to the mirror model in the target direction, wherein the target direction includes the horizontal direction and the vertical direction; Determine the position of the virtual object on the plane in the mirror model, and calculate the second distance between the virtual object and the observation camera in the target direction based on the position; Based on the first distance and the second distance of the vertex in the target direction, determine the second twist parameter corresponding to the vertex in the target direction; Based on the second distortion parameter corresponding to the vertex in each of the target directions and the first distance, the second sampling offset value of the vertex is determined; Based on the normal direction information of each vertex of the mirror model and the second sampling offset value, the sampling coordinates of the vertex in the rendering texture are determined; The rendered texture is sampled based on the sampling coordinates to obtain the target color value corresponding to the vertex; The mirror model is rendered based on the target color value of each vertex to display a mirror image with a deformation effect on the mirror model.
2. The model processing method as described in claim 1, characterized in that, Determining the sampling coordinates of the vertex in the rendered texture based on the normal direction information of each vertex of the mirror model includes: Calculate the screen space coordinates of the vertices in the mirror model; Based on the screen space coordinates, calculate the initial sampling coordinates of the vertex corresponding to the rendered texture; Based on the normal direction information of the vertex on the mirror model, the first sampling offset value corresponding to the vertex is determined; Based on the first sampling offset value, the initial sampling coordinates of the vertex are offset to obtain the sampling coordinates of the vertex corresponding to the rendering texture.
3. The model processing method as described in claim 2, characterized in that, Before determining the first sampling offset value corresponding to the vertex based on the normal direction information of the vertex on the mirror model, the method further includes: Determine the first torsion parameter corresponding to the mirror model; The step of determining the first sampling offset value corresponding to the vertex based on the normal direction information of the vertex on the mirror model includes: Based on the normal direction information of the vertex in the mirror model, the basic sampling offset value is determined; The first sampling offset value corresponding to the vertex is obtained by multiplying the first distortion parameter and the base sampling offset value of the vertex.
4. The model processing method as described in claim 1, characterized in that, The step of capturing a virtual scene image that the mirror model needs to reflect using a camera corresponding to the mirror model, and using it as the rendering texture of the mirror model, includes: Identify the virtual objects in the virtual scene that are to be displayed in the mirror image of the mirror model; Obtain the target distance between the virtual object and the mirror model; Using a mirror camera corresponding to the mirror model, the virtual object is photographed based on the target distance to obtain a virtual scene image containing the virtual object, which serves as the rendering texture of the mirror model.
5. The model processing method as described in claim 4, characterized in that, The step of determining the virtual object to be displayed in the mirror image of the mirror model in the virtual scene includes: Obtain object information of virtual objects that can be displayed in the mirror image of the mirror model; Obtain the location of the candidate virtual object in the virtual scene that matches the object information; When the position of the candidate virtual object is within the imaging range of the mirror model, the candidate virtual object is determined to be a virtual object to be displayed in the mirror image of the mirror model.
6. The model processing method as described in claim 1, characterized in that, Determining the second distortion parameter corresponding to the vertex in the target direction based on the first and second distances of the vertex in the target direction includes: Calculate the difference between the first distance and the second distance along the same target direction. The absolute value of the difference is normalized to obtain the second twist parameter corresponding to the vertex in the target direction.
7. The model processing method as described in claim 6, characterized in that, The step of determining the second sampling offset value of a vertex based on the second distortion parameter corresponding to the vertex in each of the target directions and the first distance includes: The second distortion parameter corresponding to each of the target directions is mapped to a preset numerical range to obtain the mapped distortion parameter; Obtain the distortion adjustment coefficients corresponding to each of the target directions; Based on the mapping distortion parameters of the vertex in each of the target directions, the first distance, and the distortion adjustment coefficient, the second sampling offset value of the vertex in each of the target directions is calculated.
8. A model processing device, characterized in that, include: The acquisition unit is used to acquire a mirror model in a virtual scene. The surface of the mirror model is uneven, and the normal directions of different vertices of the mirror model are not exactly the same. The virtual scene includes virtual objects. The shooting unit is used to capture the virtual scene image that the mirror model needs to reflect through the mirror camera corresponding to the mirror model, as the rendering texture of the mirror model; The determining unit is used to determine the sampling coordinates of the vertex in the rendered texture based on the normal direction information and the second sampling offset value of each vertex of the mirror model; A sampling unit is used to sample the rendered texture based on the sampling coordinates to obtain the target color value corresponding to the vertex; A rendering unit is used to render the mirror model based on the target color value of each vertex, so as to display a mirror image with deformation effect on the mirror model; The second distortion parameter determination unit is used to obtain a first distance between the vertex of the mirror model and the observation camera corresponding to the mirror model in a target direction, the target direction including a horizontal direction and a vertical direction; determine the position of the virtual object on the plane in the mirror model; calculate a second distance between the virtual object and the observation camera in the target direction based on the position; determine a second distortion parameter corresponding to the vertex in the target direction based on the first distance and the second distance of the vertex in the target direction; and determine a second sampling offset value of the vertex based on the second distortion parameter corresponding to the vertex in each of the target directions and the first distance.
9. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a computer program that, when executed by the processor, causes the processor to perform the steps of any one of the methods described in claims 1 to 7.
10. A computer-readable storage medium, characterized in that, It includes a computer program that, when run on an electronic device, causes the electronic device to perform the steps of any of the methods described in claims 1 to 7.
Citation Information
Patent Citations
Tri-dimensional application program convex mirror effect simulation method
CN101149841A
Image rendering method and device, storage medium and computer equipment
CN117710559A