35 #include <libFreeWRL.h>
37 #include "../vrml_parser/Structs.h"
38 #include "../main/headers.h"
39 #include "../opengl/OpenGL_Utils.h"
40 #include "../opengl/Textures.h"
41 #include "../scenegraph/Component_Shape.h"
42 #include "../scenegraph/RenderFuncs.h"
43 #include "../scenegraph/LinearAlgebra.h"
185 GLuint front_texture;
192 void *Component_VolumeRendering_constructor(){
197 void Component_VolumeRendering_init(
struct tComponent_VolumeRendering *t){
200 t->prv = Component_VolumeRendering_constructor();
204 p->front_texture = 0;
212 void Component_VolumeRendering_clear(
struct tComponent_VolumeRendering *t){
228 GLfloat box [108] = {1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, };
234 float boxvert [24] = {
235 -.5f,-.5f, .5f, .5f,-.5f, .5f, -.5f,.5f, .5f, .5f,.5f, .5f,
236 -.5f,-.5f,-.5f, .5f,-.5f,-.5f, -.5f,.5f,-.5f, .5f,.5f,-.5f,
239 ushort boxtriindccw [48] = {
253 ushort boxtriindcw [48] = {
268 int i,j,itri, ind, jvert;
271 ConsoleMessage(
"compile_volumedata\n");
272 if(node->_boxtris == NULL){
273 node->_boxtris = MALLOC(
void *,108 *
sizeof(
float));
275 boxtris = (
float*)node->_boxtris;
279 boxtris[i*3 + j] = .5f * node->dimensions.c[j] * box[i*3 + j];
283 for(itri=0;itri<12;itri++){
284 for(jvert=0;jvert<3;jvert++) {
286 ind = boxtriindccw[itri*4 + jvert];
287 vert = &boxvert[ind*3];
289 boxtris[(itri*3 +jvert)*3 + j] = node->dimensions.c[j]*vert[j];
297 void pushnset_framebuffer(
int ibuffer);
298 void popnset_framebuffer();
302 #ifdef GL_DEPTH_COMPONENT32
303 #define FW_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT32
305 #define FW_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT16
310 void __gluMultMatricesd(
const GLDOUBLE a[16],
const GLDOUBLE b[16], GLDOUBLE r[16]);
311 int __gluInvertMatrixd(
const GLDOUBLE m[16], GLDOUBLE invOut[16]);
312 ivec4 get_current_viewport();
315 unsigned int prep_volumestyle(
struct X3D_Node *vstyle,
unsigned int volflags){
318 switch(vstyle->_nodeType){
319 case NODE_OpacityMapVolumeStyle:
320 volflags = volflags << 4;
321 volflags |= SHADERFLAGS_VOLUME_STYLE_OPACITY;
323 case NODE_BlendedVolumeStyle:
328 case NODE_BoundaryEnhancementVolumeStyle:
329 volflags = volflags << 4;
330 volflags |= SHADERFLAGS_VOLUME_STYLE_BOUNDARY;
332 case NODE_CartoonVolumeStyle:
333 volflags = volflags << 4;
334 volflags |= SHADERFLAGS_VOLUME_STYLE_CARTOON;
336 case NODE_ComposedVolumeStyle:
343 for(i=0;i<style->renderStyle.n;i++){
344 volflags = prep_volumestyle(style->renderStyle.p[i], volflags);
348 case NODE_EdgeEnhancementVolumeStyle:
349 volflags = volflags << 4;
350 volflags |= SHADERFLAGS_VOLUME_STYLE_EDGE;
352 case NODE_ProjectionVolumeStyle:
353 volflags = volflags << 4;
354 volflags |= SHADERFLAGS_VOLUME_STYLE_PROJECTION;
356 case NODE_ShadedVolumeStyle:
357 volflags = volflags << 4;
358 volflags |= SHADERFLAGS_VOLUME_STYLE_SHADED;
360 case NODE_SilhouetteEnhancementVolumeStyle:
361 volflags = volflags << 4;
362 volflags |= SHADERFLAGS_VOLUME_STYLE_SILHOUETTE;
364 case NODE_ToneMappedVolumeStyle:
365 volflags = volflags << 4;
366 volflags |= SHADERFLAGS_VOLUME_STYLE_TONE;
377 void pushnset_viewport(
float *vpFraction);
378 void popnset_viewport();
379 int haveFrameBufferObject();
380 void render_volumestyle(
struct X3D_Node *vstyle, GLint myProg){
383 switch(vstyle->_nodeType){
384 case NODE_OpacityMapVolumeStyle:
393 if(style->transferFunction){
399 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, style->transferFunction,tmpN);
400 tg->RenderFuncs.texturenode = (
void*)tmpN;
405 loadTextureNode(tmpN,NULL);
406 tti = getTableTableFromTextureNode(tmpN);
407 if(tti && tti->status >= TEX_LOADED){
408 glActiveTexture(GL_TEXTURE0+3);
409 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
413 iopactex = GET_UNIFORM(myProg,
"fw_opacTexture");
414 glUniform1i(iopactex,havetexture);
418 case NODE_BlendedVolumeStyle:
434 int *fbohandles = style->_fbohandles.p;
436 float vp[4] = {0.0f,1.0f,0.0f,1.0f};
438 glGetIntegerv(GL_VIEWPORT, iviewport);
439 if(haveFrameBufferObject()){
440 if(fbohandles[0] == 0){
441 GLuint depthrenderbuffer;
443 glGenFramebuffers(1, (GLuint *) &fbohandles[0]);
444 pushnset_framebuffer(fbohandles[0]);
447 glGenRenderbuffers(1, &depthrenderbuffer);
448 glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
449 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, iviewport[2],iviewport[3]);
450 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
453 glGenTextures(1,(GLuint *) &fbohandles[1]);
454 glBindTexture(GL_TEXTURE_2D, fbohandles[1]);
455 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iviewport[2], iviewport[3], 0, GL_RGBA , GL_UNSIGNED_BYTE, 0);
456 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
457 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
459 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbohandles[1], 0);
462 glGenTextures(1,(GLuint *)&fbohandles[2]);
463 glBindTexture(GL_TEXTURE_2D, fbohandles[2]);
464 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iviewport[2], iviewport[3], 0, GL_RGBA , GL_UNSIGNED_BYTE, 0);
465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
471 if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
472 printf(
"ouch framebuffer not complete\n");
475 pushnset_framebuffer(fbohandles[0]);
476 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbohandles[1], 0);
479 pushnset_viewport(vp);
480 glViewport(0,0,iviewport[2],iviewport[3]);
481 glClearColor(0.0f,0.0f,0.0f,0.0f);
482 FW_GL_CLEAR(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
487 case NODE_BoundaryEnhancementVolumeStyle:
494 GLint ibebound, iberetain, ibefactor;
495 ibebound = GET_UNIFORM(myProg,
"fw_boundaryOpacity");
496 glUniform1f(ibebound,style->boundaryOpacity);
497 iberetain = GET_UNIFORM(myProg,
"fw_retainedOpacity");
498 glUniform1f(iberetain,style->retainedOpacity);
499 ibefactor = GET_UNIFORM(myProg,
"fw_opacityFactor");
500 glUniform1f(ibefactor,style->opacityFactor);
503 case NODE_CartoonVolumeStyle:
511 GLint itoonsteps, itoonortho, itoonparallel;
512 itoonsteps = GET_UNIFORM(myProg,
"fw_colorSteps");
513 glUniform1i(itoonsteps,style->colorSteps);
514 itoonortho = GET_UNIFORM(myProg,
"fw_orthoColor");
515 glUniform4fv(itoonortho,1,style->orthogonalColor.c);
516 itoonparallel = GET_UNIFORM(myProg,
"fw_paraColor");
517 glUniform4fv(itoonparallel,1,style->parallelColor.c);
521 case NODE_ComposedVolumeStyle:
526 for(i=0;i<style->renderStyle.n;i++){
527 render_volumestyle(style->renderStyle.p[i], myProg);
531 case NODE_EdgeEnhancementVolumeStyle:
540 GLint iedgeColor, igradientThreshold;
542 rgba = style->edgeColor.c;
543 iedgeColor = GET_UNIFORM(myProg,
"fw_edgeColor");
544 glUniform4fv(iedgeColor,1,rgba);
545 igradientThreshold = GET_UNIFORM(myProg,
"fw_cosGradientThreshold");
546 glUniform1f(igradientThreshold,cosf(style->gradientThreshold));
550 case NODE_ProjectionVolumeStyle:
556 GLint iintensity, itype;
559 iintensity = GET_UNIFORM(myProg,
"fw_intensityThreshold");
560 glUniform1f(iintensity,style->intensityThreshold);
561 itype = GET_UNIFORM(myProg,
"fw_projType");
562 if(style->_type == 0){
563 ctype = style->type->strptr;
564 if(!strcmp(ctype,
"MIN"))
566 else if(!strcmp(ctype,
"MAX"))
568 else if(!strcmp(ctype,
"AVERAGE"))
570 style->_type = ktype;
572 glUniform1i(itype,style->_type);
575 case NODE_ShadedVolumeStyle:
578 GLint iphase, ilite, ishadow;
588 {0.0f, 0.0f, 0.0f, 1.0f},
589 {0.0f, 0.0f, 0.0f, 1.0f},
590 {0.8f, 0.8f, 0.8f, 1.0f},
591 {0.0f, 0.0f, 0.0f, 1.0f},
598 GLint myMaterialAmbient;
599 GLint myMaterialDiffuse;
600 GLint myMaterialSpecular;
601 GLint myMaterialShininess;
602 GLint myMaterialEmission;
604 GLint myMaterialBackAmbient;
605 GLint myMaterialBackDiffuse;
606 GLint myMaterialBackSpecular;
607 GLint myMaterialBackShininess;
608 GLint myMaterialBackEmission;
614 RENDER_MATERIAL_SUBNODES(style->material);
618 matone = get_material_oneSided();
619 mattwo = get_material_twoSided();
621 if (matone != NULL) {
625 memcpy(&myap->emissionColour,matone->_verifiedColor.p, 3*
sizeof(
float));
627 }
else if (mattwo != NULL) {
628 memcpy (&myap->fw_FrontMaterial, mattwo->_verifiedFrontColor.p, sizeof (
struct fw_MaterialParameters));
629 memcpy (&myap->fw_BackMaterial, mattwo->_verifiedBackColor.p, sizeof (
struct fw_MaterialParameters));
631 memcpy(&myap->emissionColour,mattwo->_verifiedFrontColor.p, 3*
sizeof(
float));
639 fw_FrontMaterial = &myap->fw_FrontMaterial;
640 fw_BackMaterial = &myap->fw_BackMaterial;
643 PRINT_GL_ERROR_IF_ANY(
"BEGIN sendMaterialsToShader");
648 myMaterialEmission = GET_UNIFORM(myProg,
"fw_FrontMaterial.emission");
649 myMaterialDiffuse = GET_UNIFORM(myProg,
"fw_FrontMaterial.diffuse");
650 myMaterialShininess = GET_UNIFORM(myProg,
"fw_FrontMaterial.shininess");
651 myMaterialAmbient = GET_UNIFORM(myProg,
"fw_FrontMaterial.ambient");
652 myMaterialSpecular = GET_UNIFORM(myProg,
"fw_FrontMaterial.specular");
654 myMaterialBackEmission = GET_UNIFORM(myProg,
"fw_BackMaterial.emission");
655 myMaterialBackDiffuse = GET_UNIFORM(myProg,
"fw_BackMaterial.diffuse");
656 myMaterialBackShininess = GET_UNIFORM(myProg,
"fw_BackMaterial.shininess");
657 myMaterialBackAmbient = GET_UNIFORM(myProg,
"fw_BackMaterial.ambient");
658 myMaterialBackSpecular = GET_UNIFORM(myProg,
"fw_BackMaterial.specular");
661 profile_start(
"sendvec");
662 GLUNIFORM4FV(myMaterialAmbient,1,fw_FrontMaterial->ambient);
663 GLUNIFORM4FV(myMaterialDiffuse,1,fw_FrontMaterial->diffuse);
664 GLUNIFORM4FV(myMaterialSpecular,1,fw_FrontMaterial->specular);
665 GLUNIFORM4FV(myMaterialEmission,1,fw_FrontMaterial->emission);
666 GLUNIFORM1F(myMaterialShininess,fw_FrontMaterial->shininess);
668 GLUNIFORM4FV(myMaterialBackAmbient,1,fw_BackMaterial->ambient);
669 GLUNIFORM4FV(myMaterialBackDiffuse,1,fw_BackMaterial->diffuse);
670 GLUNIFORM4FV(myMaterialBackSpecular,1,fw_BackMaterial->specular);
671 GLUNIFORM4FV(myMaterialBackEmission,1,fw_BackMaterial->emission);
672 GLUNIFORM1F(myMaterialBackShininess,fw_BackMaterial->shininess);
673 profile_end(
"sendvec");
685 if(style->_phaseFunction == 0){
686 if(!strcmp(style->phaseFunction->strptr,
"NONE"))
687 style->_phaseFunction = 1;
688 else if(!strcmp(style->phaseFunction->strptr,
"Henyey-Greenstein"))
689 style->_phaseFunction = 2;
691 iphase = GET_UNIFORM(myProg,
"fw_phase");
692 glUniform1i(iphase,style->_phaseFunction);
693 ilite = GET_UNIFORM(myProg,
"fw_lighting");
694 glUniform1i(ilite,style->lighting);
695 ishadow = GET_UNIFORM(myProg,
"fw_shadows");
696 glUniform1i(ishadow,style->shadows);
699 case NODE_SilhouetteEnhancementVolumeStyle:
706 GLint isilbound, isilretain, isilsharp;
707 isilbound = GET_UNIFORM(myProg,
"fw_BoundaryOpacity");
708 glUniform1f(isilbound,style->silhouetteBoundaryOpacity);
709 isilretain = GET_UNIFORM(myProg,
"fw_RetainedOpacity");
710 glUniform1f(isilretain,style->silhouetteRetainedOpacity);
711 isilsharp = GET_UNIFORM(myProg,
"fw_Sharpness");
712 glUniform1f(isilsharp,style->silhouetteSharpness);
715 case NODE_ToneMappedVolumeStyle:
724 icool = GET_UNIFORM(myProg,
"fw_coolColor");
725 glUniform4fv(icool,1,style->coolColor.c);
726 iwarm = GET_UNIFORM(myProg,
"fw_warmColor");
727 glUniform4fv(iwarm,1,style->warmColor.c);
743 {
"ONE_MINUS_ALPHA1",5},
744 {
"ONE_MINUS_ALPHA2",6},
747 int lookup_blendfunc(
const char *funcname){
752 if(!strcmp(blendfuncs[i].ctype,funcname)){
753 iret = blendfuncs[i].itype;
757 }
while(blendfuncs[i].ctype);
761 void sendExplicitMatriciesToShader (GLint ModelViewMatrix, GLint ProjectionMatrix, GLint NormalMatrix, GLint *TextureMatrix, GLint ModelViewInverseMatrix);
769 switch(vstyle->_nodeType){
770 case NODE_OpacityMapVolumeStyle:
774 tg->RenderFuncs.textureStackTop = 0;
775 tg->RenderFuncs.texturenode = NULL;
778 case NODE_BlendedVolumeStyle:
793 GLuint pixelType = GL_RGBA;
794 int *fbohandles = style->_fbohandles.p;
795 if(fbohandles[0] > 0){
797 static int iframe = 0;
801 int method_draw_cube, method_draw_quad;
805 if(0)
if(iframe==500){
811 glGetIntegerv(GL_VIEWPORT, iviewport);
813 ttip->texdata = MALLOC (GLvoid *, 4*iviewport[2]*iviewport[3]);
820 FW_GL_READPIXELS (iviewport[0],iviewport[1],iviewport[2],iviewport[3],pixelType,GL_UNSIGNED_BYTE, ttip->texdata);
821 ttip->x = iviewport[2];
822 ttip->y = iviewport[3];
828 sprintf(namebuf,
"%s%d.web3dit",
"blended_fbo_",0);
829 saveImage_web3dit(ttip, namebuf);
830 FREE_IF_NZ(ttip->texdata);
833 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbohandles[2], 0);
836 glClearColor(0.0f,0.0f,0.0f,0.0f);
837 FW_GL_CLEAR(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
841 nsubstyle = style->renderStyle ? 1 : 0;
842 caps = getVolumeProgram(&style->renderStyle,nsubstyle, SHADERFLAGS_VOLUME_DATA_BASIC);
844 render_GENERIC_volume_data(caps,&style->renderStyle,nsubstyle,style->voxels,(
struct X3D_VolumeData*)dataParent );
851 if(0)
if(iframe==500){
857 glGetIntegerv(GL_VIEWPORT, iviewport);
859 ttip->texdata = MALLOC (GLvoid *, 4*iviewport[2]*iviewport[3]);
865 FW_GL_READPIXELS (iviewport[0],iviewport[1],iviewport[2],iviewport[3],pixelType,GL_UNSIGNED_BYTE, ttip->texdata);
866 ttip->x = iviewport[2];
867 ttip->y = iviewport[3];
873 sprintf(namebuf,
"%s%d.web3dit",
"blended_fbo_",1);
874 saveImage_web3dit(ttip, namebuf);
875 FREE_IF_NZ(ttip->texdata);
876 printf(
"wrote blended_fbo_.web3dit \n");
878 popnset_framebuffer();
890 method_draw_cube = method_draw_quad = 0;
891 method_draw_cube = 1;
892 if(method_draw_cube){
894 GLint iwtc1, iwtc2, iwtf1, iwtf2;
902 GLint Vertices, mvm, proj;
903 double modelviewMatrix[16], projMatrix[16];
907 shader_requirements.volume = SHADERFLAGS_VOLUME_STYLE_BLENDED << 4;
909 caps = getMyShaders(shader_requirements);
910 enableGlobalShader(caps);
911 myProg = caps->myShaderProgram;
929 iwtc1 = GET_UNIFORM(myProg,
"fw_iwtc1");
930 iwtc2 = GET_UNIFORM(myProg,
"fw_iwtc2");
931 iwtf1 = GET_UNIFORM(myProg,
"fw_iwtf1");
932 iwtf2 = GET_UNIFORM(myProg,
"fw_iwtf2");
933 glUniform1f(iwtc1,style->weightConstant1);
934 glUniform1f(iwtc2,style->weightConstant2);
935 if(style->_weightFunction1 == 0)
936 style->_weightFunction1 = lookup_blendfunc(style->weightFunction1->strptr);
937 if(style->_weightFunction2 == 0)
938 style->_weightFunction2 = lookup_blendfunc(style->weightFunction2->strptr);
939 glUniform1i(iwtf1,style->_weightFunction1);
940 glUniform1i(iwtf2,style->_weightFunction2);
943 glActiveTexture ( GL_TEXTURE0 );
944 glBindTexture(GL_TEXTURE_2D,style->_fbohandles.p[1]);
945 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
947 glActiveTexture ( GL_TEXTURE0+1 );
948 glBindTexture(GL_TEXTURE_2D,style->_fbohandles.p[2]);
949 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
951 TextureUnit= GET_UNIFORM(myProg,
"fw_Texture_unit0");
952 glUniform1i(TextureUnit,0);
953 TextureUnit= GET_UNIFORM(myProg,
"fw_Texture_unit1");
954 glUniform1i(TextureUnit,1);
958 if(style->weightTransferFunction1){
964 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, style->weightTransferFunction1,tmpN);
965 tg->RenderFuncs.texturenode = (
void*)tmpN;
970 loadTextureNode(tmpN,NULL);
971 tti = getTableTableFromTextureNode(tmpN);
972 if(tti && tti->status >= TEX_LOADED){
973 glActiveTexture(GL_TEXTURE0+2);
974 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
978 if(style->weightTransferFunction2){
984 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, style->weightTransferFunction2,tmpN);
985 tg->RenderFuncs.texturenode = (
void*)tmpN;
990 loadTextureNode(tmpN,NULL);
991 tti = getTableTableFromTextureNode(tmpN);
992 if(tti && tti->status >= TEX_LOADED){
993 glActiveTexture(GL_TEXTURE0+3);
994 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
998 iopactex = GET_UNIFORM(myProg,
"fw_haveTransfers");
999 glUniform1i(iopactex,havetextures);
1002 glGetIntegerv(GL_VIEWPORT, iviewport);
1004 vp = GET_UNIFORM(myProg,
"fw_viewport");
1005 viewport[0] = (float)iviewport[0];
1006 viewport[1] = (float)iviewport[1];
1007 viewport[2] = (float)iviewport[2];
1008 viewport[3] = (float)iviewport[3];
1009 GLUNIFORM4F(vp,viewport[0],viewport[1],viewport[2],viewport[3]);
1013 Vertices = GET_ATTRIB(myProg,
"fw_Vertex");
1014 mvm = GET_UNIFORM(myProg,
"fw_ModelViewMatrix");
1015 proj = GET_UNIFORM(myProg,
"fw_ProjectionMatrix");
1016 sendExplicitMatriciesToShader(mvm,proj,-1,NULL,-1);
1017 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
1018 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, projMatrix);
1020 glEnableVertexAttribArray(Vertices);
1022 glVertexAttribPointer(Vertices, 3, GL_FLOAT, GL_FALSE, 0, dataParent->_boxtris);
1025 glEnable(GL_CULL_FACE);
1027 glDrawArrays(GL_TRIANGLES,0,36);
1028 glDisable(GL_CULL_FACE);
1030 }
else if(method_draw_quad){
1041 case NODE_ComposedVolumeStyle:
1046 for(i=0;i<style->renderStyle.n;i++){
1047 fin_volumestyle(style->renderStyle.p[i],dataParent);
1057 int volstyle_needs_normal(
struct X3D_Node *vstyle){
1074 need_normal = FALSE;
1075 if(style0->enabled){
1076 switch(vstyle->_nodeType){
1077 case NODE_ComposedVolumeStyle:
1081 for(i=0;i<style->renderStyle.n;i++){
1082 need_normal = need_normal || volstyle_needs_normal(style->renderStyle.p[i]);
1086 case NODE_CartoonVolumeStyle:
1087 case NODE_EdgeEnhancementVolumeStyle:
1088 case NODE_ShadedVolumeStyle:
1089 case NODE_SilhouetteEnhancementVolumeStyle:
1090 case NODE_ToneMappedVolumeStyle:
1094 need_normal = need_normal || (style->surfaceNormals == NULL);
1111 printf(
"compile_isosurfacevolumedata not implemented\n");
1122 printf(
"compile_segmentedvolumedata \n");
1126 static int once = 0;
1127 unsigned int volflags;
1132 ConsoleMessage(
"getVolumeProgram\n");
1135 for(i=0;i<nstyle;i++){
1137 if(style0->enabled){
1138 volflags = prep_volumestyle(renderStyle[i], volflags);
1142 volflags = SHADERFLAGS_VOLUME_STYLE_DEFAULT;
1146 printf(
"volflags= ");
1148 printf(
"%d ",((volflags >> (8-i-1)*4) & 0xF));
1171 shader_requirements.volume = VOLUME_DATA_FLAG;
1172 shader_requirements.volume |= (volflags << 4);
1174 shader_requirements.base |= getShaderFlags().base & CLIPPLANE_SHADER;
1176 caps = getMyShaders(shader_requirements);
1177 enableGlobalShader(caps);
1188 GLint inids, ienable;
1190 int *enabledIDs = node->segmentEnabled.p;
1191 int nIDs = node->segmentEnabled.n;
1192 myProg = caps->myShaderProgram;
1198 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, segmentIDs,tmpN);
1199 tg->RenderFuncs.texturenode = (
void*)tmpN;
1203 tti = getTableTableFromTextureNode(tmpN);
1204 if(tti && tti->status >= TEX_LOADED){
1209 GLint tex3dUseVertex, ttiles, repeatSTR, magFilter;
1210 ttiles = GET_UNIFORM(myProg,
"tex3dTiles");
1211 GLUNIFORM1IV(ttiles,3,tti->tiles);
1214 tex3dUseVertex = GET_UNIFORM(myProg,
"tex3dUseVertex");
1215 glUniform1i(tex3dUseVertex,0);
1216 repeatSTR = GET_UNIFORM(myProg,
"repeatSTR");
1217 glUniform1iv(repeatSTR,3,tti->repeatSTR);
1218 magFilter = GET_UNIFORM(myProg,
"magFilter");
1219 glUniform1i(magFilter,0);
1221 TextureUnit= GET_UNIFORM(myProg,
"fw_Texture_unit1");
1222 glUniform1i(TextureUnit,itexture);
1223 glActiveTexture(GL_TEXTURE0+itexture);
1224 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
1225 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1228 inids = GET_UNIFORM(myProg,
"fw_nIDs");
1229 glUniform1i(inids,nIDs);
1230 ienable = GET_UNIFORM(myProg,
"fw_enableIDs");
1231 glUniform1iv(ienable,nIDs,enabledIDs);
1234 if(node->renderStyle.n){
1235 int i, *styleflags,instyles;
1238 styleflags = MALLOC(
int*,
sizeof(
int)*node->renderStyle.n);
1239 for(i=0;i<node->renderStyle.n;i++){
1240 styleflags[i] = prep_volumestyle(node->renderStyle.p[i],0);
1243 istyles = GET_UNIFORM(myProg,
"fw_surfaceStyles");
1244 glUniform1iv(istyles,node->renderStyle.n,styleflags);
1245 instyles = GET_UNIFORM(myProg,
"fw_nStyles");
1246 glUniform1i(instyles,node->renderStyle.n);
1253 float *getTransformedClipPlanes();
1254 int getClipPlaneCount();
1257 static int once = 0;
1260 GLint Vertices, mvm, proj, mvpi;
1261 double modelviewMatrix[16],projMatrix[16], mvp[16], mvpinverse[16];
1264 GLint iclipplanes, inclipplanes;
1273 myProg = caps->myShaderProgram;
1278 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, voxels,tmpN);
1279 tg->RenderFuncs.texturenode = (
void*)tmpN;
1298 tti = getTableTableFromTextureNode(tmpN);
1299 if(tti && tti->status >= TEX_LOADED){
1300 GLint ttiles, tex3dUseVertex,repeatSTR,magFilter;
1301 ttiles = GET_UNIFORM(myProg,
"tex3dTiles");
1302 GLUNIFORM1IV(ttiles,3,tti->tiles);
1305 tex3dUseVertex = GET_UNIFORM(myProg,
"tex3dUseVertex");
1306 glUniform1i(tex3dUseVertex,0);
1307 repeatSTR = GET_UNIFORM(myProg,
"repeatSTR");
1308 glUniform1iv(repeatSTR,3,tti->repeatSTR);
1309 magFilter = GET_UNIFORM(myProg,
"magFilter");
1310 glUniform1i(magFilter,1);
1312 glActiveTexture(GL_TEXTURE0);
1313 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
1314 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1320 for(i=0;i<nstyle;i++){
1322 if(style0->enabled){
1323 render_volumestyle(renderStyle[i],myProg);
1331 Vertices = GET_ATTRIB(myProg,
"fw_Vertex");
1332 mvm = GET_UNIFORM(myProg,
"fw_ModelViewMatrix");
1333 proj = GET_UNIFORM(myProg,
"fw_ProjectionMatrix");
1335 ConsoleMessage(
"vertices %d mvm %d proj %d\n",Vertices,mvm,proj);
1336 sendExplicitMatriciesToShader(mvm,proj,-1,NULL,-1);
1337 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
1338 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, projMatrix);
1341 __gluMultMatricesd(modelviewMatrix, projMatrix, mvp);
1342 if (!__gluInvertMatrixd(mvp, mvpinverse))
return;
1344 matmultiplyFULL(mvp,modelviewMatrix,projMatrix);
1347 matinverseFULL(mvpinverse,mvp);
1349 matdouble2float4(spmat,mvpinverse);
1351 mvpi = GET_UNIFORM(myProg,
"fw_ModelViewProjInverse");
1352 GLUNIFORMMATRIX4FV(mvpi,1,GL_FALSE,spmat);
1357 clipplanes = getTransformedClipPlanes();
1359 nsend = getClipPlaneCount();
1360 iclipplanes = GET_UNIFORM(myProg,
"fw_clipplanes");
1361 inclipplanes = GET_UNIFORM(myProg,
"fw_nclipplanes");
1363 GLUNIFORM4FV(iclipplanes,nsend,clipplanes);
1364 GLUNIFORM1I(inclipplanes,nsend);
1375 if (caps->haveLightInShader) {
1376 sendLightInfo(caps);
1377 sendFogToShader(caps);
1384 glGetIntegerv(GL_VIEWPORT, iviewport);
1385 vp = GET_UNIFORM(myProg,
"fw_viewport");
1386 viewport[0] = (float)iviewport[0];
1387 viewport[1] = (float)iviewport[1];
1388 viewport[2] = (float)iviewport[2];
1389 viewport[3] = (float)iviewport[3];
1390 GLUNIFORM4F(vp,viewport[0],viewport[1],viewport[2],viewport[3]);
1391 dim = GET_UNIFORM(myProg,
"fw_dimensions");
1392 dimensions = node->dimensions.c;
1393 GLUNIFORM3F(dim,dimensions[0],dimensions[1],dimensions[2]);
1395 if(!once) ConsoleMessage(
"dim %d vp %d \n",dim,vp );
1398 glEnableVertexAttribArray(Vertices);
1399 glVertexAttribPointer(Vertices, 3, GL_FLOAT, GL_FALSE, 0, node->_boxtris);
1401 glEnable(GL_CULL_FACE);
1412 glDrawArrays(GL_TRIANGLES,0,36);
1413 glDisable(GL_CULL_FACE);
1415 tg->RenderFuncs.textureStackTop = 0;
1416 tg->RenderFuncs.texturenode = NULL;
1420 for(i=0;i<nstyle;i++)
1421 fin_volumestyle(renderStyle[i],node);
1433 static int once = 0;
1436 if (renderstate()->render_blend == (node->_renderFlags & VF_Blend)) {
1440 printf(
"child segmentedvolumedata \n");
1444 caps = getVolumeProgram(node->renderStyle.p,node->renderStyle.n, SHADERFLAGS_VOLUME_DATA_SEGMENT);
1447 render_SEGMENTED_volume_data(caps,node->segmentIdentifiers,itexture,node);
1449 render_GENERIC_volume_data(caps,node->renderStyle.p,node->renderStyle.n,node->voxels,(
struct X3D_VolumeData*)node );
1464 GLint istep, itol,ivals,invals;
1465 myProg= caps->myShaderProgram;
1466 istep = GET_UNIFORM(myProg,
"fw_stepSize");
1467 glUniform1f(istep,node->contourStepSize);
1468 itol = GET_UNIFORM(myProg,
"fw_tolerance");
1469 glUniform1f(itol,node->surfaceTolerance);
1471 ivals = GET_UNIFORM(myProg,
"fw_surfaceVals");
1472 glUniform1fv(ivals,node->surfaceValues.n,node->surfaceValues.p);
1473 invals = GET_UNIFORM(myProg,
"fw_nVals");
1474 glUniform1i(invals,node->surfaceValues.n);
1475 if(node->renderStyle.n){
1479 int *styleflags = MALLOC(
int*,
sizeof(
int)*node->renderStyle.n);
1480 for(i=0;i<node->renderStyle.n;i++){
1481 styleflags[i] = prep_volumestyle(node->renderStyle.p[i],0);
1484 glUniform1iv(ivals,node->renderStyle.n,styleflags);
1485 instyles = GET_UNIFORM(myProg,
"fw_nStyles");
1486 glUniform1i(instyles,node->renderStyle.n);
1503 static int once = 0;
1505 if (renderstate()->render_blend == (node->_renderFlags & VF_Blend)) {
1506 unsigned int voldataflags;
1511 printf(
"child segmentedvolumedata \n");
1512 voldataflags = SHADERFLAGS_VOLUME_DATA_ISO;
1514 MODE = node->surfaceValues.n == 1 ? 1 : 3;
1515 MODE = node->contourStepSize != 0.0f && MODE == 1 ? 2 : 1;
1517 voldataflags |= SHADERFLAGS_VOLUME_DATA_ISO_MODE3;
1518 caps = getVolumeProgram(node->renderStyle.p,node->renderStyle.n, voldataflags);
1520 render_ISO_volume_data(caps,node);
1522 render_GENERIC_volume_data(caps,node->renderStyle.p,node->renderStyle.n,node->voxels,(
struct X3D_VolumeData*)node );
1531 static int once = 0;
1534 if (renderstate()->render_blend == (node->_renderFlags & VF_Blend)) {
1537 printf(
"child volumedata \n");
1538 if(node->renderStyle) nstyles = 1;
1539 caps = getVolumeProgram(&node->renderStyle,nstyles, SHADERFLAGS_VOLUME_DATA_BASIC);
1541 render_GENERIC_volume_data(caps,&node->renderStyle,nstyles,node->voxels,(
struct X3D_VolumeData*)node );