Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShKernelSurfaceImpl.hpp

Go to the documentation of this file.
00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Bryan Chan, Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #ifndef SHUTIL_KERNELSURFACEIMPL_HPP 00028 #define SHUTIL_KERNELSURFACEIMPL_HPP 00029 00030 #include <sstream> 00031 #include "ShSyntax.hpp" 00032 #include "ShPosition.hpp" 00033 #include "ShManipulator.hpp" 00034 #include "ShAlgebra.hpp" 00035 #include "ShProgram.hpp" 00036 #include "ShNibbles.hpp" 00037 #include "ShKernelSurface.hpp" 00038 #include "ShFunc.hpp" 00039 00044 namespace ShUtil { 00045 00046 using namespace SH; 00047 00048 template<typename T> 00049 ShProgram ShKernelSurface::diffuse() { 00050 ShProgram kernel = SH_BEGIN_FRAGMENT_PROGRAM { 00051 typename T::InputType SH_DECL(kd); 00052 typename T::InputType SH_DECL(irrad); 00053 ShInputNormal3f SH_DECL(normal); 00054 ShInputVector3f SH_DECL(lightVec); 00055 ShInputPosition4f SH_DECL(posh); 00056 00057 irrad *= pos(dot(normalize(normal), normalize(lightVec))); 00058 typename T::OutputType SH_DECL(result); 00059 result = irrad * kd; 00060 } SH_END; 00061 return kernel; 00062 } 00063 00064 template<typename T> 00065 ShProgram ShKernelSurface::specular() { 00066 ShProgram kernel = SH_BEGIN_FRAGMENT_PROGRAM { 00067 typename T::InputType SH_DECL(ks); 00068 ShInputAttrib1f SH_DECL(specExp); 00069 typename T::InputType SH_DECL(irrad); 00070 00071 ShInputNormal3f SH_DECL(normal); 00072 ShInputVector3f SH_DECL(halfVec); 00073 ShInputVector3f SH_DECL(lightVec); 00074 ShInputPosition4f SH_DECL(posh); 00075 00076 normal = normalize(normal); 00077 halfVec = normalize(halfVec); 00078 lightVec = normalize(lightVec); 00079 irrad *= pos(normal | lightVec); 00080 00081 typename T::OutputType SH_DECL(result); 00082 result = irrad * ks * pow(pos(normal | halfVec),specExp); 00083 } SH_END; 00084 return kernel; 00085 } 00086 00087 00088 template<typename T> 00089 ShProgram ShKernelSurface::phong() { 00090 ShProgram kernel = SH_BEGIN_PROGRAM("gpu:fragment") { 00091 typename T::InputType SH_DECL(kd); 00092 typename T::InputType SH_DECL(ks); 00093 ShInputAttrib1f SH_DECL(specExp); 00094 typename T::InputType SH_DECL(irrad); 00095 00096 ShInputNormal3f SH_DECL(normal); 00097 ShInputVector3f SH_DECL(halfVec); 00098 ShInputVector3f SH_DECL(lightVec); 00099 ShInputPosition4f SH_DECL(posh); 00100 00101 typename T::OutputType SH_DECL(result); 00102 00103 normal = normalize(normal); 00104 halfVec = normalize(halfVec); 00105 lightVec = normalize(lightVec); 00106 irrad *= pos(normal | lightVec); 00107 result = irrad * (kd + ks * pow(pos(normal | halfVec), specExp)); 00108 } SH_END; 00109 return kernel; 00110 } 00111 00112 template<typename T> 00113 ShProgram ShKernelSurface::gooch() { 00114 ShProgram kernel = SH_BEGIN_PROGRAM("gpu:fragment") { 00115 typename T::InputType SH_DECL(kd); 00116 typename T::InputType SH_DECL(cool); 00117 typename T::InputType SH_DECL(warm); 00118 typename T::InputType SH_DECL(irrad); 00119 00120 ShInputNormal3f SH_DECL(normal); 00121 ShInputVector3f SH_DECL(lightVec); 00122 ShInputPosition4f SH_DECL(posh); 00123 00124 typename T::OutputType SH_DECL(result); 00125 00126 normal = normalize(normal); 00127 lightVec = normalize(lightVec); 00128 result = lerp(mad((normal | lightVec), ShConstAttrib1f(0.5f), ShConstAttrib1f(0.5f)) * irrad, warm, cool) * kd; 00129 } SH_END; 00130 return kernel; 00131 } 00132 00133 template<typename T> 00134 ShProgram ShKernelSurface::null() { 00135 ShProgram kernel = SH_BEGIN_PROGRAM("gpu:fragment") { 00136 typename T::InputType SH_DECL(irrad); 00137 ShInputPosition4f SH_DECL(posh); 00138 00139 typename T::OutputType SH_DECL(result) = irrad; 00140 } SH_END; 00141 return kernel; 00142 } 00143 00144 } 00145 00146 #endif

Generated on Mon Oct 18 14:17:39 2004 for Sh by doxygen 1.3.7