Image rendering
This application provides an image rendering method and apparatus, an electronic device, a computer-readable storage medium, and a computer program product. The method comprises the following steps: acquiring texture data of a virtual object; performing differential fitting processing on the texture data to obtain fitted texture data; baking the fitted texture data into a texture image to obtain a rendered texture image; and performing, based on the rendered texture image, image rendering processing corresponding to the virtual.
1 . An image rendering method comprising:
acquiring, by a computing device, texture data of a virtual object;
performing, based on physically based rendering (PBR) processing, a rendering processing corresponding to the virtual object to obtain a target rendering graph corresponding to the virtual object;
iteratively performing differential fitting processing on the texture data to obtain fitted texture data until an iteration end condition is satisfied, wherein the iteration end condition is obtained by:
acquiring historical detail degrees of a plurality of historical virtual objects in a virtual scene;
determining a detail degree for rendering the virtual object based on the historical detail degrees; and
determining the iteration end condition based on the detail degree;
baking, based on a rendering loss function value associated with the fitted texture data and the target rendering graph satisfying a threshold, the fitted texture data into a texture image to obtain a rendered texture image; and
performing, based on the rendered texture image, image rendering processing corresponding to the virtual object.
2 . The method according to claim 1 , wherein the iteratively performing differential fitting processing comprises the following iterative processing:
performing fitted rendering processing on the texture data to obtain a fitted rendering graph;
constructing a rendering loss function based on a difference between the target rendering graph and the fitted rendering graph;
updating the texture data based on the rendering loss function until the iteration end condition is satisfied; and
selecting the texture data updated at an end of an iteration as the fitted texture data.
3 . The method according to claim 1 , wherein the performing the rendering processing comprises:
acquiring rendering data of the virtual object.
4 . The method according to claim 2 , wherein the performing fitted rendering processing comprises:
determining a fitted mapping relationship between texture data and a rendering graph; and
mapping the texture data based on the fitted mapping relationship to obtain the fitted rendering graph.
5 . The method according to claim 2 , wherein the constructing the rendering loss function comprises:
determining a pixel value difference between the target rendering graph and the fitted rendering graph in a screen space; and
determining the rendering loss function based on the pixel value difference and a size of the target rendering graph.
6 . The method according to claim 5 , wherein the determining the pixel value difference comprises:
determining a first pixel value corresponding to a pixel in the fitted rendering graph, and determining a second pixel value corresponding to the pixel in the target rendering graph;
determining a pixel value difference of the pixel based on an absolute value of a difference value between the first pixel value and the second pixel value; and
summing pixel value differences of a plurality of pixels in the target rendering graph as the pixel value difference between the target rendering graph and the fitted rendering graph in the screen space.
7 . The method according to claim 2 , wherein the updating comprises:
performing, based on the rendering loss function, partial derivative processing on the texture data to obtain a gradient of the rendering loss function; and
updating the texture data based on the gradient of the rendering loss function.
8 . The method according to claim 1 , wherein the iteration end condition comprises a number of the iteration reaching a set number.
9 . The method according to claim 8 , further comprising:
displaying a setting entry of the iteration end condition, wherein the iteration end condition comprises content input through a setting operation for the setting entry.
10 . The method according to claim 1 ,
wherein types of the detail degree comprise at least one of the following:
a highest historical detail degree;
a historical detail degree with a highest application frequency; and
a detail degree averaged over the historical detail degrees.
11 . The method according to claim 8 , further comprising:
acquiring scene data of a virtual scene;
training a condition prediction model based on historical scene data, a historical target rendering graph, and a historical iteration end condition; and
perform condition prediction processing, based on the scene data of the virtual scene and the target rendering graph, using the condition prediction model to obtain the iteration end condition.
12 . The method according to claim 1 , wherein the performing image rendering processing comprises:
determining two-dimensional (2D) texture coordinates of the virtual object; and
performing, based on the 2D texture coordinates, sampling fitting processing on the rendered texture image to obtain the rendered virtual object.
13 . An image rendering apparatus configured to:
acquire texture data of a virtual object;
perform, based on physically based rendering (PBR) processing, a rendering processing corresponding to the virtual object to obtain a target rendering graph corresponding to the virtual object;
iteratively perform differential fitting processing on the texture data to obtain fitted texture data until an iteration end condition is satisfied, wherein the iteration end condition is obtained by:
acquiring historical detail degrees of a plurality of historical virtual objects in a virtual scene;
determining a detail degree for rendering the virtual object based on the historical detail degrees; and
determining the iteration end condition based on the detail degree;
bake, based on a rendering loss function value associated with the fitted texture data and the target rendering graph satisfying a threshold, the fitted texture data into a texture image to obtain a rendered texture image; and
perform, based on the rendered texture image, image rendering processing corresponding to the virtual object.
14 . The image rendering apparatus according to claim 13 , wherein the image rendering apparatus is configured to iteratively perform differential fitting processing by performing the following iterative processing:
performing fitted rendering processing on the texture data to obtain a fitted rendering graph;
constructing a rendering loss function based on a difference between the target rendering graph and the fitted rendering graph;
updating the texture data based on the rendering loss function until the iteration end condition is satisfied; and
selecting the texture data updated at an end of an iteration as the fitted texture data.
15 . The image rendering apparatus according to claim 13 , wherein the image rendering apparatus is configured to perform the rendering processing by:
acquiring rendering data of the virtual object.
16 . The image rendering apparatus according to claim 14 , wherein the image rendering apparatus is configured to perform fitted rendering processing by:
determining a fitted mapping relationship between texture data and a rendering graph; and
mapping the texture data based on the fitted mapping relationship to obtain the fitted rendering graph.
17 . The image rendering apparatus according to claim 14 , wherein the image rendering apparatus is configured to construct the rendering loss function by:
determining a pixel value difference between the target rendering graph and the fitted rendering graph in a screen space; and
determining the rendering loss function based on the pixel value difference and a size of the target rendering graph.
18 . The image rendering apparatus according to claim 14 , wherein the image rendering apparatus is configured to update the texture data by:
performing, based on the rendering loss function, partial derivative processing on the texture data to obtain a gradient of the rendering loss function; and
updating the texture data based on the gradient of the rendering loss function.
19 . The image rendering apparatus according to claim 13 , wherein the iteration end condition comprises at least one of the following:
a value of the rendering loss function being less than a threshold; and
a number of the iteration reaching a set number.
20 . A non-transitory computer-readable medium storing instructions that, when executed, cause:
acquiring texture data of a virtual object;
performing, based on physically based rendering (PBR) processing, a rendering processing corresponding to the virtual object to obtain a target rendering graph corresponding to the virtual object;
iteratively performing differential fitting processing on the texture data to obtain fitted texture data until an iteration end condition is satisfied, wherein the iteration end condition is obtained by:
acquiring historical detail degrees of a plurality of historical virtual objects in a virtual scene;
determining a detail degree for rendering the virtual object based on the historical detail degrees; and
determining the iteration end condition based on the detail degree;
baking, based on a rendering loss function value associated with the fitted texture data and the target rendering graph satisfying a threshold, the fitted texture data into a texture image to obtain a rendered texture image; and
performing, based on the rendered texture image, image rendering processing corresponding to the virtual object.