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

xtoon_texture.C

Go to the documentation of this file.
00001 #include "gtex/gl_extensions.H"
00002 #include "gtex/paper_effect.H"
00003 #include "geom/gl_view.H"
00004 #include "std/config.H"
00005 #include "xtoon_texture.H"
00006 
00007 #include <iostream>
00008 
00009 using namespace std;
00010 using namespace mlib;
00011 
00012 /**********************************************************************
00013  * Globals
00014  **********************************************************************/
00015 
00016 bool     ntt_paper_flag;       //If paper's being used
00017 Wpt      ntt_light_pos;        //Used to fetch light pos
00018 Wvec     ntt_light_dir;        //Used to fetch light dir
00019 bool     ntt_positional;       //Used to flag if pos or dir
00020 int      ntt_detail_map = XToonTexture::User;
00021 double   ntt_target_length;
00022 double   ntt_max_factor;
00023 double   ntt_smooth_factor;
00024 int      ntt_smooth_rings = 3;
00025 bool     ntt_smooth_enabled = false;
00026 bool     ntt_elliptic_enabled = false;
00027 bool     ntt_spheric_enabled = false;
00028 bool     ntt_cylindric_enabled = false;
00029 bool     ntt_curv_enabled = false;
00030 Wtransf  ntt_prev_matrix;
00031 Wtransf  ntt_cur_matrix;
00032 bool     ntt_inv_detail = false;
00033 
00034 bool     ntt_is_init_vertex_program = false;
00035 bool     ntt_use_vertex_program = false;
00036 bool     ntt_use_vertex_program_arb = false;
00037 bool     ntt_use_vertex_program_nv = false;
00038 
00039 GLuint   ntt_toon_prog_nv;
00040 GLuint   ntt_toon_prog_detail_arb, ntt_toon_prog_depth_arb, ntt_toon_prog_focus_arb, ntt_toon_prog_flow_arb;
00041 GLuint   ntt_toon_prog_curvature_arb, ntt_toon_prog_orientation_arb, ntt_toon_prog_specularity_arb;
00042 GLuint   ntt_toon_prog_lookup_arb, ntt_toon_prog_orientation_lookup_arb, ntt_toon_prog_specularity_lookup_arb;
00043 
00044 LIST<str_ptr>*    XToonTexture::_toon_texture_names = 0;
00045 LIST<TEXTUREptr>* XToonTexture::_toon_texture_ptrs = 0;
00046 LIST<str_ptr>*    XToonTexture::_toon_texture_remap_orig_names = 0;
00047 LIST<str_ptr>*    XToonTexture::_toon_texture_remap_new_names = 0;
00048 
00049 /*****************************************************************
00050  * Texture Remapping
00051  *****************************************************************/
00052 
00053 char *toon_remap_base = "nprdata/toon_textures/";
00054 char *toon_remap_fnames[][2] = 
00055 {
00056 //   {"dark-8.png",    "1D--dark-8.png"},
00057 //   {"mydot4.png",    "2D--dash-normal-8-32.png"},
00058 //   {"one_d.png",     "1D--gauss-narrow-8.png"},
00059    {NULL,            NULL}
00060 };
00061 
00062 /*****************************************************************
00063  * Shaders
00064  *****************************************************************/
00065 
00066 const unsigned char NPRToonShaderNV[]=
00067                         //env[0]-env[3] modelview
00068                         //env[4]-env[7] projection
00069                         //env[12]-env[15] texture0
00070                         //env[16]-env[19] texture1
00071                         //env[20] xy(1,1) in ndc
00072                         //env[21] light pos
00073                         //env[22] light dir
00074                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00075 {
00076 "!!VP1.0\
00077 DP4 R0.x,v[OPOS],c[0];\
00078 DP4 R0.y,v[OPOS],c[1];\
00079 DP4 R0.z,v[OPOS],c[2];\
00080 DP4 R0.w,v[OPOS],c[3];\
00081 DP4 R1.x,R0,c[4];\
00082 DP4 R1.y,R0,c[5];\
00083 DP4 R1.z,R0,c[6];\
00084 DP4 R1.w,R0,c[7];\
00085 MOV o[HPOS],R1;\
00086 MUL R2,R1,c[20];\
00087 DP4 o[TEX1].x,R2,c[16];\
00088 DP4 o[TEX1].y,R2,c[17];\
00089 DP4 o[TEX1].z,R2,c[18];\
00090 DP4 o[TEX1].w,R2,c[19];\
00091 ADD R4,c[21],-v[OPOS];\
00092 DP3 R4.w,R4,R4;\
00093 RSQ R4.w,R4.w;\
00094 MUL R4,R4,R4.w;\
00095 SLT R11,R11,R11;\
00096 SGE R10,R11,c[23];\
00097 MUL R5,c[23],R4;\
00098 MAD R5,R10,c[22],R5;\
00099 DP3 R6.x,v[NRML],R5;\
00100 MOV R6.y,R1.z;\
00101 MOV R6.zw,R11;\
00102 DP4 o[TEX0].x,R6,c[12];\
00103 DP4 o[TEX0].y,R6,c[13];\
00104 MOV o[COL0],v[COL0];\
00105 END"
00106 };
00107 
00108 
00109 
00110 
00111 const unsigned char NPRToonShaderDetailARB[]=
00112                         //env[21] light pos
00113                         //env[22] light dir
00114                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00115                         //env[24] target length
00116                         //env[25] max factor
00117                         //env[26] smooth factor
00118 {
00119 "!!ARBvp1.0\n\
00120 \
00121 ATTRIB iPos          = vertex.position;\
00122 ATTRIB iNorm         = vertex.normal;\
00123 ATTRIB iCol          = vertex.color;\
00124 ATTRIB iSmoothedNorm = vertex.attrib[1];\
00125 \
00126 OUTPUT oPos  = result.position;\
00127 OUTPUT oCol  = result.color;\
00128 OUTPUT oTex0 = result.texcoord[0];\
00129 OUTPUT oTex1 = result.texcoord[1];\
00130 OUTPUT oTex2 = result.texcoord[2];\
00131 \
00132 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00133 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00134 PARAM  cLPos      = program.env[21];\
00135 PARAM  cLDir      = program.env[22];\
00136 PARAM  cLPosFlag  = program.env[23];\
00137 PARAM  cTargetLen = program.env[24];\
00138 PARAM  cMaxFactor = program.env[25];\
00139 PARAM  cSmooth    = program.env[26];\
00140 \
00141 PARAM  mMVP[4]  =  { state.matrix.mvp };\
00142 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00143 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00144 PARAM  mTex2[4] =  { state.matrix.texture[2] };\
00145 \
00146 TEMP   tXY;\
00147 TEMP   tLDirFlag;\
00148 TEMP   tLPosVec;\
00149 TEMP   tLFinalVec;\
00150 TEMP   tDetail;\
00151 TEMP   tNorm;\
00152 \
00153 DP4 tXY.x, mMVP[0], iPos;\
00154 DP4 tXY.y, mMVP[1], iPos;\
00155 DP4 tXY.z, mMVP[2], iPos;\
00156 DP4 tXY.w, mMVP[3], iPos;\
00157 ""\
00158 SGE tLDirFlag,cZero,cLPosFlag;\
00159 \
00160 SUB tLPosVec,  cLPos,   iPos;\
00161 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00162 RSQ tLPosVec.w,tLPosVec.w;\
00163 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00164 \
00165 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00166 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00167 \
00168 MOV tDetail, cTargetLen;\
00169 \
00170 DP4 oTex0.x, mTex0[0], tLFinalVec;\
00171 DP4 oTex0.y, mTex0[1], tLFinalVec;\
00172 DP4 oTex0.z, mTex0[2], tLFinalVec;\
00173 DP4 oTex0.w, mTex0[3], tLFinalVec;\
00174 \
00175 DP4 oTex1.x, mTex1[0], iNorm;\
00176 DP4 oTex1.y, mTex1[1], iNorm;\
00177 DP4 oTex1.z, mTex1[2], iNorm;\
00178 DP4 oTex1.w, mTex1[3], iNorm;\
00179 \
00180 DP4 oTex2.x, mTex2[0], tDetail;\
00181 DP4 oTex2.y, mTex2[1], tDetail;\
00182 DP4 oTex2.z, mTex2[2], tDetail;\
00183 DP4 oTex2.w, mTex2[3], tDetail;\
00184 \
00185 MOV oPos, tXY;\
00186 MOV oCol, iCol;\
00187 \
00188 END"
00189 };
00190 
00191 
00192 const unsigned char NPRToonShaderDepthARB[]=
00193                         //env[20] xy(1,1) in ndc
00194                         //env[21] light pos
00195                         //env[22] light dir
00196                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00197                         //env[24] target length
00198                         //env[25] max factor
00199                         //env[26] smooth factor
00200 {
00201 "!!ARBvp1.0\n\
00202 \
00203 ATTRIB iPos          = vertex.position;\
00204 ATTRIB iNorm         = vertex.normal;\
00205 ATTRIB iCol          = vertex.color;\
00206 ATTRIB iSmoothedNorm = vertex.attrib[1];\
00207 \
00208 OUTPUT oPos  = result.position;\
00209 OUTPUT oCol  = result.color;\
00210 OUTPUT oTex0 = result.texcoord[0];\
00211 OUTPUT oTex1 = result.texcoord[1];\
00212 OUTPUT oTex2 = result.texcoord[2];\
00213 \
00214 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00215 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00216 PARAM  cLPos      = program.env[21];\
00217 PARAM  cLDir      = program.env[22];\
00218 PARAM  cLPosFlag  = program.env[23];\
00219 PARAM  cTargetLen = program.env[24];\
00220 PARAM  cMaxFactor = program.env[25];\
00221 PARAM  cSmooth    = program.env[26];\
00222 \
00223 PARAM  mMV[4]   =  { state.matrix.modelview };\
00224 PARAM  mMVP[4]  =  { state.matrix.mvp };\
00225 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00226 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00227 PARAM  mTex2[4] =  { state.matrix.texture[2] };\
00228 \
00229 TEMP   tEye;\
00230 TEMP   tRate;\
00231 TEMP   tXY;\
00232 TEMP   tLDirFlag;\
00233 TEMP   tLPosVec;\
00234 TEMP   tLFinalVec;\
00235 TEMP   tDetail;\
00236 TEMP   tNorm;\
00237 \
00238 DP4 tEye.x, mMV[0], iPos;\
00239 DP4 tEye.y, mMV[1], iPos;\
00240 DP4 tEye.z, mMV[2], iPos;\
00241 DP4 tEye.w, mMV[3], iPos;\
00242 \
00243 DP4 tXY.x, mMVP[0], iPos;\
00244 DP4 tXY.y, mMVP[1], iPos;\
00245 DP4 tXY.z, mMVP[2], iPos;\
00246 DP4 tXY.w, mMVP[3], iPos;\
00247 ""\
00248 SGE tLDirFlag,cZero,cLPosFlag;\
00249 \
00250 SUB tLPosVec,  cLPos,   iPos;\
00251 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00252 RSQ tLPosVec.w,tLPosVec.w;\
00253 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00254 \
00255 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00256 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00257 \
00258 LOG tRate,cMaxFactor.x;\
00259 RCP tRate,tRate.z;\
00260 RCP tDetail,cTargetLen.x;\
00261 MUL tDetail,tDetail,-tEye.z;\
00262 LOG tDetail,tDetail.x;\
00263 MUL tDetail,tDetail.z,tRate;\
00264 MIN tDetail, tDetail, cOne;\
00265 MAX tDetail, tDetail, cZero;\
00266 \
00267 SUB tNorm,iSmoothedNorm,iNorm;\
00268 MUL tNorm,tNorm,cSmooth.x;\
00269 ADD tNorm,tNorm,iNorm;\
00270 DP3 tNorm.w,tNorm,tNorm;\
00271 RSQ tNorm.w,tNorm.w;\
00272 MUL tNorm,tNorm,tNorm.w;\
00273 \
00274 DP4 oTex0.x, mTex0[0], tLFinalVec;\
00275 DP4 oTex0.y, mTex0[1], tLFinalVec;\
00276 DP4 oTex0.z, mTex0[2], tLFinalVec;\
00277 DP4 oTex0.w, mTex0[3], tLFinalVec;\
00278 \
00279 DP4 oTex1.x, mTex1[0], tNorm;\
00280 DP4 oTex1.y, mTex1[1], tNorm;\
00281 DP4 oTex1.z, mTex1[2], tNorm;\
00282 DP4 oTex1.w, mTex1[3], tNorm;\
00283 \
00284 DP4 oTex2.x, mTex2[0], tDetail;\
00285 DP4 oTex2.y, mTex2[1], tDetail;\
00286 DP4 oTex2.z, mTex2[2], tDetail;\
00287 DP4 oTex2.w, mTex2[3], tDetail;\
00288 \
00289 MOV oPos, tXY;\
00290 MOV oCol, iCol;\
00291 \
00292 END"
00293 };
00294 
00295 const unsigned char NPRToonShaderFocusARB[]=
00296                         //env[20] xy(1,1) in ndc
00297                         //env[21] light pos
00298                         //env[22] light dir
00299                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00300                         //env[24] target length
00301                         //env[25] max factor
00302                         //env[26] smooth factor
00303 {
00304 "!!ARBvp1.0\n\
00305 \
00306 ATTRIB iPos          = vertex.position;\
00307 ATTRIB iNorm         = vertex.normal;\
00308 ATTRIB iCol          = vertex.color;\
00309 ATTRIB iSmoothedNorm = vertex.attrib[1];\
00310 \
00311 OUTPUT oPos  = result.position;\
00312 OUTPUT oCol  = result.color;\
00313 OUTPUT oTex0 = result.texcoord[0];\
00314 OUTPUT oTex1 = result.texcoord[1];\
00315 OUTPUT oTex2 = result.texcoord[2];\
00316 \
00317 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00318 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00319 PARAM  cLPos      = program.env[21];\
00320 PARAM  cLDir      = program.env[22];\
00321 PARAM  cLPosFlag  = program.env[23];\
00322 PARAM  cTargetLen = program.env[24];\
00323 PARAM  cMaxFactor = program.env[25];\
00324 PARAM  cSmooth    = program.env[26];\
00325 \
00326 PARAM  mMVIT[4]   =  { state.matrix.modelview.invtrans };\
00327 PARAM  mMVP[4]  =  { state.matrix.mvp };\
00328 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00329 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00330 PARAM  mTex2[4] =  { state.matrix.texture[2] };\
00331 PARAM  mFocus[4]=  { state.matrix.program[0] };\
00332 \
00333 TEMP   tEye;\
00334 TEMP   tFocus;\
00335 TEMP   tRate;\
00336 TEMP   tXY;\
00337 TEMP   tLDirFlag;\
00338 TEMP   tLPosVec;\
00339 TEMP   tLFinalVec;\
00340 TEMP   tDetail;\
00341 TEMP   tNorm;\
00342 TEMP   tDist;\
00343 TEMP   tInf;\
00344 TEMP   tSup;\
00345 TEMP   tSign;\
00346 TEMP   zMin;\
00347 TEMP   zMax;\
00348 TEMP   tDinf;\
00349 TEMP   tDsup;\
00350 \
00351 DP4 tXY.x, mMVP[0], iPos;\
00352 DP4 tXY.y, mMVP[1], iPos;\
00353 DP4 tXY.z, mMVP[2], iPos;\
00354 DP4 tXY.w, mMVP[3], iPos;\
00355 ""\
00356 SGE tLDirFlag,cZero,cLPosFlag;\
00357 \
00358 SUB tLPosVec,  cLPos,   iPos;\
00359 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00360 RSQ tLPosVec.w,tLPosVec.w;\
00361 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00362 \
00363 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00364 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00365 \
00366 SUB tEye, mMVIT[3], iPos;\
00367 DP3 tEye.x, tEye, tEye;\
00368 POW tEye.x, tEye.x, 0.5;\
00369 \
00370 SGE tInf, mFocus[0].x, tEye.x;\
00371 MAD tSign, 2.0, -tInf, 1.0;\
00372 MUL zMin, tSign, cTargetLen.x;\
00373 MUL zMax, zMin, cMaxFactor.x;\
00374 ADD zMin, mFocus[0].x, zMin;\
00375 ADD zMax, mFocus[0].x, zMax;\
00376 \
00377 RCP tRate, zMax;\
00378 MUL tDinf, tRate, tEye.x;\
00379 LOG tDinf, tDinf;\
00380 MOV tDinf, tDinf.z;\
00381 MUL tRate, tRate, zMin;\
00382 LOG tRate, tRate;\
00383 RCP tRate, tRate.z;\
00384 MUL tDinf, tRate, tDinf;\
00385 SUB tDinf, cOne,  tDinf;\
00386 \
00387 RCP tRate, zMin;\
00388 MUL tDsup, tRate, tEye.x;\
00389 LOG tDsup, tDsup;\
00390 MOV tDsup, tDsup.z;\
00391 MUL tRate, tRate, zMax;\
00392 LOG tRate, tRate;\
00393 RCP tRate, tRate.z;\
00394 MUL tDsup, tRate, tDsup;\
00395 \
00396 MUL tDinf, tDinf, tInf;\
00397 SUB tSup,  cOne,  tInf;\
00398 MUL tDsup, tDsup, tSup;\
00399 ADD tDetail, tDsup, tDinf;\
00400 MIN tDetail, tDetail, cOne;\
00401 MAX tDetail, tDetail, cZero;\
00402 \
00403 SUB tNorm,iSmoothedNorm,iNorm;\
00404 MUL tNorm,tNorm,cSmooth.x;\
00405 ADD tNorm,tNorm,iNorm;\
00406 DP3 tNorm.w,tNorm,tNorm;\
00407 RSQ tNorm.w,tNorm.w;\
00408 MUL tNorm,tNorm,tNorm.w;\
00409 \
00410 DP4 oTex0.x, mTex0[0], tLFinalVec;\
00411 DP4 oTex0.y, mTex0[1], tLFinalVec;\
00412 DP4 oTex0.z, mTex0[2], tLFinalVec;\
00413 DP4 oTex0.w, mTex0[3], tLFinalVec;\
00414 \
00415 DP4 oTex1.x, mTex1[0], tNorm;\
00416 DP4 oTex1.y, mTex1[1], tNorm;\
00417 DP4 oTex1.z, mTex1[2], tNorm;\
00418 DP4 oTex1.w, mTex1[3], tNorm;\
00419 \
00420 DP4 oTex2.x, mTex2[0], tDetail;\
00421 DP4 oTex2.y, mTex2[1], tDetail;\
00422 DP4 oTex2.z, mTex2[2], tDetail;\
00423 DP4 oTex2.w, mTex2[3], tDetail;\
00424 \
00425 MOV oPos, tXY;\
00426 MOV oCol, iCol;\
00427 \
00428 END"
00429 };
00430 
00431 /*
00432 // MUL zMax, zMin, cMaxFactor.x;\
00433 
00434 
00435 
00436 // \
00437 // LOG tRate,cMaxFactor.x;\
00438 // RCP tRate,tRate.z;\
00439 // RCP tDetail,cTargetLen.x;\
00440 // SUB tEye, tEye.x, mFocus[0].x;\
00441 // MAX tEye, tEye, -tEye;\
00442 // MUL tDetail,tDetail,tEye;\
00443 // LOG tDetail,tDetail.x;\
00444 // MUL tDetail,tDetail.z,tRate;\
00445 // MIN tDetail, tDetail, cOne;\
00446 // MAX tDetail, tDetail, cZero;\
00447 */
00448 const unsigned char NPRToonShaderFlowARB[]=
00449                         //env[20] xy(1,1) in ndc
00450                         //env[21] light pos
00451                         //env[22] light dir
00452                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00453                         //env[24] target length
00454                         //env[25] max factor
00455                         //env[26] smooth factor
00456 {
00457 "!!ARBvp1.0\n\
00458 \
00459 ATTRIB iPos          = vertex.position;\
00460 ATTRIB iNorm         = vertex.normal;\
00461 ATTRIB iCol          = vertex.color;\
00462 ATTRIB iSmoothedNorm = vertex.attrib[1];\
00463 \
00464 OUTPUT oPos  = result.position;\
00465 OUTPUT oCol  = result.color;\
00466 OUTPUT oTex0 = result.texcoord[0];\
00467 OUTPUT oTex1 = result.texcoord[1];\
00468 OUTPUT oTex2 = result.texcoord[2];\
00469 \
00470 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00471 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00472 PARAM  cLPos      = program.env[21];\
00473 PARAM  cLDir      = program.env[22];\
00474 PARAM  cLPosFlag  = program.env[23];\
00475 PARAM  cTargetLen = program.env[24];\
00476 PARAM  cMaxFactor = program.env[25];\
00477 PARAM  cSmooth    = program.env[26];\
00478 \
00479 PARAM  mMV[4]   =  { state.matrix.modelview };\
00480 PARAM  mMVP[4]  =  { state.matrix.mvp };\
00481 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00482 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00483 PARAM  mTex2[4] =  { state.matrix.texture[2] };\
00484 PARAM  mPrevM[4]=  { state.matrix.program[0] };\
00485 PARAM  mCurM[4] =  { state.matrix.program[1] };\
00486 \
00487 TEMP   tXY;\
00488 TEMP   tLDirFlag;\
00489 TEMP   tLPosVec;\
00490 TEMP   tLFinalVec;\
00491 TEMP   tPrevPix;\
00492 TEMP   tCurPix;\
00493 TEMP   tDetail;\
00494 TEMP   tNorm;\
00495 \
00496 DP4 tXY.x, mMVP[0], iPos;\
00497 DP4 tXY.y, mMVP[1], iPos;\
00498 DP4 tXY.z, mMVP[2], iPos;\
00499 DP4 tXY.w, mMVP[3], iPos;\
00500 ""\
00501 SGE tLDirFlag,cZero,cLPosFlag;\
00502 \
00503 SUB tLPosVec,  cLPos,   iPos;\
00504 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00505 RSQ tLPosVec.w,tLPosVec.w;\
00506 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00507 \
00508 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00509 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00510 \
00511 DP4 tPrevPix.x, mPrevM[0], iPos;\
00512 DP4 tPrevPix.y, mPrevM[1], iPos;\
00513 DP4 tPrevPix.z, mPrevM[2], iPos;\
00514 DP4 tPrevPix.w, mPrevM[3], iPos;\
00515 RCP tPrevPix.w, tPrevPix.w;\
00516 MUL tPrevPix, tPrevPix, tPrevPix.w;\
00517 DP4 tCurPix.x, mCurM[0], iPos;\
00518 DP4 tCurPix.y, mCurM[1], iPos;\
00519 DP4 tCurPix.z, mCurM[2], iPos;\
00520 DP4 tCurPix.w, mCurM[3], iPos;\
00521 RCP tCurPix.w, tCurPix.w;\
00522 MUL tCurPix, tCurPix, tCurPix.w;\
00523 SUB tDetail, tCurPix, tPrevPix;\
00524 DP3 tDetail.x, tDetail, tDetail;\
00525 POW tDetail, tDetail.x, 0.5;\
00526 SUB tNorm, cMaxFactor.x, cOne;\
00527 MUL tNorm, tNorm, cTargetLen.x;\
00528 RCP tNorm, tNorm.x;\
00529 SUB tDetail, tDetail, cTargetLen.x;\
00530 MUL tDetail, tDetail, tNorm;\
00531 MIN tDetail, tDetail, cOne;\
00532 MAX tDetail, cZero, tDetail;\
00533 \
00534 SUB tNorm,iSmoothedNorm,iNorm;\
00535 MUL tNorm,tNorm,cSmooth.x;\
00536 ADD tNorm,tNorm,iNorm;\
00537 DP3 tNorm.w,tNorm,tNorm;\
00538 RSQ tNorm.w,tNorm.w;\
00539 MUL tNorm,tNorm,tNorm.w;\
00540 \
00541 DP4 oTex0.x, mTex0[0], tLFinalVec;\
00542 DP4 oTex0.y, mTex0[1], tLFinalVec;\
00543 DP4 oTex0.z, mTex0[2], tLFinalVec;\
00544 DP4 oTex0.w, mTex0[3], tLFinalVec;\
00545 \
00546 DP4 oTex1.x, mTex1[0], tNorm;\
00547 DP4 oTex1.y, mTex1[1], tNorm;\
00548 DP4 oTex1.z, mTex1[2], tNorm;\
00549 DP4 oTex1.w, mTex1[3], tNorm;\
00550 \
00551 DP4 oTex2.x, mTex2[0], tDetail;\
00552 DP4 oTex2.y, mTex2[1], tDetail;\
00553 DP4 oTex2.z, mTex2[2], tDetail;\
00554 DP4 oTex2.w, mTex2[3], tDetail;\
00555 \
00556 MOV oPos, tXY;\
00557 MOV oCol, iCol;\
00558 \
00559 END"
00560 };
00561 
00562 
00563 
00564 
00565 const unsigned char NPRToonShaderCurvatureARB[]=
00566                         //env[20] xy(1,1) in ndc
00567                         //env[21] light pos
00568                         //env[22] light dir
00569                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00570                         //env[24] target length
00571                         //env[25] max factor
00572                         //env[26] smooth factor
00573 {
00574 "!!ARBvp1.0\n\
00575 \
00576 ATTRIB iPos          = vertex.position;\
00577 ATTRIB iNorm         = vertex.normal;\
00578 ATTRIB iCol          = vertex.color;\
00579 ATTRIB iSmoothedNorm = vertex.attrib[1];\
00580 ATTRIB iCurv         = vertex.attrib[5];\
00581 \
00582 OUTPUT oPos  = result.position;\
00583 OUTPUT oCol  = result.color;\
00584 OUTPUT oTex0 = result.texcoord[0];\
00585 OUTPUT oTex1 = result.texcoord[1];\
00586 OUTPUT oTex2 = result.texcoord[2];\
00587 \
00588 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00589 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00590 PARAM  cLPos      = program.env[21];\
00591 PARAM  cLDir      = program.env[22];\
00592 PARAM  cLPosFlag  = program.env[23];\
00593 PARAM  cTargetLen = program.env[24];\
00594 PARAM  cMaxFactor = program.env[25];\
00595 PARAM  cSmooth    = program.env[26];\
00596 \
00597 PARAM  mMVP[4]  =  { state.matrix.mvp };\
00598 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00599 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00600 PARAM  mTex2[4] =  { state.matrix.texture[2] };\
00601 \
00602 TEMP   tXY;\
00603 TEMP   tLDirFlag;\
00604 TEMP   tLPosVec;\
00605 TEMP   tLFinalVec;\
00606 TEMP   tDetail;\
00607 TEMP   tNorm;\
00608 \
00609 DP4 tXY.x, mMVP[0], iPos;\
00610 DP4 tXY.y, mMVP[1], iPos;\
00611 DP4 tXY.z, mMVP[2], iPos;\
00612 DP4 tXY.w, mMVP[3], iPos;\
00613 ""\
00614 SGE tLDirFlag,cZero,cLPosFlag;\
00615 \
00616 SUB tLPosVec,  cLPos,   iPos;\
00617 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00618 RSQ tLPosVec.w,tLPosVec.w;\
00619 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00620 \
00621 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00622 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00623 ""\
00624 RCP tDetail, cTargetLen.x;\
00625 MUL tDetail, iCurv.z, tDetail;\
00626 SUB tDetail, cOne, tDetail;\
00627 MAX tDetail, tDetail, cZero;\
00628 MIN tDetail, tDetail, cOne;\
00629 \
00630 SUB tNorm,iSmoothedNorm,iNorm;\
00631 MUL tNorm,tNorm,cSmooth.x;\
00632 ADD tNorm,tNorm,iNorm;\
00633 DP3 tNorm.w,tNorm,tNorm;\
00634 RSQ tNorm.w,tNorm.w;\
00635 MUL tNorm,tNorm,tNorm.w;\
00636 \
00637 DP4 oTex0.x, mTex0[0], tLFinalVec;\
00638 DP4 oTex0.y, mTex0[1], tLFinalVec;\
00639 DP4 oTex0.z, mTex0[2], tLFinalVec;\
00640 DP4 oTex0.w, mTex0[3], tLFinalVec;\
00641 \
00642 DP4 oTex1.x, mTex1[0], tNorm;\
00643 DP4 oTex1.y, mTex1[1], tNorm;\
00644 DP4 oTex1.z, mTex1[2], tNorm;\
00645 DP4 oTex1.w, mTex1[3], tNorm;\
00646 \
00647 DP4 oTex2.x, mTex2[0], tDetail;\
00648 DP4 oTex2.y, mTex2[1], tDetail;\
00649 DP4 oTex2.z, mTex2[2], tDetail;\
00650 DP4 oTex2.w, mTex2[3], tDetail;\
00651 \
00652 MOV oPos, tXY;\
00653 MOV oCol, iCol;\
00654 \
00655 END"
00656 };
00657 
00658 
00659 
00660 
00661 
00662 const unsigned char NPRToonShaderOrientationARB[]=
00663                         //env[20] xy(1,1) in ndc
00664                         //env[21] light pos
00665                         //env[22] light dir
00666                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00667                         //env[24] target length
00668                         //env[25] max factor
00669                         //env[26] smooth factor
00670 {
00671 "!!ARBvp1.0\n\
00672 \
00673 ATTRIB iPos          = vertex.position;\
00674 ATTRIB iNorm         = vertex.normal;\
00675 ATTRIB iCol          = vertex.color;\
00676 ATTRIB iSmoothedNorm = vertex.attrib[1];\
00677 \
00678 OUTPUT oPos  = result.position;\
00679 OUTPUT oCol  = result.color;\
00680 OUTPUT oTex0 = result.texcoord[0];\
00681 OUTPUT oTex1 = result.texcoord[1];\
00682 OUTPUT oTex2 = result.texcoord[2];\
00683 \
00684 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00685 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00686 PARAM  cLPos      = program.env[21];\
00687 PARAM  cLDir      = program.env[22];\
00688 PARAM  cLPosFlag  = program.env[23];\
00689 PARAM  cTargetLen = program.env[24];\
00690 PARAM  cMaxFactor = program.env[25];\
00691 PARAM  cSmooth    = program.env[26];\
00692 \
00693 PARAM  mMVP[4]  =  { state.matrix.mvp };\
00694 PARAM  mMVIT[4] =  { state.matrix.modelview.invtrans };\
00695 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00696 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00697 PARAM  mTex2[4] =  { state.matrix.texture[2] };\
00698 \
00699 TEMP   tXY;\
00700 TEMP   tLDirFlag;\
00701 TEMP   tLPosVec;\
00702 TEMP   tLFinalVec;\
00703 TEMP   tView;\
00704 TEMP   tNorm;\
00705 \
00706 DP4 tXY.x, mMVP[0], iPos;\
00707 DP4 tXY.y, mMVP[1], iPos;\
00708 DP4 tXY.z, mMVP[2], iPos;\
00709 DP4 tXY.w, mMVP[3], iPos;\
00710 ""\
00711 SGE tLDirFlag,cZero,cLPosFlag;\
00712 \
00713 SUB tLPosVec,  cLPos,   iPos;\
00714 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00715 RSQ tLPosVec.w,tLPosVec.w;\
00716 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00717 \
00718 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00719 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00720 \
00721 SUB tView, mMVIT[3], iPos;\
00722 DP3 tView.w, tView, tView;\
00723 RSQ tView.w, tView.w;\
00724 MUL tView, tView, tView.w;\
00725 \
00726 SUB tNorm,iSmoothedNorm,iNorm;\
00727 MUL tNorm,tNorm,cSmooth.x;\
00728 ADD tNorm,tNorm,iNorm;\
00729 DP3 tNorm.w,tNorm,tNorm;\
00730 RSQ tNorm.w,tNorm.w;\
00731 MUL tNorm,tNorm,tNorm.w;\
00732 \
00733 DP4 oTex0.x, mTex0[0], tLFinalVec;\
00734 DP4 oTex0.y, mTex0[1], tLFinalVec;\
00735 DP4 oTex0.z, mTex0[2], tLFinalVec;\
00736 DP4 oTex0.w, mTex0[3], tLFinalVec;\
00737 \
00738 DP4 oTex1.x, mTex1[0], tNorm;\
00739 DP4 oTex1.y, mTex1[1], tNorm;\
00740 DP4 oTex1.z, mTex1[2], tNorm;\
00741 DP4 oTex1.w, mTex1[3], tNorm;\
00742 \
00743 DP4 oTex2.x, mTex2[0], tView;\
00744 DP4 oTex2.y, mTex2[1], tView;\
00745 DP4 oTex2.z, mTex2[2], tView;\
00746 DP4 oTex2.w, mTex2[3], tView;\
00747 \
00748 MOV oPos, tXY;\
00749 MOV oCol, iCol;\
00750 \
00751 END"
00752 };
00753 
00754 
00755 const unsigned char NPRToonShaderSpecularityARB[]=
00756                         //env[20] xy(1,1) in ndc
00757                         //env[21] light pos
00758                         //env[22] light dir
00759                         //env[23] pos->1,1,1,1 dir->0,0,0,0
00760                         //env[24] target length
00761                         //env[25] max factor
00762                         //env[26] smooth factor
00763 {
00764 "!!ARBvp1.0\n\
00765 \
00766 ATTRIB iPos          = vertex.position;\
00767 ATTRIB iNorm         = vertex.normal;\
00768 ATTRIB iCol          = vertex.color;\
00769 ATTRIB iSmoothedNorm = vertex.attrib[1];\
00770 \
00771 OUTPUT oPos  = result.position;\
00772 OUTPUT oCol  = result.color;\
00773 OUTPUT oTex0 = result.texcoord[0];\
00774 OUTPUT oTex1 = result.texcoord[1];\
00775 OUTPUT oTex2 = result.texcoord[2];\
00776 \
00777 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00778 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00779 PARAM  cLPos      = program.env[21];\
00780 PARAM  cLDir      = program.env[22];\
00781 PARAM  cLPosFlag  = program.env[23];\
00782 PARAM  cTargetLen = program.env[24];\
00783 PARAM  cMaxFactor = program.env[25];\
00784 PARAM  cSmooth    = program.env[26];\
00785 \
00786 PARAM  mMVP[4]  =  { state.matrix.mvp };\
00787 PARAM  mMVIT[4] =  { state.matrix.modelview.invtrans };\
00788 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00789 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00790 PARAM  mTex2[4] =  { state.matrix.texture[2] };\
00791 \
00792 TEMP   tXY;\
00793 TEMP   tLDirFlag;\
00794 TEMP   tLPosVec;\
00795 TEMP   tLFinalVec;\
00796 TEMP   tView;\
00797 TEMP   tNorm;\
00798 \
00799 DP4 tXY.x, mMVP[0], iPos;\
00800 DP4 tXY.y, mMVP[1], iPos;\
00801 DP4 tXY.z, mMVP[2], iPos;\
00802 DP4 tXY.w, mMVP[3], iPos;\
00803 ""\
00804 SGE tLDirFlag,cZero,cLPosFlag;\
00805 \
00806 SUB tLPosVec,  cLPos,   iPos;\
00807 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00808 RSQ tLPosVec.w,tLPosVec.w;\
00809 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00810 \
00811 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00812 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00813 \
00814 SUB tView, mMVIT[3], iPos;\
00815 DP3 tView.w, tView, tView;\
00816 RSQ tView.w, tView.w;\
00817 MUL tView, tView, tView.w;\
00818 \
00819 SUB tNorm,iSmoothedNorm,iNorm;\
00820 MUL tNorm,tNorm,cSmooth.x;\
00821 ADD tNorm,tNorm,iNorm;\
00822 DP3 tNorm.w,tNorm,tNorm;\
00823 RSQ tNorm.w,tNorm.w;\
00824 MUL tNorm,tNorm,tNorm.w;\
00825 \
00826 DP4 oTex0.x, mTex0[0], tLFinalVec;\
00827 DP4 oTex0.y, mTex0[1], tLFinalVec;\
00828 DP4 oTex0.z, mTex0[2], tLFinalVec;\
00829 DP4 oTex0.w, mTex0[3], tLFinalVec;\
00830 \
00831 DP4 oTex1.x, mTex1[0], tNorm;\
00832 DP4 oTex1.y, mTex1[1], tNorm;\
00833 DP4 oTex1.z, mTex1[2], tNorm;\
00834 DP4 oTex1.w, mTex1[3], tNorm;\
00835 \
00836 DP4 oTex2.x, mTex2[0], tView;\
00837 DP4 oTex2.y, mTex2[1], tView;\
00838 DP4 oTex2.z, mTex2[2], tView;\
00839 DP4 oTex2.w, mTex2[3], tView;\
00840 \
00841 MOV oPos, tXY;\
00842 MOV oCol, iCol;\
00843 \
00844 END"
00845 };
00846 
00847 
00848 
00849 const unsigned char NPRToonShaderLookupARB[]=
00850                         //env[20] inverse detail
00851 {
00852 "!!ARBfp1.0\n\
00853 \
00854 ATTRIB iLight     = fragment.texcoord[0];\
00855 ATTRIB iNormal    = fragment.texcoord[1];\
00856 ATTRIB iDetail    = fragment.texcoord[2];\
00857 \
00858 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00859 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00860 PARAM  cInvDetail = program.env[20];\
00861 \
00862 OUTPUT oCol  = result.color;\
00863 \
00864 TEMP tLight;\
00865 TEMP tNormal;\
00866 TEMP tDetail;\
00867 TEMP toonCoords;\
00868 \
00869 MOV tLight, iLight;\
00870 DP3 tLight.w, tLight, tLight;\
00871 RCP tLight.w, tLight.w;\
00872 MUL tLight, tLight, tLight.w;\
00873 \
00874 MOV tNormal, iNormal;\
00875 DP3 tNormal.w, tNormal, tNormal;\
00876 RCP tNormal.w, tNormal.w;\
00877 MUL tNormal, tNormal, tNormal.w;\
00878 \
00879 SUB tDetail, iDetail.x, cInvDetail.x;\
00880 MAX tDetail, tDetail, -tDetail;\
00881 \
00882 DP3 toonCoords.x, tLight, tNormal;\
00883 MAX toonCoords.x, toonCoords.x, cZero;\
00884 MOV toonCoords.y, tDetail.x;\
00885 MOV toonCoords.z, cZero;\
00886 MOV toonCoords.w, cOne;\
00887 \
00888 TEX oCol, toonCoords, texture[0], 2D;\
00889 \
00890 END"
00891 };
00892 
00893 
00894 const unsigned char NPRToonShaderOrientationLookupARB[]=
00895                         //env[20] inverse detail
00896                         //env[21] target length
00897 {
00898 "!!ARBfp1.0\n\
00899 \
00900 ATTRIB iLight  = fragment.texcoord[0];\
00901 ATTRIB iNormal = fragment.texcoord[1];\
00902 ATTRIB iView   = fragment.texcoord[2];\
00903 \
00904 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00905 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00906 PARAM  cInvDetail = program.env[20];\
00907 PARAM  cTargetLen = program.env[21];\
00908 \
00909 OUTPUT oCol  = result.color;\
00910 \
00911 TEMP tLight;\
00912 TEMP tNormal;\
00913 TEMP tView;\
00914 TEMP tDetail;\
00915 TEMP toonCoords;\
00916 \
00917 MOV tLight, iLight;\
00918 DP3 tLight.w, tLight, tLight;\
00919 RSQ tLight.w, tLight.w;\
00920 MUL tLight, tLight, tLight.w;\
00921 \
00922 MOV tNormal, iNormal;\
00923 DP3 tNormal.w, tNormal, tNormal;\
00924 RSQ tNormal.w, tNormal.w;\
00925 MUL tNormal, tNormal, tNormal.w;\
00926 \
00927 MOV tView, iView;\
00928 DP3 tView.w, tView, tView;\
00929 RSQ tView.w, tView.w;\
00930 MUL tView, tView, tView.w;\
00931 \
00932 DP3 tDetail, tView, tNormal;\
00933 POW tDetail, tDetail.x, cTargetLen.x;\
00934 SUB tDetail, cOne, tDetail;\
00935 MAX tDetail, tDetail, cZero;\
00936 MIN tDetail, tDetail, cOne;\
00937 SUB tDetail, tDetail.x, cInvDetail.x;\
00938 MAX tDetail, tDetail, -tDetail;\
00939 \
00940 DP3 toonCoords.x, tLight, tNormal;\
00941 MAX toonCoords.x, toonCoords.x, cZero;\
00942 MOV toonCoords.y, tDetail.x;\
00943 MOV toonCoords.z, cZero;\
00944 MOV toonCoords.w, cOne;\
00945 \
00946 TEX oCol, toonCoords, texture[0], 2D;\
00947 \
00948 END"
00949 };
00950 
00951 
00952 const unsigned char NPRToonShaderSpecularityLookupARB[]=
00953                         //env[20] inverse detail
00954                         //env[21] target length
00955 {
00956 "!!ARBfp1.0\n\
00957 \
00958 ATTRIB iLight  = fragment.texcoord[0];\
00959 ATTRIB iNormal = fragment.texcoord[1];\
00960 ATTRIB iView   = fragment.texcoord[2];\
00961 \
00962 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00963 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00964 PARAM  cHalf      = {0.5,0.5,0.5,0.5};\
00965 PARAM  cInvDetail = program.env[20];\
00966 PARAM  cTargetLen = program.env[21];\
00967 \
00968 OUTPUT oCol  = result.color;\
00969 \
00970 TEMP tLight;\
00971 TEMP tNormal;\
00972 TEMP tView;\
00973 TEMP tHalf;\
00974 TEMP tDetail;\
00975 TEMP toonCoords;\
00976 \
00977 MOV tLight, iLight;\
00978 DP3 tLight.w, tLight, tLight;\
00979 RSQ tLight.w, tLight.w;\
00980 MUL tLight, tLight, tLight.w;\
00981 \
00982 MOV tNormal, iNormal;\
00983 DP3 tNormal.w, tNormal, tNormal;\
00984 RSQ tNormal.w, tNormal.w;\
00985 MUL tNormal, tNormal, tNormal.w;\
00986 \
00987 MOV tView, iView;\
00988 DP3 tView.w, tView, tView;\
00989 RSQ tView.w, tView.w;\
00990 MUL tView, tView, tView.w;\
00991 \
00992 ADD tHalf, tView, tLight;\
00993 DP3 tHalf.w, tHalf, tHalf;\
00994 RSQ tHalf.w, tHalf.w;\
00995 MUL tHalf, tHalf, tHalf.w;\
00996 \
00997 MOV tDetail, cZero;\
00998 DP3 tDetail.x, tHalf, tNormal;\
00999 MAX tDetail, tDetail, cZero;\
01000 POW tDetail, tDetail.x, cTargetLen.x;\
01001 SUB tDetail, cOne, tDetail.x;\
01002 MAX tDetail, tDetail, cZero;\
01003 MIN tDetail, tDetail, cOne;\
01004 SUB tDetail, tDetail.x, cInvDetail.x;\
01005 MAX tDetail, tDetail, -tDetail;\
01006 \
01007 DP3 toonCoords.x, tLight, tNormal;\
01008 MAX toonCoords.x, toonCoords.x, cZero;\
01009 MOV toonCoords.y, tDetail.x;\
01010 MOV toonCoords.z, cZero;\
01011 MOV toonCoords.w, cOne;\
01012 \
01013 TEX oCol, toonCoords, texture[0], 2D;\
01014 \
01015 END"
01016 };
01017 
01018 
01019 
01020 
01021 /////////////////////////////////////
01022 // init_vertex_program_nv()
01023 /////////////////////////////////////
01024 
01025 bool ntt_init_vertex_program_nv()
01026 {
01027 #ifdef NON_NVIDIA_GFX
01028   return false;
01029 #else
01030   if (GLExtensions::gl_nv_vertex_program_supported())
01031     {
01032       err_mesg(ERR_LEV_INFO, "XToonTexture::init() - Can use NV vertex programs!");
01033 #ifdef GL_NV_vertex_program
01034       glGenProgramsNV(1, &ntt_toon_prog_nv); 
01035       glBindProgramNV(GL_VERTEX_PROGRAM_NV, ntt_toon_prog_nv); 
01036       glLoadProgramNV(GL_VERTEX_PROGRAM_NV, ntt_toon_prog_nv, strlen((char * ) NPRToonShaderNV), NPRToonShaderNV);
01037 #endif
01038       return true;
01039     }
01040   else
01041     {
01042       return false;
01043     }
01044 #endif
01045 }
01046 
01047 /////////////////////////////////////
01048 // init_vertex_program_arb()
01049 /////////////////////////////////////
01050 
01051 bool ntt_init_vertex_program_arb()
01052 {
01053    assert(!ntt_is_init_vertex_program);
01054 
01055    if (GLExtensions::gl_arb_vertex_program_supported()) {
01056      bool success = false, native = false;
01057      err_mesg(ERR_LEV_INFO, "XToonTexture::init() - Can use ARB vertex programs!");
01058 #ifdef GL_ARB_vertex_program
01059      glGenProgramsARB(1, &ntt_toon_prog_detail_arb); 
01060      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_detail_arb); 
01061      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01062          strlen((char * ) NPRToonShaderDetailARB), NPRToonShaderDetailARB);
01063      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderDetailARB);
01064      
01065      glGenProgramsARB(1, &ntt_toon_prog_depth_arb); 
01066      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_depth_arb); 
01067      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01068          strlen((char * ) NPRToonShaderDepthARB), NPRToonShaderDepthARB);
01069      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderDepthARB);
01070      
01071      glGenProgramsARB(1, &ntt_toon_prog_focus_arb); 
01072      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_focus_arb); 
01073      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01074          strlen((char * ) NPRToonShaderFocusARB), NPRToonShaderFocusARB);
01075      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderFocusARB);
01076      
01077      glGenProgramsARB(1, &ntt_toon_prog_flow_arb); 
01078      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_flow_arb); 
01079      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01080          strlen((char * ) NPRToonShaderFlowARB), NPRToonShaderFlowARB);
01081      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderFlowARB);
01082      
01083      glGenProgramsARB(1, &ntt_toon_prog_curvature_arb); 
01084      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_curvature_arb); 
01085      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01086          strlen((char * ) NPRToonShaderCurvatureARB), NPRToonShaderCurvatureARB);
01087      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderCurvatureARB);
01088      
01089      glGenProgramsARB(1, &ntt_toon_prog_orientation_arb); 
01090      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_orientation_arb); 
01091      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01092          strlen((char * ) NPRToonShaderOrientationARB), NPRToonShaderOrientationARB);
01093      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderOrientationARB);
01094      
01095      glGenProgramsARB(1, &ntt_toon_prog_specularity_arb); 
01096      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_specularity_arb); 
01097      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01098          strlen((char * ) NPRToonShaderSpecularityARB), NPRToonShaderSpecularityARB);
01099      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderSpecularityARB);
01100 
01101      
01102 #endif
01103    } else{
01104      return false;
01105    }
01106 
01107 
01108    if (GLExtensions::gl_arb_fragment_program_supported()) {
01109      bool success = false, native = false;
01110      err_mesg(ERR_LEV_INFO, "XToonTexture::init() - Can use ARB vertex programs!");
01111 #ifdef GL_ARB_fragment_program     
01112 
01113      glGenProgramsARB(1, &ntt_toon_prog_lookup_arb); 
01114      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ntt_toon_prog_lookup_arb); 
01115      glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01116          strlen((char * ) NPRToonShaderLookupARB), NPRToonShaderLookupARB);
01117      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderLookupARB);
01118 
01119      glGenProgramsARB(1, &ntt_toon_prog_orientation_lookup_arb); 
01120      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ntt_toon_prog_orientation_lookup_arb); 
01121      glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01122          strlen((char * ) NPRToonShaderOrientationLookupARB), NPRToonShaderOrientationLookupARB);
01123      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderOrientationLookupARB);
01124 
01125      glGenProgramsARB(1, &ntt_toon_prog_specularity_lookup_arb); 
01126      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ntt_toon_prog_specularity_lookup_arb); 
01127      glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
01128          strlen((char * ) NPRToonShaderSpecularityLookupARB), NPRToonShaderSpecularityLookupARB);
01129      success = GLExtensions::gl_arb_vertex_program_loaded("XToonTexture::init() - ", native, NPRToonShaderSpecularityLookupARB);
01130 
01131 #endif
01132      return success;
01133    } else{
01134      return false;
01135    }
01136 
01137 }
01138 
01139 /////////////////////////////////////
01140 // init_vertex_program()
01141 /////////////////////////////////////
01142 
01143 void ntt_init_vertex_program() {
01144    assert(!ntt_is_init_vertex_program);
01145 
01146    ntt_use_vertex_program_arb = ntt_init_vertex_program_arb();
01147    ntt_use_vertex_program_nv =  ntt_init_vertex_program_nv();
01148 
01149    if (ntt_use_vertex_program_nv || ntt_use_vertex_program_arb){
01150      err_mesg(ERR_LEV_INFO, "XToonTexture::init() - Will use vertex programs!");
01151      ntt_use_vertex_program = true;
01152    } else {
01153      err_mesg(ERR_LEV_INFO, "XToonTexture::init() - Won't be using vertex programs!");
01154      ntt_use_vertex_program = false;
01155    }
01156 
01157    ntt_is_init_vertex_program = true;
01158 }
01159 
01160 /////////////////////////////////////
01161 // setup_vertex_program_nv()
01162 /////////////////////////////////////
01163 void ntt_setup_vertex_program_nv()
01164 {
01165 #if defined(GL_NV_vertex_program) && !defined(NON_NVIDIA_GFX)
01166 
01167    NDCpt n(XYpt(1,1));
01168 
01169    glBindProgramNV(GL_VERTEX_PROGRAM_NV, ntt_toon_prog_nv); 
01170 
01171    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW, GL_IDENTITY_NV);
01172    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4, GL_PROJECTION, GL_IDENTITY_NV);
01173    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 12, GL_TEXTURE, GL_IDENTITY_NV);
01174    if (GLExtensions::gl_arb_multitexture_supported())
01175    {
01176 #ifdef GL_ARB_multitexture
01177       glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 16, GL_TEXTURE1_ARB, GL_IDENTITY_NV);
01178 #endif
01179    }
01180 
01181    glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 20, (float)n[0], (float)n[1], 1, 1);
01182 
01183    glProgramParameter4dNV(GL_VERTEX_PROGRAM_NV, 21,  
01184            ntt_light_pos[0], ntt_light_pos[1], ntt_light_pos[2], 1.0f);
01185    glProgramParameter4dNV(GL_VERTEX_PROGRAM_NV, 22,  
01186            ntt_light_dir[0], ntt_light_dir[1], ntt_light_dir[2], 0.0f);
01187    if (ntt_positional)
01188       glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 23, 1, 1, 1, 1);
01189    else
01190       glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 23, 0, 0, 0, 0);
01191 
01192    glEnable(GL_VERTEX_PROGRAM_NV);  //GL_ENABLE_BIT
01193 
01194 #endif
01195 }
01196 
01197 /////////////////////////////////////
01198 // done_vertex_program_nv()
01199 /////////////////////////////////////
01200 void ntt_done_vertex_program_nv()
01201 {
01202 #if defined(GL_NV_vertex_program) && !defined(NON_NVIDIA_GFX)
01203    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0,  GL_NONE, GL_IDENTITY_NV);
01204    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4,  GL_NONE, GL_IDENTITY_NV);
01205    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 12, GL_NONE, GL_IDENTITY_NV);
01206    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 16, GL_NONE, GL_IDENTITY_NV);
01207    glDisable(GL_VERTEX_PROGRAM_NV);  //GL_ENABLE_BIT
01208 #endif
01209 }
01210 
01211 
01212 /////////////////////////////////////
01213 // setup_vertex_program_arb()
01214 /////////////////////////////////////
01215 void ntt_setup_vertex_program_arb()
01216 {
01217   
01218 
01219 #ifdef GL_ARB_vertex_program
01220    NDCpt n(XYpt(1,1));
01221    
01222    // vertex program setup
01223    if (ntt_detail_map == XToonTexture::Depth){
01224      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_depth_arb); 
01225    } else if (ntt_detail_map == XToonTexture::Orientation){
01226      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_orientation_arb); 
01227    } else if (ntt_detail_map == XToonTexture::Focus){
01228      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_focus_arb); 
01229    } else if (ntt_detail_map == XToonTexture::Specularity){
01230      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_orientation_arb); 
01231    } else if (ntt_detail_map == XToonTexture::Flow){
01232      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_flow_arb); 
01233    } else if (ntt_detail_map == XToonTexture::Curvature){
01234      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_curvature_arb); 
01235    } else { // User or default
01236      glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_detail_arb); 
01237    }
01238 
01239    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 20, n[0], n[1], 1.0, 1.0);
01240    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 21, 
01241                ntt_light_pos[0], ntt_light_pos[1], ntt_light_pos[2], 1.0);
01242    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 22,  
01243                ntt_light_dir[0], ntt_light_dir[1], ntt_light_dir[2], 0.0);
01244 
01245    if (ntt_positional) {
01246       glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 23, 1.0, 1.0, 1.0, 1.0);
01247    } else {
01248       glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 23, 0.0, 0.0, 0.0, 0.0);
01249    }
01250 
01251    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 24, ntt_target_length, 1.0, 1.0, 1.0);
01252    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 25, ntt_max_factor, 1.0, 1.0, 1.0);
01253    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 26, ntt_smooth_factor, 1.0, 1.0, 1.0);
01254    glEnable(GL_VERTEX_PROGRAM_ARB);  //GL_ENABLE_BIT
01255 
01256    // pixel program setup
01257    if (ntt_detail_map == XToonTexture::Orientation){
01258      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ntt_toon_prog_orientation_lookup_arb); 
01259      glProgramEnvParameter4dARB(GL_FRAGMENT_PROGRAM_ARB, 21, ntt_target_length, 1.0, 1.0, 1.0);
01260    } else if (ntt_detail_map == XToonTexture::Specularity){
01261      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ntt_toon_prog_specularity_lookup_arb); 
01262      glProgramEnvParameter4dARB(GL_FRAGMENT_PROGRAM_ARB, 21, ntt_target_length, 1.0, 1.0, 1.0);
01263    } else {
01264      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ntt_toon_prog_lookup_arb); 
01265    }
01266 
01267    glProgramEnvParameter4dARB(GL_FRAGMENT_PROGRAM_ARB, 20, ntt_inv_detail, 1.0, 1.0, 1.0);
01268    glEnable(GL_FRAGMENT_PROGRAM_ARB);  //GL_ENABLE_BIT
01269   
01270 
01271 #endif
01272 }
01273 
01274 /////////////////////////////////////
01275 // done_vertex_program_arb()
01276 /////////////////////////////////////
01277 void ntt_done_vertex_program_arb()
01278 {
01279 #ifdef GL_ARB_vertex_program
01280    glDisable(GL_VERTEX_PROGRAM_ARB);  //GL_ENABLE_BIT
01281    glDisable(GL_FRAGMENT_PROGRAM_ARB);  //GL_ENABLE_BIT
01282 #endif
01283 }
01284 
01285 /////////////////////////////////////
01286 // setup_vertex_program()
01287 /////////////////////////////////////
01288 void ntt_setup_vertex_program()
01289 {
01290    assert(ntt_use_vertex_program);
01291 
01292    if (ntt_use_vertex_program_arb)
01293    {
01294       ntt_setup_vertex_program_arb();
01295    }
01296    else if (ntt_use_vertex_program_nv)
01297    {
01298       ntt_setup_vertex_program_nv();
01299    }
01300    else
01301    {
01302       assert(0);
01303    }
01304 }
01305 
01306 /////////////////////////////////////
01307 // done_vertex_program()
01308 /////////////////////////////////////
01309 void ntt_done_vertex_program()
01310 {
01311    assert(ntt_use_vertex_program);
01312 
01313    if (ntt_use_vertex_program_arb)
01314    {
01315       ntt_done_vertex_program_arb();
01316    }
01317    else if (ntt_use_vertex_program_nv)
01318    {
01319       ntt_done_vertex_program_nv();
01320    }
01321    else
01322    {
01323       assert(0);
01324    }
01325 
01326 }
01327 
01328 
01329 
01330 /**********************************************************************
01331  * ToonTexCB:
01332  **********************************************************************/
01333 void 
01334 ToonTexCB::faceCB(CBvert* v, CBface*f) {
01335   Wvec n;
01336   f->vert_normal(v,n);
01337   
01338   if (!ntt_use_vertex_program){ 
01339 
01340     // use software computations
01341     double detail;
01342     if (ntt_detail_map == XToonTexture::User){
01343       detail = ntt_target_length;
01344 
01345     } else if (ntt_detail_map == XToonTexture::Depth) {
01346       Wpt eye = VIEW::peek_cam()->data()->from();
01347       Wvec at_v = VIEW::peek_cam()->data()->at_v();
01348       double d = (v->wloc()-eye)*at_v;
01349       detail = log(d/ntt_target_length)/log(ntt_max_factor);     
01350 
01351     } else if (ntt_detail_map == XToonTexture::Focus) {
01352       Wpt eye = VIEW::peek_cam()->data()->from();
01353       Wpt focus = VIEW::peek_cam()->data()->center();
01354       double d_v = (v->wloc()-eye).length();
01355       double d_c = (focus-eye).length();
01356       if (d_v>d_c) { // Dsup
01357    double d_min = d_c + ntt_target_length;
01358    double d_max = d_c + ntt_max_factor*ntt_target_length;
01359       detail = log(d_v/d_min)/log(d_max/d_min);
01360       } else { // Dinf
01361    double d_min = d_c - ntt_target_length;
01362    double d_max = d_c - ntt_max_factor*ntt_target_length;
01363       detail = 1.0 - log(d_v/d_max)/log(d_min/d_max);
01364       }
01365 
01366     } else if (ntt_detail_map == XToonTexture::Flow){
01367       Wpt prev = ntt_prev_matrix*v->wloc();
01368       Wpt cur = ntt_cur_matrix*v->wloc();
01369       double d = sqrt( (prev[0]-cur[0])*(prev[0]-cur[0]) +
01370             (prev[1]-cur[1])*(prev[1]-cur[1]) );
01371       detail = (d-ntt_target_length)/((ntt_max_factor-1)*ntt_target_length);
01372 
01373     } else if (ntt_detail_map == XToonTexture::Orientation){      
01374       Wpt eye = VIEW::peek_cam()->data()->from();
01375       Wvec view_vec = eye-v->wloc();
01376       double n_v = n * view_vec.normalized();
01377       detail = 1 - n_v*n_v / ntt_target_length;
01378 
01379     } else if (ntt_detail_map == XToonTexture::Specularity){
01380       Wpt eye = VIEW::peek_cam()->data()->from();
01381       Wvec view_vec = (eye-v->wloc()).normalized();
01382       Wvec light_vec = (ntt_positional) ? (ntt_light_pos - v->wloc()).normalized() : ntt_light_dir;
01383       Wvec half_vec = (view_vec+light_vec)*0.5;
01384       double n_h = n * half_vec;
01385       if (n_h<0.0){
01386    n_h = 0.0;
01387       }
01388       detail = 1 - pow(n_h, ntt_target_length);
01389      
01390 
01391     } else if (ntt_detail_map == XToonTexture::Curvature && ntt_curv_enabled){
01392       double G = v->k1()*v->k2();
01393       detail = 1.0-abs(G)/ntt_target_length; 
01394 
01395     } else {
01396       detail = 0.0;
01397     }
01398 
01399 
01400     // clamping
01401     if (detail < 0.0){
01402       detail = 0.0;
01403     } else if (detail > 1.0){
01404       detail = 1.0;
01405     }
01406     
01407     // inverting
01408     if (ntt_inv_detail){
01409       detail = 1.0-detail;
01410     }
01411 
01412     // compute texture coordinates
01413     if (ntt_positional) {
01414       glTexCoord2d(n * (ntt_light_pos - v->loc()).normalized(), detail);
01415     } else {
01416       glTexCoord2d(n * ntt_light_dir, detail);
01417     }
01418       
01419     // apply paper effect
01420     if (ntt_paper_flag){
01421       PaperEffect::paper_coord(NDCZpt(v->wloc()).data());
01422     }
01423     
01424     glVertex3dv(v->loc().data());
01425 
01426   } else {  // use graphics hardware
01427 
01428      Wvec sn;
01429      if (ntt_smooth_enabled) {
01430        sn = v->get_all_faces().n_ring_faces(ntt_smooth_rings).avg_normal();
01431      } else if (ntt_elliptic_enabled){
01432        BMESH* mesh = v->mesh();
01433        Wvec c_to_v = v->wloc() - mesh->get_bb().center();
01434        Wvec dim = mesh->get_bb().dim();
01435        double a = dim[0]*0.5;
01436        double b = dim[1]*0.5;
01437        double c = dim[2]*0.5;
01438        sn = Wvec(c_to_v[0]/a, c_to_v[1]/b, c_to_v[2]/c).normalized();
01439      } else if (ntt_spheric_enabled){
01440        BMESH* mesh = v->mesh();
01441        Wpt c = mesh->get_bb().center();
01442        sn = (v->wloc()-c).normalized();
01443      } else if (ntt_cylindric_enabled){
01444        BMESH* mesh = v->mesh();
01445        Wpt c = mesh->get_bb().center();
01446        Wvec axis;
01447        Wvec dim = mesh->get_bb().dim();
01448        if (dim[0]>dim[1] && dim[0]>dim[2]){
01449     axis = dim.X();
01450        } else if (dim[1]>dim[0] && dim[1]>dim[2]){
01451     axis = dim.Y();   
01452        } else {
01453     axis = dim.Z();   
01454        }
01455        Wpt v_proj = c + ((v->wloc()-c)*axis) * axis;
01456        sn = (v->wloc()-v_proj).normalized();
01457      } else {
01458        sn = n;
01459      }
01460      
01461      // get curvature info
01462      double k1, k2, G, M;
01463      if (ntt_curv_enabled){
01464        k1 = v->k1();
01465        k2 = v->k2();
01466        G = k1*k2;
01467        M = 0.5*(k1+k2);
01468      } else {
01469        G = M = k1 = k2 = DBL_MAX;
01470      }
01471      
01472      glNormal3dv(n.data());
01473      glVertexAttrib4dARB(1, sn[0], sn[1], sn[2], 1.0);
01474      glVertexAttrib4dARB(5, abs(k1), abs(k2), abs(G), abs(M));
01475      glVertex3dv(v->loc().data());
01476    }
01477 
01478 }
01479 
01480 /**********************************************************************
01481  * XToonTexture:
01482  **********************************************************************/
01483 
01484 /////////////////////////////////////
01485 // Static Variable Initialization
01486 /////////////////////////////////////
01487 TAGlist *       XToonTexture::_ntt_tags = 0;
01488 
01489 /////////////////////////////////////
01490 // update_lights()
01491 /////////////////////////////////////
01492 void
01493 XToonTexture::update_lights(CVIEWptr& v) 
01494 {
01495    if (_light_index == -1)
01496    {
01497       ntt_positional = !_light_dir;
01498       if (ntt_positional)
01499       {
01500          Wpt pos(_light_coords[0],_light_coords[1],_light_coords[2]);
01501          if (_light_cam)
01502             ntt_light_pos = v->cam()->xform().inverse() * pos;
01503          else
01504             ntt_light_pos = pos;
01505          ntt_light_pos = _patch->inv_xform() * ntt_light_pos;
01506       }
01507       else
01508       {
01509          if (_light_cam)
01510             ntt_light_dir = v->cam()->xform().inverse() * _light_coords;
01511          else
01512             ntt_light_dir = _light_coords;
01513          ntt_light_dir = (_patch->inv_xform() * ntt_light_dir).normalized();
01514       }
01515    }
01516    else
01517    {
01518       ntt_positional = v->light_get_positional(_light_index);
01519       if (ntt_positional)
01520       {
01521          if (v->light_get_in_cam_space(_light_index))
01522             ntt_light_pos = v->cam()->xform().inverse() * 
01523                                     v->light_get_coordinates_p(_light_index);
01524          else
01525             ntt_light_pos = v->light_get_coordinates_p(_light_index);
01526          ntt_light_pos = _patch->inv_xform() * ntt_light_pos;
01527       }
01528       else
01529       {
01530          if (v->light_get_in_cam_space(_light_index))
01531             ntt_light_dir = v->cam()->xform().inverse() * 
01532                                  v->light_get_coordinates_v(_light_index);
01533          else
01534             ntt_light_dir = v->light_get_coordinates_v(_light_index);
01535          ntt_light_dir = (_patch->inv_xform() * ntt_light_dir).normalized();
01536       }
01537    }
01538 }
01539 
01540 /////////////////////////////////////
01541 // draw()
01542 /////////////////////////////////////
01543 int
01544 XToonTexture::draw(CVIEWptr& v) 
01545 {
01546   stop_watch chrono;
01547   // computeC
01548 
01549    GL_VIEW::print_gl_errors("XToonTexture::draw - Begin");
01550 
01551    int dl;
01552    
01553    if (_ctrl)
01554       return _ctrl->draw(v);
01555 
01556    ntt_paper_flag = (_use_paper==1)?(true):(false);
01557 
01558    if (!ntt_is_init_vertex_program) { 
01559      ntt_cur_matrix = VIEW::peek()->wpt_to_pix_proj();
01560      ntt_init_vertex_program();
01561    }
01562 
01563    if (ntt_paper_flag)
01564    {
01565       // The enclosing NPRTexture will have already
01566       // rendered the mesh in 'background' mode.
01567       // We should enable blending and draw with
01568       // z <= mode...
01569    }
01570 
01571    update_tex();
01572    update_lights(v);
01573    update_cam();
01574 
01575    glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | 
01576                 GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01577 
01578    GL_COL(_color, _alpha*alpha());                       //GL_CURRENT_BIT
01579    glDisable(GL_LIGHTING);                               //GL_ENABLE_BIT
01580 
01581    if (_tex) {
01582       _tex->apply_texture();                             //GL_TEXTURE_BIT
01583    }
01584 
01585    //if ((_ntt_paper_flag) || (_alpha<1.0))
01586    //XXX - Just always blend, there may be alpha
01587    //in the texture...
01588    static bool OPAQUE_COMPOSITE = Config::get_var_bool("OPAQUE_COMPOSITE",false,true);
01589 
01590    if ((v->get_render_mode() == VIEW::TRANSPARENT_MODE) && (OPAQUE_COMPOSITE)) {
01591       glDisable(GL_BLEND);
01592       glBlendFunc(GL_ONE, GL_ZERO);
01593    } else {
01594       glEnable(GL_BLEND);                               //GL_ENABLE_BIT
01595 //       if (PaperEffect::is_alpha_premult()) {
01596 //    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);   //GL_COLOR_BUFFER_BIT
01597 //       } else {
01598    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //GL_COLOR_BUFFER_BIT
01599 //       }
01600    }
01601 
01602    //Don't write depth if not using the background texture
01603    if (!_transparent)
01604    {
01605       glDepthMask(GL_FALSE);                             //GL_DEPTH_BUFFER_BIT
01606    }
01607 
01608    NDCZpt origin(0,0,0);
01609    if (ntt_paper_flag && _travel_paper)
01610    {
01611       Wpt_list wbox;
01612       NDCZpt_list nbox;
01613       
01614 
01615       (_patch->xform() * _patch->mesh()->get_bb()).points(wbox);
01616       while (wbox.num() > 0) nbox += wbox.pop();
01617       
01618       static bool SCREEN_BOX = Config::get_var_bool("SCREEN_BOX",false,true);
01619 
01620       if (SCREEN_BOX)
01621       {
01622          double minx = nbox[0][0];
01623          double maxx = nbox[0][0];
01624          double miny = nbox[0][1];
01625          double maxy = nbox[0][1];
01626          for (int i=1; i<nbox.num(); i++)
01627          {
01628             if (nbox[i][0] < minx) minx = nbox[i][0];
01629             if (nbox[i][0] > maxx) maxx = nbox[i][0];
01630             if (nbox[i][1] < miny) miny = nbox[i][1];
01631             if (nbox[i][1] > maxy) maxy = nbox[i][1];
01632             origin[0] = (minx + maxx)/2.0;
01633             origin[1] = (miny + maxy)/2.0;
01634          }
01635       }
01636       else
01637       {
01638          origin = nbox.average();
01639       }
01640    }
01641 //    PaperEffect::begin_paper_effect(ntt_paper_flag, origin[0], origin[1]);
01642 
01643    if (ntt_use_vertex_program) 
01644    {
01645       
01646 
01647       // Try it with the display list
01648       if (BasicTexture::dl_valid(v) && 
01649      !(_update_smoothing || _update_elliptic ||
01650        _update_spheric ||  _update_cylindric ||
01651        _update_curvatures)) {
01652    ntt_setup_vertex_program();       // GL_ENABLE_BIT, ???
01653    BasicTexture::draw(v);
01654    ntt_done_vertex_program();
01655    
01656    //          PaperEffect::end_paper_effect(ntt_paper_flag);
01657    
01658    glPopAttrib();
01659    
01660    _frame_rate += chrono.elapsed_time();
01661    _nb_stat_frames ++;
01662    return _patch->num_faces();
01663       }
01664       
01665 
01666       // Failed. Create it.
01667       dl = _dl.get_dl(v, 1, _patch->stamp());
01668       if (dl)
01669          glNewList(dl, GL_COMPILE);
01670    }
01671 
01672    set_face_culling();                  // GL_ENABLE_BIT
01673    _patch->draw_tri_strips(_cb);
01674 
01675    if (ntt_use_vertex_program) 
01676    {
01677       // End the display list here
01678       if (_dl.dl(v)) {
01679          _dl.close_dl(v);
01680 
01681     ntt_smooth_enabled = false;
01682     ntt_elliptic_enabled = false;
01683     ntt_spheric_enabled = false;
01684     ntt_cylindric_enabled = false;
01685     _update_smoothing = false;
01686     _update_elliptic = false;
01687     _update_spheric = false;
01688     _update_cylindric = false;
01689     _update_curvatures = false;
01690 
01691          // Built it, now execute it
01692          ntt_setup_vertex_program();       // GL_ENABLE_BIT, ???
01693          BasicTexture::draw(v);
01694          ntt_done_vertex_program();
01695       }
01696    }
01697 
01698 //    PaperEffect::end_paper_effect(ntt_paper_flag);
01699 
01700    glPopAttrib();
01701 
01702    GL_VIEW::print_gl_errors("XToonTexture::draw - End");
01703    return _patch->num_faces();
01704 }
01705 
01706 /////////////////////////////////////
01707 // update()
01708 /////////////////////////////////////
01709 
01710 
01711 void
01712 XToonTexture::update_tex(void)
01713 {
01714 
01715    int ind;
01716 
01717    if (!_toon_texture_names)
01718    {
01719       _toon_texture_names = new LIST<str_ptr>; assert(_toon_texture_names);
01720       _toon_texture_ptrs = new LIST<TEXTUREptr>; assert(_toon_texture_ptrs);
01721 
01722       _toon_texture_remap_orig_names = new LIST<str_ptr>; assert(_toon_texture_remap_orig_names);
01723       _toon_texture_remap_new_names = new LIST<str_ptr>; assert(_toon_texture_remap_new_names);
01724 
01725       int i = 0;
01726       while (toon_remap_fnames[i][0] != NULL)
01727       {
01728          _toon_texture_remap_orig_names->add(str_ptr(toon_remap_base) + toon_remap_fnames[i][0]);
01729          _toon_texture_remap_new_names->add(str_ptr(toon_remap_base) + toon_remap_fnames[i][1]);
01730          i++;
01731       }
01732    }
01733 
01734    str_ptr tf = _tex_name;
01735 
01736    if (tf == NULL_STR)
01737    {
01738       assert(_tex == NULL);
01739       //_tex_name = NULL_STR;
01740       //_tex = NULL;
01741    }
01742    else if (_tex == NULL)
01743    {
01744       if ((ind = _toon_texture_names->get_index(tf)) != BAD_IND)
01745       {
01746          //Finding original name in cache...
01747 
01748          //If its a failed texture...
01749          if ((*_toon_texture_ptrs)[ind] == NULL)
01750          {
01751             //...see if it was remapped...
01752             int ii = _toon_texture_remap_orig_names->get_index(tf);
01753             //...and change to looking up the remapped name            
01754             if (ii != BAD_IND)
01755             {
01756                str_ptr old_tf = tf;
01757                tf = (*_toon_texture_remap_new_names)[ii];
01758 
01759                ind = _toon_texture_names->get_index(tf);
01760 
01761                err_mesg(ERR_LEV_SPAM, 
01762                   "XToonTexture::set_texture() - Previously remapped --===<<[[{{ (%s) ---> (%s) }}]]>>===--", 
01763                      **(Config::JOT_ROOT()+old_tf), **(Config::JOT_ROOT()+tf) );
01764             }
01765          }
01766 
01767          //Now see if the final name yields a good texture...
01768          if ((*_toon_texture_ptrs)[ind] != NULL)
01769          {
01770             _tex = (*_toon_texture_ptrs)[ind];
01771             _tex_name = tf;
01772             err_mesg(ERR_LEV_SPAM, "XToonTexture::set_texture() - Using cached copy of texture.");
01773          }
01774          else
01775          {
01776             err_mesg(ERR_LEV_INFO, "XToonTexture::set_texture() - **ERROR** Previous caching failure: '%s'...", **tf);
01777             _tex = NULL;
01778             _tex_name = NULL_STR;
01779          }
01780       }
01781       //Haven't seen this name before...
01782       else
01783       {
01784          err_mesg(ERR_LEV_SPAM, "XToonTexture::set_texture() - Not in cache...");
01785       
01786          Image i(**(Config::JOT_ROOT()+tf));
01787 
01788          //Can't load the texture?
01789          if (i.empty())
01790          {
01791             //...check for a remapped file...
01792             int ii = _toon_texture_remap_orig_names->get_index(tf);
01793 
01794             //...and use that name instead....
01795             if (ii != BAD_IND)
01796             {
01797                //...but also indicate that the original name is bad...
01798 
01799                _toon_texture_names->add(tf);
01800                _toon_texture_ptrs->add(NULL);
01801 
01802                str_ptr old_tf = tf;
01803                tf = (*_toon_texture_remap_new_names)[ii];
01804 
01805                err_mesg(ERR_LEV_ERROR, 
01806                   "XToonTexture::set_texture() - Remapping --===<<[[{{ (%s) ---> (%s) }}]]>>===--", 
01807                      **(Config::JOT_ROOT()+old_tf), **(Config::JOT_ROOT()+tf) );
01808 
01809                i.load_file(**(Config::JOT_ROOT()+tf));
01810             }
01811          }
01812 
01813          //If the final name loads, store the cached texture...
01814          if (!i.empty())
01815          {
01816             TEXTUREglptr t = new TEXTUREgl("");
01817 
01818             t->set_save_img(true);
01819             t->set_mipmap(true);
01820             t->set_wrap_s(GL_CLAMP_TO_EDGE);
01821             t->set_wrap_t(GL_CLAMP_TO_EDGE);
01822             t->set_image(i.copy(),i.width(),i.height(),i.bpp());
01823          
01824 
01825             _toon_texture_names->add(tf);
01826             _toon_texture_ptrs->add(t);
01827 
01828             err_mesg(ERR_LEV_INFO, "XToonTexture::set_texture() - Cached: (w=%d h=%d bpp=%u) %s",
01829                i.width(), i.height(), i.bpp(), **(Config::JOT_ROOT()+tf));;
01830 
01831             _tex = t;
01832             _tex_name = tf;
01833          }
01834          //Otherwise insert a failed NULL
01835          else
01836          {
01837             err_mesg(ERR_LEV_ERROR, "XToonTexture::set_texture() - *****ERROR***** Failed loading to cache: '%s'...", **(Config::JOT_ROOT()+tf));
01838          
01839             _toon_texture_names->add(tf);
01840             _toon_texture_ptrs->add(NULL);
01841 
01842             _tex = NULL;
01843             _tex_name = NULL_STR;
01844          }
01845       }   
01846    }
01847 
01848 
01849 
01850 }
01851 
01852 
01853 /*
01854 void
01855 XToonTexture::update_tex(void)
01856 {
01857    int ind;
01858 
01859    if (_tex_name == NULL_STR)
01860    {
01861       assert(_tex == NULL);
01862    }
01863    else if ((_tex_name != NULL_STR) && (_tex == NULL))
01864    {
01865       if (!_toon_texture_names)
01866       {
01867          _toon_texture_names = new LIST<str_ptr>;     assert(_toon_texture_names);
01868          _toon_texture_ptrs = new LIST<TEXTUREptr>;   assert(_toon_texture_ptrs);
01869       }
01870 
01871       if ((ind = _toon_texture_names->get_index(_tex_name)) != BAD_IND)
01872       {
01873          if ((*_toon_texture_ptrs)[ind] != NULL)
01874          {
01875             _tex = (*_toon_texture_ptrs)[ind];
01876             //_tex_name = _tex_name;
01877          }
01878          else
01879          {
01880             err_mesg(ERR_LEV_INFO, "XToonTexture::update_tex() - *****ERROR***** Previous caching failure: '%s'",
01881                           **(Config::JOT_ROOT() + _tex_name));
01882             _tex = NULL;
01883             _tex_name = NULL_STR;
01884          }
01885       }
01886       else
01887       {
01888          err_mesg(ERR_LEV_SPAM, "XToonTexture::update_tex() - Not in cache...");
01889       
01890          Image i(Config::JOT_ROOT() + _tex_name);
01891          if (!i.empty())
01892          {
01893             TEXTUREglptr t = new TEXTUREgl("");
01894 
01895             t->set_save_img(true);
01896             t->set_mipmap(true);
01897             t->set_wrap_s(GL_CLAMP_TO_EDGE);
01898             t->set_wrap_t(GL_CLAMP_TO_EDGE);
01899             t->set_image(i.copy(),i.width(),i.height(),i.bpp());
01900 
01901             _toon_texture_names->add(_tex_name);
01902             _toon_texture_ptrs->add(t);
01903 
01904             err_mesg(ERR_LEV_INFO, "XToonTexture::update_tex() - Cached: (WIDTH=%d HEIGHT=%d BPP=%u) %s", 
01905                            i.width(), i.height(), i.bpp(), **(Config::JOT_ROOT() + _tex_name));
01906             _tex = t;
01907             //_tex_name = _tex_name;
01908          }
01909          else
01910          {
01911             err_mesg(ERR_LEV_ERROR, "XToonTexture::update_tex() - *****ERROR***** Failed loading to cache: '%s'",
01912                           **(Config::JOT_ROOT() + _tex_name));
01913 
01914             _toon_texture_names->add(_tex_name);
01915             _toon_texture_ptrs->add(NULL);
01916 
01917             _tex = NULL;
01918             _tex_name = NULL_STR;
01919          }
01920       }   
01921    }
01922 
01923 }
01924 */
01925 
01926 
01927 
01928 void XToonTexture::update_cam(){
01929    if (_detail_map == Depth) {
01930      double min_depth = 1.0;
01931      double max_depth = 1000.0;
01932      ntt_target_length = max_depth*_target_length + min_depth*(1.0f-_target_length);
01933 
01934    } else if (_detail_map == Focus) {
01935      if (ntt_use_vertex_program_arb){
01936        Wpt eye = VIEW::peek_cam()->data()->from();
01937        Wpt focus = VIEW::peek_cam()->data()->center();
01938        double focus_dist = (focus-eye).length(); 
01939        Wvec focus_vec (focus_dist, focus_dist, focus_dist);
01940        Wtransf focus_matrix (focus_vec, focus_vec, focus_vec, focus_vec);
01941        glMatrixMode(GL_MATRIX0_ARB);
01942        glLoadMatrixd(focus_matrix.transpose().matrix());
01943        glMatrixMode(GL_MODELVIEW);           
01944      }     
01945 
01946      double min_depth = 1.0;
01947      double max_depth = 100.0;
01948      ntt_target_length = max_depth*_target_length + min_depth*(1.0f-_target_length);
01949 
01950    } else if (_detail_map == Flow){
01951 
01952      ntt_prev_matrix = ntt_cur_matrix;
01953      if (ntt_use_vertex_program_arb) {
01954        glMatrixMode(GL_MATRIX0_ARB);
01955        glLoadMatrixd(ntt_prev_matrix.transpose().matrix());
01956        glMatrixMode(GL_MODELVIEW);    
01957      }
01958      
01959      ntt_cur_matrix = VIEW::peek()->wpt_to_pix_proj();
01960      if (ntt_use_vertex_program_arb) {
01961        glMatrixMode(GL_MATRIX1_ARB);
01962        glLoadMatrixd(ntt_cur_matrix.transpose().matrix());       
01963        glMatrixMode(GL_MODELVIEW);    
01964      }
01965 
01966      double max_screen_dist = 2.0;
01967      ntt_target_length = _target_length*max_screen_dist;     
01968    } else if (_detail_map == Curvature){
01969      double max_curvature = 1/(100.0f*_patch->mesh()->curvature()->feature_size());
01970      ntt_target_length = _target_length * max_curvature;
01971    } else if (_detail_map == Orientation){
01972 //      float max_orientation = 2.0;
01973 //      ntt_target_length = _target_length * max_orientation;
01974      ntt_target_length = 1/_target_length - 1.0f;
01975    } else if (_detail_map == Specularity){
01976      ntt_target_length = 1.0/(1.0-_target_length);
01977    } else {
01978      ntt_target_length = _target_length;
01979     }
01980 
01981    ntt_max_factor = _max_factor;
01982    ntt_smooth_factor = _smooth_factor;
01983    ntt_detail_map = _detail_map;
01984 }
01985 
01986 
01987 
01988 
01989 
01990 /////////////////////////////////////
01991 // tags()
01992 /////////////////////////////////////
01993 CTAGlist &
01994 XToonTexture::tags() const
01995 {
01996    if (!_ntt_tags) {
01997       _ntt_tags = new TAGlist;
01998       *_ntt_tags += OGLTexture::tags();
01999 
02000       *_ntt_tags += new TAG_val<XToonTexture,int>(
02001          "use_paper",
02002          &XToonTexture::use_paper_);
02003       *_ntt_tags += new TAG_val<XToonTexture,int>(
02004          "travel_paper",
02005          &XToonTexture::travel_paper_);
02006       *_ntt_tags += new TAG_val<XToonTexture,COLOR>(
02007          "COLOR",
02008          &XToonTexture::color_);
02009       *_ntt_tags += new TAG_val<XToonTexture,double>(
02010          "alpha",
02011          &XToonTexture::alpha_);
02012 
02013       *_ntt_tags += new TAG_val<XToonTexture,int>(
02014          "light_index",
02015          &XToonTexture::light_index_);
02016       *_ntt_tags += new TAG_val<XToonTexture,int>(
02017          "light_dir",
02018          &XToonTexture::light_dir_);
02019       *_ntt_tags += new TAG_val<XToonTexture,int>(
02020          "light_cam",
02021          &XToonTexture::light_cam_);
02022       *_ntt_tags += new TAG_val<XToonTexture,Wvec>(
02023          "light_coords",
02024          &XToonTexture::light_coords_);
02025 
02026 
02027       *_ntt_tags += new TAG_meth<XToonTexture>(
02028          "texture",
02029          &XToonTexture::put_tex_name,
02030          &XToonTexture::get_tex_name,
02031          1);
02032       *_ntt_tags += new TAG_meth<XToonTexture>(
02033          "layer_name",
02034          &XToonTexture::put_layer_name,
02035          &XToonTexture::get_layer_name,
02036          1);
02037 
02038 
02039       *_ntt_tags += new TAG_meth<XToonTexture>(
02040          "transparent",
02041          &XToonTexture::put_transparent,
02042          &XToonTexture::get_transparent,
02043          0);
02044       *_ntt_tags += new TAG_meth<XToonTexture>(
02045          "annotate",
02046          &XToonTexture::put_annotate,
02047          &XToonTexture::get_annotate,
02048          0);
02049 
02050    }
02051    return *_ntt_tags;
02052 }
02053 ////////////////////////////////////
02054 // put_layer_name()
02055 /////////////////////////////////////
02056 void
02057 XToonTexture::put_layer_name(TAGformat &d) const
02058 {
02059    err_mesg(ERR_LEV_SPAM, "XToonTexture::put_layer_name()");
02060         
02061    d.id();
02062    if (get_layer_name() == NULL_STR)
02063    {
02064       err_mesg(ERR_LEV_SPAM, "XToonTexture::put_layer_name() - Wrote NULL string.");
02065       *d << "NULL_STR";
02066       *d << " ";
02067    }
02068    else
02069    {
02070       *d << **(get_layer_name());
02071       *d << " ";
02072       err_mesg(ERR_LEV_SPAM, "XToonTexture::put_layer_name() - Wrote string: '%s'", **get_tex_name());
02073    }
02074    d.end_id();
02075 }
02076 
02077 /////////////////////////////////////
02078 // get_layer_name()
02079 /////////////////////////////////////
02080 
02081 void
02082 XToonTexture::get_layer_name(TAGformat &d)
02083 {
02084    err_mesg(ERR_LEV_SPAM, "XToonTexture::get_layer_name()");
02085 
02086    //XXX - May need something to handle filenames with spaces
02087 
02088    str_ptr str, lay, space;
02089    *d >> str;      
02090    if (!(*d).ascii()) *d >> space; 
02091 
02092    if (str == "NULL_STR") 
02093    {
02094       lay = NULL_STR;
02095       err_mesg(ERR_LEV_SPAM, "XToonTexture::get_layer_name() - Loaded NULL string.");
02096    }
02097    else
02098    {
02099       lay = str;
02100       err_mesg(ERR_LEV_SPAM, "XToonTexture::get_layer_name() - Loaded string: '%s'", **lay);
02101    }
02102    set_layer_name(lay);
02103 
02104 }
02105 
02106 ////////////////////////////////////
02107 // put_texname()
02108 /////////////////////////////////////
02109 void
02110 XToonTexture::put_tex_name(TAGformat &d) const
02111 {
02112    err_mesg(ERR_LEV_SPAM, "XToonTexture::put_tex_name()");
02113 
02114    //XXX - May need something to handle filenames with spaces
02115 
02116    d.id();
02117    if (_tex_name == NULL_STR)
02118    {
02119       err_mesg(ERR_LEV_SPAM, "XToonTexture::put_tex_name() - Wrote NULL string.");
02120       *d << "NULL_STR";
02121       *d << " ";
02122    }
02123    else
02124    {
02125       *d << **(get_tex_name());
02126       *d << " ";
02127       err_mesg(ERR_LEV_SPAM, "XToonTexture::put_tex_name() - Wrote string: '%s'", **get_tex_name());
02128    }
02129    d.end_id();
02130 }
02131 
02132 /////////////////////////////////////
02133 // get_tex_name()
02134 /////////////////////////////////////
02135 
02136 void
02137 XToonTexture::get_tex_name(TAGformat &d)
02138 {
02139    err_mesg(ERR_LEV_SPAM, "XToonTexture::get_tex_name()");
02140 
02141    //XXX - May need something to handle filenames with spaces
02142 
02143    str_ptr str, space;
02144    *d >> str;      
02145    if (!(*d).ascii()) *d >> space; 
02146 
02147    if (str == "NULL_STR") 
02148    {
02149       str = NULL_STR;
02150       err_mesg(ERR_LEV_SPAM, "XToonTexture::get_tex_name() - Loaded NULL string.");
02151    }
02152    else
02153    {
02154       err_mesg(ERR_LEV_SPAM, "XToonTexture::get_tex_name() - Loaded string: '%s'", **str);
02155    }
02156    set_tex_name(str);
02157 
02158 }
02159 
02160 
02161 ////////////////////////////////////
02162 // put_transparent()
02163 /////////////////////////////////////
02164 void
02165 XToonTexture::put_transparent(TAGformat &d) const
02166 {
02167    // XXX - Deprecated
02168 }
02169 
02170 /////////////////////////////////////
02171 // get_transparent()
02172 /////////////////////////////////////
02173 void
02174 XToonTexture::get_transparent(TAGformat &d)
02175 {
02176    err_mesg(ERR_LEV_WARN, "XToonTexture::get_transparent() - ***NOTE: Loading OLD format file!***");
02177 
02178    *d >> _transparent;
02179 }
02180 
02181 ////////////////////////////////////
02182 // put_annotate()
02183 /////////////////////////////////////
02184 void
02185 XToonTexture::put_annotate(TAGformat &d) const
02186 {
02187    // XXX - Deprecated
02188 }
02189 
02190 /////////////////////////////////////
02191 // get_annotate()
02192 /////////////////////////////////////
02193 void
02194 XToonTexture::get_annotate(TAGformat &d){
02195    err_mesg(ERR_LEV_WARN, "XToonTexture::get_annotate() - ***NOTE: Loading OLD format file!***");
02196    
02197    *d >> _annotate;
02198 }
02199 
02200 
02201 
02202 void
02203 XToonTexture::update_smoothing(bool b){ 
02204   _update_smoothing = true; 
02205   _normals_smoothed = b;
02206   ntt_smooth_enabled = b;
02207   cerr << "update_smoothing" << endl;
02208 }
02209 
02210 void
02211 XToonTexture::update_elliptic (bool b){ 
02212   _update_elliptic = true; 
02213   _normals_elliptic = b;
02214   ntt_elliptic_enabled = b;
02215   cerr << "update_elliptic" << endl;
02216 }
02217 
02218 void
02219 XToonTexture::update_spheric(bool b){ 
02220   _update_spheric = true; 
02221   _normals_spheric = b;
02222   ntt_spheric_enabled = b;
02223   cerr << "update_spheric" << endl;
02224 }
02225 
02226 void
02227 XToonTexture::update_cylindric(bool b){ 
02228   _update_cylindric = true; 
02229   _normals_cylindric = b;
02230   ntt_cylindric_enabled = b;
02231   cerr << "update_cylindric" << endl;
02232 }
02233 
02234 
02235 void
02236 XToonTexture::update_curvatures(bool b){ 
02237   _update_curvatures = true; 
02238   ntt_curv_enabled = b;
02239 }
02240 
02241 
02242 void 
02243 XToonTexture::set_inv_detail(bool b){
02244   ntt_inv_detail = b;
02245 }
02246 
02247 
02248 void                 
02249 XToonTexture::print_frame_rate(){
02250   if (_nb_stat_frames==0) return;
02251 
02252   _frame_rate = _nb_stat_frames/_frame_rate;
02253   cerr << "Detail map = "  << _detail_map << endl;
02254   cerr << "_frame_rate = "  << _frame_rate << endl;
02255   cerr << "resolution = "  << VIEW::peek()->width() << " ; " << VIEW::peek()->height() << endl;
02256 
02257   _frame_rate = 0.0;
02258   _nb_stat_frames = 0;
02259 }
02260 
02261 // end of file xtoon_texture.C

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4