The transport of light within a volume of scattering media such as fog, steam, particulate clouds, or liquids can produce volumetric shading effects that, if well reconstructed by rendering, increase realism.
Volumetric shading effects can be accurately reconstructed by a full Monte Carlo simulation. However, Monte Carlo simulation is too costly for real time use. To date, there has been no success in computing lighting in a volume of scattering media in a way that is both realistic and fast enough for real time use, where, for example, a volume of scattering media, light source, and or scene objects change from frame to frame, as during a 3D game. While some techniques for real time estimation exist, they are incapable of accurately constructing high frequency close-up details. Furthermore, in real time order of efficiency, sharp shading variations (e.g., the edges of a volumetric shadow in a medium) have not been accurately computed and generally produce noticeable rendering artifacts.
Techniques discussed below relate to rendering light in scattering media in ways that are both accurate and sufficiently efficient for use in real time rendering.
The following summary is included only to introduce some concepts discussed in the Detailed Description below. This summary is not comprehensive and is not intended to delineate the scope of the claimed subject matter, which is set forth by the claims presented at the end.
Techniques are described for rendering a volume of scattering media, in particular by computing radiances of points or voxels in the scattering media. A set of sample points in the scattering media are found. Radiances of the sample points are computed. Radiance gradients of the sample points are computed from the radiances. The radiances and gradients are used to interpolate radiances throughout the scattering media. The set of sample points may be computed in an iterative dynamic manner in order to concentrate samples near features (e.g., shadow edges) of the scattering media.
Many of the attendant features will be explained below with reference to the following detailed description considered in connection with the accompanying drawings.
The present description will be better understood from the following detailed description read in light of the accompanying drawings, wherein like reference numerals are used to designate like parts in the accompanying description.
Embodiments discussed below relate to rendering volumes of scattering media in ways that may account for sharp variations of shading in the volumes. Sample points may be dynamically distributed in a medium in a manner that allows for accurate reconstruction of source radiance by interpolation and which avoids or minimizes many shading errors in the rendered result, such errors often resulting from under-sampling. Areas in the medium with samples whose reconstructed source radiance result in significant shading errors end up with more sample points, which may improve rendering accuracy. Other areas are lightly sampled to save computation. Given such a set of sample points (whether by dynamic sampling or otherwise), radiances for rendering the volume may be obtained by computing, at each of the sample points, a point's source radiance and gradient thereof, which are then used to accurately interpolate source radiances of other points in the volume. The computation of source radiances may be followed by a ray march to composite the final radiances along view rays.
Referring again to
This section describes a lighting model and density field representation (of a scattering medium) as well as a brief overview of a rendering algorithm based on the lighting model.
Source radiance for a point x in the density volume describes the local production of radiance that is directed towards the viewer v from point x. For a point source s and an isotropic, single scattering medium, source radiance for x can be computed as:
where I0 is the point source intensity, dab denotes the distance from point a to b, and the transmittance τab models the reduction of radiance due to extinction from point
e
−σ
∫
D(x)dx
a to b, computed as
In terms of source radiance, the radiance L seen at the viewer v can be computed as
where the first term describes direct transmission of radiance from the light source I0 to the viewer, and the second term accounts for single scattered radiance from x in the medium (the combined radiances of multiple such points causes glow around a light source in the medium). Note that for a point light source s, the first term in Equation (2) contributes at most a single point on the screen. In the second term, source radiances are modulated by media density and transmittance before being integrated along view rays (rays on the xout-xin line and pointing to the viewer v). An extension of Equation (2) to volumes containing scene objects will be described further below.
Regarding representation of the density field D, to compactly represent the density field D, a Gaussian model with residuals may be used. Density is represented by a weighted sum of Gaussians and a hashed residual field F:
where each Gaussian is defined by its center cj, radius rj and weight wj. A media animation is then modeled as a sequence of Gaussians and residual fields, computed in a preprocessing stage. However, preprocessing is used here for representation of the density field and it does not prevent runtime changes to media properties, lighting, or scene configuration. This representation efficiently models fine density field details, but the rendering algorithms described herein can accommodate any representation that can be rapidly reconstructed at runtime, e.g., the Gaussian+noise representation or the advected RBF (radial based function) representation, which are described elsewhere. With these alternative representations, no preprocessing would be used.
The algorithm of
This section describes techniques to derive a relatively small set of sample points in a volumetric medium. While source radiance throughout a medium can generally be reconstructed from any arbitrary sparse set of samples, sharp shading variations tend not to be well modeled without denser sampling. However, dense sampling can be cost-prohibitive if performed globally. For accurate and efficient reconstruction, methods described in this section involve dynamically placing additional samples in areas with greater shading error, which may be evaluated according to the current sampling configuration (i.e., the current set of samples) and gradient-based interpolation.
While the techniques are useful by themselves for efficient and accurate modeling of a volume of media (i.e., deriving points to approximate structure of the media), they are particularly useful when used with a technique of gradient-based interpolation to render a model of media (as the samples can serve as a basis to interpolate radiance for most other points in the volume of media). Use of gradient-based interpolation to fully render a volume of media from samples will be discussed in the next section.
To summarize, the process for dynamic sampling is performed iteratively (preferably recursively) for each animation frame. The density field, lighting, or scene geometry may change between frames. A set of initial samples is computed for each frame to be rendered, and a number of iterations will be performed for each frame to produce an increasing number of sample points for the current frame, with higher granularity of samples occurring near shading features. During an iteration for a frame, sample points 201 are evaluated for accuracy and additional samples are added where indicated. In general, accuracy of a point is determined by using a slow but accurate algorithm (e.g. ray tracing) to compute an accurate radiance, and comparing the accurate radiance value to another radiance value of the point, which is computed by a fast but generally less accurate algorithm (e.g., by gradient interpolation). The less accurate algorithm may also be used to compute radiances for the remaining (non-sampled) points in the volumetric media.
The second step involves recursively performing 224 additional sampling, which in effect “splits” samples with a high shading error (according to the metrics of step 222) into multiple samples that more finely sample the local regions (e.g., valid sphere) of original samples if such samples have a large local shading error. With this adaptive resampling scheme, it is possible to accurately and efficiently model high-frequency lighting effects.
Computing 222 the local shading error of a sample point will now be described.
In one embodiment, the shading error of a sample point due to an approximation of its source radiance, {tilde over (L)}x, can be derived from Equation (2) as
For the local shading error within a valid sphere of x, an efficiently computable metric that approximately represents the total error over all the points in the sphere may be used. The local shading error of a sample j may be measured as:
where {xij} is a set of n locally sampled points within the valid sphere of radius Rj, taken as {xj±RjX, xj±RjY, xj±RjZ}. The factor |{tilde over (L)}x
{tilde over (L)}
x
≈L
x
+(xij−xj)∇Lx
Volume tracing is used to sample source radiance values at xj and the sampled points, and density values are determined by sampling the density field (i.e., the volumetric media).
Recursively performing 224 additional sampling (sample splitting) will now be described. Starting with a sample set Q0={cj} that contains only the Gaussian centers of the samples, the local shading error Ej is computed according to Equation (5) for each valid sphere. The local shading error is compared to a given threshold, ε. Within each valid sphere for which Ej>ε, additional samples are added for more accurate modeling of the source radiance distribution in the medium. The set of added samples Qj1={q:q ∈ G1∥q−xj∥<Rx
One possible optimization would be to start generating the samples from that of the previous frame, since the consecutive frames are often temporally coherent. However, this may involve collapsing operations, which may call for an efficient GPU implementation.
A GPU implementation will now be described. The algorithm for dynamic sampling can be implemented on a GPU by combining CUDA (Compute Unified Device Architecture) and Cg shaders. The core data structure for the shaders is a renderable 3D grid information buffer that records for each vertex in the corresponding regular grid Gk an indicator for whether it is currently in the set Qk. The core data structure additionally records the local shading error for the corresponding sample. This data structure can be passed between a CUDA kernel and OpenGL using the pixel buffer object (PBO) extension.
As discussed above, for each sample-refining iteration performed for a given frame, three basic operations are performed: sampling, filtering and splitting. In one implementation, the sampling step calls the volume ray tracer and density sampler to compute Lx
Note that a pure OpenGL+CG implementation of the algorithm would also be possible, in which case the filtering CUDA kernel can be replaced with one implemented in OpenGL (see D. Horn, “Stream reduction operations for GPGPU applications”, GPU Gems 2 (2005), Addison Wesley, Chapter 36). However, this may involve many more rendering passes and redundant computations due to the absence of shared memory in a traditional graphics pipeline.
In one implementation, the maximum resolution for the regular grid was set to half that of the density field, which might be 128×128×128. Specifically, the grid resolutions in the implementation were set as follows:G1 as 16×16×16, G2 as 32×32×32, and G3 as 64×64×64. For efficiency in evaluating local shading errors, the value of τx
Referring again to the example of
Reconstructing Medium Volume from Sample Points Using Interpolation
In this section, a real-time interpolation algorithm is described. The algorithm reconstructs the source radiance throughout the volume from a relatively small set of radiance samples in the volume. The set of samples may be samples dynamically generated as discussed in the previous section. For heightened accuracy in interpolation, the source radiance at an arbitrary point is evaluated using both the radiance values and radiance gradients of the sample points. The GPU is used to expedite this computation by calculating sampled radiance quantities in multiple threads and by splatting the samples into the volume in a manner analogous to surface radiance splatting.
Regarding evaluation 260 of source radiance samples for gradient-based interpolation, a sample j is defined by a point xj in the media volume, the source radiance Lx
Evaluation 260 of source radiance and determination 262 of gradient at each sample point x will now be described. Equation (1) is used to evaluate 260 source radiance of x. In computing Equation (1), volume tracing is used for discrete integration along the ray from x to the light source sat intervals of Δ1:
where v=(s−x)/∥s−x∥ represents the ray direction. At each volume tracing step, the density is obtained from the density field and accumulated into the running sum until u exits the volume V. The transmittance is then evaluated and multiplied by I0/(4πdsv2) to yield radiance Lx.
The gradient is determined 262 numerically from the source radiance values at six points surrounding x along the three axis directions X, Y, Z:
Note that the source radiances at the various sample points may be computed in parallel on the GPU. Also, the precision of this numerical evaluation may be controlled by user defined intervals Δ1 and Δ2. The tracing step Δ1 is in inverse proportion to the performance of volume tracing. In one implementation, Δ/2 is used for Δ1 and Δ is used for Δ2, where Δ is the distance between neighboring grid points in the volume.
Gradient-based interpolation 264 by sample splatting will now be described. With the computed radiance and gradient values of Lx
L
x=ΣSWj(x) (Lx
S={j:∥x−x
j
∥<R
j
}, W
j(x)=Rj/∥x−xj∥. (7)
In interpolating the source radiance of an arbitrary point x (a non-sample point), rather than directly retrieve samples whose valid sphere covers x, the GPU may be utilized to splat the samples into the volume. First, the valid sphere of each sample is intersected with each X−Y slice of the volume, with +Z aligned to the viewing axis. The bounding quads of the intersection circles are found and grouped by slices. Then, for each slice, these bounding quads are rendered with alpha blending enabled (this is the splatting). For each pixel whose radiance is to be interpolated, the weighted approximate radiance Wj(x)(Lx
This section, describes some implementation details of a rendering pipeline configured to perform the methods and embodiments mentioned above.
Regarding density field construction, for each frame, the density field may be constructed by splatting, with a process similar to the radiance splatting described in the previous section. Here, the weight wj of each Gaussian is splatted instead of the sampled radiance. Note that splatting refers to rendering a number of primitives, often overlapped, with alpha blending. Unlike the gradient-based interpolation, no weight normalization is called for. If a residual field hash table exists, splatting may be performed with it as well, by retrieving R(x) from the hash table, multiplying it by {tilde over (D)}(x), and saving it in another color channel. Thus after splatting we have {tilde over (D)}(x) and R(x){tilde over (D)}(x) in different color channels. Dividing the latter by the former gives R(x), and adding R(x) to {tilde over (D)}(x) yields D(x). Note that it may not be possible to obtain R(x) directly in the first pass since the alpha blending is set to (GL_ONE, GL_ONE) during the splatting.
For volume ray tracing, tracing can be conducted for all sample points in a single call. This may be done by first packing the sample points into a 2D texture. A quad of the same size is drawn to trigger the pixel shader, in which volume ray tracing is performed as described in the previous section. To further improve performance, the tracing of a ray may be terminated if it exits the volume.
Regarding ray marching, given the density field and the source radiance field, a ray march is conducted. Radial based functions (RBFs) of the density representation are intersected with slices of thickness Δx that are perpendicular to the view direction (the thickness of each slice is set to the distance between neighboring grid points in the volume). Then the slices are rendered from far to near, with alpha blending set to GL_ONE and GL_SRC_ALPHA. The bounding quad of all intersections with the RBFs in each slice is rendered. For each pixel, D(x) and Lx are retrieved from 3D textures, and the RGB channels of the output are set to D(x)Lx. The alpha channel is set to the differential transmittance of the slice, computed as e−σ
Regarding scenarios where scene objects are present in the medium, Equation (2) may be modified to
L=L
s
V
sv
+L
p
V
sp+∫pX
where p is the first intersection of the view ray with a scene object, and Lp is the reflected radiance from the surface, computed as I0τspρ({right arrow over (s−p)}, {right arrow over (N)})/dsp2. The visibility term Vab is a binary function that evaluates to 1 if there exists no scene object blocking a from b, and is equal to 0 otherwise. If the view ray does not intersect a scene object, then p is set to infinity and Lp is 0.
Scene objects can affect the computation of L in three ways. First, visibility terms should be incorporated, and can lead to volumetric and cast shadows. Second, they give rise to a new background radiance term Lp. And finally, they determine the starting point of the integration in Equation (8).
To account for the visibility term, shadow mapping may be used with a small modification made to the volume tracer. A comparison of ∥s−x∥ may be added to the depth recorded in the shadow map, and exit tracing if ∥s−x∥ is larger, i.e., x is occluded from s. Note that this modification works for both the dynamic sampling algorithm and the interpolation algorithm. In one implementation, variance shadow mapping (Donnelly and Lauritzen, “Variance shadow maps”, In Proc. of SI3D 06 (2006), pp. 161-165.) may be used to reduce aliasing.
To compute Lp on the object surface, the same volume tracer may be used. For this, surface radiance splatting could be used. However, since direct but not indirect illumination is computed, much denser sampling would likely be required. High curvature regions on the object can also be problematic. Thus, in one implementation it may be assumed that all scene objects are triangulated to a proper scale, and the graphics hardware is allowed to linearly interpolate the sampled reflected radiance at vertices. Note that it is possible to interpolate the transmission τsp and apply arbitrary per-pixel shading when computing Lp.
To account for scene objects in ray marching, the objects may be drawn before ray marching, and then depth culling built into the GPU may be leveraged to correctly attenuate the reflected radiance Lp and exclude slices behind p.
Embodiments and features described above can be realized in the form of information stored in volatile 304 and/or non-volatile 306 computer or device readable storage media. This is deemed to include at least media such as optical storage (e.g., CD-ROM), magnetic media, flash ROM, RAM drives, or any current or future means of storing digital information for rapid access by a computing device. The stored information can be in the form of machine executable instructions (e.g., compiled executable binary code), source code, bytecode, or any other information that can be used to enable or configure computing devices to perform the various embodiments described above. This is also deemed to include at least volatile memory such as RAM and/or virtual memory storing information such as CPU instructions during execution of a program carrying out an embodiment, as well as non-volatile media storing information that allows a program or executable to be loaded and executed. The embodiments and featured can be performed on any type of computing device, including portable devices, workstations, servers, mobile wireless devices, and so on.