In the Figures, the left-most digit of a component reference number identifies the particular Figure in which the component first appears.
Systems and methods for real-time rendering of realistic rain are described with respect to
Although not required, real-time rendering of realistic rain is described in the general context of computer-executable instructions (program modules) being executed by computing devices such as a general-purpose computer or a mobile handheld device. Program modules generally include routines, programs, objects, components, data structures, etc., that perform particular tasks or implement particular abstract data types. While real-time rendering of realistic rain is described in the foregoing context, acts and operations described hereinafter may also be implemented in hardware.
Rendering module 114 uses static images of real rain for real-time modeling and rendering of particle-based synthetic rain into video content to generate respective synthetic rain matted frames 118. More particularly, rendering module 114 analyzes video content offline (i.e., not in real-time) to extract samples of real rain of various sizes and shapes. These extracted samples are shown as rain stroke samples/mattes 120. Each rain stroke sample 120 is a sample of actual rain stroke with alpha values defining opacity of the object, radiance values for every pixel of the rain stroke, observed rain stroke direction and color (including color of a static background of the frame). Rendering module 114 randomly selects a set of rain stroke samples 120 to model into synthetic rain particles 122, which are hereinafter often referred to as “rain particles”, “particles”, “synthetic rain”, “raindrops” or “rain strokes”. In real-time, rendering module 114 models and renders the rain particles 122 to generate synthetic rain matted frames 118 for presentation to a user.
Specifically, for each frame of a sequence of video content to which synthesized rain is to be added (i.e., target video content frames), and for each particle 122 of multiple rain particles 122, rendering module 114:
Rendering module 114 analyzes a sequence of image frames associated with video content (rain videos) to extract various shapes of rain stroke/drop samples 120 from respective ones of the image frames. For purposes of exemplary illustration, such analyzed video content is shown as a respective portion of “other program data” 124. Each rain stroke sample 120 is a sample of actual rain stroke with alpha values defining opacity of the object, radiance values for every pixel of the rain stroke, observed rain stroke direction and color (including color of a static background of the frame). In one implementation, rain stroke samples 120 form a library of real/actual rain samples.
If video content used for analysis and rain stroke sample 120 extraction is not captured using a high-speed camcorder, or other digital image capture device, the rain in successive frames is essentially independent. In other words, positions of rain strokes in successive video frames are not correlated. The positions can be totally different. Conventional techniques to detect rain (e.g., via independent pixel-by-pixel use of a median filter) do not consider: (1) rain is globally directional; and, (2) a typical scene has a mostly continuous color distribution. As a result, such conventional techniques are susceptible to image noise that degrades quality of detected rain. In contrast rendering module 114 addresses the globally directional characteristics of rain and substantially continuous scene color distribution when detecting rain strokes for extraction and archiving as rain stroke samples 120.
Specifically, rendering module 114 implements rain extraction as a nonlinear least-squares problem, as follows:
Indices i, j, and k reference pixels, color channels, and frames, respectively. Parameter I is an observed color, α is a fractional blending weight due to rain, S is a color of a static background, (CR,CG,CB) is a “color” of the rain (e.g., due to environmental factors, etc.), D0 is a principal rain direction, and λ and μ are weights.
The first term in (1), \sum_{i,j,k}, assumes the observed color is a linear blend of the colors of a scene and rain. The second term (\sum_{i,j}) encourages smoothness in the scene color distribution, while the third term (\sum_{i,k}) favors smoothness of the alpha distribution along the rain direction D0. Rendering module 114 solves for α and S alternately using an Expectation-Maximization (EM) algorithm. Rendering module 114 utilizes a median filtered version of S is used to initialize S, whereas rain direction D0 is initialized as the vertical direction. Rendering module 114 refines rain direction D0 immediately after estimating α by detecting a most salient line in a frequency spectrum of α that passes through an origin.
Once rendering module 114 determines rain direction D0 rendering module 114 rotates the rain strokes to make them practically vertical. To reduce artifacts caused by not fully modeling the rain (e.g., inter-reflection effects), rendering module 114 applies morphological erosion and dilation followed by vertical blurring. In practice, these operations are sufficient to produce plausible shapes of rain strokes (i.e., rain stroke samples 120).
For each image frame (i.e., a static scene) of a target video content sequence, rendering module 114 independently models at least a subset of these rain stroke samples 120 as rain particles 122. In one implementation, rendering module 114 randomly selects the particular rain stroke samples 120 to utilize as rain particles 122 (“particles 122”). For purposes of exemplary illustration, such a target video content sequence is shown as a respective portion of “other program data” 124. Rendering module 114 independently models each particle 122 with respect to a frame (e.g., frame coordinate system, viewpoint, background content and color, etc.) of the target video content sequence, with position (based on uniform or non-uniform distribution criteria), controlled and configurable velocity (based on physical laws), and shape (based at least on current particle velocity).
For example, and in one implementation on a frame-by-frame basis, rendering module 114 uses vertex shader logic of GPU 106 to model alpha values 126 (alpha mattes) of the rain stroke samples 120 associated with respective ones of the particles 122 in real-time as particles in 3-D world coordinate space of respective image frames. In one implementation, rendering module 114 models position of each particle 122 in frame space as a uniform random variable. In another implementation, density distribution of particles 122 across a frame is based on geometry of a scene depicted by the frame. For a real scene and arbitrary camera motion, structure from motion techniques is applied to extract scene depth. When there is no motion parallax (e.g., for a panning camera or flat scene), approximate depth is manually assigned.
Rendering module 114 determines respective velocities of particles 122 in real-time using a basic physical law, as follows. ν=ν0+gt, where g is the gravity acceleration and t is the time from the moment that the velocity of raindrop is ν0. Current velocity is v=ν=ν0+gt, where t is the time from the moment that the velocity of raindrop is v0. Velocity changes over time. Once the initial position and velocity of a raindrop (i.e., an alpha matte 126) is randomly generated, the movement of the raindrop in the world coordinate (i.e. the 3D scene) across respective frames of video content follows this physical law. In one implementation, velocity and magnitude of a rain particle 122 is user configurable.
With respect to shape, rendering module 114, for each particle 122, models each alpha matte 126 of the particle as a sphere. In this implementation, the size of the sphere is no significant, since original size of an alpha matte 126 is typically much smaller than a scene associated with a frame of video content. Rendering module 113 determines length of a rain sample matte 120 (associated with a respective particle 122) based on a particle's current velocity and the exposure time of a virtual camera (a user controllable parameter). Rendering module 114 generates rain stroke sample 120 shape by shrinking or stretching its original shape, accordingly, through interpolation. For example, suppose original rain stroke matte samples 120 were taken by a camera with exposure time t0, the rain velocity was v0, and in the novel scene of a video sequence: velocity of a raindrop is assumed to be v1, and exposure time of a virtual camera is assumed to be t1. In view of this, length of the rain stroke matte 120 is scaled by v1t1/v0t0 times, the alpha values 126 are interpolated accordingly. The diameter of the sphere 130 that models the particle 122 corresponds to the width of the alpha matte 126 after being mapped to coordinates associated with a frame.
In one implementation, and to illustrate influence of wind, rendering module 114 applies a wind model to a particle 122 to dynamically deform shape of the corresponding rain stroke sample 120.
Rendering module 114 uses GPU 106 to identify portion(s) of a scene in a frame for shading. To this end, GPU 106 generates a respective rain mask for each alpha matte 126 associated with rain particles 122. (A rain mask is a binary mask where in side the rain matte the value is 1 and outside the rain matte the value is 0). For each rain mask, rendering module 114 utilizes per-pixel shader logic of GPU 106 to compute color and intensity (attributes 128) of each particle 122. Specifically the per-pixel shader determines color and intensity of light reflected towards a viewing direction at each point in the rain mask via pre-computed radiance transfer (PRT) to generate respective shaded rain masks. For purposes of exemplary illustration, such rain masks (non-shaded and shaded) are shown as respective portions of attributes 128. System 100 assumes that there is no inter-reflection among the particles 122 (raindrops), so every raindrop is affected only by the environment map. The PRT consists of two parts: an environment map and a transfer function of a sphere model 130 associated with each particle 122.
Video content representing a real scene may not provide a complete environment map. In one implementation, rendering module 114 fills-in missing parts/generates an environment map using nearest available colors. In one implementation, a horizontal field of view in an environment map is approximately 36°. In one implementation, for video content generated by a panning camera, rendering module 114 stitches frames of the video content into a panorama, and thereby, provides wider coverage for the environment map. In one implementation, for a looming camera, rendering module 114 stitches a panorama every five frames to produce a view dependent environment map. Pixel values of a scene, particularly values associated with light sources, are of low dynamic range and may not cause noticeable effects on the rain. Because of this, rendering module 114 replaces saturated values with measured radiance of the light sources (measured when video content is captured).
In one implementation, to add realism to a rain scene 118, rendering module 114 adds homogenous fog. Rain strokes are visible in the video only when they are close enough to the camera. When the rain strokes are far away, it has the appearance of fog. In this scenario, an alpha matte of the fog is exponentially decreasing with respect to depth d; i.e., αfog=1 exp(εd), where ε is the fog density. In one implementation, values of ε between 1.35 and 1.8 are used, although other values could also be used.
To use PRT, rendering module 114 computes a transfer function of a sphere model 130 for each particle 122. The transfer function weights an environment map to produce light intensity reflected towards a viewing direction. Direct computation is difficult. To address this in view of reversibility of light, and in one implementation, rendering module 114 computes an outgoing light intensity distribution function by tracing the light in the viewing direction to determine how the light is scattered toward various directions, as shown in
To simplify this derivation, rendering module 114 uses sphere model 130 to model a rain stroke sample 120 (and corresponding alpha values 126) associated with a particle 122 as a sphere. Size of the sphere is inconsequential since it the raindrop being modeled is typically much smaller than the scene. Using principles of basic optics (please see Appendix A), rendering module 114 derives a closed-form solution for the outgoing light distribution function D(θ,φ) for the spherical raindrop model (please see Appendices B and C). θ and φ are the angles associated with the altitude and azimuth, respectively, with (0,0) aligning with the z-axis (see
When rendering module 114 applies PRT, rendering module 114 projects both the discretized transfer function and the environment map to Spherical Harmonic (SH) bases, storing only low frequency coefficients. Specifically, in this implementation, the first 16 SH coefficients are stored for both the transfer function and the environment map. In a different implementation, different number of SH coefficients are stored. When shading a pixel in the alpha matte 126, the color C of the pixel is computed as the dot product of the raindrop transfer of the environment map. Since only low frequency SH coefficients are stored, the transfer function contains only a low frequency portion. In particular, the value of transfer function in the viewing direction is reduced a greater amount (as compared to the transfer function in different directions). To compensate for this attenuation, rendering module 114 adds a portion of detected background color B (which is exactly the environment map in the viewing direction) to the rain color as follows:
C′=C+cB (2)
In this implementation, c is set to 0.7, although other values could be used. Rendering module 114 uses GPU 106 to alpha-blend the corrected rain color with the background, producing a final rain matted scene (frame) 118, as follows:
{tilde over (C)}=αC′+(1−α)B,
where α is an alpha value 126 of a pixel in the alpha matte 126. Using PRT, the effect of the environment map on the rain is realistically achieved.
In this implementation, rendering module 114 leverages alpha-blending operations of GPU 106 to blend rain stroke orientation and colors of each raindrop represented by a particle 122 with a corresponding background using the computed intensity and the alpha matte 126 to generate a rain matted background (shown as a respective portion of “other program data” 124). This appearance is represented by respective ones of the input alpha matte 126, the particle 120 associated shaded rain mask, and detected scene background (shown as a respective portion of “other program data” 124). In one implementation, if rough geometry of the scene is known, rendering module 114 automatically clips the raindrop associated with particle 122 at the scene surface. The scene surface is defined using a mesh of a synthetic scene or the depth map of video content. The clipping gives a volumetric appearance of rain. Which rain shows up in which part of the frame is determined by the scene geometry; determined after computing scene depth or by manual assignment.
Referring to
In this implementation, operations of block 402 through block 404 are performed offline (e.g., not in real-time). Although these operations have been described as being implemented by rendering module 114, in another implementation, these operations are performed by a separate program module 110 that is independent of the real-time synthesis and rendering operations of rendering module 114.
Operations of block 512 detect background of the current frame. Operations of block 514, for each rain particle 122, alpha blend the associated 3-D world coordinate mapped alpha matte 126 (using its current position, velocity, and shape) and the associated shaded rain mask with the detected background to generate a rain matted image frame (scene) 118. Operations of block 516 render the rain matted image frame 118 comprising synthesized rain for presentation to a user.
Although real-time rendering of realistic rain has been described in language specific to structural features and/or methodological operations or actions, it is understood that the implementations defined in the appended claims are not necessarily limited to the specific features or actions described. Rather, the specific features and operations discussed above with respect to
Appendix A—Transmittance and Reflectance of Light
For unpolarized incident light, the reflectance, i.e., the ratio of the reflected power to the incident power, is
where ρ=ηi/ηi, m=cos θi/cos θi, ηi and ηi are the refractive indices of the medium of incidence and transmission, respectively, and θi and θi are the angles of incidence and refraction, respectively. Please note that the angle θi of refraction is determined by Snell's law: ηi sin θi=ηi sin θi. The transmittance, i.e., the ratio of the transmitted power to the incident power, is T(θi)=1−R(θi).
In one implementation, system 100 pre-computes transfer vectors for R, G, and B channels separately.
Appendix B. Outgoing Light Intensity after Multiple Reflection
Because the radii of raindrops follow the Marshall-Palmer distribution, the radii of a vast majority of raindrops are less than 1 mm. As a result, system 100 assumes raindrop shape to be a sphere. This assumption leads to an analytically computable outgoing light intensity, even though light is refracted inside the raindrop many times.
Let Iin and dFin be the intensity of the incident light and the incident flux, respectively. Without loss of generality, the direction of incident light is (0,0), i.e., it is parallel to the z-axis of the local spherical coordinate of the raindrop. Let Ln,In, and dFn be the direction, intensity, and infinitesimal flux of outgoing light after the incident light is reflected inside the raindrop (n−1) times, respectively (
Please note that the light path lies in the plane determined by the center of the raindrop and the incident light (e.g., please see
To compute I1, by the definition of reflectance:
dF
1
=R(γ)dFin, (3)
with R(γ) being the reflectance at angle γ. Please note that
dF
in
=I
in cos γ·dωin=Iin cos γ·sin γdγdφ, (4)
dF
1
=I
1
dω
1
=I
1 sin dθ1dφ, (5)
where Iin is the intensity of the incident light, and ωin and ω1 are the infinitesimal solid angles of incident and outgoing light, respectively. As the incident light is in the direction (0,0), θ1=π−2γ. By combining (3), (4), and (5):
To compute In (n>1), we consider the light being reflected (n−2) times inside the raindrop and refracted 2 times when leaving the raindrop. Therefore,
dF
n
=[T(γ)]2[R(γ)]n−2dFin,
where
dF
n
=I
n
dω
n
=I
n sin θndθndφ.
Using the assumption that the raindrop is spherical:
θn=Θ[π−2γ−(n−1)(π−2β)],
where Θ(x)=|mod (x+π,2π)−π| restricts the angle x to be between 0 and π, and β is the refraction angle when the incident light refracts inside the raindrop for the first time (
Appendix C—Outgoing Light Intensity Distribution Function
In the previous section, scattering directions (θn,φ) and the corresponding attenuation coefficients ξn were derived, given the incident angle γ and azimuth angle φ of the incident light. Note that the incident light in direction (0,0) can hit any point on a raindrop (
where ξ1(γ)=R(γ)/4 due to (6). The denominator πIin is used for normalization, since it is the value of the integral of Is over all directions. To make the computation more efficient, rendering module 114 pre-computes an inverse table of γ's that satisfies θn(γ)=θ. ξn usually drops rapidly with increasing n. Empirically, the first nine ξn's hold about 99.8% of the full power; as a result, only ξ1, . . . , ξ9 are used in this implementation, although different number of ξn's could be used in a different implementation.