Method, device, computer readable storage medium and electronic device for rendering an object
By identifying multiple highlight regions in a two-dimensional mobile game and calculating highlight parameters in parallel, the problem of a single highlight style was solved, resulting in a rich variety of highlight styles and enhancing the game's visual effects.
Patent Information
- Application Number
- CN202111615356.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2041-12-27
AI Technical Summary
In existing technologies, the specular rendering style of objects in anime-style mobile games is monotonous, resulting in similar game styles and a lack of diversity.
By determining the first and second specular regions of the object to be rendered and obtaining their respective specular parameters, the specular reflection model is used to calculate the specular results in parallel. Combined with adjustment coefficients, shading processing is performed to generate diverse specular effects.
It enables a rich variety of specular styles for the objects to be rendered, enhancing the game's visual effects and user experience.
Smart Images

Figure CN114419223B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision, and more specifically, to a method, apparatus, computer-readable storage medium, and electronic device for rendering objects. Background Technology
[0002] In the mobile game market, anime-style games have captured a significant share. These games emphasize stylized effects, and the easiest way to express this style is through the highlights created by reflections on objects. Currently, most anime-style mobile games use the same calculation method to render highlights, resulting in a monotonous highlight style and a similar overall aesthetic across the genre.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] The present invention provides a method, apparatus, computer-readable storage medium, and electronic device for rendering objects, so as to at least solve the technical problem of the monotonous specular style of the object to be rendered due to the monotonous calculation method of specular ...
[0005] According to one aspect of the present invention, a method for rendering an object is provided, comprising: determining a first specular region of an object to be rendered and determining a second specular region within the first specular region; obtaining a first specular parameter corresponding to the first specular region; determining a second specular parameter corresponding to the second specular region based on the first specular parameter; and performing shading processing on the object to be rendered based on the first specular parameter and the second specular parameter to obtain a target rendering object.
[0006] Furthermore, the method for rendering an object also includes: obtaining parameter information corresponding to the object to be rendered, wherein the parameter information includes at least one of the following: environment information, material information; determining a first adjustment coefficient based on the parameter information; and calculating the product of a first specular parameter and the first adjustment coefficient to obtain a second specular parameter.
[0007] Furthermore, the method for rendering the object also includes: obtaining a specular reflection model, wherein the specular reflection model characterizes the intensity of light reflected by the object to be rendered; calculating in parallel the first specular parameter and the second specular parameter under the specular reflection model, and the first specular result and the second specular result; and performing color processing on the first specular region and the second specular region based on the first specular result and the second specular result respectively to obtain the target rendering object.
[0008] Furthermore, the method for rendering objects also includes: determining the lighting direction and camera view direction of the scene where the object to be rendered is located before obtaining the specular reflection model; determining the half-angle vector corresponding to the scene based on the lighting direction and camera view direction; determining the surface normal direction and specular parameters of the object to be rendered; and constructing a specular reflection model based on the half-angle vector, surface normal direction, and specular parameters.
[0009] Furthermore, the method for rendering an object also includes: determining a second adjustment coefficient based on the target rendering result corresponding to the object to be rendered; determining a first brightness value from a first specular result and a second brightness value from a second specular result; adjusting the first brightness value based on the comparison result between the first brightness value and the second adjustment coefficient to obtain a first target brightness value; adjusting the second brightness value based on the comparison result between the second brightness value and the second adjustment coefficient to obtain a second target brightness value; performing color processing on the first specular region based on the first target brightness value and performing color processing on the second specular region based on the second target brightness value to obtain the target rendering object.
[0010] Furthermore, the method for rendering the object also includes: when the first brightness value is greater than or equal to the second adjustment coefficient value, determining the first target brightness value as a first value; when the first brightness value is less than the second adjustment coefficient, determining the first target brightness value as a second value, wherein the first value is greater than the second value.
[0011] Furthermore, the method for rendering the object also includes: when the second brightness value is greater than or equal to the second adjustment coefficient, determining the second target brightness value as a first value; when the second brightness value is less than the second adjustment coefficient, determining the second target brightness value as a second value, wherein the first value is greater than the second value.
[0012] Furthermore, the method for rendering an object also includes: obtaining the lighting information of the scene where the object to be rendered is located; determining the first region information of the first specular region on the object to be rendered based on the lighting information, wherein the first region information includes at least one of the following: the position information and shape of the first specular region; determining the second region information of the second specular region on the object to be rendered based on the lighting information, wherein the second region information includes at least one of the following: the position information and shape of the second specular region.
[0013] According to another aspect of the present invention, an apparatus for rendering an object is also provided, comprising: a first determining module, configured to determine a first specular region of an object to be rendered and to determine a second specular region within the first specular region; an acquiring module, configured to acquire a first specular parameter corresponding to the first specular region; a second determining module, configured to determine a second specular parameter corresponding to the second specular region based on the first specular parameter; and a rendering module, configured to perform color processing on the object to be rendered based on the first specular parameter and the second specular parameter to obtain a target rendering object.
[0014] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-described method for rendering an object at runtime.
[0015] According to another aspect of the present invention, an electronic device is also provided, the electronic device including one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement a method for running the programs, wherein the programs are configured to execute the above-described method for rendering objects during runtime.
[0016] In this embodiment of the invention, two specular styles are used to colorize the object to be rendered in order to obtain the target rendering object. The first specular region of the object to be rendered is determined and the second specular region is determined within the first specular region. Then, the first specular parameter corresponding to the first specular region is obtained. Next, the second specular parameter corresponding to the second specular region is determined based on the first specular parameter. Finally, the object to be rendered is colored based on the first specular parameter and the second specular parameter to obtain the target rendering object.
[0017] In the above process, by determining the first highlight region and the second highlight region within the first highlight region of the object to be rendered, the number of highlights of the object in the same display area is increased, thus laying the foundation for a richer highlight style. Furthermore, by obtaining the first highlight parameter and the second highlight parameter, the style of the first highlight region and the style of the second highlight region are determined. Due to the difference between the first highlight parameter and the second highlight parameter, the styles of the first highlight region and the second highlight region are also different. Consequently, when the object to be rendered is shading based on the first highlight parameter and the second highlight parameter, two highlights with different highlight styles will be generated in the same display area of the object, thus enriching the highlight style of the object to be rendered.
[0018] Therefore, the solution provided in this application achieves the purpose of using two specular styles to color the object to be rendered in order to obtain the target object to be rendered, thereby realizing a rich technical effect of specular style of the object to be rendered, and thus solving the technical problem of the single specular style of the object to be rendered caused by the single calculation method of specular highlights of the object to be rendered in the prior art. Attached Figure Description
[0019] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0020] Figure 1 This is a schematic diagram of an optional method for rendering an object according to an embodiment of the present invention;
[0021] Figure 2 This is a schematic diagram of an optional illumination direction, surface normal direction, camera viewing angle direction, and half-angle vector according to an embodiment of the present invention;
[0022] Figure 3 This is a schematic diagram of an optional first highlight region according to an embodiment of the present invention;
[0023] Figure 4 This is a schematic diagram of an optional first highlight region adjusted based on a second adjustment coefficient according to an embodiment of the present invention;
[0024] Figure 5 This is a schematic diagram of an optional first highlight region and a second highlight region adjusted based on a second adjustment coefficient according to an embodiment of the present invention;
[0025] Figure 6 This is a schematic diagram of an optional object rendering device according to an embodiment of the present invention. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] Example 1
[0029] According to an embodiment of the present invention, a method embodiment for rendering an object is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0030] Figure 1 This is a schematic diagram of an optional method for rendering an object according to an embodiment of the present invention, such as... Figure 1 As shown, the method includes the following steps:
[0031] Step S102: Determine the first highlight region of the object to be rendered and determine the second highlight region within the first highlight region.
[0032] In step S102, a first highlight region of the object to be rendered and a second highlight region can be determined within the first highlight region by means of electronic devices, application systems, computing devices, etc. In this embodiment, the first highlight region and the second highlight region of the object to be rendered are determined by means of computing devices.
[0033] Optionally, the computing device can determine the position and shape information of the first and second specular highlight regions based on the lighting information of the scene where the object to be rendered is located and the structural feature information of the object to be rendered. The position information can represent a specific range or a point, and the shape information can represent the shape of the specular highlight. The first specular highlight region represents the area on the object to be rendered used to display specular highlights, and the second specular highlight region represents the area on the object to be rendered used to display specular highlights different from those in the first specular highlight region, and the second specular highlight region is displayed within the first specular highlight region. The object to be rendered can be a complete object or one of multiple structures that make up a complete object.
[0034] Optionally, the computing device can also determine the position and shape information of the first and second highlight regions by acquiring information input manually. The information input manually may include the coordinates of the target position or the target range corresponding to the target position, and may also include a highlight map to define the shape information of the first and second highlight regions.
[0035] It should be noted that, compared to the single specular highlight in existing technologies, by determining the first specular highlight area of the object to be rendered and the second specular highlight area within the first specular highlight area, the number of specular highlights of the object to be rendered in the same display area is increased, thereby facilitating the subsequent enrichment of specular highlight styles.
[0036] Step S104: Obtain the first highlight parameters corresponding to the first highlight region.
[0037] In step S104, the computing device can obtain a first specular parameter based on manually input information. The first specular parameter includes at least the parameter value corresponding to the specular sharpness parameter shinness. The shinness parameter describes the roughness of the object's surface. The value of the shinness parameter can affect the size of the specular area. A larger shinness parameter value indicates a higher gloss level of the object to be rendered, with more concentrated reflected specular light, resulting in a smaller specular area. Conversely, a smaller shinness parameter value indicates a lower gloss level of the object to be rendered, with more dispersed reflected specular light, resulting in a larger specular area.
[0038] It should be noted that by obtaining the first highlight parameters corresponding to the first highlight region, the size of the first highlight region is determined, thereby determining the calculation method of the first highlight region, that is, determining the style of the first highlight region.
[0039] Step S106: Determine the second highlight parameter corresponding to the second highlight region based on the first highlight parameter.
[0040] In step S106, the second specular parameter also includes at least the parameter value corresponding to the specular sharpness parameter shinness. The computing device can determine a first adjustment coefficient between the first and second specular parameters based on the environmental information (e.g., lighting information) of the object to be rendered and the material information of the object, and then determine the second specular parameter based on the first adjustment coefficient and the first specular parameter. The parameter values of the second specular parameter are different from those of the first specular parameter.
[0041] Optionally, the computing device can also determine the first adjustment coefficient between the first highlight parameter and the second highlight parameter by acquiring information input manually, thereby determining the second highlight parameter based on the first adjustment coefficient and the first highlight parameter.
[0042] It should be noted that by determining the second specular parameter corresponding to the second specular region based on the first specular parameter, the size of the second specular region is determined, thereby determining the calculation method for the second specular region, and thus determining the style of the second specular region. Furthermore, due to the difference between the first and second specular parameters, the styles of the first and second specular regions also differ. Consequently, two specular styles with different styles will be generated in the same display area of the object to be rendered, enriching the specular style of the object to be rendered.
[0043] Step S108: Based on the first specular parameter and the second specular parameter, perform shading processing on the object to be rendered to obtain the target rendering object.
[0044] In step S108, after the computing device determines the first specular parameter and the second specular parameter, it can input these parameters into the shader to perform shading processing on the object to be rendered, thereby obtaining the target rendering object. The shader can perform relevant calculations in 3D graphics computing, and it can customize the calculation methods to achieve lighting effects.
[0045] Optionally, during the process of the computing device performing color processing on the rendered object based on the shader, the computing device can also set the colors displayed in the first highlight area and the second highlight area respectively, thereby further realizing the distinction between the styles of the first highlight area and the second highlight area.
[0046] It should be noted that by performing color processing on the object to be rendered based on the first and second specular parameters, two different styles of specular highlights are generated in the same display area of the object to be rendered, thereby making the specular highlights of the target object richer and more stylized.
[0047] Based on the scheme defined in steps S102 to S108 above, it can be understood that in this embodiment of the invention, two specular styles are used to colorize the object to be rendered in order to obtain the target rendering object. This is achieved by determining the first specular region of the object to be rendered and determining the second specular region within the first specular region, then obtaining the first specular parameter corresponding to the first specular region, then determining the second specular parameter corresponding to the second specular region based on the first specular parameter, and finally colorizing the object to be rendered based on the first specular parameter and the second specular parameter to obtain the target rendering object.
[0048] It is noteworthy that, in the above process, by determining the first highlight region and the second highlight region within the first highlight region of the object to be rendered, the number of highlights of the object in the same display area is increased, thus laying the foundation for a richer highlight style. Furthermore, by obtaining the first and second highlight parameters, the styles of the first and second highlight regions are determined. Due to the difference between the first and second highlight parameters, the styles of the first and second highlight regions also differ. Consequently, when the object to be rendered is shading based on the first and second highlight parameters, two highlights with different styles will be generated in the same display area of the object, thus enriching the highlight style of the object to be rendered.
[0049] Therefore, the solution provided in this application achieves the purpose of using two specular styles to color the object to be rendered in order to obtain the target object to be rendered, thereby realizing a rich technical effect of specular style of the object to be rendered, and thus solving the technical problem of the single specular style of the object to be rendered caused by the single calculation method of specular highlights of the object to be rendered in the prior art.
[0050] In one optional embodiment, the computing device can obtain the lighting information of the scene where the object to be rendered is located, thereby determining first region information of a first specular region on the object to be rendered based on the lighting information, and determining second region information of a second specular region on the object to be rendered based on the lighting information. The first region information includes at least one of the following: the position information and shape of the first specular region; the second region information includes at least one of the following: the position information and shape of the second specular region.
[0051] Optionally, the lighting information may include information such as the direction and intensity of the light. The computing device can determine the position information of the first and second highlight regions on the object to be rendered based on the lighting direction and the structural features of the object. The position information of the first and second highlight regions may be the same or different. In this embodiment, the position information of the first and second highlight regions is the same.
[0052] Furthermore, the computing device can also determine the shapes of the first and second highlight regions on the object to be rendered based on the direction of illumination, the intensity of illumination, and the structural features of the object. For example, when the location of the first and second highlight regions is a plane, their shapes are usually regular shapes; when the location of the first and second highlight regions is not a plane, their shapes are usually irregular shapes.
[0053] It should be noted that by obtaining the lighting information of the scene where the object to be rendered is located, the first region information and the second region information are determined based on the lighting information, so that the position and shape of the first and second highlight regions are more in line with the actual situation and have realism. This allows the object to be rendered to produce realistic and vivid highlights in different environments, thereby improving the user experience.
[0054] In one optional embodiment, the computing device can obtain parameter information corresponding to the object to be rendered, determine a first adjustment coefficient based on the parameter information, and then calculate the product of the first specular parameter and the first adjustment coefficient to obtain a second specular parameter. The parameter information includes at least one of the following: environmental information and material information.
[0055] Optionally, the environmental information in the parameter information corresponding to the object to be rendered may include information such as lighting color, lighting intensity, and the scene in which the object is located. The material information in the parameter information corresponding to the object to be rendered may include information such as the color, texture, smoothness, transparency, reflectivity, refractive index, and luminosity of the object's surface. Based on the above information, the computing device can determine the first adjustment coefficient through a preset calculation model, or it can directly obtain a preset or manually input first adjustment coefficient. In this embodiment, the first adjustment coefficient is preferably the natural constant e to produce better specular effects.
[0056] Furthermore, once the first adjustment coefficient is determined, the second highlight parameter can be obtained by multiplying the first adjustment coefficient by the parameter value of the first highlight parameter.
[0057] It should be noted that by determining the first adjustment coefficient based on parameter information, and then obtaining the second specular parameter based on the first adjustment coefficient, the shading processing of the object to be rendered based on the second specular parameter will be more realistic. When the material of the object to be rendered or its environment changes, the second specular parameter of the object to be rendered will also change, thereby making the specular effect of the object to be rendered better and the style more varied.
[0058] In one optional embodiment, after determining the first specular parameter and the second specular parameter, the computing device can acquire a specular reflection model, and then calculate in parallel the first specular result and the second specular result under the specular reflection model based on the first specular parameter and the second specular parameter. Based on the first specular result and the second specular result, the first specular region and the second specular region are then shading processed to obtain the target rendering object. The specular reflection model characterizes the degree of illumination reflected by the object to be rendered.
[0059] Optionally, the computing device acquires a Bling-phong specular reflection model as the lighting model and creates this specular reflection model in a shader. Then, the computing device substitutes the first and second specular parameters into the specular reflection model to obtain the first and second specular results, respectively. The first specular result characterizes the illumination level of the first specular region, which includes at least the size of the first specular region; the second specular result characterizes the illumination level of the second specular region, which also includes at least the size of the second specular region.
[0060] Furthermore, the computing device employs a multi-core GPU architecture. This multi-core GPU design allows for the simultaneous processing of large amounts of data, significantly improving processing efficiency. Therefore, when the computing device calculates the first specular highlight result in the shader, it can simultaneously calculate the second specular highlight result using the parallel computing syntax supported by the shader. Specifically, the shader typically uses `half x` to represent a single numerical value, and it supports the `half2(x, y)` syntax for parallel computation. Therefore, when an additional value is needed (such as adding a second specular highlight parameter), the computing device can use the `half2` syntax to input the first and second specular highlight parameters into the specular reflection model, thereby enabling the parallel computation of both the first and second specular highlight results. The specular reflection model based on parallel computation is shown below:
[0061] half2(L specular1 L specular2 = max(dot(N, H), 0) half2(shinness,shinness*e)
[0062] Among them, L specular1 Indicates the first highlight result, L specular2 This represents the second highlight result, max(dot(N,H),0) half2(shinness,shinness*e) This represents the specular reflection model, where shinness represents the first specular parameter and shinness*e represents the second specular parameter.
[0063] Subsequently, the computing device performs color processing on the first highlight area and the second highlight area using the first highlight result and the second highlight result, respectively, to obtain the target rendering object.
[0064] It should be noted that by obtaining the specular reflection model and then calculating the first and second specular results under the specular reflection model in parallel with the first and second specular parameters, the mechanism of GPU parallel computing is fully utilized, and the effect of enriching the specular reflection effect of the object to be rendered is achieved without sacrificing the performance of the computing device.
[0065] In an optional embodiment, before obtaining the above-mentioned specular reflection model, it is also necessary to construct a specular reflection model. Specifically, the method of constructing the specular reflection model is described in detail below.
[0066] Optionally, the computing device determines the lighting direction and camera view direction of the scene where the object to be rendered is located, and then determines the half-angle vector corresponding to the scene based on the lighting direction and camera view direction. Next, it determines the surface normal direction and specular parameters of the object to be rendered, and then constructs a specular reflection model based on the half-angle vector, surface normal direction and specular parameters.
[0067] in, Figure 2 This is a schematic diagram of an optional illumination direction, surface normal direction, camera viewing angle direction, and half-angle vector according to an embodiment of the present invention, such as... Figure 2 As shown, the lighting direction is the direction of the natural light in the scene where the object to be rendered is located. The formula for determining the half-angle vector corresponding to the scene based on the lighting direction and the camera's viewpoint direction is as follows:
[0068] H = add(L, V)
[0069] Where L represents the direction of illumination, V represents the direction of the camera's viewpoint, and H represents the half-angle vector.
[0070] Furthermore, the surface normal direction of the object to be rendered is the direction of the object's surface as observed by the camera. The principle of the specular reflection model is based on the surface normal direction and half-angle vector of the object to be rendered, and the constructed specular reflection model is shown below:
[0071] L specular =max(dot(N,H),0) shiness
[0072] Among them, L specular The specular reflection result is represented by N, where N represents the surface normal direction, H represents the half-angle vector, and shiness represents the specular parameter. This specular reflection model describes the illumination level reflected from the surface of an object, and its calculation speed is relatively fast, making it suitable for the performance of various electronic devices (such as mobile phones and computers) or computing devices.
[0073] It should be noted that by constructing a specular reflection model, the first and second specular results can be accurately calculated, which facilitates subsequent shading processing of the object to be rendered and improves the shading effect.
[0074] In an optional embodiment, when the first specular result is used to directly colorize the object to be rendered, the coloring result is as follows: Figure 3As shown, it is easy to see that the highlight shape is relatively soft at this time, and the brightness values in different parts of the first highlight area are not completely equal. Therefore, in order to make the highlights on the target rendering object more stylized, after the computing device calculates the first highlight result and the second highlight result, the computing device can determine the second adjustment coefficient according to the target rendering result corresponding to the object to be rendered. Then, it determines the first brightness value from the first highlight result and the second brightness value from the second highlight result. Next, the computing device adjusts the first brightness value according to the comparison result between the first brightness value and the second adjustment coefficient to obtain the first target brightness value, and adjusts the second brightness value according to the comparison result between the second brightness value and the second adjustment coefficient to obtain the second target brightness value. Finally, the first highlight area is tinted based on the first target brightness value, and the second highlight area is tinted based on the second target brightness value to obtain the target rendering object.
[0075] Optionally, in this embodiment, the computing device can determine the second adjustment coefficient based on the target rendering result, or it can directly obtain the second adjustment coefficient input manually. The target rendering result can be pre-set in the computing device, or it can be calculated based on the environmental information of the object to be rendered and the material information of the object itself. After determining the second adjustment coefficient, the computing device can determine the brightness value at the location determined in the aforementioned first highlight region location information as the first brightness value, and determine the brightness value at the location determined in the aforementioned second highlight region location information as the second brightness value.
[0076] Furthermore, the computing device can directly compare the first brightness value with the second adjustment coefficient, or the second brightness value with the second adjustment coefficient, to obtain a comparison result; alternatively, it can first calculate the ratio between the first brightness value and the second adjustment coefficient, or the ratio between the second brightness value and the second adjustment coefficient, and then compare the aforementioned ratio with a preset threshold to obtain a comparison result, and then determine the first target brightness value and the second target brightness value based on the comparison result.
[0077] Furthermore, the computing device performs color processing on all pixels in the first highlight area based on the first target brightness value, so that the brightness of any point in the first highlight area is the first target brightness value. Similarly, the computing device performs color processing on all pixels in the second highlight area based on the second target brightness value, so that the brightness of any point in the second highlight area is the second target brightness value, thereby obtaining the target rendering object.
[0078] It should be noted that by determining the second adjustment coefficient, adjusting the first brightness value to the first target brightness value based on the second adjustment coefficient, and adjusting the second brightness value to the second target brightness value based on the second adjustment coefficient, the brightness value of at least a portion of the first highlight area or the second highlight area is changed, making its highlight edges sharper, thereby achieving a further change in the style of the first highlight area or the second highlight area, making its style more unique.
[0079] In one alternative embodiment, the computing device can obtain the first specular result corresponding to the first target brightness value in the following manner.
[0080] Optionally, when the first brightness value is greater than or equal to the second adjustment coefficient value, the computing device determines the first target brightness value as a first value; when the first brightness value is less than the second adjustment coefficient, the computing device determines the first target brightness value as a second value, wherein the first value is greater than the second value.
[0081] Specifically, in this embodiment, the computing device uses the step function in the shader to determine the first target brightness value. The step function is step(float a, float x), which is a step function used to return a value greater than or equal to the corresponding component in the reference vector a for each component of x, otherwise returning zero. In this embodiment, the formula for adjusting the first brightness value based on the second adjustment coefficient is as follows:
[0082] L specular =step(specularStep, L) specular )
[0083] Among them, L specular This represents the first highlight result, and `specularStep` represents the second adjustment coefficient. When the first brightness value is less than the second adjustment coefficient, the first target brightness value is determined to be 0 or another brightness value less than the brightness value corresponding to the second adjustment coefficient; when the first brightness value is greater than or equal to the second adjustment coefficient, the first brightness value is adjusted to a brightness value greater than or equal to the brightness value corresponding to the second adjustment coefficient. This achieves the determination of the first highlight result corresponding to the first target brightness value. The first highlight area adjusted based on the second adjustment coefficient is shown below. Figure 4 As shown.
[0084] It should be noted that by directly comparing the first brightness value and the second adjustment coefficient to determine the first target brightness value, the edge of the highlight can be made sharper while minimizing the increased computational load on the computing device, thereby ensuring the working efficiency of the computing device.
[0085] In one alternative embodiment, the computing device can obtain the second specular result corresponding to the second target brightness value in the following manner.
[0086] Optionally, when the second brightness value is greater than or equal to the second adjustment coefficient, the computing device determines the second target brightness value to be a first value; when the second brightness value is less than the second adjustment coefficient, the second target brightness value is determined to be a second value, wherein the first value is greater than the second value.
[0087] Specifically, the computing device can determine the second highlight result corresponding to the second target brightness value in parallel using the same method as described above for determining the first highlight result corresponding to the first target brightness value. In this embodiment, the computing device can use the aforementioned half2 syntax to simultaneously substitute the first highlight result and the second highlight result into the formula established based on the step function, thereby calculating the second highlight result corresponding to the second target brightness value in parallel while calculating the first highlight result corresponding to the first target brightness value. The formula for adjusting the brightness value based on parallel computing is as follows:
[0088] half2(L specular1 L specular2 )=step(specularStep,half2(L specular1 L specular2 ))
[0089] Among them, L specular1 Indicates the first highlight result, L specular2 This indicates the second highlight result, and specularStep indicates the second adjustment factor.
[0090] Optionally, the computing device can input the following password in the shader to determine the first specular result corresponding to the first target brightness value and the second specular result corresponding to the second target brightness value, as shown below:
[0091] Half H = L + V:
[0092] Half2 Lspecular=pow(max(dot(N, H)), half2(shinness, shinness*e));
[0093] Lspecular=step(specularStep,Lspecular);
[0094] The first and second highlight regions, adjusted based on the second adjustment factor, are as follows: Figure 5 As shown.
[0095] It should be noted that by directly comparing the second brightness value and the second adjustment coefficient, and determining the second target brightness value based on parallel computing, the increased computational load on the computing device can be minimized while making the highlight edges sharper, thereby ensuring the working efficiency of the computing device.
[0096] In an alternative embodiment, before the computing device optimizes the highlight shape based on the step function described above, the computing device may also control the degree of highlight concentration in the first region or the second region based on the parameter Smoothness, so as to make the highlight shape softer.
[0097] It should be noted that this application makes full use of the multi-threaded architecture of mobile GPUs and uses a dual-highlight form based on parallel computing to help anime-style games create unique stylized effects. While ensuring superior performance, it can also create more stylized effects to help anime-style projects change.
[0098] Therefore, the solution provided in this application achieves the purpose of using two specular styles to color the object to be rendered in order to obtain the target object to be rendered, thereby realizing a rich technical effect of specular style of the object to be rendered, and thus solving the technical problem of the single specular style of the object to be rendered caused by the single calculation method of specular highlights of the object to be rendered in the prior art.
[0099] Example 2
[0100] According to an embodiment of the present invention, an embodiment of an apparatus for rendering an object is provided, wherein, Figure 6 This is a schematic diagram of an optional rendering object apparatus according to an embodiment of the present invention, such as... Figure 6 As shown, the device includes:
[0101] The first determining module 602 is used to determine the first highlight region of the object to be rendered and to determine the second highlight region within the first highlight region.
[0102] The acquisition module 604 is used to acquire the first highlight parameters corresponding to the first highlight region;
[0103] The second determining module 606 is used to determine the second highlight parameter corresponding to the second highlight region based on the first highlight parameter;
[0104] The rendering module 608 is used to perform color processing on the object to be rendered based on the first specular parameter and the second specular parameter to obtain the target rendering object.
[0105] It should be noted that the first determining module 602, the acquisition module 604, the second determining module 606, and the rendering module 608 mentioned above correspond to steps S102 to S108 in the above embodiments. The examples and application scenarios implemented by the four modules and the corresponding steps are the same, but are not limited to the content disclosed in the above embodiment 1.
[0106] Optionally, the second determining module 606 further includes: a first sub-acquisition module, used to acquire parameter information corresponding to the object to be rendered, wherein the parameter information includes at least one of the following: environment information, material information; the first sub-determining module, used to determine a first adjustment coefficient based on the parameter information; and a first calculation module, used to calculate the product of the first specular parameter and the first adjustment coefficient to obtain the second specular parameter.
[0107] Optionally, the rendering module 608 further includes: a second sub-acquisition module for acquiring a specular reflection model, wherein the specular reflection model characterizes the intensity of light reflected by the object to be rendered; a second calculation module for parallel calculation of the first specular parameter and the second specular parameter under the specular reflection model, and the first specular result and the second specular result; and a first sub-rendering module for coloring the first specular region and the second specular region based on the first specular result and the second specular result, respectively, to obtain the target rendering object.
[0108] Optionally, the device for rendering objects further includes: a second sub-determination module for determining the lighting direction and camera view direction of the scene where the object to be rendered is located; a third sub-determination module for determining the half-angle vector corresponding to the scene based on the lighting direction and camera view direction; a fourth sub-determination module for determining the surface normal direction and specular parameters of the object to be rendered; and a construction module for constructing a specular reflection model based on the half-angle vector, surface normal direction, and specular parameters.
[0109] Optionally, the first sub-rendering module further includes: a tenth sub-determination module, used to determine a second adjustment coefficient based on the target rendering result corresponding to the object to be rendered; a fifth sub-determination module, used to determine a first brightness value from the first specular result and a second brightness value from the second specular result; a first sub-adjustment module, used to adjust the first brightness value based on the comparison result between the first brightness value and the second adjustment coefficient to obtain a first target brightness value; a second sub-adjustment module, used to adjust the second brightness value based on the comparison result between the second brightness value and the second adjustment coefficient to obtain a second target brightness value; and a second sub-rendering module, used to perform color processing on the first specular region based on the first target brightness value and on the second specular region based on the second target brightness value to obtain the target rendering object.
[0110] Optionally, the first sub-adjustment module further includes: a sixth sub-determination module, used to determine the first target brightness value as a first value when the first brightness value is greater than or equal to the second adjustment coefficient value; and a seventh sub-determination module, used to determine the first target brightness value as a second value when the first brightness value is less than the second adjustment coefficient, wherein the first value is greater than the second value.
[0111] Optionally, the second sub-adjustment module further includes: an eighth sub-determination module, used to determine the second target brightness value as a first value when the second brightness value is greater than or equal to the second adjustment coefficient; and a ninth sub-determination module, used to determine the second target brightness value as a second value when the second brightness value is less than the second adjustment coefficient, wherein the first value is greater than the second value.
[0112] Optionally, the first determining module 602 further includes: a third sub-acquisition module, used to acquire lighting information of the scene where the object to be rendered is located; a first region information determining module, used to determine the first region information of the first specular region on the object to be rendered based on the lighting information, wherein the first region information includes at least one of the following: the position information and shape of the first specular region; and a second region information determining module, used to determine the second region information of the second specular region on the object to be rendered based on the lighting information, wherein the second region information includes at least one of the following: the position information and shape of the second specular region.
[0113] Example 3
[0114] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-described method for rendering an object at runtime.
[0115] Example 4
[0116] According to another aspect of the present invention, an electronic device is also provided, the electronic device including one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement a method for running the programs, wherein the programs are configured to execute the above-described method for rendering objects at runtime.
[0117] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0118] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0119] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0120] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0121] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0122] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0123] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method of rendering an object, characterized by, The method comprises: determining a first highlight area of an object to be rendered and determining a second highlight area within the first highlight area; obtaining a first highlight parameter corresponding to the first highlight area; determining a first adjustment coefficient according to parameter information corresponding to the object to be rendered; determining a second highlight parameter corresponding to the second highlight area based on the first highlight parameter and the first adjustment coefficient; obtaining a highlight reflection model, wherein the highlight reflection model represents the degree of light reflection of the object to be rendered, and the highlight reflection model is constructed based on a half-angle vector, a surface normal direction, and a highlight parameter of the object to be rendered; parallelly calculating a first highlight result and a second highlight result of the first highlight parameter and the second highlight parameter under the highlight reflection model; determining a second adjustment coefficient according to a target rendering result corresponding to the object to be rendered; determining a first brightness value from the first highlight result and a second brightness value from the second highlight result; adjusting the first brightness value according to a comparison result between the first brightness value and the second adjustment coefficient to obtain a first target brightness value; adjusting the second brightness value according to a comparison result between the second brightness value and the second adjustment coefficient to obtain a second target brightness value; performing color processing on the first highlight area based on the first target brightness value and performing color processing on the second highlight area based on the second target brightness value to obtain a target rendering object.
2. The method of claim 1, wherein, The method further comprises: obtaining the parameter information corresponding to the object to be rendered, wherein the parameter information comprises at least one of the following: environmental information, material information; determining the second highlight parameter corresponding to the second highlight area based on the first highlight parameter and the first adjustment coefficient comprises: calculating the product of the first highlight parameter and the first adjustment coefficient to obtain the second highlight parameter.
3. The method of claim 1, wherein, Before obtaining the highlight reflection model, the method further comprises: determining a light direction of a scene where the object to be rendered is located and a camera view direction; determining a half-angle vector corresponding to the scene based on the light direction and the camera view direction; determining a surface normal direction of the object to be rendered and a highlight parameter of the object to be rendered; constructing the highlight reflection model based on the half-angle vector, the surface normal direction, and the highlight parameter.
4. The method of claim 1, wherein, Adjusting the first brightness value according to a comparison result between the first brightness value and the second adjustment coefficient to obtain a first target brightness value comprises: when the first brightness value is greater than or equal to the second adjustment coefficient, determining the first target brightness value as a first numerical value; when the first brightness value is less than the second adjustment coefficient, determining the first target brightness value as a second numerical value, wherein the first numerical value is greater than the second numerical value.
5. The method of claim 1, wherein, Adjusting the second brightness value according to a comparison result between the second brightness value and the second adjustment coefficient to obtain a second target brightness value comprises: determining the second target brightness value as a first value when the second brightness value is greater than or equal to the second adjustment coefficient; determining the second target brightness value as a second value when the second brightness value is less than the second adjustment coefficient, wherein the first value is greater than the second value.
6. The method of claim 1, wherein, determining a first highlight area of a to-be-rendered object and a second highlight area in the first highlight area, comprising: obtaining light information of a scene in which the to-be-rendered object is located; determining first area information of the first highlight area on the to-be-rendered object based on the light information, wherein the first area information at least includes one of the following: position information, shape of the first highlight area; determining second area information of the second highlight area on the to-be-rendered object based on the light information, wherein the second area information at least includes one of the following: position information, shape of the second highlight area.
7. An apparatus for rendering an object, characterized by comprising: a first determining module configured to determine a first highlight area of a to-be-rendered object and a second highlight area in the first highlight area; an obtaining module configured to obtain a first highlight parameter corresponding to the first highlight area; a second determining module configured to determine a first adjustment coefficient according to parameter information corresponding to the to-be-rendered object; determining a second highlight parameter corresponding to the second highlight area based on the first highlight parameter and the first adjustment coefficient; a rendering module configured to obtain a highlight reflection model, wherein the highlight reflection model represents a degree of light reflection of the to-be-rendered object, the highlight reflection model is constructed based on a half-angle vector, a surface normal direction, and a highlight parameter of the to-be-rendered object; to calculate, in parallel, a first highlight result and a second highlight result of the first highlight parameter and the second highlight parameter in the highlight reflection model; to determine a second adjustment coefficient according to a target rendering result corresponding to the to-be-rendered object; to determine a first brightness value from the first highlight result and a second brightness value from the second highlight result; to adjust the first brightness value according to a comparison result between the first brightness value and the second adjustment coefficient, to obtain a first target brightness value; to adjust the second brightness value according to a comparison result between the second brightness value and the second adjustment coefficient, to obtain a second target brightness value; and to perform color processing on the first highlight area based on the first target brightness value and on the second highlight area based on the second target brightness value, to obtain a target rendered object.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, wherein the computer program is configured to execute the method for rendering an object as claimed in any one of claims 1 to 6 when running.
9. An electronic device, comprising: The electronic device comprises one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, cause the one or more processors to implement a program for running, wherein the program is configured to execute the method for rendering an object as claimed in any one of claims 1 to 6 when running.
Citation Information
Patent Citations
Hair highlight rendering method, device and equipment and storage medium
CN113763525A
Image rendering method and device, electronic equipment and storage medium
CN113822981A