35#include <libFreeWRL.h>
37#include "../vrml_parser/Structs.h"
38#include "../main/headers.h"
39#include "../opengl/Frustum.h"
40#include "../opengl/OpenGL_Utils.h"
41#include "../opengl/Textures.h"
42#include "../scenegraph/Component_Shape.h"
43#include "../scenegraph/RenderFuncs.h"
44#include "../scenegraph/LinearAlgebra.h"
187 GLuint front_texture;
193}* ppComponent_VolumeRendering;
194void *Component_VolumeRendering_constructor(){
199void Component_VolumeRendering_init(
struct tComponent_VolumeRendering *t){
202 t->prv = Component_VolumeRendering_constructor();
204 ppComponent_VolumeRendering p = (ppComponent_VolumeRendering)t->prv;
206 p->front_texture = 0;
214void Component_VolumeRendering_clear(
struct tComponent_VolumeRendering *t){
218 ppComponent_VolumeRendering p = (ppComponent_VolumeRendering)t->prv;
230GLfloat 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, };
236float boxvert [24] = {
237-.5f,-.5f, .5f, .5f,-.5f, .5f, -.5f,.5f, .5f, .5f,.5f, .5f,
238-.5f,-.5f,-.5f, .5f,-.5f,-.5f, -.5f,.5f,-.5f, .5f,.5f,-.5f,
241int boxtriindccw [48] = {
255int boxtriindcw [48] = {
270 int i,j,itri, ind, jvert;
273 ConsoleMessage(
"compile_volumedata\n");
274 if(node->_boxtris == NULL){
275 node->_boxtris = MALLOC(
void *,108 *
sizeof(
float));
277 boxtris = (
float*)node->_boxtris;
281 boxtris[i*3 + j] = .5f * node->dimensions.c[j] * box[i*3 + j];
285 for(itri=0;itri<12;itri++){
286 for(jvert=0;jvert<3;jvert++) {
288 ind = boxtriindccw[itri*4 + jvert];
289 vert = &boxvert[ind*3];
291 boxtris[(itri*3 +jvert)*3 + j] = node->dimensions.c[j]*vert[j];
299void pushnset_framebuffer(
int ibuffer);
300void popnset_framebuffer();
304#ifdef GL_DEPTH_COMPONENT32
305#define FW_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT32
307#define FW_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT16
312void __gluMultMatricesd(
const GLDOUBLE a[16],
const GLDOUBLE b[16], GLDOUBLE r[16]);
313int __gluInvertMatrixd(
const GLDOUBLE m[16], GLDOUBLE invOut[16]);
314ivec4 get_current_viewport();
316unsigned int prep_volumestyle(
struct X3D_Node *vstyle,
unsigned int volflags){
319 switch(vstyle->_nodeType){
320 case NODE_OpacityMapVolumeStyle:
321 volflags = volflags << 4;
322 volflags |= SHADERFLAGS_VOLUME_STYLE_OPACITY;
324 case NODE_BlendedVolumeStyle:
329 case NODE_BoundaryEnhancementVolumeStyle:
330 volflags = volflags << 4;
331 volflags |= SHADERFLAGS_VOLUME_STYLE_BOUNDARY;
333 case NODE_CartoonVolumeStyle:
334 volflags = volflags << 4;
335 volflags |= SHADERFLAGS_VOLUME_STYLE_CARTOON;
337 case NODE_ComposedVolumeStyle:
344 for(i=0;i<style->renderStyle.n;i++){
345 volflags = prep_volumestyle(style->renderStyle.p[i], volflags);
349 case NODE_EdgeEnhancementVolumeStyle:
350 volflags = volflags << 4;
351 volflags |= SHADERFLAGS_VOLUME_STYLE_EDGE;
353 case NODE_ProjectionVolumeStyle:
354 volflags = volflags << 4;
355 volflags |= SHADERFLAGS_VOLUME_STYLE_PROJECTION;
357 case NODE_ShadedVolumeStyle:
358 volflags = volflags << 4;
359 volflags |= SHADERFLAGS_VOLUME_STYLE_SHADED;
361 case NODE_SilhouetteEnhancementVolumeStyle:
362 volflags = volflags << 4;
363 volflags |= SHADERFLAGS_VOLUME_STYLE_SILHOUETTE;
365 case NODE_ToneMappedVolumeStyle:
366 volflags = volflags << 4;
367 volflags |= SHADERFLAGS_VOLUME_STYLE_TONE;
375void applysurfaceNormalTexture(
struct X3D_Node* surfaceNormals, GLint myProg) {
378 if (surfaceNormals) {
381 textureTableIndexStruct_s* tti;
382 ttglobal tg = gglobal();
383 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node*, surfaceNormals, tmpN);
384 tg->RenderFuncs.texturenode = (
void*)tmpN;
389 loadTextureNode(tmpN, NULL);
390 tti = getTableTableFromTextureNode(tmpN);
391 if (tti && tti->status >= TEX_LOADED) {
392 glActiveTexture(GL_TEXTURE0 + 3);
393 glBindTexture(GL_TEXTURE_2D, tti->OpenGLTexture);
394 GLuint tu3 = GET_UNIFORM(myProg,
"fw_Texture_unit3");
397 if (tti->channels == 3) havetexture = 3;
400 gradtex = GET_UNIFORM(myProg,
"fw_gradTexture");
401 glUniform1i(gradtex, havetexture);
407void pushnset_viewport(
float *vpFraction);
408void popnset_viewport();
409int haveFrameBufferObject();
410void initialize_front_and_back_material_params();
411void render_volumestyle(
struct X3D_Node *vstyle, GLint myProg){
414 switch(vstyle->_nodeType){
415 case NODE_OpacityMapVolumeStyle:
424 if(style->transferFunction){
427 textureTableIndexStruct_s *tti;
428 ttglobal tg = gglobal();
430 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, style->transferFunction,tmpN);
431 tg->RenderFuncs.texturenode = (
void*)tmpN;
436 loadTextureNode(tmpN,NULL);
437 tti = getTableTableFromTextureNode(tmpN);
438 if(tti && tti->status >= TEX_LOADED){
439 glActiveTexture(GL_TEXTURE0+3);
440 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
444 iopactex = GET_UNIFORM(myProg,
"fw_opacTexture");
445 glUniform1i(iopactex,havetexture);
449 case NODE_BlendedVolumeStyle:
465 int *fbohandles = style->_fbohandles.p;
467 float vp[4] = {0.0f,1.0f,0.0f,1.0f};
469 glGetIntegerv(GL_VIEWPORT, iviewport);
470 if(haveFrameBufferObject()){
471 if(fbohandles[0] == 0){
472 GLuint depthrenderbuffer;
474 glGenFramebuffers(1, (GLuint *) &fbohandles[0]);
475 pushnset_framebuffer(fbohandles[0]);
478 glGenRenderbuffers(1, &depthrenderbuffer);
479 glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
480 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, iviewport[2],iviewport[3]);
481 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
484 glGenTextures(1,(GLuint *) &fbohandles[1]);
485 glBindTexture(GL_TEXTURE_2D, fbohandles[1]);
486 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iviewport[2], iviewport[3], 0, GL_RGBA , GL_UNSIGNED_BYTE, 0);
487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
490 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbohandles[1], 0);
493 glGenTextures(1,(GLuint *)&fbohandles[2]);
494 glBindTexture(GL_TEXTURE_2D, fbohandles[2]);
495 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iviewport[2], iviewport[3], 0, GL_RGBA , GL_UNSIGNED_BYTE, 0);
496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
497 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
502 if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
503 printf(
"ouch framebuffer not complete\n");
506 pushnset_framebuffer(fbohandles[0]);
507 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbohandles[1], 0);
510 pushnset_viewport(vp);
511 glViewport(0,0,iviewport[2],iviewport[3]);
512 glClearColor(0.0f,0.0f,0.0f,0.0f);
513 FW_GL_CLEAR(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
518 case NODE_BoundaryEnhancementVolumeStyle:
526 GLint ibebound, iberetain, ibefactor;
527 ibebound = GET_UNIFORM(myProg,
"fw_boundaryOpacity");
528 glUniform1f(ibebound,style->boundaryOpacity);
529 iberetain = GET_UNIFORM(myProg,
"fw_retainedOpacity");
530 glUniform1f(iberetain,style->retainedOpacity);
531 ibefactor = GET_UNIFORM(myProg,
"fw_opacityFactor");
532 glUniform1f(ibefactor,style->opacityFactor);
533 applysurfaceNormalTexture(style->surfaceNormals,myProg);
536 case NODE_CartoonVolumeStyle:
544 GLint itoonsteps, itoonortho, itoonparallel;
545 itoonsteps = GET_UNIFORM(myProg,
"fw_colorSteps");
546 glUniform1i(itoonsteps,style->colorSteps);
547 itoonortho = GET_UNIFORM(myProg,
"fw_orthoColor");
548 glUniform4fv(itoonortho,1,style->orthogonalColor.c);
549 itoonparallel = GET_UNIFORM(myProg,
"fw_paraColor");
550 glUniform4fv(itoonparallel,1,style->parallelColor.c);
551 applysurfaceNormalTexture(style->surfaceNormals, myProg);
555 case NODE_ComposedVolumeStyle:
560 for(i=0;i<style->renderStyle.n;i++){
561 render_volumestyle(style->renderStyle.p[i], myProg);
565 case NODE_EdgeEnhancementVolumeStyle:
574 GLint iedgeColor, igradientThreshold;
576 rgba = style->edgeColor.c;
577 iedgeColor = GET_UNIFORM(myProg,
"fw_edgeColor");
578 glUniform4fv(iedgeColor,1,
rgba);
579 igradientThreshold = GET_UNIFORM(myProg,
"fw_cosGradientThreshold");
580 glUniform1f(igradientThreshold,cosf(style->gradientThreshold));
582 applysurfaceNormalTexture(style->surfaceNormals,myProg);
585 case NODE_ProjectionVolumeStyle:
591 GLint iintensity, itype;
594 iintensity = GET_UNIFORM(myProg,
"fw_intensityThreshold");
595 glUniform1f(iintensity,style->intensityThreshold);
596 itype = GET_UNIFORM(myProg,
"fw_projType");
597 if(style->_type == 0){
598 ctype = style->type->strptr;
599 if(!strcmp(ctype,
"MIN"))
601 else if(!strcmp(ctype,
"MAX"))
603 else if(!strcmp(ctype,
"AVERAGE"))
605 style->_type = ktype;
607 glUniform1i(itype,style->_type);
610 case NODE_ShadedVolumeStyle:
613 GLint iphase, ilite, ishadow;
627 GLint myMaterialDiffuse;
628 GLint myMaterialEmissive;
629 GLint myMaterialSpecular;
630 GLint myMaterialAmbient;
631 GLint myMaterialShininess;
632 GLint myMaterialOcclusion;
633 GLint myMaterialNormalScale;
634 GLint myMaterialTransparency;
636 GLint myMaterialBackDiffuse;
637 GLint myMaterialBackEmissive;
638 GLint myMaterialBackSpecular;
639 GLint myMaterialBackShininess;
640 GLint myMaterialBackOcclusion;
641 GLint myMaterialBackNormalScale;
642 GLint myMaterialBackAmbient;
643 GLint myMaterialBackTransparency;
646 void initialize_front_and_back_material_params();
647 RENDER_MATERIAL_SUBNODES(style->material);
672 fw_FrontMaterial = &myap->fw_FrontMaterial;
673 fw_BackMaterial = &myap->fw_BackMaterial;
676 PRINT_GL_ERROR_IF_ANY(
"BEGIN sendMaterialsToShader");
681 myMaterialDiffuse = GET_UNIFORM(myProg,
"fw_FrontMaterial.diffuse");
682 myMaterialEmissive = GET_UNIFORM(myProg,
"fw_FrontMaterial.emissive");
683 myMaterialSpecular = GET_UNIFORM(myProg,
"fw_FrontMaterial.specular");
684 myMaterialAmbient = GET_UNIFORM(myProg,
"fw_FrontMaterial.ambient");
685 myMaterialShininess = GET_UNIFORM(myProg,
"fw_FrontMaterial.shininess");
686 myMaterialOcclusion = GET_UNIFORM(myProg,
"fw_FrontMaterial.occlusion");
687 myMaterialNormalScale = GET_UNIFORM(myProg,
"fw_FrontMaterial.normalScale");
688 myMaterialTransparency = GET_UNIFORM(myProg,
"fw_FrontMaterial.transparency");
690 myMaterialBackDiffuse = GET_UNIFORM(myProg,
"fw_BackMaterial.diffuse");
691 myMaterialBackEmissive = GET_UNIFORM(myProg,
"fw_BackMaterial.emissive");
692 myMaterialBackSpecular = GET_UNIFORM(myProg,
"fw_BackMaterial.specular");
693 myMaterialBackAmbient = GET_UNIFORM(myProg,
"fw_BackMaterial.ambient");
694 myMaterialBackShininess = GET_UNIFORM(myProg,
"fw_BackMaterial.shininess");
695 myMaterialBackOcclusion = GET_UNIFORM(myProg,
"fw_BackMaterial.occlusion");
696 myMaterialBackNormalScale = GET_UNIFORM(myProg,
"fw_BackMaterial.normalScale");
697 myMaterialBackTransparency = GET_UNIFORM(myProg,
"fw_BackMaterial.transparency");
700 profile_start(
"sendvec");
701 GLUNIFORM3FV(myMaterialDiffuse,1,fw_FrontMaterial->diffuse);
702 GLUNIFORM3FV(myMaterialEmissive,1,fw_FrontMaterial->emissive);
703 GLUNIFORM3FV(myMaterialSpecular,1,fw_FrontMaterial->specular);
704 GLUNIFORM1F(myMaterialAmbient,fw_FrontMaterial->ambient);
705 GLUNIFORM1F(myMaterialShininess,fw_FrontMaterial->shininess);
706 GLUNIFORM1F(myMaterialOcclusion, fw_FrontMaterial->occlusion);
707 GLUNIFORM1F(myMaterialNormalScale, fw_FrontMaterial->normalScale);
708 GLUNIFORM1F(myMaterialTransparency,fw_FrontMaterial->transparency);
710 GLUNIFORM3FV(myMaterialBackDiffuse,1,fw_BackMaterial->diffuse);
711 GLUNIFORM3FV(myMaterialBackSpecular,1,fw_BackMaterial->specular);
712 GLUNIFORM3FV(myMaterialBackEmissive,1,fw_BackMaterial->emissive);
713 GLUNIFORM1F(myMaterialBackAmbient,fw_BackMaterial->ambient);
714 GLUNIFORM1F(myMaterialBackShininess,fw_BackMaterial->shininess);
715 GLUNIFORM1F(myMaterialBackOcclusion, fw_BackMaterial->occlusion);
716 GLUNIFORM1F(myMaterialBackNormalScale, fw_BackMaterial->normalScale);
717 GLUNIFORM1F(myMaterialBackTransparency,fw_BackMaterial->transparency);
718 profile_end(
"sendvec");
730 if(style->_phaseFunction == 0){
731 if(!strcmp(style->phaseFunction->strptr,
"NONE"))
732 style->_phaseFunction = 1;
733 else if(!strcmp(style->phaseFunction->strptr,
"Henyey-Greenstein"))
734 style->_phaseFunction = 2;
736 iphase = GET_UNIFORM(myProg,
"fw_phase");
737 glUniform1i(iphase,style->_phaseFunction);
738 ilite = GET_UNIFORM(myProg,
"fw_lighting");
739 glUniform1i(ilite,style->lighting);
740 ishadow = GET_UNIFORM(myProg,
"fw_shadows");
741 glUniform1i(ishadow,style->shadows);
742 applysurfaceNormalTexture(style->surfaceNormals, myProg);
746 case NODE_SilhouetteEnhancementVolumeStyle:
753 GLint isilbound, isilretain, isilsharp;
754 isilbound = GET_UNIFORM(myProg,
"fw_BoundaryOpacity");
755 glUniform1f(isilbound,style->silhouetteBoundaryOpacity);
756 isilretain = GET_UNIFORM(myProg,
"fw_RetainedOpacity");
757 glUniform1f(isilretain,style->silhouetteRetainedOpacity);
758 isilsharp = GET_UNIFORM(myProg,
"fw_Sharpness");
759 glUniform1f(isilsharp,style->silhouetteSharpness);
760 applysurfaceNormalTexture(style->surfaceNormals, myProg);
764 case NODE_ToneMappedVolumeStyle:
773 icool = GET_UNIFORM(myProg,
"fw_coolColor");
774 glUniform4fv(icool,1,style->coolColor.c);
775 iwarm = GET_UNIFORM(myProg,
"fw_warmColor");
776 glUniform4fv(iwarm,1,style->warmColor.c);
777 applysurfaceNormalTexture(style->surfaceNormals, myProg);
794{
"ONE_MINUS_ALPHA1",5},
795{
"ONE_MINUS_ALPHA2",6},
798int lookup_blendfunc(
const char *funcname){
803 if(!strcmp(blendfuncs[i].ctype,funcname)){
804 iret = blendfuncs[i].itype;
808 }
while(blendfuncs[i].ctype);
812void sendExplicitMatriciesToShader (GLint ModelViewMatrix, GLint ProjectionMatrix, GLint NormalMatrix, GLint *TextureMatrix, GLint ModelViewInverseMatrix);
813void render_GENERIC_volume_data(s_shader_capabilities_t *caps,
struct X3D_Node **renderStyle,
int nstyle,
struct X3D_Node *voxels,
struct X3D_VolumeData *node );
814s_shader_capabilities_t * getVolumeProgram(
struct X3D_Node **renderStyle,
int nstyle,
int VOLUME_DATA_FLAG);
820 switch(vstyle->_nodeType){
821 case NODE_OpacityMapVolumeStyle:
823 ttglobal tg = gglobal();
825 tg->RenderFuncs.textureStackTop = 0;
826 tg->RenderFuncs.texturenode = NULL;
829 case NODE_BlendedVolumeStyle:
844 GLuint pixelType = GL_RGBA;
845 int *fbohandles = style->_fbohandles.p;
846 if(fbohandles[0] > 0){
848 static int iframe = 0;
849 s_shader_capabilities_t *caps;
852 int method_draw_cube, method_draw_quad;
856 if(0)
if(iframe==500){
860 textureTableIndexStruct_s ttipp, *ttip;
862 glGetIntegerv(GL_VIEWPORT, iviewport);
864 ttip->texdata = MALLOC (GLvoid *, 4*iviewport[2]*iviewport[3]);
871 FW_GL_READPIXELS (iviewport[0],iviewport[1],iviewport[2],iviewport[3],pixelType,GL_UNSIGNED_BYTE, ttip->texdata);
872 ttip->x = iviewport[2];
873 ttip->y = iviewport[3];
879 sprintf(namebuf,
"%s%d.web3dit",
"blended_fbo_",0);
880 saveImage_web3dit(ttip, namebuf);
881 FREE_IF_NZ(ttip->texdata);
884 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbohandles[2], 0);
887 glClearColor(0.0f,0.0f,0.0f,0.0f);
888 FW_GL_CLEAR(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
892 nsubstyle = style->renderStyle ? 1 : 0;
893 caps = getVolumeProgram(&style->renderStyle,nsubstyle, SHADERFLAGS_VOLUME_DATA_BASIC);
895 render_GENERIC_volume_data(caps,&style->renderStyle,nsubstyle,style->voxels,(
struct X3D_VolumeData*)dataParent );
902 if(0)
if(iframe==500){
906 textureTableIndexStruct_s ttipp, *ttip;
908 glGetIntegerv(GL_VIEWPORT, iviewport);
910 ttip->texdata = MALLOC (GLvoid *, 4*iviewport[2]*iviewport[3]);
916 FW_GL_READPIXELS (iviewport[0],iviewport[1],iviewport[2],iviewport[3],pixelType,GL_UNSIGNED_BYTE, ttip->texdata);
917 ttip->x = iviewport[2];
918 ttip->y = iviewport[3];
924 sprintf(namebuf,
"%s%d.web3dit",
"blended_fbo_",1);
925 saveImage_web3dit(ttip, namebuf);
926 FREE_IF_NZ(ttip->texdata);
927 printf(
"wrote blended_fbo_.web3dit \n");
929 popnset_framebuffer();
941 method_draw_cube = method_draw_quad = 0;
942 method_draw_cube = 1;
943 if(method_draw_cube){
945 GLint iwtc1, iwtc2, iwtf1, iwtf2;
952 s_shader_capabilities_t *caps;
953 GLint Vertices, mvm, proj;
954 double modelviewMatrix[16], projMatrix[16];
958 shader_requirements.volume = SHADERFLAGS_VOLUME_STYLE_BLENDED << 4;
960 caps = getMyShaders(shader_requirements);
961 enableGlobalShader(caps);
962 myProg = caps->myShaderProgram;
980 iwtc1 = GET_UNIFORM(myProg,
"fw_iwtc1");
981 iwtc2 = GET_UNIFORM(myProg,
"fw_iwtc2");
982 iwtf1 = GET_UNIFORM(myProg,
"fw_iwtf1");
983 iwtf2 = GET_UNIFORM(myProg,
"fw_iwtf2");
984 glUniform1f(iwtc1,style->weightConstant1);
985 glUniform1f(iwtc2,style->weightConstant2);
986 if(style->_weightFunction1 == 0)
987 style->_weightFunction1 = lookup_blendfunc(style->weightFunction1->strptr);
988 if(style->_weightFunction2 == 0)
989 style->_weightFunction2 = lookup_blendfunc(style->weightFunction2->strptr);
990 glUniform1i(iwtf1,style->_weightFunction1);
991 glUniform1i(iwtf2,style->_weightFunction2);
994 glActiveTexture ( GL_TEXTURE0 );
995 glBindTexture(GL_TEXTURE_2D,style->_fbohandles.p[1]);
996 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
998 glActiveTexture ( GL_TEXTURE0+1 );
999 glBindTexture(GL_TEXTURE_2D,style->_fbohandles.p[2]);
1000 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1002 TextureUnit= GET_UNIFORM(myProg,
"fw_Texture_unit0");
1003 glUniform1i(TextureUnit,0);
1004 TextureUnit= GET_UNIFORM(myProg,
"fw_Texture_unit1");
1005 glUniform1i(TextureUnit,1);
1009 if(style->weightTransferFunction1){
1012 textureTableIndexStruct_s *tti;
1013 ttglobal tg = gglobal();
1015 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, style->weightTransferFunction1,tmpN);
1016 tg->RenderFuncs.texturenode = (
void*)tmpN;
1021 loadTextureNode(tmpN,NULL);
1022 tti = getTableTableFromTextureNode(tmpN);
1023 if(tti && tti->status >= TEX_LOADED){
1024 glActiveTexture(GL_TEXTURE0+2);
1025 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
1029 if(style->weightTransferFunction2){
1032 textureTableIndexStruct_s *tti;
1033 ttglobal tg = gglobal();
1035 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, style->weightTransferFunction2,tmpN);
1036 tg->RenderFuncs.texturenode = (
void*)tmpN;
1041 loadTextureNode(tmpN,NULL);
1042 tti = getTableTableFromTextureNode(tmpN);
1043 if(tti && tti->status >= TEX_LOADED){
1044 glActiveTexture(GL_TEXTURE0+3);
1045 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
1049 iopactex = GET_UNIFORM(myProg,
"fw_haveTransfers");
1050 glUniform1i(iopactex,havetextures);
1053 glGetIntegerv(GL_VIEWPORT, iviewport);
1055 vp = GET_UNIFORM(myProg,
"fw_viewport");
1056 viewport[0] = (float)iviewport[0];
1057 viewport[1] = (float)iviewport[1];
1058 viewport[2] = (float)iviewport[2];
1059 viewport[3] = (float)iviewport[3];
1060 GLUNIFORM4F(vp,viewport[0],viewport[1],viewport[2],viewport[3]);
1064 Vertices = GET_ATTRIB(myProg,
"fw_Vertex");
1065 mvm = GET_UNIFORM(myProg,
"fw_ModelViewMatrix");
1066 proj = GET_UNIFORM(myProg,
"fw_ProjectionMatrix");
1067 sendExplicitMatriciesToShader(mvm,proj,-1,NULL,-1);
1068 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
1069 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, projMatrix);
1071 glEnableVertexAttribArray(Vertices);
1073 glVertexAttribPointer(Vertices, 3, GL_FLOAT, GL_FALSE, 0, dataParent->_boxtris);
1076 glEnable(GL_CULL_FACE);
1078 glDrawArrays(GL_TRIANGLES,0,36);
1079 glDisable(GL_CULL_FACE);
1081 }
else if(method_draw_quad){
1092 case NODE_ComposedVolumeStyle:
1097 for(i=0;i<style->renderStyle.n;i++){
1098 fin_volumestyle(style->renderStyle.p[i],dataParent);
1108int volstyle_needs_normal(
struct X3D_Node *vstyle){
1125 need_normal = FALSE;
1126 if(style0->enabled){
1127 switch(vstyle->_nodeType){
1128 case NODE_ComposedVolumeStyle:
1132 for(i=0;i<style->renderStyle.n;i++){
1133 need_normal = need_normal || volstyle_needs_normal(style->renderStyle.p[i]);
1137 case NODE_CartoonVolumeStyle:
1138 case NODE_EdgeEnhancementVolumeStyle:
1139 case NODE_ShadedVolumeStyle:
1140 case NODE_SilhouetteEnhancementVolumeStyle:
1141 case NODE_ToneMappedVolumeStyle:
1145 need_normal = need_normal || (style->surfaceNormals == NULL);
1162 printf(
"compile_isosurfacevolumedata not implemented\n");
1173 printf(
"compile_segmentedvolumedata \n");
1176s_shader_capabilities_t * getVolumeProgram(
struct X3D_Node **renderStyle,
int nstyle,
int VOLUME_DATA_FLAG){
1177 static int once = 0;
1178 unsigned int volflags;
1180 s_shader_capabilities_t *caps;
1183 ConsoleMessage(
"getVolumeProgram\n");
1186 for(i=0;i<nstyle;i++){
1188 if(style0->enabled){
1189 volflags = prep_volumestyle(renderStyle[i], volflags);
1193 volflags = SHADERFLAGS_VOLUME_STYLE_DEFAULT;
1197 printf(
"volflags= ");
1199 printf(
"%d ",((volflags >> (8-i-1)*4) & 0xF));
1222 shader_requirements.volume = VOLUME_DATA_FLAG;
1223 shader_requirements.volume |= (volflags << 4);
1225 shader_requirements.base |= getShaderFlags().base & CLIPPLANE_SHADER;
1227 caps = getMyShaders(shader_requirements);
1228 enableGlobalShader(caps);
1239 GLint inids, ienable;
1241 int *enabledIDs = node->segmentEnabled.p;
1242 int nIDs = node->segmentEnabled.n;
1243 myProg = caps->myShaderProgram;
1246 textureTableIndexStruct_s *tti;
1247 ttglobal tg = gglobal();
1249 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, segmentIDs,tmpN);
1250 tg->RenderFuncs.texturenode = (
void*)tmpN;
1254 tti = getTableTableFromTextureNode(tmpN);
1255 if(tti && tti->status >= TEX_LOADED){
1260 GLint tex3dUseVertex, ttiles, repeatSTR, magFilter;
1261 ttiles = GET_UNIFORM(myProg,
"tex3dTiles");
1262 GLUNIFORM1IV(ttiles,3,tti->tiles);
1265 tex3dUseVertex = GET_UNIFORM(myProg,
"tex3dUseVertex");
1266 glUniform1i(tex3dUseVertex,0);
1267 repeatSTR = GET_UNIFORM(myProg,
"repeatSTR");
1268 glUniform1iv(repeatSTR,3,tti->repeatSTR);
1269 magFilter = GET_UNIFORM(myProg,
"magFilter");
1270 glUniform1i(magFilter,0);
1272 TextureUnit= GET_UNIFORM(myProg,
"fw_Texture_unit1");
1273 glUniform1i(TextureUnit,itexture);
1274 glActiveTexture(GL_TEXTURE0+itexture);
1275 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
1276 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1279 inids = GET_UNIFORM(myProg,
"fw_nIDs");
1280 glUniform1i(inids,nIDs);
1281 ienable = GET_UNIFORM(myProg,
"fw_enableIDs");
1282 glUniform1iv(ienable,nIDs,enabledIDs);
1285 if(node->renderStyle.n){
1286 int i, *styleflags,instyles;
1289 styleflags = MALLOC(
int*,
sizeof(
int)*node->renderStyle.n);
1290 for(i=0;i<node->renderStyle.n;i++){
1291 styleflags[i] = prep_volumestyle(node->renderStyle.p[i],0);
1294 istyles = GET_UNIFORM(myProg,
"fw_surfaceStyles");
1295 glUniform1iv(istyles,node->renderStyle.n,styleflags);
1296 instyles = GET_UNIFORM(myProg,
"fw_nStyles");
1297 glUniform1i(instyles,node->renderStyle.n);
1304float *getTransformedClipPlanes();
1305int getClipPlaneCount();
1306void sendFogToShader(s_shader_capabilities_t *me);
1307void sendLightInfo2(s_shader_capabilities_t* me);
1308int peek_group_visible();
1309void render_GENERIC_volume_data(s_shader_capabilities_t *caps,
struct X3D_Node **renderStyle,
int nstyle,
struct X3D_Node *voxels,
struct X3D_VolumeData *node ) {
1310 static int once = 0;
1313 GLint Vertices, mvm, proj, mvpi;
1314 double modelviewMatrix[16],projMatrix[16], mvp[16], mvpinverse[16];
1317 GLint iclipplanes, inclipplanes;
1324 ttglobal tg = gglobal();
1326 myProg = caps->myShaderProgram;
1330 textureTableIndexStruct_s *tti;
1331 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, voxels,tmpN);
1332 tg->RenderFuncs.texturenode = (
void*)tmpN;
1351 tti = getTableTableFromTextureNode(tmpN);
1352 if(tti && tti->status >= TEX_LOADED){
1353 GLint ttiles, tex3dUseVertex,repeatSTR,magFilter;
1354 ttiles = GET_UNIFORM(myProg,
"tex3dTiles");
1355 GLUNIFORM1IV(ttiles,3,tti->tiles);
1358 tex3dUseVertex = GET_UNIFORM(myProg,
"tex3dUseVertex");
1359 glUniform1i(tex3dUseVertex,0);
1360 repeatSTR = GET_UNIFORM(myProg,
"repeatSTR");
1361 glUniform1iv(repeatSTR,3,tti->repeatSTR);
1362 magFilter = GET_UNIFORM(myProg,
"magFilter");
1363 glUniform1i(magFilter,1);
1365 glActiveTexture(GL_TEXTURE0);
1366 glBindTexture(GL_TEXTURE_2D,tti->OpenGLTexture);
1367 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1373 for(i=0;i<nstyle;i++){
1375 if(style0->enabled){
1376 render_volumestyle(renderStyle[i],myProg);
1384 Vertices = GET_ATTRIB(myProg,
"fw_Vertex");
1385 mvm = GET_UNIFORM(myProg,
"fw_ModelViewMatrix");
1386 proj = GET_UNIFORM(myProg,
"fw_ProjectionMatrix");
1388 ConsoleMessage(
"vertices %d mvm %d proj %d\n",Vertices,mvm,proj);
1389 sendExplicitMatriciesToShader(mvm,proj,-1,NULL,-1);
1390 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
1391 FW_GL_GETDOUBLEV(GL_PROJECTION_MATRIX, projMatrix);
1394 __gluMultMatricesd(modelviewMatrix, projMatrix, mvp);
1395 if (!__gluInvertMatrixd(mvp, mvpinverse))
return;
1397 matmultiplyFULL(mvp,modelviewMatrix,projMatrix);
1400 matinverseFULL(mvpinverse,mvp);
1402 matdouble2float4(spmat,mvpinverse);
1404 mvpi = GET_UNIFORM(myProg,
"fw_ModelViewProjInverse");
1405 GLUNIFORMMATRIX4FV(mvpi,1,GL_FALSE,spmat);
1410 clipplanes = getTransformedClipPlanes();
1412 nsend = getClipPlaneCount();
1413 iclipplanes = GET_UNIFORM(myProg,
"fw_clipplanes");
1414 inclipplanes = GET_UNIFORM(myProg,
"fw_nclipplanes");
1416 GLUNIFORM4FV(iclipplanes,nsend,clipplanes);
1417 GLUNIFORM1I(inclipplanes,nsend);
1428 if (caps->haveLightInShader) {
1429 sendLightInfo2(caps);
1430 sendFogToShader(caps);
1437 glGetIntegerv(GL_VIEWPORT, iviewport);
1438 vp = GET_UNIFORM(myProg,
"fw_viewport");
1439 viewport[0] = (float)iviewport[0];
1440 viewport[1] = (float)iviewport[1];
1441 viewport[2] = (float)iviewport[2];
1442 viewport[3] = (float)iviewport[3];
1443 GLUNIFORM4F(vp,viewport[0],viewport[1],viewport[2],viewport[3]);
1444 dim = GET_UNIFORM(myProg,
"fw_dimensions");
1445 dimensions = node->dimensions.c;
1446 GLUNIFORM3F(dim,dimensions[0],dimensions[1],dimensions[2]);
1448 bbox2extent6f(vecset3f(center,0.0f,0.0f,0.0f),dimensions,node->_extent);
1449 extent6f_union_extent6f(peek_group_extent(),node->_extent);
1450 if(!once) ConsoleMessage(
"dim %d vp %d \n",dim,vp );
1453 glEnableVertexAttribArray(Vertices);
1454 glVertexAttribPointer(Vertices, 3, GL_FLOAT, GL_FALSE, 0, node->_boxtris);
1456 glEnable(GL_CULL_FACE);
1467 if(peek_group_visible())
1468 glDrawArrays(GL_TRIANGLES,0,36);
1469 glDisable(GL_CULL_FACE);
1471 tg->RenderFuncs.textureStackTop = 0;
1472 tg->RenderFuncs.texturenode = NULL;
1476 for(i=0;i<nstyle;i++)
1477 fin_volumestyle(renderStyle[i],node);
1488 s_shader_capabilities_t *caps;
1489 static int once = 0;
1492 if (renderstate()->render_blend == (node->_renderFlags & VF_Blend)) {
1495 prep_BBox((
struct BBoxFields*)&node->bboxCenter);
1498 printf(
"child segmentedvolumedata \n");
1502 caps = getVolumeProgram(node->renderStyle.p,node->renderStyle.n, SHADERFLAGS_VOLUME_DATA_SEGMENT);
1505 render_SEGMENTED_volume_data(caps,node->segmentIdentifiers,itexture,node);
1507 render_GENERIC_volume_data(caps,node->renderStyle.p,node->renderStyle.n,node->voxels,(
struct X3D_VolumeData*)node );
1525 GLint istep, itol,ivals,invals;
1526 myProg= caps->myShaderProgram;
1527 istep = GET_UNIFORM(myProg,
"fw_stepSize");
1528 glUniform1f(istep,node->contourStepSize);
1529 itol = GET_UNIFORM(myProg,
"fw_tolerance");
1530 glUniform1f(itol,node->surfaceTolerance);
1532 ivals = GET_UNIFORM(myProg,
"fw_surfaceVals");
1533 glUniform1fv(ivals,node->surfaceValues.n,node->surfaceValues.p);
1534 invals = GET_UNIFORM(myProg,
"fw_nVals");
1535 glUniform1i(invals,node->surfaceValues.n);
1536 applysurfaceNormalTexture(node->gradients, myProg);
1538 if(node->renderStyle.n){
1542 int *styleflags = MALLOC(
int*,
sizeof(
int)*node->renderStyle.n);
1543 for(i=0;i<node->renderStyle.n;i++){
1544 styleflags[i] = prep_volumestyle(node->renderStyle.p[i],0);
1547 glUniform1iv(ivals,node->renderStyle.n,styleflags);
1548 instyles = GET_UNIFORM(myProg,
"fw_nStyles");
1549 glUniform1i(instyles,node->renderStyle.n);
1566 static int once = 0;
1568 if (renderstate()->render_blend == (node->_renderFlags & VF_Blend)) {
1569 unsigned int voldataflags;
1570 s_shader_capabilities_t *caps;
1573 prep_BBox((
struct BBoxFields*)&node->bboxCenter);
1576 printf(
"child segmentedvolumedata \n");
1577 voldataflags = SHADERFLAGS_VOLUME_DATA_ISO;
1579 MODE = node->surfaceValues.n == 1 ? 1 : 3;
1580 MODE = node->contourStepSize != 0.0f && MODE == 1 ? 2 : 1;
1582 voldataflags |= SHADERFLAGS_VOLUME_DATA_ISO_MODE3;
1583 caps = getVolumeProgram(node->renderStyle.p,node->renderStyle.n, voldataflags);
1587 render_ISO_volume_data(caps,node);
1589 render_GENERIC_volume_data(caps,node->renderStyle.p,node->renderStyle.n,node->voxels,(
struct X3D_VolumeData*)node );
1600 s_shader_capabilities_t *caps;
1601 static int once = 0;
1604 if (renderstate()->render_blend == (node->_renderFlags & VF_Blend)) {
1607 printf(
"child volumedata \n");
1608 if(node->renderStyle) nstyles = 1;
1610 prep_BBox((
struct BBoxFields*)&node->bboxCenter);
1612 caps = getVolumeProgram(&node->renderStyle,nstyles, SHADERFLAGS_VOLUME_DATA_BASIC);
1614 render_GENERIC_volume_data(caps,&node->renderStyle,nstyles,node->voxels,(
struct X3D_VolumeData*)node );