Unformatted text preview:

Permission to make digital or hard copies of part or all of this work for personal orclassroom use is granted without fee provided that copies are not made or distributed forprofit or direct commercial advantage and that copies show this notice on the first page orinitial screen of a display along with the full citation. Copyrights for components of thiswork owned by others than ACM must be honored. Abstracting with credit is permitted. Tocopy otherwise, to republish, to post on servers, to redistribute to lists, or to use anycomponent of this work in other works requires prior specific permission and/or a fee.Permissions may be requested from Publications Dept., ACM, Inc., 1515 Broadway, NewYork, NY 10036 USA, fax +1 (212) 869-0481, or [email protected] AlgebraMichael McCool Stefanus Du Toit Tiberiu Popa Bryan Chan Kevin MouleComputer Graphics Lab, School of Computer Science, University of WaterlooFigure 1: Some applications of shader algebra operations: surface and light shaders can be combined, output colors can bepro ces sed (in this case, halftoning was applied), and any attribute or parameter can be replaced with a texture map.AbstractAn algebra consists of a set of objects and a set of opera-tors that act on those objects. We treat shader programs asfirst-class objects and define two operators: connection andcombination. Connection is functional comp osition: the out-puts of one shader are fed into the inputs of another. Com-bination concatenates the input channels, output channels,and computations of two shaders. Similar operators can beused to manipulate streams and apply computational ker-nels expressed as shaders to streams. Connecting a shaderprogram to a stream applies that program to all elementsof the stream; combining streams concatenates the recorddefinitions of those streams.In conjunction with an optimizing compiler, these op-erators can manipulate shader programs in many usefulways, including specialization, without modifying the orig-inal source code. We demonstrate these operators in Sh, ametaprogramming shading language embedded in C++.CR Categories: I.3.7 [Computer Graphics]: Three-Dimensional Graphics and Realism—Color, shading, shad-owing, and textureKeywords: real-time rendering, shader programming,graphics hardware1 IntroductionSpecialized high-level shading languages are a standard partof offline re ndering systems and are now also available forreal-time systems. Programs written in these languages areusually called shaders. Shaders can be downloaded to theGraphics Processing Units (GPUs) used in hardware graph-ics accelerators, to process attributes bound to streams ofeither vertices or pixel fragments. We can interpret a shaderas a function that maps an input stream of homogeneousrecords to an output stream of homogeneous records. Toallow strip-mined parallelism, operations on stream recordsexecute independently.Shading languages can be used to apply GPUs to non-traditional applications such as the solution of systems ofequations or simulation. The results of these computationscan be used for graphics applications, or the GPU can simplybe used as a numerical engine.As shaders become larger and more complex the ability toreuse and encapsulate code becomes more important. Shad-ing languages can (and do) support standard forms of mod-ularity such as subroutines, but other forms of modularityare possible. A dataflow mo del, for instance, is very natu-ral for shaders, and visual dataflow languages are also oftenused in modeling and animation applications. Dataflow vi-sual languages, in turn, are related to functional languages,where higher-order functions provide useful forms of modu-larity. Object-oriented constructions such as classes mightalso be useful in shading languages.In this paper, we present an algebra over shader objects.This algebra consists of two binary operators: connectionand combination. Using these operators, we can manipulateand specialize shaders without having to modify (or evenhave access to) the source code of the original shaders. The787© 2004 ACM 0730-0301/04/0800-0787 $5.00addition of a shader algebra enables a functional style ofprogramming: shaders become first-class objects that can beop e rated upon. The same operators can be used to ex pressgeneral-purp ose stream processing.Our algebra is demonstrated in the context of Sh, an em-bedded, metaprogrammable shading language implementedentirely within C++. Sh is similar to an operator over-loaded matrix/vector library. When used in “immediate”mo de, this is exactly what it is. However, sequences of op-erations on Sh types can be captured in a “retained” modeand compiled to another target, such as a GPU shading unit.The result is a language that is as expressive as a customshading language but with all the power of C++ for creatingmo dular shaders. For instance, it is easy to add new typesto Sh, including operator overloading, or to use classes tobuild parameterized or customized versions of shaders, or touse function pointers to create procedurally parameterizedshaders. In Sh, the shader algebra extends and augmentsthese existing modularity capabilities.2 Related WorkGPUs can be seen as a form of stream processor. Stream pro-cessors are distinguished from vector processors by the factthat on-chip temporary registers are available, so it is pos-sible to perform a significant amount of arithmetic on eachstream record before the result needs to be written backto memory. General-purp ose stream processors have beendeveloped and graphics systems have been implemented onthem [Owens et al. 2000], but GPUs are also evolving to-wards a more general-purpose architecture similar to streampro ces sors . General computations on GPUs have been stud-ied by many researchers. In recent years many graphics, sim-ulation, and numerical applications have been implementedon GPUs [Trendall and Stewart 2000; Hillesland et al. 2003;Bolz et al. 2003; Kr¨uger and Westermann 2003].A shading language is a domain-specific programming lan-guage for specifying shading computations. Shade trees[Co ok 1984] captured expressions used to compute pixelsso if the parameters of the lighting model changed in a ray-tracer, an image could be quickly recomputed without redo-ing intersection calculations. Peachey and Perlin [Peachey1985; Perlin 1985] developed the idea of procedural tex-tures and lighting, and also experimented with noise func-tions. Block shaders used a network of configurable


View Full Document

UMD CMSC 828V - Shader Algebra

Download Shader Algebra
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Shader Algebra and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Shader Algebra 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?