GPU Gems 3——Chapter 13. Volumetric Light Scattering as a Post-Process

https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch13.html

in this chapter, we present a simple post-process method 后处理的方法 that produces the effect of volumetric light scattering due to shadows in the atmosphere. we improve an existing analytic model of daylight scattering to include the effect of volumetric occlusion, and we present its implementation in a pixel shader. the demo, which is included on the DVD accompanying this book, shows the technique can be applied to any animating image of arbitrary scene complexity. A screenshot 截图 from the demo appears in Figure 13-1.
在这里插入图片描述

Figure 13-1 Volumetric Light Scattering on a Highly Animated Scene in Real Time

13.1 Introduction

in the real world, we rarely see things in a vaccum真空, where nothing exists between an object and its observer. in real-time rendering, the effect of participating media on light transport is often subject to low-complexity homogeneous assumptions 低复杂度均匀假设. This is due to the intractable 棘手的 nature of the radiative transport equation (Jensen and Christensen 1998), accounting for emission, absorption, and scattering, in a complex interactive 交互的 animated environment. In this chapter, we consider the effect of volumetric shadows in the atmosphere on light scattering, and we show how this effect can be computed in real time with a GPU pixel shader post-process applied to one or more image light sources.

13.2 Crepuscular 黄昏的 Rays

under the right conditions, when a space contains a sufficiently dense mixture of light scattering media such as gas molecules 分子 and aerosols 气溶胶, light occluding objects will cast volumes of shadow and appear to create rays of light radiating from the light source. these phenomena are variously known as crepuscular rays, sunbeams, sunbursts, star flare, god rays, or light shafts. in sunlight, such volumes are effectively parallel but appear to spread out from the sun perspective.

rendering crepuscular rays was first tackled in non-real-time rendering using a modified shadow volume algorithm (Max 1986) and shortly after that, an approach was developed for multiple light sources (Nishita et al. 1987). this topic was revisited in real-time rendering, using a slice-based volume-rendering technique (Dobashi et al. 2002) and more recently applied using hardware shadow maps (Mitchell 2004). however, slice-based volume-rendering methods can exhibit sampling artifacts, demand high fill rate, and require extra scene setup. while a shadow-map method increases efficiency, here it also has the slice-based detractors 诽谤者 and requires further video memory resources and rendering synchronization. another real-time method, based on the work of Radomir Mech (2001), uses polygonal volumes (James 2003), in which overlapping volumes are accumulated using frame-buffer blending with depth peeling. a similar method (James 2004) removes the need for depth peeling using accumulated volume thickness. in our approach, we apply a per-pixel post-processing operation that requires no preprocessing or other scene setup, and which allows for detailed light shafts in animating scenes of arbitrary complexity.

in previous work (Hoffman and Preetham 2003), a GPU shader for light scattering in homogeneous media is implemented. we extend this with a post-processing step to account for volumetric shadows. the basic manifestation of this post-process can be traced to an image-processing operation, radial blur, 径向模糊 which appears in many CG demo productions (Karras 1997).

although such demos used software rasterization to apply a post-processing effect, we use hardware-accelerated shader post-processing to permit more sophisticated sampling based on an analytic model of daylight.

13.3 Volumetric Light Scattering
to calculate the illumination at each pixel, we must account for scattering from the light source to that pixel and whether or not the scattering media 散射媒介是否被遮蔽 is occluded. in the case of sunlight, we begin with our analytical model of daylight scattering (Hoffman and Preetham 2003). recall the following:
Equation 1
在这里插入图片描述
where s is the distance traveled through the media and is the angle between the ray and the sun.

13.4 the post-process pixel shader
the core of this technique is the post-process pixel shader, given in listing 13-1, which implements the simple summation of equation 4.

float4 main(float2 texCoord : TEXCOORD0) : COLOR0 
{   
	// Calculate vector from pixel to light source in screen space.    
	half2 deltaTexCoord = (texCoord - ScreenLightPos.xy);   
	// Divide by number of samples and scale by control factor.   
	deltaTexCoord *= 1.0f / NUM_SAMPLES * Density;   
	// Store initial sample.    
	half3 color = tex2D(frameSampler, texCoord);   
	// Set up illumination decay factor.    
	half illuminationDecay = 1.0f;   
	// Evaluate summation from Equation 3 NUM_SAMPLES iterations.    
	for (int i = 0; i < NUM_SAMPLES; i++)   
	{     
		// Step sample location along ray.     
		texCoord -= deltaTexCoord;     
		// Retrieve sample at new location.    
		half3 sample = tex2D(frameSampler, texCoord);     
		// Apply sample attenuation scale/decay factors.     
		sample *= illuminationDecay * Weight;     
		// Accumulate combined color.     
		color += sample;     
		// Update exponential decay factor.     
		illuminationDecay *= Decay;   
	}   
	// Output final color with a further scale control factor.    
	return float4( color * Exposure, 1); 
} 

given the initial image,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值