//**************************************************************************/ // Copyright (c) 2010 Autodesk, Inc. // All rights reserved. // // These coded instructions, statements, and computer programs contain // unpublished proprietary information written by Autodesk, Inc., and are // protected by Federal copyright law. They may not be disclosed to third // parties or copied or duplicated in any form, in whole or in part, without // the prior written consent of Autodesk, Inc. //**************************************************************************/ // DESCRIPTION: Spread the influence of DOF to neighboring pixels. // AUTHOR: Kells Elmquist // CREATED: November 2010 //**************************************************************************/ #include "Common.cgh" ///////////////////////////////////////////////////////////////////////////// // // Spread DOF circles of confusion to affected pixels // // The source image texure to be blurred uniform texture source; uniform sampler2D sourceSamp = sampler_state { Texture = ; }; // the coc/depth texture is a float2 texture that has no-abs coc in .x & linear depth in .y uniform texture cocDepth; uniform sampler2D cocDepthSamp = sampler_state { Texture = ; }; uniform int searchRadius = 8; // in pixels, radius 4 = 9x9 samples; 8 = 17x17; side=2*radius+1 uniform float2 searchDirection; // (0,1) for V pass or (1,0) for H pass uniform int sampleSpacing = 1; // stride between pixel samples in motion spreading, 1x1 default uniform float acceptThreshold = 0.01f; // similarity threshold to accept neighbor // filter kernel, return value of kernel of radius r at a distance x from the filter center // both x & r must be positive, r must be > 0 float filter( float r, float x ) { // box kernel //return 1; // linear (triangle) kernel return saturate( 1.0f - x/r ); // gaussian kernel //return 0.79788f * exp( -x*x/(0.375 * r*r) ) / r; } // DOF Pixel shader. 2 pass (H&V) filter, pass controlled by searchDirection // NOTE: This expects the common screen quad vertex shader output in common.cgh. float4 visualizeDOFBlur( VS_TO_PS_ScreenQuad In ) : COLOR0 { // Compute the offset between samples in uv space float2 offset = (float)sampleSpacing * searchDirection * gTexelSize; // center pixel //float4 s0 = tex2D(sourceSamp, In.UV); float4 c0 = tex2D(cocDepthSamp, In.UV); const float nearOffset = 0.0f; const float cocScale = 25.0f; float coc = abs( c0.x ); float z = c0.y / (20.0f + c0.y); float isNear = (c0.x < nearOffset)? 0.4f : 0.0f; float4 clrSum = float4( cocScale * coc, 0.4f * z, isNear, 1.0f ); return clrSum; } // shader for either pass of the 2 pass h/v spreading technique. technique spreadDOFPass { pass p0 { VertexShader = compile glslv VS_ScreenQuad(); PixelShader = compile glslf visualizeDOFBlur(); } }