00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
#ifndef SHUTIL_KERNELLIBIMPL_HPP
00028
#define SHUTIL_KERNELLIBIMPL_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 "ShKernelLib.hpp"
00038
#include "ShFunc.hpp"
00039
#include "ShTexCoord.hpp"
00040
#include "ShVector.hpp"
00041
#include "ShPoint.hpp"
00042
#include "ShPosition.hpp"
00043
#include "ShNormal.hpp"
00044
00049
namespace ShUtil {
00050
00051
using namespace SH;
00052
00053
template<
int N, ShBindingType Binding,
typename T>
00054 ShProgram ShKernelLib::shVsh(
const ShMatrix<N, N, Binding, T> &mv,
00055
const ShMatrix<N, N, Binding, T> &mvp,
00056
int numTangents,
int numLights)
00057 {
00058
int i;
00059 ShProgram generalVsh = SH_BEGIN_VERTEX_PROGRAM {
00060
00061 ShInputTexCoord2f
SH_NAMEDECL(u,
"texcoord");
00062 ShInputNormal3f
SH_NAMEDECL(nm,
"normal");
00063 ShVector3f tgt;
00064 ShVector3f tgt2;
00065
if(numTangents > 0) {
00066 ShInputVector3f
SH_NAMEDECL(inTangent,
"tangent");
00067 tgt = inTangent;
00068
if( numTangents > 1) {
00069 ShInputVector3f
SH_NAMEDECL(inTangent2,
"tangent2");
00070 tgt2 = inTangent2;
00071 }
else {
00072 tgt2 =
cross(nm, tgt);
00073 }
00074 }
00075 ShInputPoint3f* lpv =
new ShInputPoint3f[numLights];
00076
for(i = 0; i < numLights; ++i) lpv[i].name(makeName(
"lightPos", i));
00077 ShInputPosition4f
SH_NAMEDECL(pm,
"posm");
00078
00079
00080 ShOutputTexCoord2f
SH_NAMEDECL(uo,
"texcoord");
00081 ShOutputPoint3f
SH_NAMEDECL(pv,
"posv");
00082 ShOutputPoint4f
SH_NAMEDECL(pmo,
"posm");
00083
00084
00085 ShOutputNormal3f
SH_NAMEDECL(nv,
"normal");
00086 ShOutputVector3f
SH_NAMEDECL(tv,
"tangent");
00087 ShOutputVector3f
SH_NAMEDECL(tv2,
"tangent2");
00088 ShOutputVector3f
SH_NAMEDECL(vv,
"viewVec");
00089 ShOutputVector3f* hv =
new ShOutputVector3f[numLights];
00090
for(i = 0; i < numLights; ++i) hv[i].name(makeName(
"halfVec", i).c_str());
00091 ShOutputVector3f* lv =
new ShOutputVector3f[numLights];
00092
for(i = 0; i < numLights; ++i) lv[i].name(makeName(
"lightVec", i).c_str());
00093
00094 ShOutputPoint3f* lpo =
new ShOutputPoint3f[numLights];
00095
for(i = 0; i < numLights; ++i) lpo[i].name(makeName(
"lightPos", i).c_str());
00096
00097
00098 ShOutputNormal3f
SH_NAMEDECL(nvt,
"normalt");
00099 ShOutputVector3f
SH_NAMEDECL(vvt,
"viewVect");
00100 ShOutputVector3f* hvt =
new ShOutputVector3f[numLights];
00101
for(i = 0; i < numLights; ++i) hvt[i].name(makeName(
"halfVect", i).c_str());
00102 ShOutputVector3f* lvt =
new ShOutputVector3f[numLights];
00103
for(i = 0; i < numLights; ++i) lvt[i].name(makeName(
"lightVect", i).c_str());
00104
00105 ShOutputPosition4f
SH_NAMEDECL(pd,
"posh");
00106
00107 uo = u;
00108 pv = (mv | pm)(0,1,2);
00109 pmo = pm;
00110
00111
00112 nv =
normalize(mv | nm);
00113 vv =
normalize(-pv);
00114
for(i = 0; i < numLights; ++i) {
00115 lv[i] =
normalize(lpv[i] - pv);
00116 hv[i] =
normalize(vv + lv[i]);
00117 lpo[i] = lpv[i];
00118 }
00119
00120
00121 tv = mv | tgt;
00122 tv2 = mv | tgt2;
00123 nvt =
normalize(
changeBasis(nv, tv, tv2, nv));
00124 vvt =
normalize(
changeBasis(nv, tv, tv2, vv));
00125
for(i = 0; i < numLights; ++i) {
00126 hvt[i] =
normalize(
changeBasis(nv, tv, tv2, hv[i]));
00127 lvt[i] =
normalize(
changeBasis(nv, tv, tv2, lv[i]));
00128 }
00129
00130 pd = mvp | pm;
00131
00132
delete [] lvt;
00133
delete [] hvt;
00134
delete [] lpo;
00135
delete [] lv;
00136
delete [] hv;
00137
delete [] lpv;
00138 } SH_END;
00139
return generalVsh;
00140 }
00141
00142 }
00143
00144
#endif