ShNibblesImpl.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHNIBBLESIMPL_HPP
00021 #define SHNIBBLESIMPL_HPP
00022 
00023 #include "ShNibbles.hpp"
00024 #include "ShTexCoord.hpp"
00025 #include "ShLibNoise.hpp"
00026 
00027 namespace SH {
00028 
00029 template<typename T>
00030 ShProgram keep(const std::string & name) 
00031 {
00032   ShProgram nibble = SH_BEGIN_PROGRAM() {
00033     typename T::InOutType SH_NAMEDECL(attr, name); 
00034   } SH_END_PROGRAM;
00035   nibble.name("keep");
00036   return nibble;
00037 }
00038 
00039 template<typename T>
00040 ShProgram dup(const std::string & name) 
00041 {
00042   ShProgram nibble = SH_BEGIN_PROGRAM() {
00043     typename T::InputType SH_NAMEDECL(attr, name); 
00044     typename T::OutputType SH_NAMEDECL(attr1, name + "_1") = attr; 
00045     typename T::OutputType SH_NAMEDECL(attr2, name + "_2") = attr; 
00046   } SH_END_PROGRAM;
00047   nibble.name("dup");
00048   return nibble;
00049 }
00050 
00051 template<typename T>
00052 ShProgram lose(const std::string & name) 
00053 {
00054   ShProgram nibble = SH_BEGIN_PROGRAM() {
00055     typename T::InputType SH_NAMEDECL(attr, name);
00056   } SH_END_PROGRAM;
00057   nibble.name("lose");
00058   return nibble;
00059 };
00060 
00061 template<typename T>
00062 ShProgram shAccess(const ShBaseTexture1D<T> &tex, const std::string &tcname, const std::string & name) 
00063 {
00064   ShProgram nibble = SH_BEGIN_PROGRAM() {
00065     ShInputTexCoord1f SH_NAMEDECL(tc, tcname);
00066     typename T::OutputType SH_NAMEDECL(result, name) = tex(tc);
00067   } SH_END;
00068   nibble.name("shAccess");
00069   return nibble;
00070 }
00071 
00072 template<typename T>
00073 ShProgram shAccess(const ShBaseTexture2D<T> &tex, const std::string & tcname, const std::string & name) 
00074 {
00075   ShProgram nibble = SH_BEGIN_PROGRAM() {
00076     ShInputTexCoord2f SH_NAMEDECL(tc, tcname);
00077     typename T::OutputType SH_NAMEDECL(result, name) = tex(tc);
00078   } SH_END;
00079   nibble.name("shAccess");
00080   return nibble;
00081 }
00082 
00083 template<typename T>
00084 ShProgram shAccess(const ShBaseTextureRect<T> &tex, const std::string & tcname, const std::string & name) 
00085 {
00086   ShProgram nibble = SH_BEGIN_PROGRAM() {
00087     ShInputTexCoord2f SH_NAMEDECL(tc, tcname);
00088     typename T::OutputType SH_NAMEDECL(result, name) = tex(tc);
00089   } SH_END;
00090   nibble.name("shAccess");
00091   return nibble;
00092 }
00093 
00094 template<typename T>
00095 ShProgram shAccess(const ShBaseTexture3D<T> &tex, const std::string & tcname, const std::string & name) 
00096 {
00097   ShProgram nibble = SH_BEGIN_PROGRAM() {
00098     ShInputTexCoord3f SH_NAMEDECL(tc, tcname);
00099     typename T::OutputType SH_NAMEDECL(result, name) = tex(tc);
00100   } SH_END;
00101   nibble.name("shAccess");
00102   return nibble;
00103 }
00104 
00105 template<typename T>
00106 ShProgram shAccess(const ShBaseTextureCube<T> &tex, const std::string & tcname, const std::string & name) 
00107 {
00108   ShProgram nibble = SH_BEGIN_PROGRAM() {
00109     ShInputTexCoord3f SH_NAMEDECL(tc, tcname);
00110     typename T::OutputType SH_NAMEDECL(result, name) = tex(tc);
00111   } SH_END;
00112   nibble.name("shAccess");
00113   return nibble;
00114 }
00115 
00116 template<typename T, int Rows, int Cols, ShBindingType Binding, typename T2>
00117 ShProgram shTransform(const ShMatrix<Rows, Cols, Binding, T2> &m, const std::string & name) 
00118 {
00119   ShProgram nibble = SH_BEGIN_PROGRAM() {
00120     typename T::InOutType SH_NAMEDECL(attrib, name) = m | attrib;
00121   } SH_END;
00122   nibble.name("shTransform");
00123   return nibble;
00124 }
00125 
00126 template<typename T, typename T2>
00127 ShProgram shCast(const std::string & name)
00128 {
00129   ShProgram nibble = SH_BEGIN_PROGRAM() {
00130     typename T::InputType SH_NAMEDECL(in, name);
00131     typename T2::OutputType SH_NAMEDECL(out, name) = cast<T2::typesize>( in );
00132   } SH_END;
00133   nibble.name("shCast");
00134   return nibble;
00135 }
00136 
00137 template<typename T, typename T2>
00138 ShProgram shFillcast(const std::string & name)
00139 {
00140   ShProgram nibble = SH_BEGIN_PROGRAM() {
00141     typename T::InputType SH_NAMEDECL(in, name);
00142     typename T2::OutputType SH_NAMEDECL(out, name) = fillcast<T2::typesize>( in );
00143   } SH_END;
00144   nibble.name("shFillcast");
00145   return nibble;
00146 }
00147 
00148 #define SHNIBBLE_UNARY_OP(opfunc, opcode) \
00149 template<typename T>\
00150 ShProgram opfunc(const std::string & name) \
00151 {\
00152   ShProgram nibble = SH_BEGIN_PROGRAM() {\
00153     typename T::InOutType SH_NAMEDECL(x, name) = opcode;\
00154   } SH_END;\
00155   nibble.name(# opfunc); \
00156   return nibble; \
00157 }
00158 
00159 SHNIBBLE_UNARY_OP(shAbs, abs(x))
00160 SHNIBBLE_UNARY_OP(shAcos, acos(x))
00161 SHNIBBLE_UNARY_OP(shAcosh, acosh(x))
00162 SHNIBBLE_UNARY_OP(shAsin, asin(x))
00163 SHNIBBLE_UNARY_OP(shAsinh, asinh(x))
00164 SHNIBBLE_UNARY_OP(shAtan, atan(x))
00165 SHNIBBLE_UNARY_OP(shAtanh, atanh(x))
00166 SHNIBBLE_UNARY_OP(shCbrt, cbrt(x))
00167 SHNIBBLE_UNARY_OP(shCeil, ceil(x))
00168 SHNIBBLE_UNARY_OP(shCos, cos(x))
00169 SHNIBBLE_UNARY_OP(shCosh, cosh(x))
00170 SHNIBBLE_UNARY_OP(shDx, dx(x))
00171 SHNIBBLE_UNARY_OP(shDy, dy(x))
00172 SHNIBBLE_UNARY_OP(shFloor, floor(x))
00173 SHNIBBLE_UNARY_OP(shFrac, frac(x))
00174 SHNIBBLE_UNARY_OP(shExp, exp(x))
00175 SHNIBBLE_UNARY_OP(shExpm1, expm1(x))
00176 SHNIBBLE_UNARY_OP(shExp2, exp2(x))
00177 SHNIBBLE_UNARY_OP(shExp10, exp10(x))
00178 SHNIBBLE_UNARY_OP(shFwidth, fwidth(x))
00179 SHNIBBLE_UNARY_OP(shLog, log(x))
00180 SHNIBBLE_UNARY_OP(shLogp1, logp1(x))
00181 SHNIBBLE_UNARY_OP(shLog2, log2(x))
00182 SHNIBBLE_UNARY_OP(shLog10, log10(x))
00183 SHNIBBLE_UNARY_OP(shNormalize, normalize(x))
00184 SHNIBBLE_UNARY_OP(shNot, !x)
00185 SHNIBBLE_UNARY_OP(shPos, pos(x))
00186 SHNIBBLE_UNARY_OP(shRcp, rcp(x))
00187 SHNIBBLE_UNARY_OP(shRound, round(x))
00188 SHNIBBLE_UNARY_OP(shRsqrt, rsqrt(x))
00189 SHNIBBLE_UNARY_OP(shSat, sat(x))
00190 SHNIBBLE_UNARY_OP(shSign, sign(x))
00191 SHNIBBLE_UNARY_OP(shSin, sin(x))
00192 SHNIBBLE_UNARY_OP(shSinh, sinh(x))
00193 SHNIBBLE_UNARY_OP(shSort, sort(x))
00194 SHNIBBLE_UNARY_OP(shSqrt, sqrt(x))
00195 SHNIBBLE_UNARY_OP(shTan, tan(x))
00196 SHNIBBLE_UNARY_OP(shTanh, tanh(x))
00197 
00198 #define SHNIBBLE_BINARY_OP(opfunc, opcode) \
00199 template<typename T1, typename T2> \
00200 ShProgram opfunc(const std::string & output_name, \
00201     const std::string & input_name0, const std::string & input_name1) \
00202 { \
00203   ShProgram nibble = SH_BEGIN_PROGRAM() { \
00204     typename T1::InputType SH_NAMEDECL(a, input_name0); \
00205     typename T2::InputType SH_NAMEDECL(b, input_name1); \
00206     typename SelectType<(T1::typesize > T2::typesize), typename T1::OutputType, typename T2::OutputType>::type\
00207       SH_NAMEDECL(result, output_name) = opcode; \
00208   } SH_END; \
00209   nibble.name(# opfunc); \
00210   return nibble; \
00211 } \
00212 \
00213 template<typename T1> \
00214 ShProgram opfunc(const std::string & output_name,\
00215     const std::string & input_name0, const std::string & input_name1 ) \
00216 { \
00217   return opfunc<T1, T1>(output_name, input_name0, input_name1); \
00218 }
00219 
00220 SHNIBBLE_BINARY_OP(shAdd, a + b)
00221 SHNIBBLE_BINARY_OP(shAnd, a && b)
00222 SHNIBBLE_BINARY_OP(shAtan2, atan2(a, b)) 
00223 SHNIBBLE_BINARY_OP(shDiv, a / b)
00224 SHNIBBLE_BINARY_OP(shFaceforward, faceforward(a, b))
00225 SHNIBBLE_BINARY_OP(shMax, max(a, b))
00226 SHNIBBLE_BINARY_OP(shMin, min(a, b))
00227 SHNIBBLE_BINARY_OP(shMod, mod(a, b))
00228 SHNIBBLE_BINARY_OP(shMul, a * b)
00229 SHNIBBLE_BINARY_OP(shOr, a || b)
00230 SHNIBBLE_BINARY_OP(shPow, pow(a, b))
00231 SHNIBBLE_BINARY_OP(shReflect, reflect(a, b)) 
00232 SHNIBBLE_BINARY_OP(shSeq, a == b) 
00233 SHNIBBLE_BINARY_OP(shSle, a <= b) 
00234 SHNIBBLE_BINARY_OP(shSlt, a < b) 
00235 SHNIBBLE_BINARY_OP(shSge, a >= b) 
00236 SHNIBBLE_BINARY_OP(shSgt, a > b) 
00237 SHNIBBLE_BINARY_OP(shSne, a != b) 
00238 SHNIBBLE_BINARY_OP(shSub, a - b)
00239 
00240 #define SHNIBBLE_TERNARY_OP(opfunc, opcode) \
00241 template<typename T1, typename T2, typename T3> \
00242 ShProgram opfunc(const std::string & output_name, \
00243     const std::string & input_name0, const std::string & input_name1, \
00244     const std::string & input_name2) \
00245 { \
00246   ShProgram nibble = SH_BEGIN_PROGRAM() { \
00247     typename T1::InputType SH_NAMEDECL(a, input_name0); \
00248     typename T2::InputType SH_NAMEDECL(b, input_name1); \
00249     typename T3::InputType SH_NAMEDECL(c, input_name2); \
00250     typedef typename SelectType<(T1::typesize > T2::typesize), typename T1::OutputType, \
00251                                 typename T2::OutputType>::type T1T2; \
00252     typename SelectType<(T1T2::typesize > T3::typesize), typename T1T2::OutputType, \
00253                         typename T3::OutputType>::type SH_NAMEDECL(result, output_name) = opcode; \
00254   } SH_END; \
00255   nibble.name(# opfunc); \
00256   return nibble; \
00257 } \
00258 \
00259 template<typename T1, typename T2> \
00260 ShProgram opfunc(const std::string & output_name,\
00261     const std::string & input_name0, const std::string & input_name1, \
00262     const std::string & input_name2) \
00263 { \
00264   return opfunc<T1, T2, T2>(output_name, input_name0, input_name1, input_name2); \
00265 } \
00266 \
00267 template<typename T1> \
00268 ShProgram opfunc(const std::string & output_name,\
00269     const std::string & input_name0, const std::string & input_name1, \
00270     const std::string & input_name2) \
00271 { \
00272   return opfunc<T1, T1, T1>(output_name, input_name0, input_name1, input_name2); \
00273 }
00274 
00275 SHNIBBLE_TERNARY_OP(shClamp, clamp(a, b, c))
00276 SHNIBBLE_TERNARY_OP(shCond, cond(a, b, c))
00277 SHNIBBLE_TERNARY_OP(shMad, mad(a, b, c))
00278 SHNIBBLE_TERNARY_OP(shSmoothstep, smoothstep(a, b, c))
00279 
00280 #define SHNIBBLE_HASH_FUNC(opfunc, opcode) \
00281 template<typename T1, typename T2> \
00282 ShProgram opfunc(const std::string & output_name, const std::string & input_name0) \
00283 { \
00284   ShProgram nibble = SH_BEGIN_PROGRAM() { \
00285     typename T1::InputType SH_NAMEDECL(a, input_name0); \
00286     typename T2::OutputType SH_NAMEDECL(result, output_name) = opcode<T2::typesize>(a); \
00287   } SH_END; \
00288   nibble.name(# opfunc); \
00289   return nibble; \
00290 }
00291   
00292 SHNIBBLE_HASH_FUNC(shCellnoise, cellnoise)
00293 SHNIBBLE_HASH_FUNC(shScellnoise, scellnoise)
00294 SHNIBBLE_HASH_FUNC(shHash, SH::hash)
00295 SHNIBBLE_HASH_FUNC(shTexhash, texhash)
00296 
00297 #define SHNIBBLE_NOISE_FUNC(opfunc, opcode) \
00298 template<typename T1, typename T2> \
00299 ShProgram opfunc(const std::string & output_name, const std::string & input_name0) \
00300 { \
00301   ShProgram nibble = SH_BEGIN_PROGRAM() { \
00302     typename T1::InputType SH_NAMEDECL(a, input_name0); \
00303     typename T2::OutputType SH_NAMEDECL(result, output_name) = opcode<T2::typesize>(a); \
00304   } SH_END; \
00305   nibble.name(# opfunc); \
00306   return nibble; \
00307 }\
00308 template<typename T1, typename T2, typename T3> \
00309 ShProgram opfunc(const std::string & output_name, const std::string & input_name0, \
00310                  const std::string & input_name1) \
00311 { \
00312   ShProgram nibble = SH_BEGIN_PROGRAM() { \
00313     typename T1::InputType SH_NAMEDECL(a, input_name0); \
00314     typename T2::InputType SH_NAMEDECL(b, input_name1); \
00315     typename T3::OutputType SH_NAMEDECL(result, output_name) = opcode<T2::typesize>(a, b); \
00316   } SH_END; \
00317   nibble.name(# opfunc); \
00318   return nibble; \
00319 }
00320 
00321 SHNIBBLE_NOISE_FUNC(shLinnoise, linnoise)
00322 SHNIBBLE_NOISE_FUNC(shNoise, noise)
00323 SHNIBBLE_NOISE_FUNC(shPerlin, perlin)
00324 SHNIBBLE_NOISE_FUNC(shTurbulence, turbulence)
00325 SHNIBBLE_NOISE_FUNC(shSlinnoise, slinnoise)
00326 SHNIBBLE_NOISE_FUNC(shSnoise, snoise)
00327 SHNIBBLE_NOISE_FUNC(shSperlin, sperlin)
00328 SHNIBBLE_NOISE_FUNC(shSturbulence, sturbulence)
00329 
00330 #define SHNIBBLE_DISTANCE_FUNC(opfunc, opcode) \
00331 template<typename T1, typename T2> \
00332 ShProgram opfunc(const std::string & output_name, \
00333                  const std::string & input_name0, \
00334                  const std::string & input_name1) \
00335 { \
00336   ShProgram nibble = SH_BEGIN_PROGRAM() { \
00337     typename T1::InputType SH_NAMEDECL(a, input_name0); \
00338     typename T2::InputType SH_NAMEDECL(b, input_name1); \
00339     ShOutputAttrib1f SH_NAMEDECL(result, output_name) = opcode; \
00340   } SH_END; \
00341   nibble.name(# opfunc); \
00342   return nibble; \
00343 } \
00344 template<typename T> \
00345 ShProgram opfunc(const std::string & output_name, \
00346                  const std::string & input_name0, \
00347                  const std::string & input_name1) \
00348 { \
00349   return opfunc<T, T>(output_name, input_name0, input_name1);\
00350 }
00351 
00352 SHNIBBLE_DISTANCE_FUNC(shDistance, distance(a, b))
00353 SHNIBBLE_DISTANCE_FUNC(shDistance_1, distance_1(a, b))
00354 SHNIBBLE_DISTANCE_FUNC(shDistance_inf, distance_inf(a, b))
00355 
00356 #define SHNIBBLE_UNARY_TUPLEOP(opfunc, opcode) \
00357 template<typename T> \
00358 ShProgram opfunc(const std::string & output_name, \
00359                  const std::string & input_name0) \
00360 { \
00361   ShProgram nibble = SH_BEGIN_PROGRAM() { \
00362     typename T::InputType SH_NAMEDECL(a, input_name0); \
00363     ShOutputAttrib1f SH_NAMEDECL(result, output_name) = opcode; \
00364   } SH_END; \
00365   nibble.name(# opfunc); \
00366   return nibble; \
00367 }
00368 
00369 SHNIBBLE_UNARY_TUPLEOP(shAll, all(a));
00370 SHNIBBLE_UNARY_TUPLEOP(shAny, any(a));
00371 SHNIBBLE_UNARY_TUPLEOP(shLength, length(a))
00372 SHNIBBLE_UNARY_TUPLEOP(shLength_1, length(a))
00373 SHNIBBLE_UNARY_TUPLEOP(shLength_inf, length(a))
00374 SHNIBBLE_UNARY_TUPLEOP(shMax1, max(a));
00375 SHNIBBLE_UNARY_TUPLEOP(shMin1, min(a));
00376 SHNIBBLE_UNARY_TUPLEOP(shProd, prod(a));
00377 SHNIBBLE_UNARY_TUPLEOP(shSum, sum(a));
00378 
00379 template<int N, typename T>
00380 ShProgram shBernstein(const std::string& name, const std::string& input_name0)
00381 {
00382   ShProgram nibble = SH_BEGIN_PROGRAM() {
00383     typename T::InputType SH_NAMEDECL(a, input_name0);
00384     ShAttrib<N, SH_OUTPUT, float> SH_NAMEDECL(result, name) = bernstein<N>(a);
00385   } SH_END;
00386   nibble.name("shBernstein");
00387   return nibble;
00388 }
00389 
00390 template<typename T1, typename T2>
00391 ShProgram shBezier(const std::string& name, const std::string& input_name0,
00392                    const std::string& input_name1)
00393 {
00394   ShProgram nibble = SH_BEGIN_PROGRAM() {
00395     typename T1::InputType SH_NAMEDECL(a, input_name0);
00396     typename T2::InputType SH_NAMEDECL(b, input_name1);
00397     typename T2::OutputType SH_NAMEDECL(result, name) = bezier(a, b);
00398   } SH_END;
00399   nibble.name("shBezier");
00400   return nibble;
00401 }
00402 
00403 template<typename T> 
00404 ShProgram shCross(const std::string& name, const std::string& input_name0,
00405                   const std::string& input_name1)
00406 { 
00407   ShProgram nibble = SH_BEGIN_PROGRAM() {
00408     typename T::InputType SH_NAMEDECL(a, input_name0); 
00409     typename T::InputType SH_NAMEDECL(b, input_name1); 
00410     typename T::OutputType SH_NAMEDECL(result, name) = cross(a, b); 
00411   } SH_END; 
00412   nibble.name("shCross");
00413   return nibble;
00414 }
00415 
00416 template<typename T> 
00417 ShProgram shDiscard(const std::string & name, const std::string& input_name0)
00418 { 
00419   ShProgram nibble = SH_BEGIN_PROGRAM() {
00420     typename T::InputType SH_NAMEDECL(a, input_name0);
00421     discard(a);
00422   } SH_END;
00423   nibble.name("shDiscard");
00424   return nibble;
00425 }
00426 
00427 template<typename T> 
00428 ShProgram shDot(const std::string & name, const std::string& input_name0,
00429                 const std::string& input_name1)
00430 { 
00431   ShProgram nibble = SH_BEGIN_PROGRAM() {
00432     typename T::InputType SH_NAMEDECL(a, input_name0);
00433     typename T::InputType SH_NAMEDECL(b, input_name1);
00434     ShOutputAttrib1f SH_NAMEDECL(result, name) = dot(a, b);
00435   } SH_END;
00436   nibble.name("shDot");
00437   return nibble;
00438 }
00439 
00440 template<typename T> 
00441 ShProgram shGradient(const std::string& name, const std::string& input_name0)
00442 { 
00443   ShProgram nibble = SH_BEGIN_PROGRAM() {
00444     typename T::InputType SH_NAMEDECL(a, input_name0);
00445     ShOutputAttrib2f SH_NAMEDECL(result, name) = gradient(a); 
00446   } SH_END; 
00447   nibble.name("shGradient");
00448   return nibble;
00449 }
00450 
00451 template<int S, typename T>
00452 ShProgram shGroupsort(const std::string & name, const std::string& input_name0)
00453 { 
00454   ShProgram nibble = SH_BEGIN_PROGRAM() {
00455     typename T::InputType SH_NAMEDECL(a, input_name0);
00456     groupsort<S>(a);
00457   } SH_END;
00458   nibble.name("shGroupsort");
00459   return nibble;
00460 }
00461 
00462 template<typename T1, typename T2>
00463 ShProgram shHermite(const std::string& name, const std::string& input_name0,
00464                     const std::string& input_name1, const std::string& input_name2,
00465                     const std::string& input_name3, const std::string& input_name4)
00466 {
00467   ShProgram nibble = SH_BEGIN_PROGRAM() {
00468     typename T1::InputType SH_NAMEDECL(a, input_name0);
00469     typename T2::InputType SH_NAMEDECL(b, input_name1);
00470     typename T2::InputType SH_NAMEDECL(c, input_name2);
00471     typename T2::InputType SH_NAMEDECL(d, input_name3);
00472     typename T2::InputType SH_NAMEDECL(e, input_name4);
00473     typename T2::OutputType SH_NAMEDECL(result, name) = hermite(a, b, c, d, e);
00474   } SH_END;
00475   nibble.name("shHermite");
00476   return nibble;
00477 }
00478 
00479 template<typename T1, typename T2> 
00480 ShProgram shJoin(const std::string & name,
00481                  const std::string & input_name0, 
00482                  const std::string & input_name1)
00483 {
00484   ShProgram nibble = SH_BEGIN_PROGRAM() {
00485     typename T1::InputType SH_NAMEDECL(a, input_name0);
00486     typename T2::InputType SH_NAMEDECL(b, input_name1);
00487     ShAttrib<T1::typesize + T2::typesize, SH_OUTPUT, float> SH_NAMEDECL(result, name) = join(a, b); 
00488   } SH_END; 
00489   nibble.name("shJoin");
00490   return nibble;
00491 }
00492 
00493 template<typename T1, typename T2>
00494 ShProgram shLerp(const std::string & name, const std::string& input_name0,
00495                  const std::string& input_name1, const std::string& input_name2)
00496 { 
00497   ShProgram nibble = SH_BEGIN_PROGRAM() {
00498     typename T1::InputType SH_NAMEDECL(a, input_name0);
00499     typename T1::InputType SH_NAMEDECL(b, input_name1); 
00500     typename T2::InputType SH_NAMEDECL(alpha, input_name2);
00501     typename T1::OutputType SH_NAMEDECL(result, name) = lerp(alpha, a, b); 
00502   } SH_END; 
00503   nibble.name("shLerp");
00504   return nibble;
00505 }
00506 
00507 template<typename T1>
00508 ShProgram shLerp(const std::string & name, const std::string& input_name0,
00509                  const std::string& input_name1, const std::string& input_name2)
00510 { 
00511   return shLerp<T1, T1>(name, input_name0, input_name1, input_name2);
00512 }
00513 
00514 template<typename T> 
00515 ShProgram shLit(const std::string& name,
00516                 const std::string& input_name0, 
00517                 const std::string& input_name1,
00518                 const std::string& input_name2)
00519 { 
00520   ShProgram nibble = SH_BEGIN_PROGRAM() {
00521     typename T::InputType SH_NAMEDECL(a, input_name0);
00522     typename T::InputType SH_NAMEDECL(b, input_name1);
00523     typename T::InputType SH_NAMEDECL(c, input_name2);
00524     ShOutputAttrib4f SH_NAMEDECL(result, name) = lit(a, b, c); 
00525   } SH_END; 
00526   nibble.name("shLit");
00527   return nibble;
00528 }
00529 
00530 template<typename T1, typename T2>
00531 ShProgram shPoly(const std::string & name,
00532                  const std::string & input_name0, 
00533                  const std::string & input_name1)
00534 {
00535   ShProgram nibble = SH_BEGIN_PROGRAM() {
00536     typename T1::InputType SH_NAMEDECL(a, input_name0);
00537     typename T2::InputType SH_NAMEDECL(b, input_name1);
00538     typename T1::OutputType SH_NAMEDECL(result, name) = poly(a, b);
00539   } SH_END;
00540   nibble.name("shPoly");
00541   return nibble;
00542 }
00543 
00544 template<typename T1>
00545 ShProgram shPoly(const std::string & name,
00546                  const std::string & input_name0, 
00547                  const std::string & input_name1)
00548 {
00549   return shPoly<T1, T1>(name, input_name0, input_name1);
00550 }
00551 
00552 template<typename T1, typename T2>
00553 ShProgram shRefract(const std::string& name,
00554                     const std::string& input_name0, 
00555                     const std::string& input_name1,
00556                     const std::string& input_name2)
00557 {
00558   ShProgram nibble = SH_BEGIN_PROGRAM() {
00559     typename T1::InputType SH_NAMEDECL(a, input_name0);
00560     typename T1::InputType SH_NAMEDECL(b, input_name1);
00561     typename T2::InputType SH_NAMEDECL(c, input_name2);
00562     typename T1::OutputType SH_NAMEDECL(result, name) = refract(a, b, c);
00563   } SH_END;
00564   nibble.name("shRefract");
00565   return nibble;
00566 }
00567 
00568 template<typename T>
00569 ShProgram shRefract(const std::string& name,
00570                     const std::string& input_name0, 
00571                     const std::string& input_name1,
00572                     const std::string& input_name2)
00573 {
00574   return shRefract<T, T>(name, input_name0, input_name1, input_name2);
00575 }
00576 
00577 template<typename T>
00578 ShProgram shSmoothpulse(const std::string& name,
00579                         const std::string& input_name0, 
00580                         const std::string& input_name1,
00581                         const std::string& input_name2,
00582                         const std::string& input_name3)
00583 {
00584   ShProgram nibble = SH_BEGIN_PROGRAM() {
00585     typename T::InputType SH_NAMEDECL(a, input_name0);
00586     typename T::InputType SH_NAMEDECL(b, input_name1);
00587     typename T::InputType SH_NAMEDECL(c, input_name2);
00588     typename T::InputType SH_NAMEDECL(d, input_name3);
00589     typename T::OutputType SH_NAMEDECL(result, name) = smoothpulse(a, b, c, d);
00590   } SH_END;
00591   nibble.name("shSmoothpulse");
00592   return nibble;
00593 }
00594 
00595 } // namespace
00596 
00597 #endif // SHNIBBLESIMPL_HPP

Generated on Thu Feb 16 14:51:36 2006 for Sh by  doxygen 1.4.6