13.07.2015 Views

Paper - IDAV: Institute for Data Analysis and Visualization

Paper - IDAV: Institute for Data Analysis and Visualization

Paper - IDAV: Institute for Data Analysis and Visualization

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

18 · Lefohn, Kniss, Strzodka, Sengupta, <strong>and</strong> Owensapplications of our multiresolution, adaptive data structure: adaptive shadow maps <strong>and</strong> octree 3D paint.6.1 GPGPU 4D ArrayAfter describing the Glift components required to build <strong>and</strong> use a 4D array in Section 2, we now show a complete“be<strong>for</strong>e” <strong>and</strong> “after” trans<strong>for</strong>mation of source code with Glift. We use a GPGPU computation example because of itssimplicity; note that it demonstrates the use of Glift element iterators. Section 6.3 shows the use of Glift <strong>for</strong> graphicsGPU applications.Here, we show the Cg code <strong>for</strong> the Glift <strong>and</strong> non-Glift versions of this example. Appendix 1 shows the correspondingC++ code <strong>for</strong> both examples. For each element in the 4D array, the following kernel computes the finite discreteLaplacian. The Cg shader <strong>for</strong> the non-Glift example is:✞float4 physToVirt( float2 pa, float2 physSize, float4 sizeConst4D ){float3 curAddr4D;float addr1D = pa.y * physSize.x + pa.x;addr4D.w = floor( addr1D / sizeConst4D.w );addr1D -= addr4D.w * sizeConst4D.w;addr4D.z = floor( addr1D / sizeConst4D.z );addr1D -= addr3D.z * sizeConst4D.z;addr4D.y = floor( addr1D / sizeConst4D.y );addr4D.x = addr1D - addr4D.y * sizeConst4D.y;return addr4D;}float2 virtToPhys( float4 va, float2 physSize, float4 sizeConst4D ){float addr1D = dot( va, sizeConst4D );float normAddr1D = addr1D / physSize.x;return float2( frac( normAddr1D ) * physSize.x, normAddr1D );}float4 main( uni<strong>for</strong>m sampler2D array1,uni<strong>for</strong>m float4 virtSize,uni<strong>for</strong>m float2 physSize,uni<strong>for</strong>m float4 sizeConst,varying float2 winPos : WPOS ) : COLOR{// Get virtual address <strong>for</strong> current fragmentfloat2 pa = floor( winPos );float4 va = physToVirt( pa, physSize, sizeConst );// Finite difference discrete Laplacianfloat4 offset( 1, 0, 0, 0);float4 laplace = -8 * tex2D( array1, pa );<strong>for</strong>( float i = 0; i < 4; ++i ) {laplace += tex2D( array1, virtToPhys( va + offset, physSize, sizeConst ) );laplace += tex2D( array1, virtToPhys( va - offset, physSize, sizeConst ) );offset = offset.yzwx;}return laplace;ACM Transactions on Graphics, Vol. 25, No. 1, January 2006.☎

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!