A method and device for determining light source information of a virtual light source
By calculating the intersection point between the rays of the virtual light source and the outer surface and determining the light source direction, the problem of difficult to determine the light source information of the virtual light source is solved, and the rendering authenticity of the virtual scene is improved.
Patent Information
- Application Number
- CN202011075126.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-09
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2040-10-09
AI Technical Summary
The prior art is difficult to determine the light source information of virtual light sources with irregular shapes, which affects the authenticity rendering of virtual scenes.
By obtaining the world coordinates of the center point of the virtual light source and the alternative points of the spherical enclosure box surface, the intersection point of the ray and the outer surface of the virtual light source is calculated, and the direction of the light source at the intersection is determined.
The light source information determination of irregularly shaped virtual light sources is realized, and the rendering authenticity of virtual scenes is improved.
Smart Images

Figure CN114332203B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of virtual reality technology, and in particular to a method and device for determining light source information of a virtual light source. Background Art
[0002] With the rapid development of virtual reality technology, virtual light sources can be set in virtual scenes. For example, virtual light sources such as car taillights and street lights in virtual scenes. In order to achieve the authenticity of the virtual scene, it is necessary to first determine the light source information of the virtual light source. The light source information may include: the position of a point on the outer surface of the virtual light source and the light source direction at the point; then, according to the light source information of the virtual light source in the virtual scene, the virtual scene is rendered, which can provide users with a more realistic visual experience.
[0003] Currently, most virtual light sources are geometric models with regular shapes, such as spherical virtual light sources, rectangular surface virtual light sources, etc. In related technologies, for virtual light sources with regular shapes, light source information of the virtual light sources can be determined based on the shape of the virtual light sources themselves.
[0004] However, see Figure 1 The virtual scene shown is for Figure 1 For virtual light sources with irregular shapes, such as car lights, it is impossible to determine the light source information like spherical or rectangular virtual light sources. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method and device for determining light source information of a virtual light source, which can determine the light source information of a virtual light source of an irregular shape. The specific technical solution is as follows:
[0006] In a first aspect, in order to achieve the above-mentioned purpose, an embodiment of the present application discloses a method for determining light source information of a virtual light source, the method comprising:
[0007] Obtain the world coordinates of the center point of the virtual light source in the world coordinate system of the preset virtual scene;
[0008] Determine a candidate point on the surface of the spherical bounding box of the virtual light source, and obtain the candidate point world coordinates in the world coordinate system;
[0009] Based on the world coordinates of the center point and the world coordinates of the candidate point, calculating a ray starting from the candidate point and ending at the center point of the virtual light source, and determining an intersection point between the ray and the outer surface of the virtual light source;
[0010] Calculate the world coordinates of the intersection point in the world coordinate system;
[0011] The direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point is determined as the light source direction at the intersection point.
[0012] Optionally, the outer surface of the virtual light source is composed of a plurality of triangular facets;
[0013] The calculating, based on the world coordinates of the center point and the world coordinates of the candidate point, a ray starting from the candidate point and ending at the center point of the virtual light source, and determining an intersection point between the ray and the outer surface of the virtual light source, comprises:
[0014] Based on the world coordinates of the center point, the world coordinates of the candidate point and a ray tracing algorithm, determine the triangular facet to which the intersection point of a ray starting from the candidate point and ending at the center point of the virtual light source and the outer surface of the virtual light source belongs as the target triangular facet, as well as position parameters of the intersection point relative to the vertex of the target triangular facet;
[0015] The calculating the world coordinates of the intersection point in the world coordinate system includes:
[0016] Based on the vertex world coordinates of the vertices of the target triangle patch in the world coordinate system and the position parameter, the world coordinates of the intersection point in the world coordinate system are calculated.
[0017] Optionally, determining the direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point as the light source direction at the intersection point includes:
[0018] The direction of the normal vector pointing outside the virtual light source among the normal vectors of the target triangle patch is determined as the light source direction at the intersection point.
[0019] Optionally, before determining the candidate point on the surface of the spherical bounding box of the virtual light source and obtaining the candidate point world coordinates of the candidate point in the world coordinate system, the method further includes:
[0020] Obtain the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system;
[0021] A spherical bounding box with a center point of the circumscribed cuboid of the virtual light source as the sphere center and a length of a diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter is determined as the spherical bounding box of the virtual light source.
[0022] Optionally, obtaining the world coordinates of the center point of the virtual light source in a world coordinate system of a preset virtual scene includes:
[0023] Based on the coordinates of the center point of the virtual light source in the preset model coordinate system and the conversion relationship between the preset model coordinate system and the world coordinate system of the preset virtual scene, calculate the world coordinates of the center point of the virtual light source in the world coordinate system;
[0024] The step of obtaining the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system comprises:
[0025] Obtaining vertex model coordinates of the vertices of the circumscribed cuboid of the virtual light source in the preset model coordinate system;
[0026] Based on the vertex model coordinates and the conversion relationship, calculating the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system;
[0027] Based on the world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system, the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system is calculated.
[0028] Optionally, after determining the direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point as the light source direction at the intersection point, the method further includes:
[0029] The preset virtual scene is rendered based on the world coordinates of the intersection point and the direction of the light source at the intersection point.
[0030] In a second aspect, in order to achieve the above-mentioned purpose, an embodiment of the present application discloses a device for determining light source information of a virtual light source, the device comprising:
[0031] A center point world coordinate acquisition module is used to obtain the center point world coordinate of the virtual light source in the world coordinate system of the preset virtual scene;
[0032] A candidate point world coordinate acquisition module, used to determine a candidate point on the surface of the spherical bounding box of the virtual light source, and to acquire the candidate point world coordinate of the candidate point in the world coordinate system;
[0033] An intersection point determination module, used to calculate a ray starting from the candidate point and ending at the center point of the virtual light source based on the world coordinates of the center point and the world coordinates of the candidate point, and determine an intersection point between the ray and the outer surface of the virtual light source;
[0034] An intersection point world coordinate calculation module, used for calculating the intersection point world coordinates of the intersection point in the world coordinate system;
[0035] The light source direction determination module is used to determine the direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point as the light source direction at the intersection point.
[0036] Optionally, the outer surface of the virtual light source is composed of a plurality of triangular facets;
[0037] The intersection point determination module is specifically used to determine, based on the world coordinates of the center point, the world coordinates of the candidate point and the ray tracing algorithm, a triangular facet to which the intersection point of a ray starting from the candidate point and ending at the center point of the virtual light source and the outer surface of the virtual light source belongs, as a target triangular facet, and position parameters of the intersection point relative to the vertices of the target triangular facet;
[0038] The intersection point world coordinate calculation module is specifically used to calculate the intersection point world coordinates of the intersection point in the world coordinate system based on the vertex world coordinates of the vertices of the target triangle face in the world coordinate system and the position parameters.
[0039] Optionally, the light source direction determination module is specifically used to determine the direction of the normal vector of the target triangle patch that points outside the virtual light source as the light source direction at the intersection point.
[0040] Optionally, the device further comprises:
[0041] A length acquisition module, used for acquiring the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system before determining the candidate point on the surface of the spherical bounding box of the virtual light source and acquiring the world coordinate of the candidate point in the world coordinate system;
[0042] The spherical bounding box determination module is used to determine a spherical bounding box with the center point of the circumscribed cuboid of the virtual light source as the sphere center and the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter, as the spherical bounding box of the virtual light source.
[0043] Optionally, the center point world coordinate acquisition module is specifically used to calculate the center point world coordinates of the center point of the virtual light source in the world coordinate system based on the coordinates of the center point of the virtual light source in the preset model coordinate system and the conversion relationship between the preset model coordinate system and the world coordinate system of the preset virtual scene;
[0044] The length acquisition module comprises:
[0045] A vertex model coordinate acquisition submodule, used to acquire vertex model coordinates of the vertices of the circumscribed cuboid of the virtual light source in the preset model coordinate system;
[0046] A vertex world coordinate calculation submodule, used for calculating the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system based on the vertex model coordinates and the conversion relationship;
[0047] The length acquisition submodule is used to calculate the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system based on the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system.
[0048] Optionally, the device further comprises:
[0049] A rendering module is used to render the preset virtual scene based on the world coordinates of the intersection point and the light source direction at the intersection point after determining that the direction of the normal vector of the outer surface of the virtual light source points outside the virtual light source at the intersection point is used as the light source direction at the intersection point.
[0050] In another aspect of the implementation of the present application, in order to achieve the above-mentioned purpose, the embodiment of the present application further discloses an electronic device, the electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus;
[0051] The memory is used to store computer programs;
[0052] The processor is used to implement the method for determining light source information of a virtual light source as described in the first aspect above when executing the program stored in the memory.
[0053] In another aspect of the implementation of the present application, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is executed on a computer, the method for determining light source information of a virtual light source as described in the first aspect above is implemented.
[0054] In another aspect of the implementation of the present application, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method for determining light source information of a virtual light source described in the first aspect above.
[0055] An embodiment of the present application provides a method for determining light source information of a virtual light source, which obtains the world coordinates of the center point of the virtual light source in the world coordinate system of a preset virtual scene; determines an alternative point on the surface of a spherical bounding box of the virtual light source, and obtains the world coordinates of the alternative point in the world coordinate system; based on the world coordinates of the center point and the world coordinates of the alternative point, calculates a ray with the alternative point as the starting point and the center point of the virtual light source as the end point, and determines the intersection point of the ray with the outer surface of the virtual light source; calculates the world coordinates of the intersection point in the world coordinate system; determines the direction of the normal vector of the outer surface of the virtual light source at the intersection point, pointing outside the virtual light source, as the light source direction at the intersection point.
[0056] Based on the above processing, for an irregularly shaped virtual light source, combined with its spherical bounding box, the point on the outer surface of the virtual light source and the light source direction at the point can be determined, that is, the light source information of the irregularly shaped virtual light source can be determined.
[0057] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0059] Figure 1 A schematic diagram of a virtual scene;
[0060] Figure 2A is a schematic diagram of a light source direction of a spherical virtual light source;
[0061] Figure 2B is a schematic diagram of a virtual light source of an irregular shape;
[0062] Figure 3 A flowchart of a method for determining light source information of a virtual light source provided in an embodiment of the present application;
[0063] Figure 4 A flowchart of another method for determining light source information of a virtual light source provided in an embodiment of the present application;
[0064] Figure 5 A flowchart of another method for determining light source information of a virtual light source provided in an embodiment of the present application;
[0065] Figure 6 A flowchart of a method for determining a spherical bounding box in an embodiment of the present application;
[0066] Figure 7 Based on Figure 6 An example diagram of a spherical bounding box of a virtual light source determined by the process shown;
[0067] Figure 8 A flowchart of another method for determining light source information of a virtual light source provided in an embodiment of the present application;
[0068] Fig. 9 A structural diagram of a light source information determination device for a virtual light source provided in an embodiment of the present application;
[0069] Fig.10 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0071] In the related art, for a virtual light source with a regular shape, the light source information of the virtual light source can be determined based on the shape of the virtual light source itself.
[0072] For example, see Figure 2A , Figure 2A Schematic diagram of the light source direction of a spherical virtual light source. Figure 2A In the figure, R represents the radius of the spherical virtual light source, P is any point on the surface of the spherical virtual light source, and the normal vector at that point is The direction of the light source at that point.
[0073] However, for some virtual light sources with irregular shapes, for example, Figure 1 The headlights and Figure 2B Irregularly shaped virtual light sources in the image. Figure 2B The white light in the middle is an irregularly shaped virtual light source, and its 3D model and Figure 2B Since the shape of the virtual light source is irregular, in the related art, it is impossible to determine the light source information based on the shape of the virtual light source itself.
[0074] Based on this, the embodiment of the present application provides a method for determining light source information of a virtual light source, which can be applied to the fields of 3D virtual simulation, virtual reality target recognition, and autonomous driving. For example, in the fields of 3D virtual simulation and virtual reality, for a virtual scene containing a virtual light source, the method provided by the embodiment of the present application can be used to determine the light source information of one or more irregularly shaped virtual light sources in the virtual scene, and then the virtual scene can be rendered in combination with the light source information to achieve 3D image reconstruction.
[0075] For details, see Figure 3 , Figure 3 A flowchart of a method for determining light source information of a virtual light source provided in an embodiment of the present application, the method may include the following steps:
[0076] S301: Obtain the world coordinates of the center point of the virtual light source in the world coordinate system of a preset virtual scene.
[0077] S302: Determine candidate points on the surface of the spherical bounding box of the virtual light source, and obtain world coordinates of the candidate points in the world coordinate system.
[0078] S303: Based on the world coordinates of the center point and the world coordinates of the candidate point, a ray starting from the candidate point and ending at the center point of the virtual light source is calculated, and an intersection point between the ray and the outer surface of the virtual light source is determined.
[0079] S304: Calculate the world coordinates of the intersection point in the world coordinate system.
[0080] S305: Determine the direction of the normal vector of the outer surface of the virtual light source at the intersection point, pointing to the outside of the virtual light source, as the light source direction at the intersection point.
[0081] The method for determining the light source information of a virtual light source provided in an embodiment of the present application can determine, for an irregularly shaped virtual light source, a point on the outer surface of the virtual light source and the light source direction at the point in combination with its spherical bounding box, that is, it can determine the light source information of an irregularly shaped virtual light source.
[0082] For step S301, if the virtual light source is of regular shape, the center point of the virtual light source can be directly determined, for example, if the virtual light source is spherical, the center point of the virtual light source is the center of the sphere. If the virtual light source is of irregular shape, the center point of the smallest circumscribed cuboid of the virtual light source can be determined as the center point of the virtual light source.
[0083] For step S302, the candidate point may be any point on the surface of the spherical bounding box. Furthermore, the determined intersection point is any point on the outer surface of the virtual light source.
[0084] In one embodiment, the outer surface of the virtual light source can be composed of multiple triangular facets. Figure 4 , step S303 may include the following steps:
[0085] S3031: Based on the world coordinates of the center point, the world coordinates of the alternative point and the ray tracing algorithm, determine the triangle patch to which the intersection point of the ray with the alternative point as the starting point and the center point of the virtual light source and the outer surface of the virtual light source belongs, as the target triangle patch, and the position parameters of the intersection point relative to the vertex of the target triangle patch.
[0086] S304 may include:
[0087] S3041: Calculate the world coordinates of the intersection points in the world coordinate system based on the world coordinates of the vertices of the target triangle patch in the world coordinate system and the position parameters.
[0088] In the embodiment of the present application, in order to render a virtual scene including a virtual light source, a light source model of the virtual light source can be pre-established, the light source model can be composed of multiple triangular facets, and a coordinate system corresponding to the light source model can be generated (i.e., a preset model coordinate system in the embodiment of the present application). The origin of the preset model coordinate system can be the center point of the light source model.
[0089] Furthermore, a conversion relationship between the preset model coordinate system and the world coordinate system of the preset virtual scene can be established.
[0090] In one implementation, the preset model coordinate system can be translated and rotated to make the preset model coordinate system coincide with the world coordinate system. For example, the coordinate value of the origin of the preset model coordinate system can be added or subtracted to make the origin of the preset model coordinate system coincide with the origin of the world coordinate system.
[0091] Then, by rotating the preset model coordinate system, the preset model coordinate system is made to coincide with the world coordinate system. For example, if the coordinate value of a point in space in the preset model coordinate system is (A, B, C), and the coordinate value in the world coordinate system is (a, b, c), then we can get:
[0092] a=A*Cos(x,x')+B*Cos(y,x')+B*Cos(z,x')
[0093] b=A*Cos(x,y')+B*Cos(y,y')+B*Cos(z,y')
[0094] c=A*Cos(x,z')+B*Cos(y,z')+B*Cos(z,z')
[0095] Among them, (x,x') represents the angle between the x-axis of the preset model coordinate system and the x-axis of the world coordinate system, (y,x') represents the angle between the y-axis of the preset model coordinate system and the x-axis of the world coordinate system, (z,x') represents the angle between the z-axis of the preset model coordinate system and the x-axis of the world coordinate system, (x,y') represents the angle between the x-axis of the preset model coordinate system and the y-axis of the world coordinate system, (y,y') represents the angle between the y-axis of the preset model coordinate system and the y-axis of the world coordinate system, (z,y') represents the angle between the z-axis of the preset model coordinate system and the y-axis of the world coordinate system, (x,z') represents the angle between the x-axis of the preset model coordinate system and the z-axis of the world coordinate system, (y,z') represents the angle between the y-axis of the preset model coordinate system and the z-axis of the world coordinate system, and (z,z') represents the angle between the z-axis of the preset model coordinate system and the z-axis of the world coordinate system.
[0096] Based on the above processing, the conversion between the coordinate values in the preset model coordinate system and the coordinate values in the world coordinate system can be achieved.
[0097] In an embodiment of the present application, after determining the world coordinates of the center point and the world coordinates of the alternative point, it is possible to determine, based on a ray tracing algorithm, a ray with the alternative point as the starting point and the center point of the virtual light source as the end point, and determine the triangle patch (i.e., the target triangle patch) to which the intersection point of the ray and the outer surface of the virtual light source belongs, and it is also possible to determine the position parameters of the intersection point relative to the vertex of the target triangle patch.
[0098] For example, the three vertices of the target triangle patch are D1, D2 and D3 respectively, then the coordinate E of any point in the target triangle patch can be expressed as E=(1-uv)×D1+v×D2+u×D3. u and v represent the above position parameters.
[0099] Therefore, the coordinates of the three vertices of the target triangle patch in the world coordinate system can be obtained, and based on the above position parameters, the world coordinates of the intersection point in the world coordinate system (ie, the world coordinates of the intersection point) can be calculated.
[0100] In one implementation method, the coordinates of the vertices of each triangular face in a preset model coordinate system can be obtained in advance, and then, combined with the conversion relationship between the preset model coordinate system and the world coordinate system, the coordinates of the vertices of each triangular face in the world coordinate system can be obtained. Subsequently, when the target triangular face is determined, the coordinates of the vertices of the target triangular face in the world coordinate system can be directly obtained.
[0101] In one implementation, the target triangle face and position parameters may be determined by a ray tracing algorithm based on a GPU (Graphics Processing Unit), thereby improving the efficiency of ray tracing.
[0102] In one embodiment, Figure 3 Based on Figure 5 , S305 may include:
[0103] S3051: Determine the direction of the normal vector of the target triangle patch that points outside the virtual light source as the light source direction at the intersection point.
[0104] In an embodiment of the present application, after determining the target triangle patch, the normal vector of the target triangle patch can be calculated based on the world coordinates of the three vertices of the target triangle patch, and then, the direction of the normal vector pointing outside the virtual light source can be determined as the light source direction at the intersection point.
[0105] In one embodiment, see Figure 6 , the method may further include the following steps:
[0106] S601: Obtain the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system.
[0107] S602: Determine a spherical bounding box with a center point of a circumscribed cuboid of the virtual light source as the sphere center and a length of a diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter as the spherical bounding box of the virtual light source.
[0108] In an embodiment of the present application, a spherical bounding box of a virtual light source may be predetermined. In one implementation, a minimum circumscribed cuboid of the virtual light source may be determined, and then the length of the diagonal of the circumscribed cuboid in the world coordinate system may be calculated.
[0109] Then, a spherical bounding box with the center point of the circumscribed cuboid as the sphere center and the length of the diagonal of the circumscribed cuboid in the world coordinate system as the diameter can be determined.
[0110] For example, see Figure 7 , Figure 7 Based on Figure 6 An example diagram of the spherical bounding box of the virtual light source determined by the process shown.
[0111] Figure 7 In the figure, the bottle represents a virtual light source, R represents half the length of the diagonal of the smallest circumscribed cuboid of the virtual light source, O represents the center point of the smallest circumscribed cuboid, P represents an alternative point, and Q represents an intersection point.
[0112] In one embodiment, S301 may include the following steps: based on the coordinates of the center point of the virtual light source in the preset model coordinate system and the conversion relationship between the preset model coordinate system and the world coordinate system of the preset virtual scene, calculate the world coordinates of the center point of the virtual light source in the world coordinate system.
[0113] Accordingly, S601 may include the following steps:
[0114] Step 1: Obtain the vertex model coordinates of the vertices of the circumscribed cuboid of the virtual light source in a preset model coordinate system.
[0115] Step 2: Based on the vertex model coordinates and the transformation relationship, calculate the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system.
[0116] Step three, based on the world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system, calculate the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system.
[0117] In an embodiment of the present application, the coordinates of the center point of the virtual light source in the preset model coordinate system can be obtained. If the virtual light source is a regular shape, the center point of the virtual light source can be directly determined. For example, if the virtual light source is a sphere, the center point of the virtual light source is the center of the sphere. If the virtual light source is an irregular shape, the center point of the smallest circumscribed cuboid of the virtual light source can be determined as the center point of the virtual light source.
[0118] Furthermore, based on the conversion relationship between the preset model coordinate system and the world coordinate system, the world coordinates of the center point of the virtual light source can be calculated.
[0119] Correspondingly, the vertex model coordinates of the vertices of the circumscribed cuboid of the virtual light source in the preset model coordinate system may also be obtained, and the vertex world coordinates of the vertices of the circumscribed cuboid in the world coordinate system may be calculated according to the above conversion relationship.
[0120] Furthermore, the distance between the two vertices at both ends of the diagonal line can be calculated as the length of the diagonal line of the circumscribed cuboid.
[0121] In one embodiment, see Figure 8 After step S305, the method may further include the following steps:
[0122] S306: Rendering a preset virtual scene based on the world coordinates of the intersection point and the direction of the light source at the intersection point.
[0123] In the embodiment of the present application, after the intersection point and the direction of the light source at the intersection point are determined, the virtual scene can be rendered based on the determined information. For example, based on the intersection point and the direction of the light source at the intersection point, the shadow part and the highlight part in the virtual scene can be determined, thereby ensuring the authenticity of the virtual scene.
[0124] In practical applications, for example, multiple light rays can be traced simultaneously based on a ray tracing algorithm. The number of light rays can be the number of pixels in the image of the virtual scene that needs to be output. Then, multiple intersection points in the virtual light source and the corresponding light source directions can be determined. Accordingly, the shadows in the virtual scene can be detected based on the intersection points and the corresponding light source directions. Subsequently, the rendering of the virtual scene can be completed based on the detected shadows.
[0125] Based on the same inventive concept, the embodiment of the present application also provides a light source information determination device for a virtual light source, see Fig. 9 , Fig. 9 A structural diagram of a device for determining light source information of a virtual light source provided in an embodiment of the present application, the device comprising:
[0126] A center point world coordinate acquisition module 901 is used to acquire the center point world coordinate of the virtual light source in the world coordinate system of the preset virtual scene;
[0127] A candidate point world coordinate acquisition module 902 is used to determine a candidate point on the surface of the spherical bounding box of the virtual light source, and to acquire the candidate point world coordinate of the candidate point in the world coordinate system;
[0128] An intersection point determination module 903 is used to calculate a ray starting from the candidate point and ending at the center point of the virtual light source based on the world coordinates of the center point and the world coordinates of the candidate point, and determine an intersection point between the ray and the outer surface of the virtual light source;
[0129] An intersection point world coordinate calculation module 904, used to calculate the intersection point world coordinates of the intersection point in the world coordinate system;
[0130] The light source direction determination module 905 is used to determine the direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point as the light source direction at the intersection point.
[0131] Optionally, the outer surface of the virtual light source is composed of a plurality of triangular facets;
[0132] The intersection point determination module 903 is specifically used to determine, based on the world coordinates of the center point, the world coordinates of the candidate point and the ray tracing algorithm, a triangular face to which the intersection point of a ray starting from the candidate point and ending at the center point of the virtual light source and the outer surface of the virtual light source belongs, as a target triangular face, and position parameters of the intersection point relative to the vertices of the target triangular face;
[0133] The intersection point world coordinate calculation module 904 is specifically used to calculate the intersection point world coordinates of the intersection point in the world coordinate system based on the vertex world coordinates of the vertices of the target triangle patch in the world coordinate system and the position parameters.
[0134] Optionally, the light source direction determining module 905 is specifically configured to determine the direction of the normal vector of the target triangle patch that points outside the virtual light source as the light source direction at the intersection point.
[0135] Optionally, the device further comprises:
[0136] A length acquisition module, used for acquiring the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system before determining the candidate point on the surface of the spherical bounding box of the virtual light source and acquiring the world coordinate of the candidate point in the world coordinate system;
[0137] The spherical bounding box determination module is used to determine a spherical bounding box with the center point of the circumscribed cuboid of the virtual light source as the sphere center and the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter, as the spherical bounding box of the virtual light source.
[0138] Optionally, the center point world coordinate acquisition module 901 is specifically used to calculate the center point world coordinates of the center point of the virtual light source in the world coordinate system based on the coordinates of the center point of the virtual light source in the preset model coordinate system and the conversion relationship between the preset model coordinate system and the world coordinate system of the preset virtual scene;
[0139] The length acquisition module comprises:
[0140] A vertex model coordinate acquisition submodule, used to acquire vertex model coordinates of the vertices of the circumscribed cuboid of the virtual light source in the preset model coordinate system;
[0141] A vertex world coordinate calculation submodule, used for calculating the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system based on the vertex model coordinates and the conversion relationship;
[0142] The length acquisition submodule is used to calculate the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system based on the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system.
[0143] Optionally, the device further comprises:
[0144] A rendering module is used to render the preset virtual scene based on the world coordinates of the intersection point and the light source direction at the intersection point after determining that the direction of the normal vector of the outer surface of the virtual light source points outside the virtual light source at the intersection point is used as the light source direction at the intersection point.
[0145] The present application also provides an electronic device, such as Fig.10 As shown, it includes a processor 1001, a communication interface 1002, a memory 1003 and a communication bus 1004, wherein the processor 1001, the communication interface 1002, and the memory 1003 communicate with each other through the communication bus 1004.
[0146] Memory 1003, used for storing computer programs;
[0147] The processor 1001 is used to execute the program stored in the memory 1003, and implements the following steps:
[0148] Obtain the world coordinates of the center point of the virtual light source in the world coordinate system of the preset virtual scene;
[0149] Determine a candidate point on the surface of the spherical bounding box of the virtual light source, and obtain the candidate point world coordinates in the world coordinate system;
[0150] Based on the world coordinates of the center point and the world coordinates of the candidate point, calculating a ray starting from the candidate point and ending at the center point of the virtual light source, and determining an intersection point between the ray and the outer surface of the virtual light source;
[0151] Calculate the world coordinates of the intersection point in the world coordinate system;
[0152] The direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point is determined as the light source direction at the intersection point.
[0153] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0154] The communication interface is used for communication between the above electronic device and other devices.
[0155] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0156] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0157] The electronic device provided in the embodiment of the present application can determine, for an irregularly shaped virtual light source, a point on the outer surface of the virtual light source and the light source direction at the point in combination with its spherical bounding box, that is, it can determine the light source information of the irregularly shaped virtual light source.
[0158] The embodiment of the present application further provides a computer-readable storage medium, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the method for determining light source information of a virtual light source provided in the embodiment of the present application.
[0159] Specifically, the method for determining light source information of the virtual light source includes:
[0160] Obtain the world coordinates of the center point of the virtual light source in the world coordinate system of the preset virtual scene;
[0161] Determine a candidate point on the surface of the spherical bounding box of the virtual light source, and obtain the candidate point world coordinates in the world coordinate system;
[0162] Based on the world coordinates of the center point and the world coordinates of the candidate point, calculating a ray starting from the candidate point and ending at the center point of the virtual light source, and determining an intersection point between the ray and the outer surface of the virtual light source;
[0163] Calculate the world coordinates of the intersection point in the world coordinate system;
[0164] The direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point is determined as the light source direction at the intersection point.
[0165] It should be noted that other implementations of the method for determining the light source information of the virtual light source are partially the same as those of the aforementioned method embodiment, and will not be described in detail here.
[0166] By running the instructions stored in the computer-readable storage medium provided in the embodiment of the present application, for an irregularly shaped virtual light source, combined with its spherical bounding box, it is possible to determine the point on the outer surface of the virtual light source and the direction of the light source at the point, that is, the light source information of the irregularly shaped virtual light source can be determined.
[0167] The embodiment of the present application also provides another computer program product including instructions, which, when executed on a computer, enables the computer to execute the method for determining light source information of a virtual light source provided in the embodiment of the present application.
[0168] Specifically, the method for determining light source information of the virtual light source includes:
[0169] Obtain the world coordinates of the center point of the virtual light source in the world coordinate system of the preset virtual scene;
[0170] Determine a candidate point on the surface of the spherical bounding box of the virtual light source, and obtain the candidate point world coordinates in the world coordinate system;
[0171] Based on the world coordinates of the center point and the world coordinates of the candidate point, calculating a ray starting from the candidate point and ending at the center point of the virtual light source, and determining an intersection point between the ray and the outer surface of the virtual light source;
[0172] Calculate the world coordinates of the intersection point in the world coordinate system;
[0173] The direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point is determined as the light source direction at the intersection point.
[0174] It should be noted that other implementations of the method for determining the light source information of the virtual light source are partially the same as those of the aforementioned method embodiment, and will not be described in detail here.
[0175] By running the computer program product provided by the embodiment of the present application, for an irregularly shaped virtual light source, combined with its spherical bounding box, the point on the outer surface of the virtual light source and the light source direction at the point can be determined, that is, the light source information of the irregularly shaped virtual light source can be determined.
[0176] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0177] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0178] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, computer-readable storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0179] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A method for determining light source information of a virtual light source, characterized in that: The method comprises: Obtain the world coordinates of the center point of the virtual light source in the world coordinate system of the preset virtual scene; Determine candidate points on the surface of the spherical bounding box of the virtual light source, and obtain the candidate point world coordinates of the candidate point in the world coordinate system; wherein the spherical bounding box surface is the surface of the spherical bounding box of the virtual light source; the spherical bounding box of the virtual light source is: a spherical bounding box with the center point of the circumscribed cuboid of the virtual light source as the sphere center and the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter; Based on the world coordinates of the center point and the world coordinates of the candidate point, calculating a ray starting from the candidate point and ending at the center point of the virtual light source, and determining an intersection point between the ray and the outer surface of the virtual light source; Calculate the world coordinates of the intersection point in the world coordinate system; The direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point is determined as the light source direction at the intersection point.
2. The method according to claim 1, characterized in that: The outer surface of the virtual light source is composed of a plurality of triangular facets; The calculating, based on the world coordinates of the center point and the world coordinates of the candidate point, a ray starting from the candidate point and ending at the center point of the virtual light source, and determining an intersection point between the ray and the outer surface of the virtual light source, comprises: Based on the world coordinates of the center point, the world coordinates of the candidate point and a ray tracing algorithm, determine the triangular facet to which the intersection point of a ray starting from the candidate point and ending at the center point of the virtual light source and the outer surface of the virtual light source belongs as the target triangular facet, as well as position parameters of the intersection point relative to the vertex of the target triangular facet; The calculating the world coordinates of the intersection point in the world coordinate system includes: Based on the vertex world coordinates of the vertices of the target triangle patch in the world coordinate system and the position parameter, the world coordinates of the intersection point in the world coordinate system are calculated.
3. The method according to claim 2, characterized in that The step of determining the direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point as the light source direction at the intersection point includes: The direction of the normal vector pointing outside the virtual light source among the normal vectors of the target triangle patch is determined as the light source direction at the intersection point.
4. The method according to claim 1, characterized in that: Before determining the candidate points on the surface of the spherical bounding box of the virtual light source and obtaining the world coordinates of the candidate points in the world coordinate system, the method further includes: Obtain the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system; A spherical bounding box with a center point of the circumscribed cuboid of the virtual light source as the sphere center and a length of a diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter is determined as the spherical bounding box of the virtual light source.
5. The method according to claim 4, characterized in that The step of obtaining the world coordinates of the center point of the virtual light source in the world coordinate system of the preset virtual scene includes: Based on the coordinates of the center point of the virtual light source in the preset model coordinate system and the conversion relationship between the preset model coordinate system and the world coordinate system of the preset virtual scene, calculate the world coordinates of the center point of the virtual light source in the world coordinate system; The step of obtaining the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system comprises: Obtaining vertex model coordinates of the vertices of the circumscribed cuboid of the virtual light source in the preset model coordinate system; Based on the vertex model coordinates and the conversion relationship, calculating the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system; Based on the world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system, the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system is calculated.
6. The method according to claim 1, characterized in that After determining the direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point as the light source direction at the intersection point, the method further includes: The preset virtual scene is rendered based on the world coordinates of the intersection point and the direction of the light source at the intersection point.
7. A device for determining light source information of a virtual light source, characterized in that: The device comprises: A center point world coordinate acquisition module is used to obtain the center point world coordinate of the virtual light source in the world coordinate system of the preset virtual scene; A candidate point world coordinate acquisition module is used to determine candidate points on the surface of the spherical bounding box of the virtual light source, and obtain the candidate point world coordinates of the candidate points in the world coordinate system; wherein the spherical bounding box surface is the surface of the spherical bounding box of the virtual light source; the spherical bounding box of the virtual light source is: a spherical bounding box with the center point of the circumscribed cuboid of the virtual light source as the sphere center and the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter; An intersection point determination module, used to calculate a ray starting from the candidate point and ending at the center point of the virtual light source based on the world coordinates of the center point and the world coordinates of the candidate point, and determine an intersection point between the ray and the outer surface of the virtual light source; An intersection point world coordinate calculation module, used for calculating the intersection point world coordinates of the intersection point in the world coordinate system; The light source direction determination module is used to determine the direction of the normal vector of the outer surface of the virtual light source pointing outside the virtual light source at the intersection point as the light source direction at the intersection point.
8. The device according to claim 7, characterized in that The outer surface of the virtual light source is composed of a plurality of triangular facets; The intersection point determination module is specifically used to determine, based on the world coordinates of the center point, the world coordinates of the candidate point and the ray tracing algorithm, a triangular facet to which the intersection point of a ray starting from the candidate point and ending at the center point of the virtual light source and the outer surface of the virtual light source belongs, as a target triangular facet, and position parameters of the intersection point relative to the vertices of the target triangular facet; The intersection point world coordinate calculation module is specifically used to calculate the intersection point world coordinates of the intersection point in the world coordinate system based on the vertex world coordinates of the vertices of the target triangle face in the world coordinate system and the position parameters.
9. The device according to claim 8, characterized in that The light source direction determination module is specifically used to determine the direction of the normal vector of the target triangle patch that points outside the virtual light source as the light source direction at the intersection point.
10. The device according to claim 7, characterized in that The device also includes: A length acquisition module, used for acquiring the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system before determining the candidate point on the surface of the spherical bounding box of the virtual light source and acquiring the world coordinate of the candidate point in the world coordinate system; The spherical bounding box determination module is used to determine a spherical bounding box with the center point of the circumscribed cuboid of the virtual light source as the sphere center and the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system as the diameter, as the spherical bounding box of the virtual light source.
11. The device according to claim 10, characterized in that The center point world coordinate acquisition module is specifically used to calculate the center point world coordinates of the center point of the virtual light source in the world coordinate system based on the coordinates of the center point of the virtual light source in the preset model coordinate system and the conversion relationship between the preset model coordinate system and the world coordinate system of the preset virtual scene; The length acquisition module comprises: A vertex model coordinate acquisition submodule, used to acquire vertex model coordinates of the vertices of the circumscribed cuboid of the virtual light source in the preset model coordinate system; A vertex world coordinate calculation submodule, used for calculating the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system based on the vertex model coordinates and the conversion relationship; The length acquisition submodule is used to calculate the length of the diagonal of the circumscribed cuboid of the virtual light source in the world coordinate system based on the vertex world coordinates of the vertices of the circumscribed cuboid of the virtual light source in the world coordinate system.
12. The device according to claim 7, characterized in that The device also includes: A rendering module is used to render the preset virtual scene based on the world coordinates of the intersection point and the light source direction at the intersection point after determining that the direction of the normal vector of the outer surface of the virtual light source points outside the virtual light source at the intersection point is used as the light source direction at the intersection point.
13. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the method steps described in any one of claims 1-6 when executing the program stored in the memory.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Real point light source position calculation method based on plane surface high-dynamic range image
CN106157321A
Light source estimation method and device based on multiple spheres and intelligent electronic device
CN106840389A