Summary of the invention
The invention provides a kind of image rendering method spraying based on radiance, avoid using complicated data structure, reduced widely and played up the spent time, can be efficiently real-time carry out playing up under global illumination, and be convenient to implement.
The image rendering method spraying based on radiance, comprises the following steps:
(1) from viewpoint along each pixel image to be rendered to scene, emit beam and determine the intersecting area of object in light and scene;
(2) using the central point of described intersecting area as sampled point corresponding to this pixel, obtain and generate the information recording of each sampled point, described information recording comprises the mediation distance between position vector, method phasor, brilliant value and sampled point and each pixel;
(3) for any one pixel, according to the information recording of each sampled point, utilize Weighting value function to calculate respectively the weighted value of each sampled point on the radiance value impact of current pixel, according to the radiosity equation of distortion, calculate the brilliant contribution margin of each sampled point to current pixel, and calculate the radiation out-degree contribution margin of this sampled point to current pixel according to brilliant contribution margin;
(4) size of the threshold value of relatively more described weighted value and setting, travel through all sampled points, the weighted value that weighted value is greater than to the threshold value of setting adds up and obtains the weight cumulative sum of this pixel, and radiation out-degree contribution margin corresponding to this weighted value is weighted to the cumulative radiation out-degree weighted sum that obtains;
(5) described weight cumulative sum and the precision of setting are compared:
If the cumulative precision that is less than setting of weight, returns and carry out step (2), difference is in described intersecting area, to take at random a bit as sampled point corresponding to this pixel at random;
Otherwise, by the radiation out-degree weighted sum of described pixel, divided by weight cumulative sum, calculate the indirect illumination value of this pixel;
(6) described indirect illumination value is added to the direct illumination value of this pixel obtains the illumination value of this pixel, and utilize this illumination value to play up this pixel.
Directly illumination value is known quantity, if this pixel is light source, because light source is artificial setting, its value is also known so; If not light source, so directly illumination value is 0.
Each pixel can be thought a criss-cross zonule, and due to dispersing of light, the intersecting area obtaining in scene is generally greater than pixel region.The precision of sampling when the center of general this intersecting area is sampled point is the highest, so the present invention starts sampling from center, contributes to improve rendering efficiency.When take precision that center is sampled point when inadequate, from this intersecting area, choose at random a bit as sampled point, and proceed precision judgement, until precision reaches setting value.The sampled point of each sampling is all different from the sampled point of front once sampling.
After determining sampled point, what can obtain sampled point is position (coordinate), the radiance value of self, with vector using this location mark as position vector, and according to this position vector, according to this sampled point scenery on the scene surface curve, determine its normal vector, and calculate the mediation distance between this sampled point and each pixel by the coordinate information of sampled point in coordinate system and the coordinate information of pixel (position vector).
The present invention samples to scene by pixel, determine the sampled point of each pixel, because the radiance value of each pixel is jointly contributed and obtained by all sampled points, therefore oppositely according to radiancy formula, calculate each sampled point to the contribution of the radiance value of each pixel (brilliant contribution margin), claim this process for radiance sprinkling.The method realizes simple, and does not exist and influence each other between each pixel, can parallel processing.
The present invention is according to determining after sampled point, consider that different sampled points are all different on the impact of each pixel, with Weighting value function, calculate the impact size (weighted value) of each sampled point on this pixel, affecting less sampled point ignores to the contribution of radiance value, only consider impact the sampled point of large (being greater than the threshold value of setting) the radiance value of this pixel is adopted to contribution, with these, adopt point to understand this pixel and play up.For improving precision, further precision is calibrated, by the cumulative weight cumulative sum that obtains this pixel of all relatively large weighted values, using the employing precision of this cumulative sum as this pixel, if weight cumulative sum does not reach the precision of setting, resampling is until ask for the illumination value of this pixel again and complete and play up after reaching the precision of setting.In the present invention, by twice precision, judge, effectively improved sampling precision, and then improved rendering accuracy.
Described step (1)~(3) are carried out by GPU; Described step (4)~(6) are carried out by CPU.Complicated large scene under global illumination is difficult to be played up out rapidly by GPU always.During the playing up of common this situation, by ray trace (ray tracing) and Monte Carlo, sample to calculate.And these two kinds of methods have the judgement of more logic, or recursive sequence, but GPU is to the processing of logic judgement and to possess the data processing of topological order all unable to do what one wishes.In the present invention because step (1)~(3) only have data operation, do not have too much logic judgement, and in above-mentioned steps, each computation process does not interfere with each other, thereby can be calculated by GPU, by parallel processing, greatly improve arithmetic speed, contributed to improve rendering efficiency, and comparatively logic judgement of the ratio of precision of carrying out, by CPU, completed, but this part of calculated amount is less, be only that the partial pixel that part is not met to accuracy requirement is proofreaied and correct, so little on whole time loss impact.Most calculating of algorithm can be carried out on GPU on the whole, concurrency feature that can adequate cause GPU, rapidly and efficiently complete scene rendering.
The present invention arranges brilliant buffer area in GPU, for storing information recording, weighted value and the radiation out-degree of each sampled point.Adopt non-simple data structure, greatly reduce the consumption of storage, reduce the complexity of visit data, behind GPU execution of step (1)~(3), CPU reads the data (being about to brilliant buffer area data-mapping to CPU) that brilliant buffer area is stored, by CPU, carry out subsequent step, complete image rendering.In execution step (1), need before to carry out initialization, empty described brilliant buffer area.CPU reads after the data that brilliant buffer area stores, and the data of brilliant buffer area storage are not deleted, and still retain, and as backup, for follow-up precision, calibrate and prepare.
The threshold value of setting and the product of described precision are 1.And generally, the precision of setting is greater than 1.
Weighting value function in described step (2) is as follows:
Wherein:
be the weighted value of m sampled point on the impact of the radiance value of k pixel, p
kand n
kbe respectively position vector and the normal vector of k pixel, p
mand n
mbe respectively position vector and the normal vector of m sampled point,
be the mediation distance between m sampled point and k pixel, k=1,2,3 ... K, m=1,2,3 ... K, the sum that K is pixel.
The position vector of each pixel can directly be obtained, and its normal vector can obtain according to the position simple computation of obtaining.
The radiosity equation of the distortion in described step (3) is as follows:
Wherein
be the brilliant contribution margin of m sampled point to k pixel, E
kbe the radiance value of k sampled point,
for the rotation gradient of sampled point k,
skew gradient for sampled point k.Rotation gradient and skew gradient refer to respectively rotation gradient and the skew gradient of the position vector of sampled point.
The following formula of described step (3) basis:
Calculate the radiation out-degree contribution margin Lo of m sampled point to k pixel, ρ
dit is the diffuse reflectance of k pixel.
Described diffuse reflectance is determined by the material of sampled point corresponding to this pixel.
Image rendering method of the present invention can complete the playing up of complex scene in time loss seldom, plays up complexity only relevant to pixel, is applicable to the application of playing up of nearly all complicated large scene.Compared with prior art, following beneficial effect of the present invention:
(1) the present invention is according to determining after sampled point, consider that different sampled points are all different on the impact of each pixel, with Weighting value function, calculate the impact size (weighted value) of each sampled point on this pixel, selecting to affect the sampled point of large (being greater than the threshold value of setting) plays up this pixel, for improving precision, further this precision is calibrated, effectively improved sampling precision, and then improved rendering accuracy;
(2) in image rendering method of the present invention, simple calculations is by GPU executed in parallel, complicated logic judgement is carried out by CPU, and radiance is set in GPU sprays buffer area, reduce the consumption of storage, the complexity that reduces visit data, reduces time loss greatly, makes the real-time of scene rendering obtain and significantly improve.
Embodiment
The image rendering method spraying based on radiance, comprises the following steps:
The image rendering method spraying based on radiance, comprises the following steps:
(1) from viewpoint along each pixel image to be rendered to scene, emit beam and determine the intersecting area of object in light and scene;
(2) using the central point of described intersecting area as sampled point corresponding to this pixel, obtain and generate the information recording of each sampled point, described information recording comprises the mediation distance between position vector, method phasor, brilliant value and sampled point and each pixel;
(3) for any one pixel, according to the information recording of each sampled point, utilize Weighting value function to calculate respectively the weighted value of each sampled point on the radiance value impact of current pixel, according to the radiosity equation of distortion, calculate the brilliant contribution margin of each sampled point to current pixel, and calculate the radiation out-degree contribution margin of this sampled point to current pixel according to brilliant contribution margin;
(4) size of the threshold value of relatively more described weighted value and setting, travel through all sampled points, the weighted value that weighted value is greater than to the threshold value of setting adds up and obtains the weight cumulative sum of this pixel, and radiation out-degree contribution margin corresponding to this weighted value is weighted to the cumulative radiation out-degree weighted sum that obtains;
(5) described weight cumulative sum and the precision of setting are compared:
If the cumulative precision that is less than setting of weight, returns and carry out step (2), difference is in described intersecting area, to take at random a bit as sampled point corresponding to this pixel at random;
Otherwise, by the radiation out-degree weighted sum of described pixel, divided by weight cumulative sum, calculate the indirect illumination value of this pixel;
(6) described indirect illumination value is added to the direct illumination value of this pixel obtains the illumination value of this pixel, and utilize this illumination value to play up this pixel.
In this image rendering method, threshold value and precision are set by artificial, and in the present embodiment, this threshold value is 1/a), and this precision is a.
In the present embodiment, after determining sampled point, what can obtain sampled point is position (coordinate), the radiance value of self, with vector using this location mark as position vector, and according to this position vector, according to this sampled point scenery on the scene surface curve, determine its normal vector, according to the coordinate of each sampled point and pixel in coordinate system, calculate the mediation distance between this sampled point and each pixel.
In the present embodiment, this pixel is not light source, and therefore directly illumination value is 0.
Step in this image rendering method (1)~(3) are carried out by GPU; Step (4)~(5) are carried out by CPU.
Weighting value function in step (2) is as follows:
Wherein:
be the weighted value of m sampled point on the impact of the radiance value of k pixel, p
kand n
kbe respectively position vector and the normal vector of k pixel, p
mand n
mbe respectively position vector and the normal vector of m sampled point,
be the mediation distance between m sampled point and k pixel, k=1,2,3 ... K, m=1,2,3 ... K, the sum that K is pixel.
The position vector of each pixel can directly be obtained, and its normal vector can obtain according to the position simple computation of obtaining.
The radiosity equation of the distortion in step (3) is as follows:
Wherein
be the brilliant contribution margin of m sampled point to k pixel, E
kbe the radiance value of k sampled point,
for sampled point k rotation gradient,
for sampled point k skew gradient.Rotation gradient and skew gradient refer to respectively rotation gradient and the skew gradient of the position vector of sampled point.
The following formula of step (3) basis:
Calculate the radiation out-degree contribution margin Lo of m sampled point to k pixel, ρ
dbe the diffuse reflectance of k pixel, wherein diffuse reflectance is determined by the material of sampled point corresponding to this pixel.
The above; be only the specific embodiment of the present invention, but the protection domain of invention is not limited to this, is anyly familiar with those skilled in the art in the technical scope that the present invention discloses; the variation that can expect easily or replacement, within all should being encompassed in protection scope of the present invention.