-
Notifications
You must be signed in to change notification settings - Fork 2
/
NV20VolRen3D.cpp
1672 lines (1446 loc) · 60.6 KB
/
NV20VolRen3D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ________ ____ ___
// | \ / | / /
// +---+ \/ |/ /
// +--+| |\ /| <
// | || | \ / | |\ \
// | | \/ | | \ \
// \_____| |__| \__\
// Copyright 2001
// Joe Michael Kniss
// << [email protected] >>
// "All Your Base are Belong to Us"
//-------------------------------------------------------------------------
// NV20VolRen3D.cpp: implementation of the NV20VolRen3D class.
//
//////////////////////////////////////////////////////////////////////
#ifdef WIN32
#include <windows.h>
#endif
#include "NV20VolRen3D.h"
#include <iostream.h>
#include "VectorMath.h"
#include "glUE.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
NV20VolRen3D::NV20VolRen3D()
{
go = 0;
}
NV20VolRen3D::~NV20VolRen3D()
{
}
//================================================================= INIT
//======================================================================
void NV20VolRen3D::init()
{
if(gluvv.mv){
go = 1;
createVolumes();
}
create2DDepTex();
}
//================================================================= DRAW
//======================================================================
void NV20VolRen3D::draw()
{
if(!go) return;
renderVolume();
//renderSlice();
}
//======================================================== Render Volume
//======================================================================
//========== NOTES ===========================================
// Standard brick vertex ordering:
//
// (011) (111)
// 6 +---------+ 7 Where 1's are the size of the brick
// /| /| allong that axis
// / | / |
// (001)/ |(101) / |
// 4 +---------+ 5 |
// | | | |(110) z axis
// | 2 +-----+---+ 3 ^
// | /(010) | / | y axis
// | / | / | /
// |/ |/ |/
// 0 +---------+ 1 +-------> x axis
// (000) (100)
//
void NV20VolRen3D::renderVolume()
{
//-------------- Re-Scale Alpha values ---------------------------------
if(gluvv.volren.scaleAlphas){
if((lastSamp != gluvv.volren.sampleRate)||(gluvv.volren.loadTLUT)){ //see if the sample rate changed
if((lastGoodSamp != gluvv.volren.goodSamp) || gluvv.volren.loadTLUT){ //good sample rate changed
copyScale(gluvv.volren.goodSamp * 1/gluvv.volren.gamma, gDeptex);
lastGoodSamp = gluvv.volren.goodSamp;
}
if((lastInteSamp != gluvv.volren.interactSamp) || gluvv.volren.loadTLUT){ //interact samp rate changed
copyScale(gluvv.volren.interactSamp * 1/gluvv.volren.gamma, iDeptex);
lastInteSamp = gluvv.volren.interactSamp;
}
if(gluvv.volren.sampleRate == gluvv.volren.goodSamp){ //which one do we load (good)
loadDepTex(gDeptex);
lastSamp = gluvv.volren.goodSamp;
}
else if(gluvv.volren.sampleRate == gluvv.volren.interactSamp){ //(interactive)
loadDepTex(iDeptex);
lastSamp = gluvv.volren.interactSamp;
}
if(gluvv.volren.loadTLUT){ //now load the transfer function
loadDepTex(gluvv.volren.deptex2, deptex2Name);
}
gluvv.volren.loadTLUT = 0;
}
} else { //just do gamma scale, don't update for the sample rate (for testing purposes)
if(gluvv.volren.loadTLUT){
copyScale(1/gluvv.volren.gamma, gDeptex);
loadDepTex(gDeptex);
loadDepTex(gluvv.volren.deptex2, deptex2Name);
gluvv.volren.loadTLUT = 0;
}
}
//-------------- end Re-Scale Alpha values ------------------------------
//-------------- do dot product with clip and view dir
float vdir[3];
subV3(vdir, gluvv.env.eye, gluvv.clip.pos);
normalizeV3(vdir);
normalizeV3(gluvv.clip.dir);
float dv = dotV3(vdir,gluvv.clip.dir);
float globalModV[16]; //save original tranform
glGetFloatv(GL_MODELVIEW_MATRIX, globalModV); //save the world model view
//-------------- end do dot product with clip and view dir
glPushMatrix();{ //move to the volume location
glTranslatef(gluvv.rinfo.trans[0], //translate
gluvv.rinfo.trans[1],
gluvv.rinfo.trans[2]);
glMultMatrixf(gluvv.rinfo.xform); //rotate
glTranslatef(-gluvv.mv->xfSize/2, //center
-gluvv.mv->yfSize/2,
-gluvv.mv->zfSize/2);
//-------------- draw clip slices --------------------------------------
for(int i=0; i<gluvv.mv->numSubVols; ++i){
drawClip(i, dv, globalModV);
}
//-------------- end draw clip slices ----------------------------------
//----------------------------------------------------------------------
//-------------- render the volume -------------------------------------
setupShaders();
setupRegComb();
GLdouble mv[16];
glGetDoublev(GL_MODELVIEW_MATRIX, mv); //save modelview matrix
if(gluvv.shade == gluvvShadeMIP)
glBlendEquationEXT(GL_MAX);
renderBricks(mv); //RENDER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
glBlendEquationEXT(GL_FUNC_ADD);
resetShaders();
resetRegComb();
//-------------- end render the volume ---------------------------------
//----------------------------------------------------------------------
#if 1
gluvv.reblend = GB_UNDER; //force gluvv.display to composite the background
#endif
//-------------- draw clip slices --------------------------------------
for(i=0; i<gluvv.mv->numSubVols; ++i){
drawClip(i, -dv, globalModV);
}
//-------------- end draw clip slices ----------------------------------
} glPopMatrix();
resetShaders();
resetRegComb();
resetClips();
}
//======================================================== Render Bricks
//======================================================================
void NV20VolRen3D::renderBricks(GLdouble mv[16])
{
if(gluvv.mv->numSubVols > 1){ //render multiple bricked volumes
int *order = new int[gluvv.mv->numSubVols]; //the correct draw order
float *zval = new float[gluvv.mv->numSubVols];//zvalue of each subvolume
for(int i=0; i< gluvv.mv->numSubVols; ++i){ //compute zvalues
Volume *v = &gluvv.mv->volumes[i];
order[i] = i;
float c[3] = {v->xfPos + v->xfSize/2.0, v->yfPos + v->yfSize/2.0, v->zfPos + v->zfSize/2.0};
float center[3];
translateV3W(center, mv, c);
zval[i] = (float)(center[0]*center[0] + center[1]*center[1] + center[2]*center[2]);
}
for(i=0; i< gluvv.mv->numSubVols-1; ++i){ //now sort
for(int j=i+1; j<gluvv.mv->numSubVols; ++j){
if(zval[order[i]] < zval[order[j]]){//test for swap
int tmp = order[i];
order[i] = order[j];
order[j] = tmp;
}
}
}
for(i=0 ; i< gluvv.mv->numSubVols; ++i){ //finaly render
Volume *v = &gluvv.mv->volumes[order[i]];
float sxf = v->xfSize;
float syf = v->yfSize;
float szf = v->zfSize;
float vo[8][3] = {{0,0,0},{sxf,0,0},{0,syf,0},{sxf,syf,0},{0,0,szf},{sxf,0,szf},{0,syf,szf},{sxf,syf,szf}};
float tx[8][3] = {{0,0,0},{1 ,0,0},{0,1 ,0},{1 ,1 ,0},{0,0,1 },{1 ,0,1 },{0,1 ,1 },{1 ,1 ,1 }};
float axis[3] = {0,0,1};
glPushMatrix(); {
setupClips(order[i],vo,tx);
glTranslatef(v->xfPos, v->yfPos, v->zfPos);
render3DVA(gluvv.volren.sampleRate,mv,order[i],vo,tx,axis);
} glPopMatrix();
}
} else { //just render one volume!
float sxf = gluvv.mv->xfSize;
float syf = gluvv.mv->yfSize;
float szf = gluvv.mv->zfSize;
float vo[8][3] = {{0,0,0},{sxf,0,0},{0,syf,0},{sxf,syf,0},{0,0,szf},{sxf,0,szf},{0,syf,szf},{sxf,syf,szf}};
float tx[8][3] = {{0,0,0},{1 ,0,0},{0,1 ,0},{1 ,1 ,0},{0,0,1 },{1 ,0,1 },{0,1 ,1 },{1 ,1 ,1 }};
float axis[3] = {0,0,1};
setupClips(0,vo,tx);
render3DVA(gluvv.volren.sampleRate,mv,0,vo,tx,axis);
}
}
//========================================================== Setup Clips
//======================================================================
void NV20VolRen3D::setupClips(int vol, float vo[8][3], float tx[8][3])
{
Volume *v = &gluvv.mv->volumes[vol];
if(gluvv.clip.on && gluvv.clip.ortho){
float cp[3];
cp[0] = gluvv.clip.vpos[0] > v->xfPos ?
(gluvv.clip.vpos[0] < v->xfSize + v->xfPos ? gluvv.clip.vpos[0] - v->xfPos : v->xfSize) : 0;
cp[1] = gluvv.clip.vpos[1] > v->yfPos ?
(gluvv.clip.vpos[1] < v->yfSize + v->yfPos ? gluvv.clip.vpos[1] - v->yfPos : v->yfSize) : 0;
cp[2] = gluvv.clip.vpos[2] > v->zfPos ?
(gluvv.clip.vpos[2] < v->zfSize + v->zfPos ? gluvv.clip.vpos[2] - v->zfPos : v->zfSize) : 0;
switch(gluvv.clip.oaxis){
case VolRenAxisXPos:
tx[1][0] = cp[0]/v->xfSize;
tx[3][0] = cp[0]/v->xfSize;
tx[5][0] = cp[0]/v->xfSize;
tx[7][0] = cp[0]/v->xfSize;
vo[1][0] = cp[0];
vo[3][0] = cp[0];
vo[5][0] = cp[0];
vo[7][0] = cp[0];
break;
case VolRenAxisXNeg:
tx[0][0] = cp[0]/v->xfSize;
tx[2][0] = cp[0]/v->xfSize;
tx[4][0] = cp[0]/v->xfSize;
tx[6][0] = cp[0]/v->xfSize;
vo[0][0] = cp[0];
vo[2][0] = cp[0];
vo[4][0] = cp[0];
vo[6][0] = cp[0];
break;
case VolRenAxisYPos:
tx[2][1] = cp[1]/v->yfSize;
tx[3][1] = cp[1]/v->yfSize;
tx[6][1] = cp[1]/v->yfSize;
tx[7][1] = cp[1]/v->yfSize;
vo[2][1] = cp[1];
vo[3][1] = cp[1];
vo[6][1] = cp[1];
vo[7][1] = cp[1];
break;
case VolRenAxisYNeg:
tx[0][1] = cp[1]/v->yfSize;
tx[1][1] = cp[1]/v->yfSize;
tx[4][1] = cp[1]/v->yfSize;
tx[5][1] = cp[1]/v->yfSize;
vo[0][1] = cp[1];
vo[1][1] = cp[1];
vo[4][1] = cp[1];
vo[5][1] = cp[1];
break;
case VolRenAxisZPos:
tx[4][2] = cp[2]/v->zfSize;
tx[5][2] = cp[2]/v->zfSize;
tx[6][2] = cp[2]/v->zfSize;
tx[7][2] = cp[2]/v->zfSize;
vo[4][2] = cp[2];
vo[5][2] = cp[2];
vo[6][2] = cp[2];
vo[7][2] = cp[2];
break;
case VolRenAxisZNeg:
tx[0][2] = cp[2]/v->zfSize;
tx[1][2] = cp[2]/v->zfSize;
tx[2][2] = cp[2]/v->zfSize;
tx[3][2] = cp[2]/v->zfSize;
vo[0][2] = cp[2];
vo[1][2] = cp[2];
vo[2][2] = cp[2];
vo[3][2] = cp[2];
break;
}
}
}
//============================================================ drawClips
//======================================================================
void NV20VolRen3D::drawClip(int vol, float dv, float wmv[16])
{
if((!gluvv.clip.ortho)){
switch(gluvv.dmode){
case GDM_V1:
case GDM_V1G:
case GDM_V2:
case GDM_VGH_VG:
case GDM_VGH_V:
cerr << "clipping" << endl;
glActiveTexture(GL_TEXTURE2_ARB); { //3rd & 4th axis, or clipping
glEnable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_CULL_FRAGMENT_NV);
}
glPushMatrix();{ //this sets the clipping plane
glLoadIdentity(); //clips are set in world space
glMultMatrixf(wmv); //origional world space coords
glTranslatef(gluvv.clip.pos[0], //location of clipping plane
gluvv.clip.pos[1],
gluvv.clip.pos[2]);
glMultMatrixf(gluvv.clip.xform); //rotation of clip plane
GLdouble zup[4] = {0, 0, -1, 0}; // always in z direction
glEnable(GL_CLIP_PLANE5); //enable the gl clip plane
glClipPlane(GL_CLIP_PLANE5, zup);
} glPopMatrix();
break;
}
}
if((!gluvv.clip.on)||(!gluvv.clip.ortho)) return;
Volume *v = &gluvv.mv->volumes[vol];
float c[4][3];
copyV3(c[0],gluvv.clip.corners[0]);
copyV3(c[1],gluvv.clip.corners[1]);
copyV3(c[2],gluvv.clip.corners[2]);
copyV3(c[3],gluvv.clip.corners[3]);
//this moves the clip plane to sub-volume space
c[0][0] = CLAMP_ARB(0,c[0][0]-v->xfPos,v->xfSize);
c[1][0] = CLAMP_ARB(0,c[1][0]-v->xfPos,v->xfSize);
c[2][0] = CLAMP_ARB(0,c[2][0]-v->xfPos,v->xfSize);
c[3][0] = CLAMP_ARB(0,c[3][0]-v->xfPos,v->xfSize);
c[0][1] = CLAMP_ARB(0,c[0][1]-v->yfPos,v->yfSize);
c[1][1] = CLAMP_ARB(0,c[1][1]-v->yfPos,v->yfSize);
c[2][1] = CLAMP_ARB(0,c[2][1]-v->yfPos,v->yfSize);
c[3][1] = CLAMP_ARB(0,c[3][1]-v->yfPos,v->yfSize);
c[0][2] = CLAMP_ARB(0,c[0][2]-v->zfPos,v->zfSize);
c[1][2] = CLAMP_ARB(0,c[1][2]-v->zfPos,v->zfSize);
c[2][2] = CLAMP_ARB(0,c[2][2]-v->zfPos,v->zfSize);
c[3][2] = CLAMP_ARB(0,c[3][2]-v->zfPos,v->zfSize);
glEnable(GL_REGISTER_COMBINERS_NV);
glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 1);
// I am just using these to replace the texture's alpha with a different one
float alpha[4] = {1,0,0,gluvv.clip.alpha};
glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, alpha); //set W
float greenish[4] = {0,1,0,1};
glCombinerParameterfvNV(GL_CONSTANT_COLOR1_NV, greenish); //set W
//blue is the primary color
glColor4f(0,0,1,1);
#if 0 //this is not used right now
//now for some painfull swizling
//extract the red, extract the green
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_CONSTANT_COLOR0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_CONSTANT_COLOR1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER0_NV, GL_RGB,
GL_SPARE0_NV, GL_SPARE1_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_TRUE, GL_FALSE);
//alpha goes to red + green
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_B_NV, GL_CONSTANT_COLOR0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_C_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_D_NV, GL_CONSTANT_COLOR1_NV, GL_UNSIGNED_INVERT_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER1_NV, GL_RGB,
GL_DISCARD_NV, GL_DISCARD_NV, GL_TEXTURE1_ARB, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//add blue now
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_A_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_B_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER1_NV, GL_RGB,
GL_DISCARD_NV, GL_DISCARD_NV, GL_TEXTURE0_ARB, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
#endif
//replace alpha
glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_CONSTANT_COLOR0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_CONSTANT_COLOR0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
float offset = .001; //this is used to avoid z-compete when the slice is on top
glPushMatrix();{
//make sure we draw this in sub-volume space
glTranslatef(v->xfPos, v->yfPos, v->zfPos);
switch(gluvv.clip.oaxis){
case VolRenAxisXPos:
if((dv < 0)&&(c[0][0] > 0)&&(c[0][0]<v->xfSize)){
float ov[3] = {offset, 0, 0}; //offset vector
for(int i=0; i<4; ++ i)
addV3(c[i],c[i],ov);
renderSlice(c,vol);
}
break;
case VolRenAxisXNeg:
if(dv > 0){
float ov[3] = {-offset, 0, 0}; //offset vector
for(int i=0; i<4; ++ i)
addV3(c[i],c[i],ov);
renderSlice(c,vol);
}
break;
case VolRenAxisYPos:
if((dv > 0)&&(c[0][1] > 0)&&(c[0][1]<v->yfSize)){
float ov[3] = {0, offset, 0}; //offset vector
for(int i=0; i<4; ++ i)
addV3(c[i],c[i],ov);
renderSlice(c,vol);
}
break;
case VolRenAxisYNeg:
if((dv < 0)&&(c[0][1] > 0)&&(c[0][1]<v->yfSize)){
float ov[3] = {0, -offset, 0}; //offset vector
for(int i=0; i<4; ++ i)
addV3(c[i],c[i],ov);
renderSlice(c,vol);
}
break;
case VolRenAxisZPos:
if((dv < 0)&&(c[0][2] > 0)&&(c[0][2]<v->zfSize)){
float ov[3] = {0, 0, offset}; //offset vector
for(int i=0; i<4; ++ i)
addV3(c[i],c[i],ov);
renderSlice(c,vol);
}
break;
case VolRenAxisZNeg:
if((dv > 0)&&(c[0][2] > 0)&&(c[0][2]<v->zfSize)){
float ov[3] = {0, 0, -offset}; //offset vector
for(int i=0; i<4; ++ i)
addV3(c[i],c[i],ov);
renderSlice(c,vol);
}
break;
}
} glPopMatrix();
glDisable(GL_REGISTER_COMBINERS_NV); //clean up opengl state
glActiveTexture(GL_TEXTURE0_ARB); {
glDisable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
}
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
//============================================== Render Slice w/ corners
//======================================================================
void NV20VolRen3D::renderSlice(float c[4][3], int vol)
{
glActiveTexture(GL_TEXTURE0_ARB); { //this is for the slice
glEnable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
glBindTexture(GL_TEXTURE_3D, texNames[vol]);
}
Volume *v = &gluvv.mv->volumes[vol];
glBegin(GL_QUADS);{
glMultiTexCoord3fARB(GL_TEXTURE0_ARB,c[0][0]/(v->xfSize),c[0][1]/(v->yfSize),c[0][2]/(v->zfSize));
glVertex3f(c[0][0], c[0][1], c[0][2]);
glMultiTexCoord3fARB(GL_TEXTURE0_ARB,c[1][0]/(v->xfSize),c[1][1]/(v->yfSize),c[1][2]/(v->zfSize));
glVertex3f(c[1][0], c[1][1], c[1][2]);
glMultiTexCoord3fARB(GL_TEXTURE0_ARB,c[2][0]/(v->xfSize),c[2][1]/(v->yfSize),c[2][2]/(v->zfSize));
glVertex3f(c[2][0], c[2][1], c[2][2]);
glMultiTexCoord3fARB(GL_TEXTURE0_ARB,c[3][0]/(v->xfSize),c[3][1]/(v->yfSize),c[3][2]/(v->zfSize));
glVertex3f(c[3][0], c[3][1], c[3][2]);
} glEnd();
}
//=========================================================== resetClips
//======================================================================
void NV20VolRen3D::resetClips()
{
glDisable(GL_CLIP_PLANE0);
}
//======================================================== Setup Shaders
//======================================================================
void NV20VolRen3D::setupShaders()
{
glEnable(GL_TEXTURE_SHADER_NV); {
GlErr("nv20volren", "enable shader");
glActiveTexture(GL_TEXTURE0_ARB); { //this is for the slice
glEnable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
}
glActiveTexture(GL_TEXTURE1_ARB); { //this is for the transfer function
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DEPENDENT_AR_TEXTURE_2D_NV);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, deptexName);
}
glActiveTexture(GL_TEXTURE2_ARB); { // for shading or clipping (not both)
if((gluvv.shade == gluvvShadeDiff) || (gluvv.shade == gluvvShadeDSpec)){
glEnable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
//glBindTexture(GL_TEXTURE_3D, shadeNames[0]);
} else {
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
}
}
glActiveTexture(GL_TEXTURE3_ARB); { //3rd & 4th axis, or clipping
switch(gluvv.dmode){ //hey! we use this for 3rd & 4th axies
case GDM_VGH:
case GDM_V1GH:
case GDM_V2G:
case GDM_V2GH:
case GDM_V3:
case GDM_V3G:
case GDM_V4:
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DEPENDENT_GB_TEXTURE_2D_NV);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, deptex2Name);
break;
case GDM_V1:
case GDM_V1G:
case GDM_V2:
case GDM_VGH_VG:
case GDM_VGH_V:
if(!gluvv.clip.ortho) break; //we want to take care of this elsewhere
default:
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
}
}
GlErr("set up shader", "after texture3");
}
}
void NV20VolRen3D::resetShaders()
{
glActiveTexture(GL_TEXTURE3_ARB); { //not used
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
}
glActiveTexture(GL_TEXTURE2_ARB); { //not used
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
}
glActiveTexture(GL_TEXTURE1_ARB); { //not used
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_NONE);
}
glActiveTexture(GL_TEXTURE0_ARB); { //not used
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
glDisable(GL_TEXTURE_SHADER_NV);
}
//======================================================= Setup Reg Comb
//======================================================================
void NV20VolRen3D::setupRegComb()
{
if((gluvv.shade == gluvvShadeDiff) || (gluvv.shade == gluvvShadeDSpec)){
float vdir[3];
subV3(vdir, gluvv.env.eye, gluvv.env.at);
normalizeV3(vdir);
float ltdir[3];
subV3(ltdir, gluvv.light.pos, gluvv.env.at);
normalizeV3(ltdir);
float ltoe[3];
subV3(ltoe,vdir,ltdir);
scaleV3(.5, ltoe);
float half[4];
addV3(half,ltdir, ltoe);
half[3] = 1;
float vhalf[4];
float invx[16];
inverseMatrix(invx, gluvv.rinfo.xform);
translateV3(vhalf,invx,half);
negateV3(vhalf);
normalizeV3(vhalf);
vhalf[0] = vhalf[0]/2 + .5;
vhalf[1] = vhalf[1]/2 + .5;
vhalf[2] = vhalf[2]/2 + .5;
glFogfv(GL_FOG_COLOR, vhalf);
float lpos[4];
translateV3W(lpos, invx, ltdir);
negateV3(lpos);
normalizeV3(ltdir);
lpos[0] = lpos[0]/2 + .5;
lpos[1] = lpos[1]/2 + .5;
lpos[2] = lpos[2]/2 + .5;
lpos[3] = .3;
glCombinerParameterfvNV(GL_CONSTANT_COLOR1_NV, lpos); //set light direction
float ltstuff[4] = {0,0,0,gluvv.light.intens};
glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, ltstuff); //set light intensity
glEnable(GL_REGISTER_COMBINERS_NV);
glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 6);
//------------------------------------
//specular dot product (rgb)
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE2_ARB, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_FOG, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_EXPAND_NEGATE_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_FOG, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER0_NV, GL_RGB,
GL_TEXTURE0_ARB, GL_SPARE1_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_TRUE, GL_FALSE);
switch(gluvv.dmode){ //third axis stuff (alpha)
case GDM_VGH:
case GDM_V1GH:
case GDM_V2G:
case GDM_V2GH:
case GDM_V3:
case GDM_V3G:
case GDM_V4: //multipy third axis
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_TEXTURE3_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerOutputNV(GL_COMBINER0_NV, GL_ALPHA,
GL_TEXTURE1_ARB, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
GlErr("nv20volren","gcom7.4");
default: //nothing here
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerOutputNV(GL_COMBINER0_NV, GL_ALPHA,
GL_DISCARD_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
}
//------------------------------------
//diffuse dot product (rgb)
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE2_ARB, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_B_NV, GL_CONSTANT_COLOR1_NV, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE2_ARB, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_D_NV, GL_CONSTANT_COLOR1_NV, GL_EXPAND_NEGATE_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER1_NV, GL_RGB,
GL_SPARE0_NV, GL_TEXTURE2_ARB, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_TRUE, GL_FALSE);
//specular 2nd power (alpha)
glCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
glCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
glCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
glCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
glCombinerOutputNV(GL_COMBINER1_NV, GL_ALPHA,
GL_DISCARD_NV, GL_DISCARD_NV, GL_SPARE1_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//------------------------------------
//compute diffuse contribution - diffuse * color (rgb)
glCombinerInputNV(GL_COMBINER2_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE2_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER2_NV, GL_RGB, GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER2_NV, GL_RGB, GL_VARIABLE_C_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER2_NV, GL_RGB, GL_VARIABLE_D_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER2_NV, GL_RGB,
GL_DISCARD_NV, GL_DISCARD_NV, GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
GlErr("nv20volren","gcom1.4");
//specular 4th power (alpha) & (light intensity * alpha)
glCombinerInputNV(GL_COMBINER2_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER2_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER2_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_CONSTANT_COLOR0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER2_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerOutputNV(GL_COMBINER2_NV, GL_ALPHA,
GL_SPARE1_NV, GL_SPARE0_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//------------------------------------
//no rgb here
glCombinerInputNV(GL_COMBINER3_NV, GL_RGB, GL_VARIABLE_A_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER3_NV, GL_RGB, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER3_NV, GL_RGB, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER3_NV, GL_RGB, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER3_NV, GL_RGB,
GL_DISCARD_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//specular 8th power (alpha) & (ambient contrib * alpha)
glCombinerInputNV(GL_COMBINER3_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER3_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER3_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_CONSTANT_COLOR1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER3_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerOutputNV(GL_COMBINER3_NV, GL_ALPHA,
GL_SPARE1_NV, GL_TEXTURE0_ARB, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//------------------------------------
//add diffuse * (light intensity * alpha) + ambiant * (ambient contrib * alpha) (rgb)
glCombinerInputNV(GL_COMBINER4_NV, GL_RGB, GL_VARIABLE_A_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER4_NV, GL_RGB, GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER4_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER4_NV, GL_RGB, GL_VARIABLE_D_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER4_NV, GL_RGB,
GL_DISCARD_NV, GL_DISCARD_NV, GL_TEXTURE1_ARB, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
GlErr("nv20volren","gcom2.4");
//specular 16th power (alpha)
glCombinerInputNV(GL_COMBINER4_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER4_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER4_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER4_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerOutputNV(GL_COMBINER4_NV, GL_ALPHA,
GL_SPARE1_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//------------------------------------
//no rgb here
glCombinerInputNV(GL_COMBINER5_NV, GL_RGB, GL_VARIABLE_A_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER5_NV, GL_RGB, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER5_NV, GL_RGB, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER5_NV, GL_RGB, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER5_NV, GL_RGB,
GL_DISCARD_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//specular * (light * alpha) (alpha)
glCombinerInputNV(GL_COMBINER5_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER5_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER5_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER5_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerOutputNV(GL_COMBINER5_NV, GL_ALPHA,
GL_SPARE1_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
//------------------------------------
// color = (1-diffuse+amb) * specular + diffuse + amb
glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_INVERT_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_E_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_F_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
GlErr("nv20volren","fcom.0");
}
else{ //no shading
glEnable(GL_REGISTER_COMBINERS_NV);
glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 1);
switch(gluvv.dmode){ //third axis stuff
case GDM_VGH:
case GDM_V1GH:
case GDM_V2G:
case GDM_V2GH:
case GDM_V3:
case GDM_V3G:
case GDM_V4:
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_TEXTURE3_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glCombinerOutputNV(GL_COMBINER0_NV, GL_ALPHA,
GL_TEXTURE1_ARB, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
GlErr("nv20volren","gcom7.4");
break;
}
glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_E_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_F_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
GlErr("nv20volren","fcom.0");
}
}
void NV20VolRen3D::resetRegComb()
{
glDisable(GL_REGISTER_COMBINERS_NV);
}
//=================================================== Render 3D Vec Algn
//======================================================================
void NV20VolRen3D::render3DVA(float sampleFrequency,
GLdouble mv[16],
unsigned int v,
float vo[8][3], //volume vertex coords model-space coords
float tx[8][3], //texture vertex coords tex-space coords
float axis[3]) //axis to slice along world-space coords
{
float rv[8][3]; //the rotated volume (may include a scale)
float maxval = -10; //(tmp)
float minval = 10;
int minvert = 0;
GLdouble mvinv[16];
inverseMatrix(mvinv, mv); //invert model view matrix
for(int i=0; i<8; ++i){ //translate model to world coords (view space)
translateV3(rv[i], mv, vo[i]);
if(maxval < MAX(maxval, rv[i][2])){
maxval = MAX(maxval, rv[i][2]);
}
if(minval > MIN(minval, rv[i][2])){
minval = MIN(minval, rv[i][2]);
minvert = i; //determine the starting point for slicing
}
}
// fix this function so that the eye is the universal reference point for all volumes!
// we will get artifacts at brick boundaries otherwise!
//find the slice plane point 'sp' (initial) and the slice plane normal 'sn'
//sp is the sliceing starting point, simply the vertex farthest from the eye
float sp[3] = {vo[minvert][0], vo[minvert][1], vo[minvert][2]};
//float vpn[3] = {0,0,1}; //view plane normal, points to eye (temp variable)
float vpn[3];
vpn[0] = axis[0]; vpn[1] = axis[1]; vpn[2] = axis[2];
float sn[3]; //slice plane normal
translateV3(sn, mvinv, vpn); //move vpn to sn (model space);
//note: sn & sp are defined in Model Space, ie the space where the volume
// is alligned with the (x,y,z) axies
float normsn = (float)sqrt(sn[0]*sn[0] + sn[1]*sn[1] + sn[2]*sn[2]); //normalize
sn[0]/=normsn;
sn[1]/=normsn;
sn[2]/=normsn;
//now find the distance we need to slice (|max_vertex - min_vertex|)
float maxd[3] = {0, 0, maxval}; //(tmp) only use z-coord (view space)
float mind[3] = {0, 0, minval}; //(tmp) ditto (view space)
float maxv[3], minv[3]; //(tmp)
translateV3(maxv, mvinv, maxd); //translate back to model space
translateV3(minv, mvinv, mind); //ditto
maxv[0] -= minv[0]; //subtract
maxv[1] -= minv[1];
maxv[2] -= minv[2];
//now take the norm of this vector... we have the distance to be sampled
float dist = (float)sqrt(maxv[0]*maxv[0] + maxv[1]*maxv[1] + maxv[2]*maxv[2]);
//draw a red bounding box
//if(m_bbb) renderBBoxBrackets(sizef[0], sizef[1], sizef[2]);
//if(m_bb) renderBBox(sizef[0], sizef[1], sizef[2]);
glDisable(GL_LIGHTING); //light makes it look bad!
glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);
//glEnable(GL_TEXTURE_3D_EXT);
glActiveTexture(GL_TEXTURE2_ARB);
glBindTexture(GL_TEXTURE_3D, shadeNames[v]);
glActiveTexture(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_3D, texNames[v]);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glColor4f(1, 1, 1, 1);
GlErr("NV20VolRen3D","drawVA");
//distance between samples
float dis = gluvv.mv->xfSize / (gluvv.mv->xiSize * sampleFrequency);
float del[3] = {sn[0]*dis, sn[1]*dis, sn[2]*dis};
int samples = (int)((dist) / dis);//(total distance to be sampled)/(sample spacing)
//samples /= 40;
//del[0] *= 40;
//del[1] *= 40;
//del[2] *= 40;
float poly[6][3]; // for edge intersections
float tcoord[6][3]; // for texture intersections
float tpoly[6][3]; // for transformed edge intersections
int edges; // total number of edge intersections
//highly un-optimized!!!!!!!!!
for(i = 0 ; i < samples; ++i){ //for each slice
//increment the slice plane point by the slice distance
sp[0] += del[0];
sp[1] += del[1];
sp[2] += del[2];
edges = 0;
//now check each edge of the volume for intersection with..
//the plane defined by sp & sn
//front bottom edge
edges += intersect(vo[0], vo[1], tx[0], tx[1], rv[0], rv[1], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//front left edge
edges += intersect(vo[0], vo[2], tx[0], tx[2], rv[0], rv[2], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//front right edge
edges += intersect(vo[1], vo[3], tx[1], tx[3], rv[1], rv[3], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//left bottom edge
edges += intersect(vo[4], vo[0], tx[4], tx[0], rv[4], rv[0], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//right bottom edge
edges += intersect(vo[1], vo[5], tx[1], tx[5], rv[1], rv[5], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//front top edge
edges += intersect(vo[2], vo[3], tx[2], tx[3], rv[2], rv[3], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//back bottom edge
edges += intersect(vo[4], vo[5], tx[4], tx[5], rv[4], rv[5], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//back left edge
edges += intersect(vo[4], vo[6], tx[4], tx[6], rv[4], rv[6], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//back right edge
edges += intersect(vo[5], vo[7], tx[5], tx[7], rv[5], rv[7], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//back top edge
edges += intersect(vo[6], vo[7], tx[6], tx[7], rv[6], rv[7], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//left top edge
edges += intersect(vo[2], vo[6], tx[2], tx[6], rv[2], rv[6], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);
//right top edge
edges += intersect(vo[3], vo[7], tx[3], tx[7], rv[3], rv[7], sp, sn,
poly[edges], tcoord[edges], tpoly[edges]);