Summary of the invention
Object of the present invention is exactly to solve the problem, propose a kind of multiple light courcess accelerated method towards programmable shader, first the method achieves Lightcuts algorithm under programmable shader environment, by light source is clustered into tree structure, and then cutting is carried out to light source tree, reduce the actual number of light sources played up, the relation of render time and number of light sources can be reduced to sublinear, and stability is relatively good, good acceleration effect can be had in most cases.
To achieve these goals, the present invention adopts following technical scheme:
Towards a multiple light courcess accelerated method for programmable shader, comprising:
(1) render engine reads the light source information in document scene, extracts illumination parameter needed for Lightcuts algorithm, stored in light source chained list;
(2) before render scenes, utilize Lightcuts algorithm to carry out cluster to light source, traversal light source chained list, every class light source is built to the light source tree of the overall situation;
(3), in render process, point to be rendered on geometric jacquard patterning unit surface is positioned in buffer zone; To playing up a cluster in buffer zone: point close on same object has identical material, affects by identical light source, therefore next step is played up one group close on same object and a little asks a public light source to cut, and plays up;
(4) that organizes for each plays up a little, utilizes the light source tree of the overall situation, cuts playing up a grouping calculating light source;
(5) value of shade field parameter and background luminance parameter is set, if current light source node brightness L
cbe less than shade field parameter value, then get the estimated value of its background luminance parameter value as the brightness of current light source node, carry out the calculating asking light source to cut;
(6) this light source of render engine identification cut in tinter file, use light source cut replace original light source throw light on;
(7) repeat render process, play up until all and a little played up, export rendering result image.
In described step (3), to play up the concrete grammar a little asking common light source to cut as follows to close on same object:
A. each group is played up and is a little shared a storehouse storing light source and cut; Arrange marker bit, whether performed by mark is first point that this group plays up a little;
If what b. perform is first point, then normal execution asks light source to cut, and result is stored into storehouse; If not first point, then the light source calculated from the last time storehouse cuts open the beginning, and the light source of asking performing current point cuts process, and result still leaves in storehouse;
C. constantly circulation performs step b, is a little all finished until this group is played up, and the result in storehouse is exactly that the common light source played up a little of this group is cut.
In described step (4), to playing up a concrete grammar that grouping calculating light source cuts be:
1) two value: L of light source node in light source tree are estimated
cand upperbound; Described L
crepresent that light source cluster is actual and be irradiated to estimating of the brightness of playing up a little; Light source cluster representated by upperbound representation theory glazing source node is irradiated to plays up an expectation maximal value for the brightness produced;
2) if maxupperbound<0.02* ∑ L
c, illustrate that the upperbound value of all light source nodes in storehouse all meets and be less than 0.02* ∑ L
ccondition, then storehouse inner light source node is the light source node of finally trying to achieve, and calculates complete; Wherein, maxupperbound is the maximal value of the upperbound of all nodes in stack, and 0.02 is weber parameter;
Otherwise divide this light source node, pop by the node divided, its child node is stacked; Calculate upperbound and L newly entering stack node
c.
In described step (5), if after employing background luminance, in computation process afterwards, the light source node brightness L estimated
cwhen value has been more than or equal to again shade field parameter value, then recovers use and estimate light source node brightness L
ccarry out the calculating asking light source to cut.
Described shade field parameter acquiescence gets the intermediate value 0.05 of absolute threshold for sensation limit, and described background luminance parameter is more than or equal to shade field parameter value, and acquiescence gets absolute threshold for sensation limit 0.1.
In described step (3) to the method playing up a cluster in buffer zone be:
1st step: for the set of same group of light source, finds two light sources that wherein weight is minimum;
2nd step: two light sources minimum for weight build a father node, in two light sources, Stochastic choice light source represents light source as it, record bounding box information and total luminance value;
3rd step: father node is added light cluster, two child nodes are deleted from light cluster;
4th step: jump to the 1st step and perform, until only remain node, i.e. a root node in the set of this group light source, light source tree structure completes; Wherein leaf node is actual light source, and internal node is for representing light source.
In described 1st step, the computing method of weight are shown below:
W=I
c(a
c 2+c
2(1–cosβ
c)
2)
Wherein, I
cbe two light-source brightness and, a
cit is the catercorner length of two light source axis aligned bounding box; Value for pointolite and directional light c is 0, and for spotlight, c is the constant in a contact space size and spotlight direction, relevant to the catercorner length of scene bounding box; β
cfor 1/2 of these two light source binding angles.
Beneficial effect of the present invention
1. the present invention is directed to Lightcuts algorithm acceleration effect this problem unsatisfactory of playing up of dash area in scene has been carried out analyzing and innovatory algorithm, propose shade territory and background luminance two parameters, the render process of dash area is controlled, avoid the calculating that some are unnecessary, accelerate the efficiency that shaded side is played up.
2. the present invention adopts the method for a cluster played up, and a little asks for Lightcuts to one group of same material, space length near playing up, the structure time that the light source of minimizing cuts, lifting rendering efficiency.
3. in order to make algorithm support to play up flow process under programmable shader, the present invention devises relevant interface, and the programmable shader making it support business to play up generally to adopt, improves algorithm availability.
Embodiment
Below in conjunction with specific embodiment and accompanying drawing, the invention will be further described.
Lightcuts algorithm is mainly divided into light source cluster and asks for light source and cut two parts.
A. light source cluster:
Light source cluster in scene is become a binary tree by light source cluster process, as shown in Figure 1.Step is as follows:
1) for the set of all similar light sources, find two light sources that wherein weight is minimum, the computing method of weight are as shown in formula (1):
W=I
c(a
c 2+ c
2(1 – cos β
c)
2) formula (1)
Wherein I
cbe two light-source brightness and, a
cit is the catercorner length of two light source axis aligned bounding box.Value for pointolite and directional light c is 0.For spotlight, c is the constant in a contact space size and spotlight direction, relevant to the catercorner length of scene bounding box, β
cfor 1/2 of these two light source binding angles.
2) for two light sources that weight is minimum build a father node, in two light sources, Stochastic choice light source represents light source as it, record bounding box information and total luminance value.Bounding box be meant to slightly large with volume and the simple solid of characteristic replaces complicated geometric object approx.
3) father node is added light cluster, two child nodes are deleted from light cluster.
4) jump to the first step to perform, until only remain node, i.e. a root node in light cluster, light source tree structure completes.Wherein leaf node is actual light source, and internal node is for representing light source.
B. light source is asked to cut:
The simplification of multiple light courcess to be carried out under the prerequisite ensureing rendering result quality, just need according to weber principle split vertexes solving in the process that light source cuts.In fission process, for the representative light source node in light source tree, there are two value: L
cand upperbound.These two values just calculate when finding node:
L
crepresent that light source cluster is actual and be irradiated to estimating of the brightness of playing up a little.Its computing formula (2) is as follows:
L
c(x, w) ≈ M
j(x, w) G
j(x) V
j(x) ∑
i ∈ Ci
iformula (2)
Wherein gather C and represent a light source cluster, x represents and plays up point (comprising position, the information such as normal direction), and w represents viewpoint direction, and M represents the material factor, and G represents geometric factor, and V represents observability, and I represents light-source brightness.I represents actual light source, and j is the representative light source of current cluster.Light source cluster in upperbound representation theory representated by node is irradiated to plays up an expectation maximal value (supposing that light source is all visible) for the brightness produced.Its computing formula and L
cformula identical, just in computation process, material factor M, geometric factor G and visibility factor V want capping value.
The concrete process asking light source to cut as shown in Figure 2, comprising:
1) set up a storehouse to deposit result.First root node is stacked, calculate upperbound and L of root node
c.
2) if maxupperbound<0.02* ∑ L
c(maxupperbound is the maximal value of the upperbound of all nodes in stack, and 0.02 is weber parameter), illustrates that the upperbound value of all nodes in stack all meets and is less than 0.02* ∑ L
ccondition, then stack interior nodes is the node of finally trying to achieve, and calculates complete.Otherwise divide this node (if there is child node), pop by the node divided, its child node is stacked.Calculate upperbound and L newly entering stack node
c.
The result be just through after Lightcuts simplify of arithmetic stored in final storehouse, namely a light source cuts.
The more local execution efficiency of original Lightcuts algorithm shade in scene is lower, and in the shaded side that a large amount of light source is all blocked, the number that light source cuts inner light source equals actual light source number substantially.These shaded side estimate brightness L
cvery little (being likely 0), thus weber parameter 0.02 and L
cproduct also very little, and the upper limit estimated value upperbound representing light source is not owing to considering to block, and generally all can be greater than 0.02*L
c.Cause asking light source to cut process interior joint constantly to divide, until leaf node.
In order to accelerate actual rendering efficiency, the present invention proposes shade territory and background luminance two optional empirical parameters.When calculating the light source performed, as the total illumination value L estimated
cbe less than shade field parameter value (for ensureing rendering effect, the error that neutralization brings when estimating total illumination, acquiescence gets the intermediate value 0.05 of absolute threshold for sensation limit) time, thinking that this is played up a little is in shade, background luminance parameter value (be generally more than or equal to shade field parameter value, be defaulted as absolute threshold for sensation limit 0.1) is got to it and estimates brightness L as current
cvalue, carry out the calculating asking light source to cut.If after employing background luminance, in computation process afterwards, the total illumination value estimated has been more than or equal to again shade field parameter value, then recover use and estimate brightness L
ccalculate, guarantee accuracy.
Play up in suitable increase shadow region a little estimate brightness, rationally can reduce light source and cut inner light source sum, improve the efficiency played up of shaded side, the actual result played up also meets expection, and the picture quality that can ensure.
In order to raise the efficiency, some grouping close on same object be played up, only need execution material shader, just can play up maximum 256 points.Close some general law is more or less the same to position, the light source calculated cuts also roughly the same, so according to this feature, the method that employing incremental computations common light source is cut to adapt to engine to the flow process playing up a packet transaction, and accelerates the speed asking light source to cut.
Programmable shader is widely used in playing up, but traditional Lightcuts algorithm does not generally support the light source that programmable shader describes.The present invention extracts the necessary parameter of Lightcuts algorithm from extraction light source tinter and transmits, thus supports programmable shader.The information spinner extracted will comprise: light source type, light-source brightness, evanescent mode, light source position, direction, range of exposures.
In render engine, realize Lightcuts algorithm, first must obtain light source information, to set up light source tree.And the process setting up light source tree must be carried out before playing up each point, achievement process can regard a kind of pre-service as, overall Exactly-once.Render engine can travel through all light sources to calculate plays up an illumination value at place.Apply Lightcuts algorithm to accelerate, need to add the process asking light source to cut before traversal, prescind the original light source of replacement with the light source obtained and play up, reach the object of acceleration.
Multiple light courcess accelerated method towards programmable shader of the present invention comprises the following steps:
1) render engine reads light source information in document scene, and Lightcuts resolves and extracts required illumination parameter, stored in light source chained list.
2) before render scenes, Lightcuts algorithm carries out cluster to light source, traversal light source chained list, every class light source is built to the light source tree of the overall situation.
3), in render process, during the illumination of render engine calculation level, Lightcuts algorithm is performed:
3.1), when playing up point, point to be rendered is positioned in buffer zone.
3.2) to playing up a cluster in buffer zone, point close on same object has identical material, affects by identical light source, by its cluster, plays up.
3.3) play up a little for one group 256, utilize global light source to set, solve a light source and cut.
3.4) cutting interior light source to light source to travel through, according to shade territory or background luminance parameter estimation light source, scene is affected, ignoring without affecting light source.Submission is played up and is performed light source tinter
4) render engine performs corresponding light source tinter, calculates illumination result.Choose next to mark words and phrases for special attention, repeat step 2, until played up, export rendering result image.
Realize details:
1) the light source shader of programmable shader definition and material shader has very large dirigibility, needs to define the interface that matches with Lightcuts algorithm and retrains.Only extract necessary parameter during Interface design to transmit, avoid unnecessary calculating, also prevent interface parameters to tinter constraint too much simultaneously, affect the dirigibility of programmable shader.
In above-mentioned design proposal, asking light source to cut needs to estimate the value (L of direct illumination
c), in this and material, directly the calculating of illumination part has is much repetition, and twice calculating causes efficiency to reduce.Confirm that the workload of in double counting more than 90% comes from solving of observability V through experiment.The calculating of observability relates to hacures and whole scene and asks and hand over (trace function), and relevant to dough sheet number in scene, complexity is very high.So devise trace_reuse interface parameters, render engine is calculated the knot fruit of asking obtained in Lc process and pass to material shader and reuse, improve acceleration effect.
2) in engine renders flow process, in order to raise the efficiency, some grouping close on same object be played up, so only need execution material tinter, just can play up maximum 256 points.Close some general law is more or less the same to position, and the light source calculated cuts also roughly the same.According to this feature, the method that the present invention adopts incremental computations common light source to cut, cutting playing up a grouping calculating light source, accelerating the speed asking light source to cut.Computing method are as follows:
1. one group of point shares a storehouse storing light source and cut.Arrange marker bit, whether performed by mark is first point of one group of point.
If what 2. perform is first point, then normal execution asks light source to cut, and result is stored into storehouse.If not first point, then the light source calculated from the last time storehouse cuts open the beginning, and the light source of asking performing current point cuts process, and result still leaves in storehouse.
3. constantly circulation performs second step, until one group of point is all finished, the result in storehouse is exactly that this common light source organizing point is cut.
For a Rendering algorithms, be namely a process three-dimensional scenic being converted into picture, include video camera in scene, solid, light source, material, the information such as pinup picture texture.Before rendering task starts, the expression of three-dimensional scenic in modeling software is converted into the representation that render engine can read and identify, in Transformation Program, according to of the present invention, in programmable shader, realize Lightcuts algorithm and relevant improvement.User submits a contextual data file bag comprising complete information to afterwards, and render engine can identify the video camera described in these files, solid, the information such as light source.After whole contextual data is read in, start to play up, execution algorithm in coloring process, output image.
Pudong's dim light of night scene is one and plays up example, and this scene comprises 110,000 tri patchs, 724 light sources, and all solids, light source, material all adopt and meet Renderman specification, and light source, material use programmable shader to describe.Concrete scene information data are as shown in table 1
Table 1
Lightcuts algorithm integration render engine of the present invention carries out following steps process:
1) user submits render scenes data to, and render engine reads contextual data, and Lightcuts resolves and extracts required illumination parameter, stored in the light source chained list of 724 light source compositions, resolves the valuation of user context brightness empirical parameter.
2) before render scenes, Lightcuts algorithm carries out cluster to light source, traversal light source chained list, building the global light source tree of 724 light source compositions, cutting for solving light source.
3) in render process, render engine calculates certain dough sheet material and is, needs to calculate this dough sheet illumination, then perform Lightcuts algorithm:
3.1) will dough sheet be positioned over a little in buffer zone.
3.2) to playing up a cluster in buffer zone, point close on same object has identical material, affects by identical light source, by its cluster, plays up.
3.3) play up a little for one group 256, utilize global light source to set, solve a light source and cut.
3.4) cutting interior light source to light source to travel through, according to shade territory or background luminance parameter estimation light source, scene is affected, ignoring without affecting light source.Submission is played up and is performed light source tinter
4) render engine performs corresponding light source tinter, calculates illumination result.Choose next to mark words and phrases for special attention, repeat step 2, until played up, export rendering result image.
In Pudong's dim light of night scene, traditional rendering intent, each average treatment quantity of light source of playing up is 724, use article [Lightcuts:a scalable approach to illumination] original method average treatment quantity of light source 275, this method average treatment quantity of light source is 149.The multiple light courcess optimized algorithm of comparing original, it accelerates number percent greatly between 30% to 40%.The concrete statistics of primal algorithm and innovatory algorithm of the present invention is adopted to contrast as shown in table 2.Not accelerating, adopting primal algorithm to accelerate to contrast as shown in Figure 3 with adopting the present invention's render time accelerated of improving one's methods.
Table 2
By reference to the accompanying drawings the specific embodiment of the present invention is described although above-mentioned; but not limiting the scope of the invention; one of ordinary skill in the art should be understood that; on the basis of technical scheme of the present invention, those skilled in the art do not need to pay various amendment or distortion that creative work can make still within protection scope of the present invention.