Ambient light shielding processing method and device and storage medium
By drawing the outline and light source data on the rendering target, combining the data of the depth buffer and the normal buffer, calculating the ambient occlusion factor and performing color updates, the problem of complex and high-cost ambient occlusion processing is solved, and a more efficient implementation is achieved. Accurate results and streamlined process.
Patent Information
- Application Number
- CN202410701840.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-06
AI Technical Summary
In the existing technology, the ambient light occlusion processing process is complex and costly, and there is a lack of effective solutions.
By drawing the outline information and light source data of the target image on the rendering target, combined with the data in the depth buffer and normal buffer, the ambient occlusion factor is calculated and the color is updated, simplifying the ambient occlusion processing process.
It achieves more accurate calculation of the ambient light occlusion factor, reduces processing costs, simplifies the operation process, and improves the realism and three-dimensionality of the image.
Smart Images

Figure CN118608651A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an ambient light occlusion processing method, device and storage medium. Background Art
[0002] Ambient occlusion is a technology in computer graphics that simulates the shadow effect of an object surface under ambient light. Ambient occlusion can enhance the three-dimensionality and realism of an object, making the scene more natural and realistic. In related technologies, professional equipment or platforms are mainly used to perform image ambient occlusion processing to achieve image rendering, but this method is difficult to operate, costly and has poor compatibility.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present invention provide an ambient light occlusion processing method, device and storage medium to at least solve the technical problems of the method of performing ambient light occlusion by using additional tools in the related art, which has a complex operation process and high operation cost.
[0005] According to one aspect of an embodiment of the present invention, there is provided an ambient occlusion processing method, comprising: using an image drawing class to draw contour information corresponding to a target image on a rendering target to obtain a first image rendering result; obtaining light source data to be added to the target image; using the image drawing class to add the light source data to the first image rendering result to obtain a second image rendering result; based on depth values corresponding to a plurality of pixels included in the target image pre-stored in a depth buffer, and normal vectors corresponding to the plurality of pixels pre-stored in a normal buffer, determining ambient occlusion factors corresponding to the plurality of pixels respectively, wherein the depth value is used to indicate distance information from the corresponding pixel to a target viewpoint; based on the ambient occlusion factors corresponding to the plurality of pixels respectively, performing a color update on the second image rendering result to obtain a target image rendering result.
[0006] According to another aspect of an embodiment of the present invention, there is also provided an ambient occlusion processing device, comprising: a contour drawing module, used to draw contour information corresponding to a target image on a rendering target using an image drawing class, to obtain a first image rendering result; a light source data acquisition module, used to obtain light source data to be added to the target image; a light source data adding module, used to add the light source data to the first image rendering result using the image drawing class, to obtain a second image rendering result; an ambient occlusion factor determination module, used to determine ambient occlusion factors corresponding to a plurality of pixels respectively included in the target image pre-stored in a depth buffer, based on depth values respectively corresponding to the plurality of pixels included in the target image, and normal vectors respectively corresponding to the plurality of pixels pre-stored in a normal buffer, wherein the depth value is used to indicate distance information from the corresponding pixel to a target viewpoint; and a color update module, used to perform a color update on the second image rendering result based on the ambient occlusion factors respectively corresponding to the plurality of pixels, to obtain a target image rendering result.
[0007] According to another aspect of an embodiment of the present invention, a non-volatile storage medium is provided, wherein the non-volatile storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing any one of the ambient light occlusion processing methods.
[0008] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the steps of any one of the ambient light occlusion processing methods are implemented.
[0009] In an embodiment of the present invention, an image drawing class is used to draw contour information corresponding to a target image on a rendering target to obtain a first image rendering result; light source data to be added to the target image is obtained; the image drawing class is used to add the light source data to the first image rendering result to obtain a second image rendering result; based on depth values corresponding to a plurality of pixels included in the target image pre-stored in a depth buffer, and normal vectors corresponding to the plurality of pixels pre-stored in a normal buffer, ambient light occlusion factors corresponding to the plurality of pixels are determined, wherein the depth value is used to indicate distance information from the corresponding pixel to the target viewpoint; based on the plurality of pixels, the ambient light occlusion factors corresponding to the plurality of pixels are determined. The color of the second image rendering result is updated according to the corresponding ambient occlusion factor, and the target image rendering result is obtained, so as to achieve the purpose of setting the depth buffer and the normal buffer to store the depth and normal information of each pixel in the image, more accurately calculating the ambient occlusion factor based on the depth and normal information of each pixel in the image stored in the depth buffer and the normal buffer, and performing color correction and rendering of the image based on the ambient occlusion factor, thereby achieving the technical effect of simplifying the ambient occlusion processing flow and reducing the ambient occlusion processing cost, and further solving the technical problem of complex operation process and high operation cost of the method of performing ambient occlusion through additional tools in the related art. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0011] Figure 1 is a flow chart of an ambient light occlusion processing method according to an embodiment of the present invention;
[0012] Figure 2 is a flow chart of an optional ambient occlusion processing method according to an embodiment of the present invention;
[0013] Figure 3 is a schematic diagram of an ambient light occlusion processing device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0014] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0015] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0016] First, to facilitate understanding of the embodiments of the present invention, some terms or nouns involved in the present invention are explained below:
[0017] BufferedImage object, a class used to represent images in Java, can be used to operate image data. It can contain different types of image data, such as grayscale images, RGB images, etc., and provides a wealth of methods to operate image data, such as cropping, scaling, drawing, etc. BufferedImage objects are often used in graphics processing, image recognition, image editing and other fields.
[0018] Ambient occlusion, a technology used to simulate global illumination, can enhance the details and layering of object surfaces and improve the realism and three-dimensionality of the scene.
[0019] Java awt, a package that contains all the classes used to create user interfaces and draw graphical images.
[0020] According to an embodiment of the present invention, a method embodiment of ambient occlusion processing is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0021] Figure 1 is a flow chart of an ambient light occlusion processing method according to an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:
[0022] Step S102, using an image drawing class to draw contour information corresponding to a target image on a rendering target, to obtain a first image rendering result;
[0023] Optionally, the target image is an image including one or more graphics (or geometries) to be drawn on the rendering target. The rendering target refers to a "canvas" or "surface" for drawing images or images, allowing graphics, text or images to be drawn on the rendering target. A buffered image java.awt.image.BufferedImage object can be created as a rendering target, and the width, height and color mode of the rendering target can also be set through the object. The image drawing class can be used as a rendering tool. The image drawing class can be but is not limited to a two-dimensional Graphics2D object for the image, that is, a java.awt.Graphics2D object is created as a rendering tool, its drawing context can be obtained from the BufferedImage object, and its rendering parameters can be set.
[0024] In an optional embodiment, before using an image drawing class to add light source data to a first image rendering result to obtain a second image rendering result, the method further includes: determining, based on the first image rendering result, first depth values corresponding to a plurality of pixels respectively included in the target image, and first normal vectors corresponding to the plurality of pixels respectively; updating the first depth values corresponding to the plurality of pixels respectively to a depth buffer, and updating the first normal vectors corresponding to the plurality of pixels respectively to a normal buffer.
[0025] Optionally, the depth buffer is used to temporarily store the depth value of each pixel in the target image. The depth value is used to indicate the distance information (such as the closest distance or depth) from each pixel in the rendered scene to the observer (i.e., the target viewpoint), and is used to determine which objects block other objects. The target viewpoint refers to a virtual camera or video camera, that is, the viewpoint at which the scene is rendered. The virtual camera simulates the perspective of the human eye or camera and determines the angle and position from which the scene is observed and rendered. The normal buffer is used to temporarily store the normal vector of each pixel in the target image. The normal vector corresponds to the direction of the pixel surface and is used to determine which directions of light will be blocked. You can create a java.awt.image.BufferedImage object as a depth buffer, and you can set its width, height, and color mode, and fill its pixels with an initial value; you can create a java.awt.image.BufferedImage object as a normal buffer, and you can set its width, height, and color mode, and fill its pixels with an initial value.
[0026] After the rendering tool (i.e., image drawing class) is used to draw the contour information corresponding to the target image on the rendering target and the first image rendering result is obtained, the depth value and normal vector (i.e., the first depth value and the first normal vector) of each pixel reflected in the first image rendering result need to be updated to the depth buffer and the normal buffer respectively for the subsequent calculation of the ambient occlusion factor. It should be noted that the depth value and normal vector of each pixel stored in the depth buffer and the normal buffer will be updated with the image rendering progress in the rendering target and will be consistent with the image rendering progress.
[0027] Optionally, the depth buffer and the normal buffer may or may not pre-store the depth value and the normal vector of each pixel in the target image. If the depth value and the normal vector of each pixel are not pre-stored in the depth buffer and the normal buffer, the obtained first depth value and the first normal vector of each pixel are directly stored in the corresponding depth buffer and the normal buffer; if the depth value and the normal vector of each pixel in the target image are pre-stored in the depth buffer and the normal buffer, it is necessary to compare the obtained first depth value and the first normal vector with the corresponding values pre-stored in the depth buffer and the normal buffer, and determine whether to update the depth value and the normal vector based on the comparison result.
[0028] In an optional embodiment, updating the first depth values corresponding to the plurality of pixels to the depth buffer includes: detecting whether the first depth values corresponding to the plurality of pixels are less than the depth value of the corresponding pixel stored in the depth buffer; and updating the first depth value of the first depth values corresponding to the plurality of pixels, which is less than the depth value of the corresponding pixel stored in the depth buffer, to the depth buffer. That is, if the first depth value of the corresponding pixel is smaller than the value of the corresponding position in the depth buffer (that is, closer to the observer), the depth value of the position in the depth buffer is updated to the first depth value.
[0029] In an optional embodiment, the first normal vectors corresponding to the multiple pixels are updated to the normal buffer, including: detecting whether the first normal vectors corresponding to the multiple pixels are consistent with the normal vectors of the corresponding pixels stored in the normal buffer; updating the first normal vectors corresponding to the multiple pixels that are inconsistent with the normal vectors of the corresponding pixels to the normal buffer; and there is no need to update the first normal vectors that are consistent to the normal buffer. The above method can ensure that the latest acquired normal vector is updated to the normal buffer, and the normal vectors of each pixel stored in the normal buffer are synchronously updated.
[0030] Step S104, obtaining light source data to be added to the target image;
[0031] Optionally, the light source data is used to add a light source to an object (such as an object) in the target image to achieve an image rendering effect. The light source data may be obtained based on a predetermined rendering scene.
[0032] Step S106, using an image drawing class to add the light source data to the first image rendering result to obtain a second image rendering result;
[0033] Optionally, based on the light source data in the scene, use an image drawing class (such as a Graphics2D object) to draw its influence range onto a rendering target, add the light source data to the first image rendering result, and obtain a second image rendering result, in which a glowing effect is added.
[0034] In an optional embodiment, before determining the ambient occlusion factors corresponding to the multiple pixels respectively based on the depth values corresponding to the multiple pixels included in the target image stored in the depth buffer and the normal vectors corresponding to the multiple pixels stored in the normal buffer, the method also includes: determining the second depth values corresponding to the multiple pixels respectively and the second normal vectors corresponding to the multiple pixels respectively based on the second image rendering result; updating the second depth values corresponding to the multiple pixels respectively to the depth buffer, and updating the second normal vectors corresponding to the multiple pixels respectively to the normal buffer.
[0035] Optionally, when the image rendering result changes, the depth value and normal vector of each pixel stored in the depth buffer and the normal buffer are synchronously updated according to the obtained second image rendering result. Specifically, based on the second image rendering result, the second depth value and the second normal vector corresponding to each pixel can be extracted, and the depth buffer and the normal buffer are synchronously updated based on the obtained second depth value and the second normal vector for subsequent calculation of the ambient occlusion factor. The above method can ensure that the ambient occlusion factor is calculated based on the most recently stored and updated depth value and normal vector in the depth buffer and the normal buffer, and the ambient occlusion factor obtained on this basis is more accurate and reliable.
[0036] It should be noted that compared with the method of directly determining the depth value and normal vector of each pixel based on the final image rendering result on the rendering target, the synchronous update of the depth value and normal vector of each pixel gradually according to the image rendering progress on the rendering target can avoid the layer-by-layer superposition based on image rendering, which leads to the inability to accurately know the depth value and normal vector of some pixels due to occlusion and other reasons, resulting in low accuracy in the calculation of the ambient occlusion factor.
[0037] In an optional embodiment, updating the second depth values corresponding to the plurality of pixels to the depth buffer includes: detecting whether the second depth values corresponding to the plurality of pixels are less than the depth values of the corresponding pixels stored in the depth buffer; updating the second depth values corresponding to the plurality of pixels, which are less than the depth values of the corresponding pixels stored in the depth buffer, to the depth buffer;
[0038] Optionally, for each of the multiple pixels included in the target image, it is determined whether the second depth value of the pixel is less than the depth value of the pixel stored in the depth buffer. If so, the second depth value of the pixel is updated to the depth buffer, otherwise the corresponding depth value of the depth buffer is kept unchanged. It should be noted that the smaller the depth value, the closer the pixel is to the observer. The above method can ensure that the pixel closest to the observer will be displayed, thereby producing a correct depth perception effect.
[0039] In an optional embodiment, the second normal vectors corresponding to the multiple pixels are updated to the normal buffer, including: detecting whether the second normal vectors corresponding to the multiple pixels are consistent with the normal vectors of the corresponding pixels stored in the normal buffer; and updating the second normal vectors corresponding to the multiple pixels that are inconsistent with the normal vectors of the corresponding pixels to the normal buffer.
[0040] Optionally, the second normal vector of each pixel is compared with the normal vector stored in the normal buffer. If they are inconsistent, the second normal vector of the pixel is updated to the normal buffer. Otherwise, there is no need to update the normal vector. It should be noted that when the corresponding pixel is rendered, the normal vector of the pixel will change accordingly. Based on this, it can be guaranteed that the latest normal vector is updated to the normal buffer.
[0041] Step S108, determining ambient occlusion factors corresponding to the plurality of pixels respectively based on the depth values respectively corresponding to the plurality of pixels included in the target image pre-stored in the depth buffer and the normal vectors respectively corresponding to the plurality of pixels pre-stored in the normal buffer, wherein the depth value is used to indicate distance information from the corresponding pixel to the target viewpoint;
[0042] Optionally, ambient occlusion is a graphics technique used to simulate shadow effects caused by light being blocked in an environment. For each pixel in the rendering target, its ambient occlusion factor can be calculated based on its values in the depth buffer and the normal buffer. The depth value and normal vector stored in the depth buffer and the normal buffer are obtained after the latest update based on the second image rendering result. The ambient occlusion factor is calculated based on the most recently stored and updated depth value and normal vector in the depth buffer and the normal buffer, and the ambient occlusion factor obtained on this basis is more accurate and reliable.
[0043] In an optional embodiment, based on depth values corresponding to multiple pixels included in a target image pre-stored in a depth buffer and normal vectors corresponding to multiple pixels pre-stored in a normal buffer, ambient occlusion factors corresponding to multiple pixels are determined, including: taking multiple pixels as target pixels, and obtaining ambient occlusion factors corresponding to the multiple pixels in the following manner: determining multiple neighbor pixels of the target pixel within a predetermined neighborhood from the multiple pixels; determining depth values corresponding to the multiple neighbor pixels from the depth values corresponding to the multiple pixels stored in the depth buffer; determining normal vectors corresponding to the multiple neighbor pixels from the normal vectors corresponding to the multiple pixels stored in the normal buffer; obtaining the ambient occlusion factor corresponding to the target pixel based on the depth values corresponding to the multiple neighbor pixels and the normal vectors corresponding to the multiple neighbor pixels.
[0044] Optionally, the predetermined neighborhood may be a spherical area centered on the target pixel, and multiple pixels within the spherical area are used as multiple neighbor pixels of the target pixel. Based on the depth values and normal vectors of each neighbor pixel stored in the depth buffer and the normal buffer, the ambient occlusion factor corresponding to the target pixel is fitted, and the ambient occlusion factor corresponding to the target pixel is obtained on this basis.
[0045] It should be noted that the role of the ambient occlusion factor is to increase the sense of reality and fidelity during the rendering process, making the lighting in the scene more natural. By considering the occlusion of light by surrounding pixels, the propagation of light in the real environment can be simulated, making the rendered image more realistic. At the same time, calculating the ambient occlusion factor can also enhance the layering and three-dimensional sense of the scene, making the spatial relationship between pixels clearer. By considering the influence of surrounding pixels on lighting, richer shadow effects can be produced, thereby enhancing the three-dimensional sense and depth of the scene.
[0046] In an optional embodiment, based on the depth values corresponding to multiple neighbor pixels respectively and the normal vectors corresponding to the multiple neighbor pixels respectively, an ambient light occlusion factor corresponding to the target pixel is obtained, including: based on the depth values corresponding to the multiple neighbor pixels respectively and the depth value of the target pixel stored in the depth buffer, obtaining the distances between the multiple neighbor pixels and the target pixel respectively; calculating the angles between the normal vectors corresponding to the multiple neighbor pixels respectively and the normal vector of the target pixel stored in the normal buffer, to obtain the angle values corresponding to the multiple neighbor pixels respectively; based on the distances between the multiple neighbor pixels and the target pixel respectively and the angle values corresponding to the multiple neighbor pixels respectively, obtaining the ambient light occlusion factor corresponding to the target pixel.
[0047] Optionally, the value of the depth buffer represents the distance from each pixel to the observer (i.e., the target viewpoint), and the value of the normal buffer represents the normal vector corresponding to each pixel; based on the value in the depth buffer, the distance between each neighbor pixel and the target pixel is calculated, which can be measured using the Euclidean distance or other distance measurement methods; based on the normal information in the normal buffer, the normal angle between each neighbor pixel and the target pixel is calculated, which can be calculated using the dot product operation; and the ambient occlusion factor is further calculated based on the distance and normal angle information. In the above method, the ambient occlusion factor around each pixel is calculated, that is, the degree to which the ambient light is blocked in the area is calculated. The ambient occlusion factor can be used to simulate the lighting effect in the real world, making the rendered image more realistic and true. Distance attenuation takes into account the attenuation effect of light when it propagates in space, while the normal angle takes into account the shielding effect of the surface normal on the light. Comprehensive calculation can obtain an ambient occlusion factor, which is used to adjust the final color of the pixel, making the rendering result more realistic and detailed.
[0048] In an optional embodiment, based on the distances between multiple neighbor pixels and the target pixel, and the angle values corresponding to the multiple neighbor pixels, an ambient light shielding factor corresponding to the target pixel is obtained, including: constructing an attenuation function, wherein the attenuation function is used to indicate the functional relationship between the distance, the angle value and the ambient light shielding factor between the neighbor pixel and the target pixel; based on the distances between multiple neighbor pixels and the target pixel, and the angle values corresponding to the multiple neighbor pixels, using the attenuation function to obtain the ambient light attenuation factors corresponding to the multiple neighbor pixels; based on the ambient light attenuation factors corresponding to the multiple neighbor pixels, the ambient light shielding factor corresponding to the target pixel is obtained.
[0049] Optionally, based on the distance and normal angle information, an attenuation function (usually an exponential function) can be used to calculate the ambient occlusion factor. When setting the attenuation function, the effect of distance and angle on the ambient occlusion factor can be considered, so that neighbor pixels that are farther away from the target pixel and have a smaller angle are more occluded. By setting the attenuation function, the effect of occlusion on light propagating in the environment can be simulated, thereby affecting the brightness of the object surface. By calculating the ambient occlusion factor through the attenuation function, the propagation and reflection of light in the environment can be more realistically simulated, making the rendered object surface look more realistic and natural.
[0050] Optionally, the attenuation function can be constructed as follows: occlusionFactor = exp(-k*(d+b*cos(θ))). Wherein, occlusionFactor represents the ambient occlusion factor, k is a constant used to control the attenuation speed, d is the distance between the neighbor pixel and the target pixel, θ is the angle value, and b is a constant used to control the effect of the angle on the ambient occlusion factor. In the attenuation function, the exponential part of the exponential function is composed of the distance and the angle, which means that places with smaller distances and angles will have higher ambient occlusion factors, while places with larger distances and angles will have lower ambient occlusion factors. Optionally, the ambient light attenuation factors corresponding to multiple neighbor pixels can be averaged or weighted averaged, and the result obtained can be used as the ambient light occlusion factor corresponding to the target pixel.
[0051] Step S110: updating the color of the second image rendering result based on the ambient light occlusion factors corresponding to the plurality of pixels, to obtain a target image rendering result.
[0052] Optionally, the ambient occlusion factor can be used to simulate the shadow effect under ambient light, affecting the final color calculation of the pixel. In the above manner, based on the ambient occlusion factors corresponding to multiple pixels, the color of the second image rendering result is updated, and the obtained target image rendering result can better present the ambient occlusion effect.
[0053] Through the above steps S102 to S110, it is possible to set a depth buffer and a normal buffer to store the depth and normal information of each pixel in the image, more accurately calculate the ambient occlusion factor based on the depth and normal information of each pixel in the image stored in the depth buffer and the normal buffer, and perform color correction and rendering of the image based on the ambient occlusion factor, thereby achieving the technical effect of simplifying the ambient occlusion processing flow and reducing the ambient occlusion processing cost, thereby solving the technical problem of complex operation process and high operation cost in the method of performing ambient occlusion through additional tools in the related art.
[0054] Based on the above embodiments and optional embodiments, the present invention proposes an optional implementation mode: Figure 2 is a flow chart of an optional ambient light occlusion processing method according to an embodiment of the present invention. Figure 2 As shown, the method includes:
[0055] S1, create a buffered image java.awt.image.BufferedImage object as the rendering target, set its width, height and color mode;
[0056] S2, create a two-dimensional java.awt.Graphics2D object as a rendering tool, obtain its drawing context from the BufferedImage object, and set its rendering parameters;
[0057] S3, create a java.awt.image.BufferedImage object as a depth buffer, set its width, height, and color mode, and fill its pixels with an initial value;
[0058] S4, create a java.awt.image.BufferedImage object as a normal buffer, set its width, height and color mode, and fill its pixels with an initial value;
[0059] S5, according to the geometric data in the scene, that is, the target image data, use the Graphics2D object to draw its outline onto the rendering target, obtain the first image rendering result, and simultaneously update the corresponding depth value and normal vector in the depth buffer and the normal buffer;
[0060] S6, according to the light source data in the scene, use the Graphics2D object to draw its influence range on the rendering target, add the light source data to the first image rendering result, obtain the second image rendering result, and simultaneously update the corresponding depth value and normal vector in the depth buffer and the normal buffer;
[0061] S7, for each pixel in the rendering target, that is, each pixel in the second image rendering result, calculate its ambient occlusion factor according to its depth value in the depth buffer and the normal vector in the normal buffer, that is, the degree to which each pixel is blocked by ambient light from surrounding geometric bodies;
[0062] S8, adjusting the color value of each pixel in the rendering target according to the ambient occlusion factor so that the pixel presents an ambient occlusion effect;
[0063] S9, outputting the rendering target as the final rendering result, that is, the target image rendering result.
[0064] Through the above steps S1 to S9, the purpose of setting a depth buffer and a normal buffer to store the depth and normal information of each pixel in the image can be achieved, the ambient occlusion factor can be calculated more accurately based on the depth and normal information of each pixel in the image stored in the depth buffer and the normal buffer, and the color correction and rendering of the image can be performed based on the ambient occlusion factor, thereby achieving an efficient and high-quality ambient occlusion effect based on the Java awt software package without relying on a third-party library or hardware acceleration, thereby simplifying the ambient occlusion processing flow and reducing the ambient occlusion processing cost, thereby solving the technical problem of complex operation process and high operation cost in the method of performing ambient occlusion through additional tools in the related art.
[0065] In this embodiment, an ambient light shielding processing device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and will not be repeated hereafter. As used below, the terms "module" and "device" can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0066] According to an embodiment of the present invention, a device embodiment for implementing the above-mentioned ambient light occlusion processing method is also provided. Figure 3 is a schematic diagram of the structure of an ambient light occlusion processing device according to an embodiment of the present invention. Figure 3 As shown, the above-mentioned ambient light occlusion processing device includes: a contour drawing module 300, a light source data acquisition module 302, a light source data adding module 304, an ambient light occlusion factor determination module 306, and a color updating module 308, wherein:
[0067] The contour drawing module 300 is used to draw contour information corresponding to the target image on the rendering target by using the image drawing class to obtain a first image rendering result;
[0068] A light source data acquisition module 302, connected to the contour drawing module 300, for acquiring light source data to be added to the target image;
[0069] A light source data adding module 304, connected to the light source data acquiring module 302, for adding the light source data to the first image rendering result by using an image drawing class to obtain a second image rendering result;
[0070] The ambient occlusion factor determination module 306 is connected to the light source data adding module 304, and is used to determine the ambient occlusion factors corresponding to the plurality of pixels respectively based on the depth values corresponding to the plurality of pixels included in the target image pre-stored in the depth buffer, and the normal vectors corresponding to the plurality of pixels pre-stored in the normal buffer, wherein the depth value is used to indicate the distance information from the corresponding pixel to the target viewpoint;
[0071] The color updating module 308 is connected to the ambient light occlusion factor determining module 306 and is used to update the color of the second image rendering result based on the ambient light occlusion factors corresponding to the plurality of pixels to obtain the target image rendering result.
[0072] In an embodiment of the present invention, a contour drawing module 300 is set to draw contour information corresponding to a target image on a rendering target using an image drawing class to obtain a first image rendering result; a light source data acquisition module 302 is connected to the contour drawing module 300 and is used to obtain light source data to be added to the target image; a light source data adding module 304 is connected to the light source data acquisition module 302 and is used to add the light source data to the first image rendering result using an image drawing class to obtain a second image rendering result; an ambient light occlusion factor determination module 306 is connected to the light source data adding module 304 and is used to determine ambient light occlusion factors corresponding to multiple pixels respectively based on depth values corresponding to multiple pixels included in the target image pre-stored in a depth buffer and normal vectors corresponding to multiple pixels pre-stored in a normal buffer, wherein the depth The degree value is used to indicate the distance information from the corresponding pixel to the target viewpoint; the color update module 308 is connected to the ambient occlusion factor determination module 306, and is used to update the color of the second image rendering result based on the ambient occlusion factors corresponding to multiple pixels, so as to obtain the target image rendering result, thereby achieving the purpose of setting a depth buffer and a normal buffer to store the depth and normal information of each pixel in the image, more accurately calculating the ambient occlusion factor based on the depth and normal information of each pixel in the image stored in the depth buffer and the normal buffer, and performing color correction and rendering of the image based on the ambient occlusion factor, thereby achieving the technical effect of simplifying the ambient occlusion processing flow and reducing the ambient occlusion processing cost, and further solving the technical problem of the method of performing ambient occlusion through additional tools in the related art, which has a complex operation process and high operation cost.
[0073] It should be noted that the above modules can be implemented by software or hardware. For example, for the latter, it can be implemented in the following ways: the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0074] It should be noted that the above-mentioned contour drawing module 300, light source data acquisition module 302, light source data addition module 304, ambient light occlusion factor determination module 306, and color update module 308 correspond to steps S102 to S110 in the embodiment, and the examples and application scenarios implemented by the above-mentioned modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiment. It should be noted that the above-mentioned modules can be run in a computer terminal as part of the device.
[0075] It should be noted that the optional or preferred implementation of this embodiment can refer to the relevant description in the embodiment, which will not be repeated here.
[0076] The above-mentioned ambient light occlusion processing device may also include a processor and a memory. The above-mentioned contour drawing module 300, light source data acquisition module 302, light source data adding module 304, ambient light occlusion factor determination module 306, color update module 308, etc. are all stored in the memory as program modules, and the processor executes the above-mentioned program modules stored in the memory to realize corresponding functions.
[0077] The processor includes a kernel, which retrieves the corresponding program module from the memory. The kernel may be one or more. The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. The memory includes at least one memory chip.
[0078] According to an embodiment of the present application, an embodiment of a non-volatile storage medium is also provided. Optionally, in this embodiment, the non-volatile storage medium includes a stored program, wherein when the program is executed, the device where the non-volatile storage medium is located is controlled to execute any one of the ambient light shielding processing methods.
[0079] Optionally, in this embodiment, the non-volatile storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group, and the non-volatile storage medium includes a stored program.
[0080] Optionally, when the program is running, the device where the non-volatile storage medium is located is controlled to perform the following functions: use an image drawing class to draw contour information corresponding to the target image on the rendering target to obtain a first image rendering result; obtain light source data to be added to the target image; use an image drawing class to add the light source data to the first image rendering result to obtain a second image rendering result; based on depth values corresponding to multiple pixels included in the target image pre-stored in the depth buffer, and normal vectors corresponding to multiple pixels pre-stored in the normal buffer, determine ambient occlusion factors corresponding to multiple pixels respectively, wherein the depth value is used to indicate distance information from the corresponding pixel to the target viewpoint; based on the ambient occlusion factors corresponding to the multiple pixels respectively, update the color of the second image rendering result to obtain a target image rendering result.
[0081] According to an embodiment of the present application, an embodiment of a processor is also provided. Optionally, in this embodiment, the processor is used to run a program, wherein the program executes any one of the ambient light occlusion processing methods when it is run.
[0082] According to an embodiment of the present application, an embodiment of a computer program product is also provided. Optionally, in this embodiment, the computer program product includes a computer program, and when the computer program is executed by a processor, the computer program implements any one of the steps of the ambient light occlusion processing method.
[0083] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing a program initialized with the following method steps: using an image drawing class to draw contour information corresponding to a target image on a rendering target to obtain a first image rendering result; obtaining light source data to be added to the target image; using an image drawing class to add the light source data to the first image rendering result to obtain a second image rendering result; based on depth values corresponding to a plurality of pixels included in the target image pre-stored in a depth buffer, and normal vectors corresponding to a plurality of pixels pre-stored in a normal buffer, determining ambient occlusion factors corresponding to a plurality of pixels, respectively, wherein the depth value is used to indicate distance information from the corresponding pixel to a target viewpoint; based on the ambient occlusion factors corresponding to a plurality of pixels, respectively, updating the color of the second image rendering result to obtain a target image rendering result.
[0084] An embodiment of the present invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: using an image drawing class to draw contour information corresponding to a target image on a rendering target to obtain a first image rendering result; obtaining light source data to be added to the target image; using an image drawing class to add the light source data to the first image rendering result to obtain a second image rendering result; based on depth values corresponding to a plurality of pixels included in the target image pre-stored in a depth buffer, and normal vectors corresponding to a plurality of pixels pre-stored in a normal buffer, determining ambient light occlusion factors corresponding to a plurality of pixels, wherein the depth value is used to indicate distance information from the corresponding pixel to a target viewpoint; based on the ambient light occlusion factors corresponding to a plurality of pixels, the color of the second image rendering result is updated to obtain a target image rendering result.
[0085] The above sequence of the embodiments of the present invention is for description only and does not represent the superiority or inferiority of the embodiments.
[0086] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0087] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the above modules can be a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, modules or indirect coupling or communication connection of modules, which can be electrical or other forms.
[0088] The modules described above as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0089] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of software functional modules.
[0090] If the above-mentioned integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable non-volatile storage medium. Based on this understanding, the technical solution of the present invention is essentially 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. The computer software product is stored in a non-volatile storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the various embodiments of the present invention. The aforementioned non-volatile storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0091] The above are only preferred embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for processing ambient light occlusion, characterized in that: include: Using an image drawing class to draw contour information corresponding to a target image on a rendering target, to obtain a first image rendering result; Acquire light source data to be added to the target image; Using the image drawing class to add the light source data to the first image rendering result to obtain a second image rendering result; Determine ambient occlusion factors corresponding to the plurality of pixels respectively, based on depth values respectively corresponding to the plurality of pixels included in the target image pre-stored in the depth buffer, and normal vectors respectively corresponding to the plurality of pixels pre-stored in the normal buffer, wherein the depth values are used to indicate distance information from the corresponding pixels to the target viewpoint; Based on the ambient light occlusion factors respectively corresponding to the multiple pixels, the color of the second image rendering result is updated to obtain a target image rendering result.
2. The method according to claim 1, characterized in that Before using the image drawing class to add the light source data to the first image rendering result to obtain the second image rendering result, the method further includes: Based on the first image rendering result, determine first depth values respectively corresponding to a plurality of pixels included in the target image, and first normal vectors respectively corresponding to the plurality of pixels; The first depth values respectively corresponding to the plurality of pixels are updated to the depth buffer, and the first normal vectors respectively corresponding to the plurality of pixels are updated to the normal buffer.
3. The method according to claim 2, characterized in that Before determining the ambient occlusion factors respectively corresponding to the plurality of pixels included in the target image based on the depth values respectively corresponding to the plurality of pixels stored in the depth buffer and the normal vectors respectively corresponding to the plurality of pixels stored in the normal buffer, the method further includes: Determine, based on the second image rendering result, second depth values corresponding to the plurality of pixels respectively, and second normal vectors corresponding to the plurality of pixels respectively; The second depth values respectively corresponding to the plurality of pixels are updated to the depth buffer, and the second normal vectors respectively corresponding to the plurality of pixels are updated to the normal buffer.
4. The method according to claim 3, characterized in that: The updating of the second depth values respectively corresponding to the plurality of pixels to the depth buffer comprises: Detecting whether the second depth values respectively corresponding to the plurality of pixels are less than the depth values of the corresponding pixels stored in the depth buffer; updating the second depth values respectively corresponding to the plurality of pixels, which are less than the depth values of the corresponding pixels stored in the depth buffer, to the depth buffer; The updating of the second normal vectors respectively corresponding to the plurality of pixels to the normal buffer includes: Detect whether the second normal vectors respectively corresponding to the multiple pixels are consistent with the normal vectors of the corresponding pixels stored in the normal buffer; update the second normal vectors respectively corresponding to the multiple pixels that are inconsistent with the normal vector of the corresponding pixel to the normal buffer.
5. The method according to claim 1, characterized in that The determining, based on the depth values respectively corresponding to the plurality of pixels included in the target image pre-stored in the depth buffer and the normal vectors respectively corresponding to the plurality of pixels pre-stored in the normal buffer, the ambient occlusion factors respectively corresponding to the plurality of pixels, comprises: The plurality of pixels are respectively used as target pixels, and the ambient light occlusion factors corresponding to the plurality of pixels are obtained in the following manner: Determine, from the plurality of pixels, a plurality of neighbor pixels of the target pixel within a predetermined neighborhood; Determine the depth values corresponding to the plurality of neighbor pixels respectively from the depth values corresponding to the plurality of pixels respectively stored in the depth buffer; Determine normal vectors corresponding to the plurality of neighboring pixels respectively from the normal vectors corresponding to the plurality of pixels respectively stored in the normal buffer; Based on the depth values respectively corresponding to the plurality of neighbor pixels and the normal vectors respectively corresponding to the plurality of neighbor pixels, an ambient light occlusion factor corresponding to the target pixel is obtained.
6. The method according to claim 5, characterized in that The obtaining the ambient light occlusion factor corresponding to the target pixel based on the depth values respectively corresponding to the plurality of neighbor pixels and the normal vectors respectively corresponding to the plurality of neighbor pixels comprises: Based on the depth values respectively corresponding to the plurality of neighbor pixels and the depth value of the target pixel stored in the depth buffer, obtaining the distances between the plurality of neighbor pixels and the target pixel respectively; Calculating the angles between the normal vectors corresponding to the plurality of neighbor pixels and the normal vector of the target pixel stored in the normal buffer, to obtain the angle values corresponding to the plurality of neighbor pixels; Based on the distances between the plurality of neighbor pixels and the target pixel, and the angle values corresponding to the plurality of neighbor pixels, an ambient light shielding factor corresponding to the target pixel is obtained.
7. The method according to claim 6, characterized in that The obtaining the ambient light shielding factor corresponding to the target pixel based on the distances between the plurality of neighbor pixels and the target pixel, and the angle values corresponding to the plurality of neighbor pixels, comprises: Constructing an attenuation function, wherein the attenuation function is used to indicate a functional relationship between a distance between a neighbor pixel and the target pixel, an angle value, and an ambient light occlusion factor; Based on the distances between the plurality of neighbor pixels and the target pixel, and the angle values respectively corresponding to the plurality of neighbor pixels, the attenuation function is used to obtain the ambient light attenuation factors respectively corresponding to the plurality of neighbor pixels; Based on the ambient light attenuation factors respectively corresponding to the plurality of neighbor pixels, an ambient light shielding factor corresponding to the target pixel is obtained.
8. An ambient light occlusion processing device, characterized in that: include: A contour drawing module, used to draw contour information corresponding to a target image on a rendering target by using an image drawing class, to obtain a first image rendering result; A light source data acquisition module, used to acquire light source data to be added to the target image; A light source data adding module, used to add the light source data to the first image rendering result by using the image drawing class to obtain a second image rendering result; an ambient occlusion factor determination module, configured to determine ambient occlusion factors corresponding to a plurality of pixels respectively included in the target image based on depth values respectively corresponding to the plurality of pixels pre-stored in a depth buffer, and normal vectors respectively corresponding to the plurality of pixels pre-stored in a normal buffer, wherein the depth value is used to indicate distance information from the corresponding pixel to a target viewpoint; The color update module is used to update the color of the second image rendering result based on the ambient light occlusion factors corresponding to the multiple pixels respectively, so as to obtain a target image rendering result.
9. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the ambient light occlusion processing method described in any one of claims 1 to 7.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the ambient light occlusion processing method according to any one of claims 1 to 7 are implemented.
