Method and device for obtaining camera angle of depth camera, and electronic device
By adjusting the camera angle of the depth camera to follow the rotation of the object model, the problem of distorted shadow effects in cartoon rendering was solved, achieving realism and stability in shadow representation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-09
- Publication Date
- 2026-04-10
AI Technical Summary
In cartoon rendering, using depth maps obtained from existing depth cameras can cause stretching of shadow areas or distortion of shadow effects on object models, especially when the object model is at a near right angle to the light source.
By obtaining the orientation of objects and the direction of light sources in the virtual scene, the initial camera angle of the depth camera is determined, and the camera angle is adjusted according to the rotation angle of the object to ensure that the depth camera follows the rotation of the object model and maintains a certain angle to avoid distortion of the shadow effect.
It effectively improves the realism of shadow representation in cartoon rendering, ensuring that shadow effects are not stretched or lost when the object model is rotated.
Smart Images

Figure CN116036586B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to a camera angle acquisition method and device of a depth camera, an electronic device and a computer readable storage medium (storage medium). BACKGROUND
[0002] In the process of game development, ShadowMap is usually used to simulate real physical light and shadow, that is, a depth camera is built in the direction of the light source to obtain a depth map of a virtual scene or an object model, and then a shadow area on the object model is determined based on the depth map and a corresponding shadow effect is rendered.
[0003] However, it is difficult to meet the shadow representation in cartoon rendering when the depth camera is built in the direction of the light source. For example, when the object of the object model is oriented at an angle close to a right angle with the direction of the light source, the shadow rendering of the object model using the depth map obtained by the depth camera often causes the shadow area of the object model to be stretched, and even the shadow effect is distorted. SUMMARY
[0004] Therefore, it is necessary to provide a camera angle acquisition method and device of a depth camera, an electronic device and a storage medium to improve the authenticity of shadow representation in cartoon rendering in view of the above technical problems.
[0005] In a first aspect, the present application provides a camera angle acquisition method of a depth camera, which comprises:
[0006] obtaining an object orientation of an object model in a virtual scene and a light source direction of a main light source;
[0007] determining an initial camera angle of the depth camera according to a direction vector of the light source direction, wherein the depth camera is used to obtain a depth map for rendering a shadow effect of the object model;
[0008] obtaining an object rotation angle of the object model relative to the main light source on a reference horizontal plane according to the object orientation of the object model and the light source direction of the main light source;
[0009] when the object rotation angle is greater than a preset first angle threshold, adjusting a rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain a final camera angle of the depth camera.
[0010] In a second aspect, the present application provides a shadow rendering method, characterized in that the method comprises:
[0011] obtaining an object model in a virtual scene and a depth camera for the object model;
[0012] The camera angle of the depth camera is obtained, and the depth camera is controlled to obtain a depth map of the virtual scene at the camera angle; wherein the camera angle of the depth camera is obtained by the method for obtaining the camera angle of the depth camera described above;
[0013] The depth information of the object model is obtained from the depth map, and the real-time shadow of the object model is rendered based on the depth information.
[0014] In a third aspect, the present application provides a device for obtaining the camera angle of a depth camera, which comprises:
[0015] A parameter obtaining module is configured to obtain the object orientation of an object model in a virtual scene and the light source direction of a main light source;
[0016] A camera setting module is configured to determine the initial camera angle of the depth camera according to the direction vector of the light source direction; wherein the depth camera is configured to obtain a depth map used for rendering the shadow effect of the object model;
[0017] A rotation angle obtaining module is configured to obtain the object rotation angle of the object model relative to the main light source on a reference horizontal plane according to the object orientation of the object model and the light source direction of the main light source;
[0018] A camera angle adjusting module is configured to adjust the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle when the object rotation angle is greater than a preset first angle threshold, to obtain the final camera angle of the depth camera.
[0019] In a fourth aspect, the present application provides a device for rendering a shadow, which comprises:
[0020] An object model obtaining module is configured to obtain an object model in a virtual scene and a depth camera for the object model;
[0021] A camera angle obtaining module is configured to obtain the camera angle of the depth camera, and control the depth camera to obtain a depth map of the virtual scene at the camera angle; wherein the camera angle of the depth camera is obtained by the device for obtaining the camera angle of the depth camera described above;
[0022] A shadow rendering module is configured to obtain the depth information of the object model from the depth map, and render the real-time shadow of the object model based on the depth information.
[0023] In a fifth aspect, the present application further provides an electronic device, which comprises:
[0024] One or more processors;
[0025] A memory; and
[0026] One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the camera angle acquisition method or the shadow rendering method of the depth camera.
[0027] In a sixth aspect, the present application also provides a computer readable storage medium, which stores a computer program, and the computer program is loaded by a processor to execute the steps in the camera angle acquisition method or the steps in the shadow rendering method of the depth camera.
[0028] In a seventh aspect, the embodiments of the present application provide a computer program product or a computer program, which includes computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to make the computer device execute the method provided in the first aspect or the second aspect.
[0029] The camera angle acquisition method, the device, the computer device and the storage medium of the depth camera described above, by acquiring the object orientation of the object model and the light source direction of the main light source in the virtual scene, determining the initial camera angle of the depth camera according to the direction vector of the light source direction, acquiring the object rotation angle of the object model compared with the main light source on the reference horizontal plane according to the object orientation of the object model and the light source direction of the main light source, and adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle when the object rotation angle is greater than the first angle threshold, obtaining the final camera angle of the depth camera. By acquiring the object rotation angle of the object model compared with the main light source on the reference horizontal plane, and then adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane based on the object rotation angle, the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane is offset, the depth camera is controlled to rotate following the rotation of the object model, the camera direction of the depth camera and the object orientation of the object model maintain a certain angle, and the situation that the shadow transition is stretched to cause the distortion of the shadow effect or the loss of the shadow effect when the object rotation angle of the object model compared with the main light source is too large is avoided, and the reality of the shadow representation in the cartoon rendering is effectively improved. BRIEF DESCRIPTION OF DRAWINGS
[0030] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed 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 labor.
[0031] Figure 1Ais a scene diagram of a depth camera arrangement in the prior art;
[0032] Figure 1B is another scene diagram of a depth camera arrangement in the prior art;
[0033] Figure 2 is a flow diagram of a method of obtaining a camera angle of a depth camera in an embodiment of the application;
[0034] Figure 3 is a diagram of a camera angle of a depth camera in an embodiment of the application;
[0035] Figure 4 is a flow diagram of a method of obtaining a camera angle of a depth camera in an embodiment of the application;
[0036] Figure 5A is another diagram of a camera angle of a depth camera in an embodiment of the application;
[0037] Figure 5B is yet another diagram of a camera angle of a depth camera in an embodiment of the application;
[0038] Figure 6A is a diagram of a pleated skirt shadow effect in an embodiment of the application;
[0039] Figure 6B is another diagram of a pleated skirt shadow effect in an embodiment of the application;
[0040] Figure 7A is another diagram of a camera angle of a depth camera in an embodiment of the application;
[0041] Figure 7B is yet another diagram of a camera angle of a depth camera in an embodiment of the application;
[0042] Figure 7C is still another diagram of a camera angle of a depth camera in an embodiment of the application;
[0043] Figure 8 is a flow diagram of a method of rendering shadows in an embodiment of the application;
[0044] Figure 9 is a diagram of a device for obtaining a camera angle of a depth camera in an embodiment of the application;
[0045] Figure 10 is a diagram of a device for rendering shadows in an embodiment of the application;
[0046] Figure 11 is a diagram of a computer device in an embodiment of the application. DETAILED DESCRIPTION
[0047] 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. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the scope of the present application.
[0048] In the description of the present application, the terms "first", "second" are used only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise explicitly specified.
[0049] In the description of the present application, the word "for example" is used to indicate "as an example, illustration or description". Any embodiment described as "for example" in the present application is not necessarily interpreted as more preferred or more advantageous than other embodiments. The following description is given in order to enable any person skilled in the art to implement and use the present application. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can realize the present application without using these specific details. In other examples, well-known structures and processes will not be described in detail to avoid unnecessary details making the description of the present application obscure. Therefore, the present application is not intended to be limited to the shown embodiments, but is consistent with the broadest scope consistent with the principles and characteristics disclosed in the present application.
[0050] Before introducing the technical solutions disclosed in the present application, the application scenarios and related terms involved in the embodiments of the present application are first introduced. The technical solutions of the present application can be applied in game production or animation production. Exemplarily, the technical solutions of the present application can be applied in cartoon animation production. Of course, in some other embodiments, the technical solutions of the present application can also be applied to game production in cartoon animation style, and the technical solutions of the present application do not specially limit this. More specifically:
[0051] Virtual scene refers to the scene set in game production or animation production, which can be a three-dimensional scene or a two-dimensional scene.
[0052] Depth camera refers to a virtual camera set based on a main light source in a virtual scene, which is used to obtain the depth value of each element in the virtual scene. The initial camera direction of the depth camera is generally set as the light propagation direction of the main light source.
[0053] In the existing game production or animation production, the shadow map of the object model is usually set in the direction of the light source by a depth camera, and the depth map is obtained by shooting the virtual scene through the depth camera; for any pixel point in the virtual scene, the vertex coordinates of the corresponding vertex of the pixel point in the virtual scene are converted into the projection coordinates in the corresponding camera coordinate system of the depth camera based on the projection transformation matrix of the depth camera, and then the value of the pixel point on the z-axis of the projection coordinates is compared with the depth value of the pixel point in the depth map. When the value of the pixel point on the z-axis of the projection coordinates is greater than the depth value of the pixel point in the depth map, the pixel point is determined to be an occluded pixel point, that is, the pixel point is a shadow pixel point, otherwise the pixel point is determined to be a pixel point without being occluded. It can be understood that the shadow pixel points in the virtual scene constitute a shadow area, and the shadow rendering of the virtual scene is performed based on the shadow area to increase the reality of the virtual scene.
[0054] However, in the rendering process of the cartoon animation, the shadow effect of the cartoon animation is different from the real physical simulation. Taking the object model as a virtual character as an example, the decorations (such as bow ties, pleated skirts, etc.) on the virtual character often produce a certain shadow projection effect on the virtual character. When the virtual character turns, whether the virtual character and the light source form an angle close to a right angle or the virtual character completely faces away from the light source, the decorations will still produce a certain shadow projection effect on the virtual character.
[0055] In the existing shadow rendering technical solutions, the depth camera is set in the direction of the light source, referring to Figure 1A and Figure 1B , Figure 1A and Figure 1B , a rectangular parallelepiped is used to represent the model corresponding to the virtual character, a triangular pyramid is used to represent the decorations on the virtual character, and a circle is used to represent the main light source in the virtual scene; referring to Figure 1A When the angle between the virtual character and the light source is close to a right angle, that is, the angle between direction 1 and direction 2 is close to a right angle, the shadow area corresponding to the decorations determined based on the depth map shot by the depth camera presents a very long stretched area, and even causes no shadow area, and the shadow effect disappears; referring to Figure 1B When the angle between the virtual character and the light source is greater than a right angle, that is, the angle between direction 1 and direction 2 is greater than a right angle, for example, the virtual character faces away from the light source, the shadow corresponding to the decorations cannot be projected on the virtual character, and the shadow effect disappears.
[0056] To solve the above problems, the embodiment of the present application provides a method for obtaining a camera angle of a depth camera, which can run on a terminal device or a server. The terminal device can be a local terminal device. The server can be a physical server, a server cluster composed of multiple physical servers, or a distributed system. The server can also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, and big data and artificial intelligence platforms.
[0057] Referring to Figure 2 The embodiment of the present application provides a method for obtaining a camera angle of a depth camera, which is mainly illustrated by taking the method applied to a server as an example. The method comprises steps S210 to S240, which are specifically as follows:
[0058] In step S210, an object orientation of an object model in a virtual scene and a light source direction of a main light source are obtained.
[0059] The object model refers to an object in the virtual scene to be rendered for shadow effect rendering. Taking a game scene as an example, the object model can be a virtual character in the game scene to be rendered for shadow effect by three-dimensional drawing, such as a human virtual character in the game scene.
[0060] The object orientation of the object model can be a positive direction of a model space where the object model is located. The light source direction refers to a light propagation direction of the main light source in the virtual scene.
[0061] In step S220, an initial camera angle of a depth camera is determined according to a direction vector of the light source direction. The depth camera is used to obtain a depth map for rendering the shadow effect of the object model.
[0062] The depth camera refers to a virtual camera based on the main light source in the virtual scene, which is used to obtain depth values of different objects in the virtual scene. The camera angle of the depth camera refers to a view direction of a lens view angle of the depth camera.
[0063] Specifically, the initial camera angle of the depth camera can be set as the light source direction, that is, the initial view direction of the lens view angle of the depth camera is consistent with the light propagation direction of the main light source in the virtual scene. More specifically, the initial spatial position of the depth camera can be set as the position of the main light source.
[0064] In step S230, an object rotation angle of the object model relative to the main light source on a reference horizontal plane is obtained according to the object orientation of the object model and the light source direction of the main light source.
[0065] The reference horizontal plane refers to a horizontal plane in the virtual scene. Specifically, the reference horizontal plane can be a plane formed by the X-axis and the Y-axis in the world coordinate system corresponding to the virtual scene, i.e., the XY plane.
[0066] The object rotation angle of the object model relative to the main light source on the reference horizontal plane refers to the yaw of the object of the object model relative to the direction in which the object model points to the main light source. See Figure 3 Taking the XY plane as the world coordinate system under the reference horizontal plane, Figure 3 The point shown in the figure indicates the position of the object model, the circle indicates the main light source in the virtual scene, the direction 1 indicates the object orientation of the object model, the direction 2 indicates the light source direction of the main light source, and the object rotation angle of the object model relative to the main light source refers to the angle value of the object orientation (direction 1 in the figure) of the object model rotating to the direction in which the main light source is located (direction 3 in the figure) around the Z-axis.
[0067] In one embodiment, as Figure 4 shown, the step of obtaining the object rotation angle of the object model relative to the main light source on the reference horizontal plane according to the object orientation of the object model and the light source direction of the main light source includes: step S410, obtaining a first projection direction of the object orientation of the object model on the reference horizontal plane; step S420, obtaining a connecting line direction of the object model pointing to the main light source and a second projection direction of the connecting line direction on the reference horizontal plane; and step S430, obtaining the object rotation angle of the object model relative to the main light source on the reference horizontal plane according to the first projection direction and the second projection direction.
[0068] The first projection direction refers to the directional component of the object orientation of the object model on the reference horizontal plane; the connecting line direction of the object model pointing to the main light source refers to a vector connecting line with the position of the object model as the starting point and the position of the depth camera as the ending point, and the second projection direction refers to the directional component of the connecting line direction of the object model pointing to the main light source on the reference horizontal plane.
[0069] After obtaining the projection directions of the object orientation and the connecting line direction on the reference horizontal plane, the angle value of the included angle between the first projection direction and the second projection direction can be derived through dot product operation, and the angle value of the included angle between the first projection direction and the second projection direction is determined as the object rotation angle of the object model relative to the main light source on the reference horizontal plane.
[0070] Specifically, in one embodiment, the step of obtaining the object rotation angle of the object model relative to the main light source on the reference horizontal plane according to the first projection direction and the second projection direction can specifically include: performing dot product operation on the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction to obtain a dot product result; determining an angle value of the included angle between the first projection direction and the second projection direction according to the dot product result; and determining the angle value as the object rotation angle of the object model relative to the main light source.
[0071] The first unit vector refers to a vector with a vector direction being the first projection direction and a vector module length being 1, and similarly, the second unit vector refers to a vector with a vector direction being the second projection direction and a vector module length being 1.
[0072] Specifically, for the first projection direction, after obtaining the first projection direction of the object toward the reference horizontal plane, the direction vector of the first projection direction can be normalized to obtain the first unit vector corresponding to the first projection direction; for the second projection direction, after obtaining the second projection direction of the object toward the reference horizontal plane, the direction vector of the second projection direction can be normalized to obtain the second unit vector corresponding to the second projection direction; and then, the dot product result of the first unit vector and the second unit vector can be calculated through dot product operation.
[0073] It can be understood that the dot product operation of two vectors is equal to the modulus of the vector multiplied by the cosine value of the included angle of the vector, and since the first unit vector and the second unit vector are both 1, the dot product result between the first unit vector and the second unit vector is the cosine value of the included angle between the first projection direction and the second projection direction; therefore, the angle value of the included angle between the first projection direction and the second projection direction can be calculated based on the inverse cosine function according to the dot product result between the first unit vector and the second unit vector, and the included angle is determined as the angle value of the object rotation angle of the object model relative to the main light source.
[0074] In step S240, when the object rotation angle is greater than a preset first angle threshold, the initial camera angle of the depth camera on the reference horizontal plane is adjusted according to the object rotation angle to obtain the final camera angle of the depth camera.
[0075] The first angle threshold is a preset threshold value for determining whether the rotation angle of the initial camera angle on the reference horizontal plane needs to be adjusted according to the object rotation angle on the reference horizontal plane.
[0076] After obtaining the object rotation angle of the object model relative to the main light source, the object rotation angle can be compared with the first angle threshold. When the object rotation angle is equal to the first angle threshold or smaller than the first angle threshold, the depth camera's camera angle remains unchanged from its initial position. That is, the depth camera's camera position is the same as the main light source's position, and the depth camera's camera angle is in the same direction as the light propagation of the main light source. When the object rotation angle is larger than the first angle threshold, the initial camera angle of the depth camera can be adjusted.
[0077] Specifically, in one embodiment, the step of adjusting the initial camera angle of the depth camera on the reference horizontal plane based on the object rotation angle involves keeping the depth camera lens pointing towards the object model and controlling the depth camera to rotate horizontally around the object model on the reference horizontal plane based on the object rotation angle. By controlling the depth camera to rotate horizontally around the object model on the reference horizontal plane based on the object rotation angle, the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane is shifted, that is, the initial camera angle rotates horizontally. This allows the depth camera to rotate with the object model, maintaining a certain angle between the camera angle of the depth camera and the object orientation of the object model. This avoids excessive stretching of the calculated shadow area when the object rotation angle of the object model relative to the main light source is too large, which could lead to distortion or loss of the shadow effect.
[0078] For example, see Figure 5A ,like Figure 5A As shown, the object orientation of the object model is direction 1. The initial camera angle of the depth camera is set based on the light source direction of the main light source, i.e., the initial camera angle of the depth camera is direction 2. The direction of the line connecting the object model to the main light source is direction 3, which is the opposite direction of direction 2. The object rotation angle of the object model relative to the main light source is the angle between direction 1 and direction 3. Assuming that the object rotation angle of the object model relative to the main light source is less than the first angle threshold, the spatial position of the depth camera remains unchanged at the initial spatial position. When the object orientation of the object model changes from direction 1 to direction 1', the object rotation angle of the object model relative to the main light source is the angle between direction 1' and direction 3. Assuming that the object rotation angle of the object model relative to the main light source is greater than the first angle threshold, the depth camera can be controlled to rotate horizontally around the object model on the reference horizontal plane according to the object rotation angle, so that the camera angle of the depth camera changes from direction 2 to direction 2'.
[0079] In the method for obtaining the camera angle of the depth camera, the object orientation of the object model in the virtual scene and the light source direction of the main light source are obtained; the initial camera angle of the depth camera is determined according to the direction vector of the light source direction; the object rotation angle of the object model relative to the main light source on the reference horizontal plane is obtained according to the object orientation of the object model and the light source direction of the main light source; when the object rotation angle is greater than the first angle threshold, the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane is adjusted according to the object rotation angle, to obtain the final camera angle of the depth camera. By obtaining the object rotation angle of the object model relative to the main light source on the reference horizontal plane, and then adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane based on the object rotation angle, the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane is offset, the depth camera is controlled to rotate following the rotation of the object model, the camera orientation of the depth camera and the object orientation of the object model maintain a certain included angle, and the case that the transition stretching of the shadow area calculated based on the depth camera is too large when the object rotation angle of the object model relative to the main light source is too large is avoided, so that the shadow effect is distorted or the shadow effect is lost.
[0080] In one embodiment, when the object rotation angle is greater than the first angle threshold, the step of adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain the final camera angle of the depth camera includes: determining the angle difference between the object rotation angle and the first angle threshold as the rotation angle adjustment amount of the depth camera on the reference horizontal plane; adjusting the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount to obtain the final camera angle of the depth camera.
[0081] Specifically, the angle value of the object rotation angle is subtracted by the first angle threshold to obtain the rotation angle adjustment amount of the depth camera on the reference horizontal plane, and then the depth camera is controlled to rotate horizontally around the object model on the reference horizontal plane by the rotation angle adjustment amount, so that the initial camera angle of the depth camera is horizontally rotated on the reference horizontal plane to obtain the final camera angle of the depth camera, so that the included angle between the camera angle of the depth camera and the object orientation of the object model is maintained as the first angle threshold, and the case that the transition stretching of the shadow area calculated based on the depth camera is too large is avoided, so that the shadow effect is distorted or the shadow effect is lost.
[0082] Further, the step of adjusting the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount to obtain the final camera angle of the depth camera comprises: obtaining a first projection direction of the object orientation of the object model on the reference horizontal plane; obtaining a line direction of the object model pointing to the main light source and a second projection direction of the line direction on the reference horizontal plane; if the first projection direction is on the right side of the second projection direction, rotating the rotation angle of the initial camera angle on the reference horizontal plane to the clockwise direction by the rotation angle adjustment amount; if the first projection direction is on the left side of the second projection direction, rotating the rotation angle of the initial camera angle on the reference horizontal plane to the counterclockwise direction by the rotation angle adjustment amount.
[0083] Specifically, in the process of adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane, it can be judged whether the object orientation corresponding to the first projection direction is on the left side or the right side of the line direction corresponding to the second projection direction; when the first projection direction is on the left side of the second projection direction, i.e. the object orientation is on the left side of the line direction of the object model pointing to the main light source, the depth camera can be controlled to rotate counterclockwise around the object model on the reference horizontal plane, so that the rotation angle of the initial camera angle on the reference horizontal plane is rotated clockwise by the rotation angle adjustment amount; when the first projection direction is on the right side of the second projection direction, i.e. the object orientation is on the right side of the line direction of the object model pointing to the main light source, the depth camera can be controlled to rotate clockwise around the object model on the reference horizontal plane, so that the rotation angle of the initial camera angle on the reference horizontal plane is rotated counterclockwise by the rotation angle adjustment amount.
[0084] For example, assuming that the first angle threshold is set to 30 degrees, referring to FIG. 4, the first projection direction of the object orientation of the object model on the reference horizontal plane is on the left side of the line direction of the object model pointing to the main light source, and the rotation angle of the initial camera angle on the reference horizontal plane is rotated counterclockwise by 30 degrees. Figure 5BThe object orientation of the object model is direction 1, and the initial camera angle of the depth camera is set based on the light source direction of the main light source, i.e., the initial camera angle of the depth camera is direction 2; wherein the direction of the line connecting the object model to the main light source is direction 3, direction 3 is the opposite direction of direction 2, and the object rotation angle of the object model relative to the main light source is the included angle A between direction 1 and direction 3. Assuming that the object rotation angle A of the object model relative to the main light source is 25 degrees at this time, the spatial position of the depth camera remains unchanged at the initial spatial position. When the object orientation of the object model changes from direction 1 to direction 1', the object rotation angle of the object model relative to the main light source is the included angle B between direction 1' and direction 3. Assuming that the object rotation angle B of the object model relative to the main light source is 90 degrees at this time, the depth camera is controlled to rotate 60 degrees clockwise on the reference horizontal plane around the object model, so that the camera angle of the depth camera changes from direction 2 to direction 2', and the included angle between the camera angle of the depth camera and the object orientation of the object model remains 30 degrees. When the object orientation of the object model changes from direction 1 to direction 1'', the object rotation angle of the object model relative to the main light source is the included angle C between direction 1'' and direction 3. Assuming that the object rotation angle B of the object model relative to the main light source is -90 degrees at this time, the depth camera is controlled to rotate 60 degrees counterclockwise on the reference horizontal plane around the object model, so that the camera angle of the depth camera changes from direction 2 to direction 2'', and the included angle between the camera angle of the depth camera and the object orientation of the object model remains 30 degrees.
[0085] Further, whether the first projection direction is on the left side or the right side of the second projection direction can be determined based on the cross product result between the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction. Specifically, in an embodiment, the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction are cross-multiplied to obtain a cross product result; when the cross product result is less than or equal to zero, it is determined that the first projection direction is on the right side of the second projection direction; when the cross product result is greater than zero, it is determined that the first projection direction is on the left side of the second projection direction. Since the cross product of two vectors is equal to the modulus of the vector multiplied by the sine value of the included angle of the vector, when the cross product result of the first unit vector and the second unit vector is less than or equal to zero, i.e., the first projection direction is on the right side of the second projection direction, when the cross product result of the first unit vector and the second unit vector is greater than zero, i.e., the first projection direction is on the left side of the second projection direction.
[0086] With the rotation of the object model, when the object orientation of the object model changes from one side (such as the left side) to the other side (such as the right side) of the line connecting the object model to the main light source, determining the angle difference between the object rotation angle and the first angle threshold as the rotation angle adjustment of the depth camera on the reference horizontal plane is easy to cause the jump of the shadow area.
[0087] To avoid the jump of the shadow area, in an embodiment, the step of adjusting the rotation angle of the initial shooting angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain the final shooting angle of the depth camera includes: if the angle value of the object rotation angle is less than or equal to a preset second angle threshold, determining the angle difference between the object rotation angle and the first angle threshold as the rotation angle adjustment amount of the depth camera on the reference horizontal plane; if the angle value of the object rotation angle is greater than the second angle threshold, obtaining the ratio between the supplementary angle corresponding to the object rotation angle and the supplementary angle corresponding to the second angle threshold, and obtaining the rotation angle adjustment amount of the depth camera on the reference horizontal plane according to the ratio, the first angle threshold and the second angle threshold; and adjusting the rotation angle of the initial shooting angle on the reference horizontal plane based on the rotation angle adjustment amount to obtain the final shooting angle of the depth camera.
[0088] In the formula, the second angle threshold is greater than the first angle threshold and less than the difference between the flat angle and the first angle threshold; for example, the first angle threshold is 30 degrees, and the value of the second angle threshold is in the range of [30, 150).
[0089] In the formula, the supplementary angle corresponding to the object rotation angle represents the angle between the object orientation of the object model in the direction of the object rotation angle and the light propagation direction of the main light source, and the supplementary angle corresponding to the second angle threshold represents the angle between the object orientation of the object model in the direction of the second angle threshold and the light propagation direction of the main light source.
[0090] Specifically, after obtaining the object rotation angle, it is compared whether the object rotation angle is greater than the second angle threshold. When the angle value of the object rotation angle is less than or equal to the preset second angle threshold, the angle difference between the object rotation angle and the first angle threshold is determined as the rotation angle adjustment amount of the depth camera on the reference horizontal plane, so that the included angle between the shooting orientation of the depth camera and the object orientation of the object model is kept as the first angle threshold. When the angle value of the object rotation angle is greater than the second angle threshold, the ratio between the supplementary angle corresponding to the object rotation angle and the supplementary angle corresponding to the second angle threshold is obtained, and then the rotation angle adjustment amount of the depth camera on the reference horizontal plane is obtained according to the ratio, the first angle threshold and the second angle threshold, so that the included angle between the shooting orientation of the depth camera and the object orientation of the object model is gradually reduced, and when the object orientation of the object model is rotated to the direction consistent with the direction of the light source, the included angle between the shooting orientation of the depth camera and the object orientation of the object model is 0.
[0091] More specifically, when the angle value of the object rotation angle is greater than the second angle threshold, the rotation angle adjustment amount of the depth camera on the reference horizontal plane can be obtained by the following formula (1):
[0092]
[0093] wherein X represents the object rotation angle, Y represents the rotation angle adjustment amount, A represents the second angle threshold, and B represents the first angle threshold.
[0094] Taking the first angle threshold as 30 degrees and the second angle threshold as 90 degrees as an example, assuming that the angle value of the object rotation angle is X, but A is greater than 90 degrees, the rotation angle adjustment amount Y of the depth camera on the reference horizontal plane can be calculated according to the following formula (2):
[0095]
[0096] After obtaining the rotation angle adjustment amount of the depth camera on the reference horizontal plane, the depth camera can be controlled to rotate horizontally around the object model on the reference horizontal plane by the rotation angle adjustment amount, so that the initial camera angle of the depth camera is horizontally rotated on the reference horizontal plane to obtain the final camera angle of the depth camera. Similarly, in the process of adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane, it can be determined whether the first projection direction is on the left side or the right side of the second projection direction; when the first projection direction is on the left side of the second projection direction, the depth camera can be controlled to rotate counterclockwise horizontally around the object model on the reference horizontal plane, so that the rotation angle of the initial camera angle on the reference horizontal plane rotates clockwise by the rotation angle adjustment amount; when the first projection direction is on the right side of the second projection direction, the depth camera can be controlled to rotate clockwise horizontally around the object model on the reference horizontal plane, so that the rotation angle of the initial camera angle on the reference horizontal plane rotates counterclockwise by the rotation angle adjustment amount.
[0097] The above-mentioned camera angle acquisition method of the depth camera will be further described in combination with a specific application scenario. Specifically, taking the object model as a cartoon character model wearing a pleated skirt as an example, wherein, as shown in Figure 6A and Figure 6B No matter how the cartoon character model turns, the pleated skirt on the cartoon character model will produce a certain shadow effect to ensure the three-dimensionality and authenticity of the pleated skirt on the cartoon character model.
[0098] Step 1, obtaining the object orientation of the cartoon character model in the virtual scene and the light source direction of the main light source.
[0099] Wherein the object orientation of the cartoon character model is denoted as vector ActorForward, and the light source direction (i.e. the light propagation direction) of the main light source is denoted as vector LightDir. Referring to Figure 7A and Figure 7B A cuboid is used to represent the cartoon character model, a triangular pyramid is used to represent the pleated skirt on the cartoon character model, and a circle is used to represent the main light source in the virtual scene.
[0100] Step 2, according to the direction vector of the light source direction, determine the initial camera angle of the depth camera.
[0101] Specifically, the rotation angle (Yaw) of the initial camera angle of the depth camera in the direction on the XY plane can be obtained by the following steps:
[0102] First, obtain the direction component of the vector LightDir on the XY plane, and normalize the direction vector to obtain a third unit vector; as shown in the following formula: Figure 7A The direction 2 is the direction of the third unit vector, which can be represented as the projection of the light source direction on the XY plane, or as the projection of the initial camera angle of the depth camera on the XY plane.
[0103] Then, perform cross product operation on the third unit vector and the X-axis positive direction vector (1, 0, 0) of the XY plane, and determine the light source direction according to the left-hand screw rule and the result of the cross product operation to determine whether the third unit vector is on the right side of the X-axis or on the left side of the X-axis; it can be understood that when the result of the cross product operation is greater than 0, the light source direction is on the right side of the X-axis; otherwise, when the result of the cross product operation is less than 0, the light source direction is on the left side of the X-axis.
[0104] At the same time, perform dot product operation on the third unit vector and the X-axis positive direction vector (1, 0, 0) of the XY plane, and use the inverse cosine function to calculate the angle between the third unit vector and the X-axis direction vector based on the dot product result of the dot product operation.
[0105] Finally, combined with the light source direction determination result, the rotation angle (Yaw) of the third unit vector on the XY plane relative to the X-axis can be obtained, which is the rotation angle of the initial camera angle of the depth camera on the XY plane, and the initial rotation angle is recorded as a floating point value OriginRot; wherein, the light source direction is on the left side of the X-axis, and the initial rotation angle is multiplied by negative one. Because the rotation angle (Yaw) is generally in the range of -180 degrees to 180 degrees, the initial rotation angle exceeding the angle range is degenerated into the angle range, for example, the initial rotation angle is 181 degrees, and the final recorded angle value is -179 degrees.
[0106] Step 3, according to the object orientation of the cartoon character model and the light source direction of the main light source, obtain the object rotation angle of the cartoon character model relative to the main light source on the reference horizontal plane.
[0107] Wherein, the reference horizontal plane is the XY plane. Specifically, obtain the direction component of the vector ActorForward on the XY plane, and normalize the direction vector to obtain a first unit vector; as shown in the following formula: Figure 7AThe direction 1 shown is the direction corresponding to the first unit vector. This direction 1 can be represented as the projection of the cartoon character model's object orientation onto the XY plane.
[0108] Then, the direction of the line connecting the object model to the main light source is obtained, as well as the direction component of the line in the XY plane, and the direction vector is normalized to obtain the second unit vector; it can be understood that the direction of the line connecting the object model to the main light source can be represented as -LightDir.
[0109] like Figure 7A The opposite direction of direction 2 shown is the projection of the line connecting the object model to the main light source onto the XY plane.
[0110] After obtaining the first unit vector and the second unit vector, the first unit vector and the second unit vector are subjected to a dot product operation. The angle between the first unit vector and the second unit vector is calculated based on the dot product result using the inverse cosine function. This angle is the rotation angle of the cartoon character model relative to the main light source in the XY plane.
[0111] Step 4: When the object rotation angle is greater than the preset first angle threshold, adjust the rotation angle of the initial shooting angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain the final shooting angle of the depth camera.
[0112] The first angle threshold can be set to 30 degrees. The object's rotation angle is compared to the preset first angle threshold. When the object's rotation angle is less than or equal to the first angle threshold (i.e., the cartoon character model's orientation is within a 60-degree fan-angle range of the main light source), the OrientRot value can be directly output as the depth camera's viewing angle. In other words, the depth camera's viewing angle remains unchanged, and the spatial position of the depth camera is the same as the spatial position of the main light source. Figure 7A As shown. When the object's rotation angle is greater than the first angle threshold, that is, the cartoon character model's rotation angle in the XY plane is greater than 30 degrees relative to the main light source, the initial camera angle of the depth camera in the XY plane needs to be adjusted so that the initial camera angle of the depth camera rotates around the cartoon character model; as shown. Figure 7B As shown, Figure 7B The direction 3 shown is the projection of the line connecting the object model to the main light source onto the XY plane, which is the direction corresponding to the second unit vector. The object rotation angle is the angle between direction 1 and direction 3. When the object rotation angle is greater than the first angle threshold, the rotation angle of the initial camera angle of the depth camera on the XY plane needs to be adjusted so that the camera angle of the depth camera is adjusted from direction 2 to direction 4.
[0113] In one scenario, the angle value of the object's rotation angle can be subtracted from the first angle threshold, and the resulting difference is the adjustment amount of the depth camera's rotation angle in the XY plane. Simultaneously, based on the first projection direction and the second projection direction, it is determined whether the first projection direction is to the right or left of the second projection direction. Based on whether the first projection direction is to the right or left of the second projection direction, the rotation angle of the depth camera's initial imaging angle in the XY plane can be controlled to rotate counterclockwise or clockwise by the rotation angle adjustment amount.
[0114] by Figures 7A-7C For example, see Figure 7A When the rotation angle of the cartoon character model in the XY plane relative to the main light source is less than a first preset threshold, the spatial position of the depth camera is the same as that of the main light source, and the rotation angle of the depth camera's shooting direction in the XY plane is consistent with the rotation angle of the main light source's light source direction in the XY plane. When the object orientation of the cartoon character model rotates, and the angle between the cartoon character model and the main light source exceeds the first preset threshold, the rotation angle of the initial shooting angle of the depth camera in the XY plane needs to be adjusted. Specifically, when the object orientation of the cartoon character model rotates, and the object orientation of the cartoon character model is to the right of the line connecting the object model to the main light source, the rotation angle of the initial shooting angle of the depth camera in the XY plane is controlled to rotate clockwise by the amount of rotation adjustment. See [link to relevant documentation]. Figure 7B The depth camera's viewing angle is adjusted from direction 2 to direction 4; when the cartoon character model's object orientation rotates, and the cartoon character model's object orientation is to the left of the line connecting the object model to the main light source, the initial viewing angle of the depth camera in the XY plane is rotated counterclockwise. See [reference needed for rotation angle adjustment]. Figure 7C The depth camera's shooting angle was adjusted from direction 2 to direction 5.
[0115] In the above scenario, the depth camera's OriginRot calculation output relies on the object orientation of the cartoon character model, i.e., the vector ActorForward (or the first unit vector). When the cartoon character model's object orientation shifts from the right to the left along the connecting line, the OriginRot vector rotates from a positive value (150° = 180° + (-30°)) to a negative value (-150° = -180° + 30°). This manifests as a problem in the shadow effect: when the cartoon character model is backlit, the shadow area corresponding to the pleated skirt will jump from the left to the right.
[0116] Therefore, in another case, it can be judged whether the angle value of the object rotation angle is greater than the preset second angle threshold value first. If the angle value of the object rotation angle is less than or equal to the preset second angle threshold value, the angle difference between the object rotation angle and the first angle threshold value is determined as the rotation angle adjustment amount of the depth camera on the reference horizontal plane. If the angle value of the object rotation angle is greater than the second angle threshold value, the ratio between the corresponding complementary angle of the object rotation angle and the corresponding complementary angle of the second angle threshold value is obtained, and the rotation angle adjustment amount of the depth camera on the reference horizontal plane is obtained according to the ratio, the first angle threshold value and the second angle threshold value. The rotation angle of the initial camera angle on the reference horizontal plane is adjusted based on the rotation angle adjustment amount to obtain the final camera angle of the depth camera. At the same time, it is judged whether the first projection direction is on the right side or the left side of the second projection direction according to the first projection direction and the second projection direction, so as to control the rotation of the initial camera angle of the depth camera on the XY plane to rotate counterclockwise or clockwise by the rotation angle adjustment amount according to whether the first projection direction is on the right side or the left side of the second projection direction.
[0117] Specifically, taking the first angle threshold value as 30 degrees and the second angle threshold value as 90 degrees as an example, the dot product result of the second unit vector and the first unit vector is calculated first. It is judged whether the dot product result is greater than zero. According to the definition of dot product, if the dot product result of the two vectors is greater than 0, it proves that the included angle between the second unit vector and the first unit vector is acute (< 90°). When the dot product result of the two vectors is less than 0, the included angle between the second unit vector and the first unit vector is obtuse (> 90°).
[0118] When the included angle between the second unit vector and the first unit vector is acute, the angle difference between the object rotation angle and the first angle threshold value is determined as the rotation angle adjustment amount of the depth camera on the reference horizontal plane. When the included angle between the second unit vector and the first unit vector is obtuse, the included angle between the object orientation and the light orientation is subtracted by 90 degrees to obtain the percentage of the included angle between the object orientation and the light orientation relative to 90 degrees. Then, the remaining rotation angle of the depth camera is obtained by using 120 degrees multiplied by the percentage. Finally, the angle that the depth camera needs to be deflected relative to the direction of the light source is obtained by subtracting the remaining rotation angle from 180 degrees. By obtaining the ratio between the corresponding complementary angle of the object rotation angle and the corresponding complementary angle of the second angle threshold value, and then obtaining the rotation angle adjustment amount of the depth camera on the reference horizontal plane according to the ratio, the first angle threshold value and the second angle threshold value, the angle value between the camera orientation of the depth camera and the object orientation of the object model gradually decreases. When the object orientation of the object model rotates to the direction consistent with the direction of the light source, the angle value between the camera orientation of the depth camera and the object orientation of the object model is 0, avoiding the jumping of the shadow area.
[0119] Further, the embodiment of the present application also provides a shadow rendering method, specifically, as shown in the figure Figure 8 The shadow rendering method comprises the following steps:
[0120] In step S810, an object model in a virtual scene and a depth camera for the object model are acquired.
[0121] The object model refers to an object in the virtual scene to be rendered for shadow effect rendering; taking a game scene as the virtual scene, the object model can be a virtual character in the game scene to be rendered for shadow effect by three-dimensional drawing, for example, a human virtual character in the game scene. The depth camera refers to a virtual camera set based on a main light source in the virtual scene, used to acquire a depth map of the virtual scene.
[0122] In step S820, a camera angle of the depth camera is acquired, and the depth camera is controlled to acquire a depth map of the virtual scene at the camera angle; wherein the camera angle of the depth camera is acquired by the above-mentioned camera angle acquisition method of the depth camera.
[0123] The acquisition step of the camera angle of the depth camera can specifically comprise: acquiring an object orientation of the object model in the virtual scene and a light source direction of the main light source, and then determining an initial camera angle of the depth camera according to a direction vector of the light source direction; and acquiring an object rotation angle of the object model relative to the main light source on a reference horizontal plane according to the object orientation of the object model and the light source direction of the main light source; when the object rotation angle is greater than a preset first angle threshold, adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain a final camera angle of the depth camera.
[0124] After the camera angle of the depth camera is determined, the depth camera can be controlled to shoot the virtual scene at the camera angle to acquire a depth map of the virtual scene. It can be understood that the pixel value of each pixel point in the depth map can represent the depth value of the corresponding vertex in the virtual scene.
[0125] In step S830, the depth information of the object model is acquired from the depth map, and the real-time shadow of the object model is rendered based on the depth information.
[0126] Specifically, the depth information of each vertex on the object model can be obtained from the depth map, and then the vertex coordinates of each vertex on the object model in the world coordinate system are converted into camera coordinates of the camera coordinate system in which the depth camera is located, and the actual depth value of each vertex on the object model is determined based on the camera coordinates; if the actual depth value of a certain vertex on the object model is greater than the depth information of the vertex in the depth map, the vertex is in the shadow, all vertices on the object model are analyzed to determine all vertices in the shadow, and the shadow area on the object model is obtained, and then the real-time shadow of the object model is rendered based on the shadow area.
[0127] The above shadow rendering method obtains the object rotation angle of the object model relative to the main light source on the reference horizontal plane, and then adjusts the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane based on the object rotation angle, so that the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane is offset to determine the camera direction of the depth camera, and then the depth camera is controlled to obtain the depth map of the virtual scene at the camera angle, finally the depth information of the object model is obtained from the depth map, and the real-time shadow of the object model is rendered based on the depth information. By controlling the depth camera to rotate following the rotation of the object model, the camera direction of the depth camera maintains a certain angle with the object direction of the object model, avoiding the case that the shadow rendered by the depth map obtained by using the depth camera is stretched too much when the object rotation angle of the object model relative to the main light source is too large, resulting in distortion of the shadow effect or loss of the shadow effect, effectively improving the authenticity of the shadow effect in cartoon rendering.
[0128] In order to better implement the depth camera camera angle obtaining method provided by the embodiments of the present application, on the basis of the depth camera camera angle obtaining method provided by the embodiments of the present application, a depth camera camera angle obtaining device is further provided in the embodiments of the present application, as shown in Figure 9 The depth camera camera angle obtaining device 900 comprises:
[0129] The parameter obtaining module 910 is configured to obtain the object direction of the object model in the virtual scene and the light source direction of the main light source.
[0130] The camera setting module 920 is configured to determine the initial camera angle of the depth camera according to the direction vector of the light source direction.
[0131] The rotation angle obtaining module 930 is configured to obtain the object rotation angle of the object model relative to the main light source on the reference horizontal plane according to the object direction of the object model and the light source direction of the main light source.
[0132] The camera angle adjusting module 940 is configured to adjust the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle when the object rotation angle is greater than a preset first angle threshold, to obtain a final camera angle of the depth camera.
[0133] In some embodiments of the present application, the camera angle adjusting module 940 is specifically configured to determine the angle difference between the object rotation angle and the first angle threshold as a rotation angle adjustment amount of the depth camera on the reference horizontal plane, and adjust the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount, to obtain the final camera angle of the depth camera.
[0134] In some embodiments of the present application, the camera angle adjusting module 940 is specifically configured to, if the angle value of the object rotation angle is less than or equal to a preset second angle threshold, determine the angle difference between the object rotation angle and the first angle threshold as the rotation angle adjustment amount of the depth camera on the reference horizontal plane; if the angle value of the object rotation angle is greater than the second angle threshold, obtain a ratio between a complementary angle corresponding to the object rotation angle and a complementary angle corresponding to the second angle threshold, and obtain the rotation angle adjustment amount of the depth camera on the reference horizontal plane according to the ratio, the first angle threshold and the second angle threshold; and adjust the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount, to obtain the final camera angle of the depth camera.
[0135] In some embodiments of the present application, the camera angle adjusting module 940 is specifically further configured to obtain a first projection direction of the object orientation of the object model on the reference horizontal plane, obtain a line direction of the object model pointing to the main light source and a second projection direction of the line direction on the reference horizontal plane, control the rotation angle of the initial camera angle on the reference horizontal plane to rotate by the rotation angle adjustment amount in the clockwise direction if the first projection direction is on the right side of the second projection direction, and control the rotation angle of the initial camera angle on the reference horizontal plane to rotate by the rotation angle adjustment amount in the counterclockwise direction if the first projection direction is on the left side of the second projection direction.
[0136] In some embodiments of the present application, the camera angle adjusting module 940 is specifically further configured to perform a cross product operation on a first unit vector corresponding to the first projection direction and a second unit vector corresponding to the second projection direction to obtain a cross product result, determine that the first projection direction is on the right side of the second projection direction when the cross product result is less than or equal to zero, and determine that the first projection direction is on the left side of the second projection direction when the cross product result is greater than zero.
[0137] In some embodiments of this application, the rotation angle acquisition module 930 is used to acquire the first projection direction of the object model's orientation on the reference horizontal plane; acquire the direction of the line connecting the object model to the main light source, and the second projection direction of the line on the reference horizontal plane; and acquire the object rotation angle of the object model relative to the main light source on the reference horizontal plane based on the first projection direction and the second projection direction.
[0138] In some embodiments of this application, the rotation angle acquisition module 930 is used to perform a dot product operation on the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction to obtain the dot product result; determine the angle value between the first projection direction and the second projection direction based on the dot product result; and determine the angle value as the object rotation angle of the object model relative to the main light source.
[0139] In some embodiments of this application, the camera angle acquisition device 900 of the depth camera can be implemented as a computer program, and the computer program can be implemented in, for example... Figure 11 The computer device shown operates on this device. The computer device's memory can store the various program modules that make up the camera angle acquisition device 900 of the depth camera, for example, Figure 9 The parameter acquisition module 910, camera setting module 920, rotation angle acquisition module 930, and camera angle adjustment module 940 are shown. The computer program comprised of these modules causes the processor to execute the steps in the camera angle acquisition method of the depth camera according to the various embodiments of this application described in this specification.
[0140] For example, Figure 11 The computer device shown can be used as follows Figure 9 The parameter acquisition module 910 in the depth camera's angle acquisition device 900 executes step S210. The computer device can execute step S220 via the camera setting module 920. The computer device can execute step S230 via the rotation angle acquisition module 930. The computer device can execute step S240 via the camera angle adjustment module 940. The computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communication with external computer devices via a network connection. When the computer program is executed by the processor, it implements a method for acquiring the angle of a depth camera.
[0141] The application embodiments also provide a shadow rendering apparatus, such as Figure 10As shown in the figure, the shadow rendering apparatus 1000 comprises:
[0142] an object model obtaining module 1010, configured to obtain an object model in a virtual scene and a depth camera for the object model;
[0143] a camera angle obtaining module 1020, configured to obtain a camera angle of the depth camera, and control the depth camera to obtain a depth map of the virtual scene at the camera angle; wherein the camera angle of the depth camera is obtained by the camera angle obtaining apparatus of the depth camera;
[0144] a shadow rendering module 1030, configured to obtain depth information of the object model from the depth map, and render real-time shadow of the object model based on the depth information.
[0145] In some embodiments of the present application, the shadow rendering apparatus 1000 can be implemented in the form of a computer program, which can run on a computer device as shown in the figure. The memory of the computer device can store various program modules constituting the shadow rendering apparatus 1000, such as the object model obtaining module 1010, the camera angle obtaining module 1020 and the shadow rendering module 1030 shown in the figure. The computer program constituted by various program modules makes the processor execute the steps in the depth camera camera angle obtaining method of various embodiments of the present application described in the specification. Figure 11 Figure 10 In some embodiments of the present application, the shadow rendering apparatus 1000 can be implemented in the form of a computer program, which can run on a computer device as shown in the figure. The memory of the computer device can store various program modules constituting the shadow rendering apparatus 1000, such as the object model obtaining module 1010, the camera angle obtaining module 1020 and the shadow rendering module 1030 shown in the figure. The computer program constituted by various program modules makes the processor execute the steps in the depth camera camera angle obtaining method of various embodiments of the present application described in the specification.
[0146] For example, the computer device can execute step S810 through the object model obtaining module 1010 in the depth camera camera angle obtaining apparatus 900 as shown in the figure. The computer device can execute step S820 through the camera angle obtaining module 1020. The computer device can execute step S830 through the shadow rendering module 1030. The computer device comprises a processor, a memory and a network interface connected through a system bus. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The network interface of the computer device is configured to communicate with external computer devices through network connection. The computer program is executed by the processor to implement a depth camera camera angle obtaining method. Figure 11 Figure 9 For example, the computer device can execute step S810 through the object model obtaining module 1010 in the depth camera camera angle obtaining apparatus 900 as shown in the figure. The computer device can execute step S820 through the camera angle obtaining module 1020. The computer device can execute step S830 through the shadow rendering module 1030. The computer device comprises a processor, a memory and a network interface connected through a system bus. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The network interface of the computer device is configured to communicate with external computer devices through network connection. The computer program is executed by the processor to implement a depth camera camera angle obtaining method.
[0147] Those skilled in the art can understand that Figure 11 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0148] In some embodiments of the present application, an electronic device is provided, comprising one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to perform the following steps:
[0149] Obtaining an object orientation of an object model of an object in a virtual scene and a light source direction of a main light source;
[0150] Determining an initial camera angle of the depth camera according to a direction vector of the light source direction;
[0151] Obtaining an object rotation angle of the object model relative to the main light source on a reference horizontal plane according to the object orientation of the object model and the light source direction of the main light source;
[0152] When the object rotation angle is greater than a preset first angle threshold, adjusting a rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain a final camera angle of the depth camera.
[0153] In some embodiments of the present application, when the processor executes the computer program, the following steps are also implemented: determining an angle difference between the object rotation angle and the first angle threshold as a rotation angle adjustment amount of the depth camera on the reference horizontal plane; and adjusting the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount to obtain the final camera angle of the depth camera.
[0154] In some embodiments of the present application, when the processor executes the computer program, the following steps are also implemented: if the angle value of the object rotation angle is less than or equal to a preset second angle threshold, determining an angle difference between the object rotation angle and the first angle threshold as a rotation angle adjustment amount of the depth camera on the reference horizontal plane; if the angle value of the object rotation angle is greater than the second angle threshold, obtaining a ratio between a complementary angle corresponding to the object rotation angle and a complementary angle corresponding to the second angle threshold, and obtaining the rotation angle adjustment amount of the depth camera on the reference horizontal plane according to the ratio, the first angle threshold and the second angle threshold; and adjusting the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount to obtain the final camera angle of the depth camera.
[0155] In some embodiments of the present application, the processor, when executing the computer program, further implements the following steps: obtaining a first projection direction of an object orientation of the object model on a reference horizontal plane; obtaining a line direction of the object model pointing to the main light source, and a second projection direction of the line direction on the reference horizontal plane; if the first projection direction is on the right side of the second projection direction, controlling the rotation angle of the initial camera angle on the reference horizontal plane to rotate a rotation angle adjustment amount in the clockwise direction; if the first projection direction is on the left side of the second projection direction, controlling the rotation angle of the initial camera angle on the reference horizontal plane to rotate a rotation angle adjustment amount in the counterclockwise direction.
[0156] In some embodiments of the present application, the processor, when executing the computer program, further implements the following steps: performing a cross product operation on a first unit vector corresponding to the first projection direction and a second unit vector corresponding to the second projection direction to obtain a cross product result; when the cross product result is less than or equal to zero, determining that the first projection direction is on the right side of the second projection direction; when the cross product result is greater than zero, determining that the first projection direction is on the left side of the second projection direction.
[0157] In some embodiments of the present application, the processor, when executing the computer program, further implements the following steps: keeping the lens of the depth camera pointing to the object model, and controlling the depth camera to rotate horizontally around the object model on the reference horizontal plane according to the object rotation angle.
[0158] In some embodiments of the present application, the processor, when executing the computer program, further implements the following steps: obtaining a first projection direction of an object orientation of the object model on a reference horizontal plane; obtaining a line direction of the object model pointing to the main light source, and a second projection direction of the line direction on the reference horizontal plane; obtaining an object rotation angle of the object model relative to the main light source on the reference horizontal plane according to the first projection direction and the second projection direction.
[0159] In some embodiments of the present application, the processor, when executing the computer program, further implements the following steps: performing a dot product operation on a first unit vector corresponding to the first projection direction and a second unit vector corresponding to the second projection direction to obtain a dot product result; determining an angle value of an included angle between the first projection direction and the second projection direction according to the dot product result; and determining the angle value as the object rotation angle of the object model relative to the main light source.
[0160] In some embodiments of the present application, an electronic device is provided, comprising one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the following steps:
[0161] obtaining an object model in a virtual scene and a depth camera for the object model;
[0162] An angle of view of the depth camera is acquired, and the depth camera is controlled to acquire a depth map of the virtual scene at the angle of view; the angle of view of the depth camera is acquired by the method for acquiring an angle of view of a depth camera.
[0163] Depth information of the object model is acquired from the depth map, and real-time shadows of the object model are rendered based on the depth information.
[0164] In some embodiments of the present application, a computer readable storage medium is provided, which stores a computer program. When the computer program is loaded by a processor, the processor executes the following steps:
[0165] An object orientation of an object model in the virtual scene and a light source direction of a main light source are acquired;
[0166] An initial angle of view of the depth camera is determined according to a direction vector of the light source direction;
[0167] An object rotation angle of the object model relative to the main light source on a reference horizontal plane is acquired according to the object orientation of the object model and the light source direction of the main light source.
[0168] When the object rotation angle is greater than a preset first angle threshold, an angle of rotation of the initial angle of view of the depth camera on the reference horizontal plane is adjusted according to the object rotation angle, to obtain a final angle of view of the depth camera.
[0169] In some embodiments of the present application, when the computer program is executed by the processor, the following steps are further implemented: an angle difference between the object rotation angle and the first angle threshold is determined as an angle adjustment amount of the depth camera on the reference horizontal plane; and the angle of rotation of the initial angle of view on the reference horizontal plane is adjusted based on the angle adjustment amount, to obtain the final angle of view of the depth camera.
[0170] In some embodiments of the present application, when the computer program is executed by the processor, the following steps are further implemented: if an angle value of the object rotation angle is less than or equal to a preset second angle threshold, an angle difference between the object rotation angle and the first angle threshold is determined as an angle adjustment amount of the depth camera on the reference horizontal plane; if the angle value of the object rotation angle is greater than the second angle threshold, a ratio between a complementary angle corresponding to the object rotation angle and a complementary angle corresponding to the second angle threshold is acquired, and the angle adjustment amount of the depth camera on the reference horizontal plane is acquired according to the ratio, the first angle threshold and the second angle threshold; and the angle of rotation of the initial angle of view on the reference horizontal plane is adjusted based on the angle adjustment amount, to obtain the final angle of view of the depth camera.
[0171] In some embodiments of the present application, the computer program, when executed by the processor, further implements the following steps: obtaining a first projection direction of an object orientation of the object model on a reference horizontal plane; obtaining a line direction of the object model pointing to the main light source, and a second projection direction of the line direction on the reference horizontal plane; if the first projection direction is on the right side of the second projection direction, rotating the rotation angle of the initial camera angle on the reference horizontal plane in the clockwise direction by the rotation angle adjustment amount; if the first projection direction is on the left side of the second projection direction, rotating the rotation angle of the initial camera angle on the reference horizontal plane in the counterclockwise direction by the rotation angle adjustment amount.
[0172] In some embodiments of the present application, the computer program, when executed by the processor, further implements the following steps: performing cross product operation on the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction to obtain a cross product result; when the cross product result is less than or equal to zero, determining that the first projection direction is on the right side of the second projection direction; when the cross product result is greater than zero, determining that the first projection direction is on the left side of the second projection direction.
[0173] In some embodiments of the present application, the computer program, when executed by the processor, further implements the following steps: keeping the lens of the depth camera pointing to the object model, and controlling the depth camera to rotate horizontally around the object model on the reference horizontal plane according to the object rotation angle.
[0174] In some embodiments of the present application, the computer program, when executed by the processor, further implements the following steps: obtaining a first projection direction of an object orientation of the object model on a reference horizontal plane; obtaining a line direction of the object model pointing to the main light source, and a second projection direction of the line direction on the reference horizontal plane; obtaining an object rotation angle of the object model relative to the main light source on the reference horizontal plane according to the first projection direction and the second projection direction.
[0175] In some embodiments of the present application, the computer program, when executed by the processor, further implements the following steps: performing dot product operation on the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction to obtain a dot product result; determining an angle value of an included angle between the first projection direction and the second projection direction according to the dot product result; and determining the angle value as the object rotation angle of the object model relative to the main light source.
[0176] In some embodiments of the present application, a computer readable storage medium is provided, which stores a computer program, and the computer program is loaded by a processor to make the processor execute the following steps:
[0177] obtaining an object model in a virtual scene and a depth camera for the object model;
[0178] An angle of view of the depth camera is acquired, and the depth camera is controlled to acquire a depth map of the virtual scene at the angle of view; the angle of view of the depth camera is acquired by the method for acquiring an angle of view of a depth camera.
[0179] Depth information of the object model is acquired from the depth map, and real-time shadows of the object model are rendered based on the depth information.
[0180] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware, and the computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, storage, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. The non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. The volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory. As an illustration but not limitation, the RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc.
[0181] The technical features of the above embodiments can be combined in any way. To make the description concise, not all possible combinations of the technical features in the above embodiments are described, but as long as the combinations of the technical features do not exist contradictions, they should be considered as the scope of the present application.
[0182] The above describes in detail a depth camera angle of view acquisition method, device, computer device and storage medium provided by the embodiments of the present application. The principles and implementation manners of the present application are described by applying specific examples. The above embodiment descriptions are only used to help understand the method and core idea of the present application. Meanwhile, for those skilled in the art, the specific implementation manners and application range can be changed according to the idea of the present application. The above description should not be understood as a limitation of the present application.
Claims
1. A method for obtaining the camera angle of a depth camera, characterized in that, The method comprises: acquiring an object orientation of an object model in a virtual scene and a light source direction of a main light source; determining an initial camera angle of a depth camera according to a direction vector of the light source direction, wherein the depth camera is used to acquire a depth map used for rendering a shadow effect of the object model; acquiring an object rotation angle of the object model relative to the main light source on a reference horizontal plane according to the object orientation of the object model and the light source direction of the main light source; when the object rotation angle is greater than a preset first angle threshold, adjusting a rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain a final camera angle of the depth camera.
2. The method of claim 1, wherein, The step of adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain the final camera angle of the depth camera comprises: determining an angle difference between the object rotation angle and the first angle threshold as a rotation angle adjustment amount of the depth camera on the reference horizontal plane; adjusting the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount to obtain the final camera angle of the depth camera.
3. The method of claim 1, wherein, The step of adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain the final camera angle of the depth camera comprises: if an angle value of the object rotation angle is less than or equal to a preset second angle threshold, determining an angle difference between the object rotation angle and the first angle threshold as a rotation angle adjustment amount of the depth camera on the reference horizontal plane; if the angle value of the object rotation angle is greater than the second angle threshold, acquiring a ratio between a complementary angle corresponding to the object rotation angle and a complementary angle corresponding to the second angle threshold, and acquiring the rotation angle adjustment amount of the depth camera on the reference horizontal plane according to the ratio, the first angle threshold and the second angle threshold; adjusting the rotation angle of the initial camera angle on the reference horizontal plane based on the rotation angle adjustment amount to obtain the final camera angle of the depth camera.
4. The method according to any one of claims 2 or 3, characterized in that, The step of adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain the final camera angle of the depth camera comprises: acquiring a first projection direction of the object orientation of the object model on the reference horizontal plane; acquiring a line direction of the object model pointing to the main light source and a second projection direction of the line direction on the reference horizontal plane; if the first projection direction is on the right side of the second projection direction, rotating the rotation angle of the initial camera angle on the reference horizontal plane in a clockwise direction by the rotation angle adjustment amount; if the first projection direction is on the left side of the second projection direction, rotating the rotation angle of the initial camera angle on the reference horizontal plane in a counterclockwise direction by the rotation angle adjustment amount.
5. The method of claim 4, wherein, The step of obtaining the line direction of the object model pointing to the main light source and the second projection direction of the line direction on the reference horizontal plane further comprises: Cross product operation is performed on the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction to obtain a cross product result; When the cross product result is less than or equal to zero, it is determined that the first projection direction is on the right side of the second projection direction; When the cross product result is greater than zero, it is determined that the first projection direction is on the left side of the second projection direction.
6. The method of claim 1, wherein, The step of adjusting the rotation angle of the initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle comprises: The lens of the depth camera is kept pointing to the object model, and the depth camera is controlled to rotate horizontally around the object model on the reference horizontal plane according to the object rotation angle.
7. The method of claim 1, wherein, The step of obtaining the object rotation angle of the object model on the reference horizontal plane relative to the main light source according to the object orientation of the object model and the light source direction of the main light source comprises: Obtaining the first projection direction of the object orientation of the object model on the reference horizontal plane; Obtaining the line direction of the object model pointing to the main light source and the second projection direction of the line direction on the reference horizontal plane; According to the first projection direction and the second projection direction, the object rotation angle of the object model on the reference horizontal plane relative to the main light source is obtained.
8. The method of claim 7, wherein, The step of obtaining the object rotation angle of the object model on the reference horizontal plane relative to the main light source according to the first projection direction and the second projection direction comprises: Dot product operation is performed on the first unit vector corresponding to the first projection direction and the second unit vector corresponding to the second projection direction to obtain a dot product result; According to the dot product result, the angle value of the included angle between the first projection direction and the second projection direction is determined; The angle value is determined as the object rotation angle of the object model relative to the main light source.
9. A shadow rendering method, characterized by, The method comprises: Obtaining an object model in a virtual scene and a depth camera for the object model; Obtaining a camera angle of the depth camera, and controlling the depth camera to obtain a depth map of the virtual scene at the camera angle; wherein the camera angle of the depth camera is obtained by the camera angle obtaining method of the depth camera of any one of claims 1 to 8; Obtaining depth information of the object model from the depth map, and rendering real-time shadows of the object model based on the depth information.
10. A device for acquiring the camera angle of a depth camera, characterized in that, The device comprises: A parameter obtaining module for obtaining the object orientation of an object model in a virtual scene and the light source direction of a main light source; A camera setting module for determining an initial camera angle of a depth camera according to the direction vector of the light source direction; wherein the depth camera is used to obtain a depth map for rendering shadow effects of the object model; The rotation angle obtaining module is configured to obtain an object rotation angle of the object model relative to the main light source on a reference horizontal plane according to an object orientation of the object model and a light source direction of the main light source. The camera angle adjusting module is configured to adjust an initial camera angle of the depth camera on the reference horizontal plane according to the object rotation angle to obtain a final camera angle of the depth camera when the object rotation angle is greater than a preset first angle threshold.
11. A shadow rendering apparatus, characterized by comprising: The apparatus comprises: An object model obtaining module is configured to obtain an object model in a virtual scene and a depth camera for the object model. A camera angle obtaining module is configured to obtain a camera angle of the depth camera, and control the depth camera to obtain a depth map of the virtual scene at the camera angle; wherein the camera angle of the depth camera is obtained by the camera angle obtaining apparatus of the depth camera. A shadow rendering module is configured to obtain depth information of the object model from the depth map, and render a real-time shadow of the object model based on the depth information.
12. An electronic device, comprising: The electronic device comprises: One or more processors; Memory; and One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the camera angle obtaining method of the depth camera or the shadow rendering method of claim 9.
13. A computer-readable storage medium, characterized in that, A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in the camera angle obtaining method of the depth camera or the steps in the shadow rendering method of claim 9.
Citation Information
Patent Citations
Face image processing method, device and electronic device
CN108229278A
Image processing device, image processing system, and image processing method
CN108886575A