29 #include "rawVolModelRenderer.h"
31 #include "fragmentShader.glsl.h"
32 #include "vertexShader.glsl.h"
39 RawVolumeModelRenderer::RawVolumeModelRenderer(
const std::string& filename,
40 const uint32_t precision )
41 : _rawModel( filename )
42 , _precision( precision )
49 static void renderSlices(
const SliceClipper& sliceClipper )
51 int numberOfSlices =
static_cast<int>( 3.6 / sliceClipper.sliceDistance );
53 for(
int s = 0; s < numberOfSlices; ++s )
55 glBegin( GL_POLYGON );
56 for(
int i = 0; i < 6; ++i )
59 sliceClipper.getPosition( i, numberOfSlices-1-s );
61 glVertex4f( pos.x(), pos.y(), pos.z(), 1.0 );
68 void RawVolumeModelRenderer::_putVolumeDataToShader(
69 const VolumeInfo& volumeInfo,
70 const float sliceDistance,
71 const eq::Matrix4f& invRotationM,
72 const eq::Vector4f& taintColor,
73 const int normalsQuality )
75 LBASSERT( _glewContext );
77 GLhandleARB shader = _shaders.getProgram();
80 const DataInTextureDimensions& TD = volumeInfo.TD;
85 tParamNameGL = glGetUniformLocationARB( shader,
"W" );
86 glUniform1fARB( tParamNameGL, TD.W );
88 tParamNameGL = glGetUniformLocationARB( shader,
"H" );
89 glUniform1fARB( tParamNameGL, TD.H );
91 tParamNameGL = glGetUniformLocationARB( shader,
"D" );
92 glUniform1fARB( tParamNameGL, TD.D );
94 tParamNameGL = glGetUniformLocationARB( shader,
"Do" );
95 glUniform1fARB( tParamNameGL, TD.Do );
97 tParamNameGL = glGetUniformLocationARB( shader,
"Db" );
98 glUniform1fARB( tParamNameGL, TD.Db );
101 glActiveTextureARB( GL_TEXTURE1 );
102 glBindTexture( GL_TEXTURE_2D, volumeInfo.preint );
103 tParamNameGL = glGetUniformLocationARB( shader,
"preInt" );
104 glUniform1iARB( tParamNameGL, 1 );
107 glActiveTextureARB( GL_TEXTURE0 );
108 glBindTexture( GL_TEXTURE_3D, volumeInfo.volume );
109 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );
111 tParamNameGL = glGetUniformLocationARB( shader,
"volume" );
112 glUniform1iARB( tParamNameGL , 0 );
114 tParamNameGL = glGetUniformLocationARB( shader,
"sliceDistance" );
115 glUniform1fARB( tParamNameGL, sliceDistance );
117 tParamNameGL = glGetUniformLocationARB( shader,
"perspProj" );
118 glUniform1fARB( tParamNameGL, _ortho ? 0.0f : 1.0f );
120 tParamNameGL = glGetUniformLocationARB( shader,
"shininess" );
121 glUniform1fARB( tParamNameGL, 8.0f );
123 tParamNameGL = glGetUniformLocationARB( shader,
"taint" );
124 glUniform4fARB( tParamNameGL, taintColor.r(),
129 tParamNameGL = glGetUniformLocationARB( shader,
"sizeVec" );
130 glUniform3fARB( tParamNameGL, volumeInfo.voxelSize.W,
131 volumeInfo.voxelSize.H,
132 volumeInfo.voxelSize.D );
134 tParamNameGL = glGetUniformLocationARB( shader,
"normalsQuality");
135 glUniform1iARB( tParamNameGL, normalsQuality );
141 tParamNameGL = glGetUniformLocationARB( shader,
"viewVec" );
142 glUniform3fARB( tParamNameGL, invRotationM.array[8],
143 invRotationM.array[9],
144 invRotationM.array[10] );
148 bool RawVolumeModelRenderer::render
150 const eq::Range& range,
151 const eq::Matrix4d& modelviewM,
152 const eq::Matrix3d& modelviewITM,
153 const eq::Matrix4f& invRotationM,
154 const eq::Vector4f& taintColor,
155 const int normalsQuality
158 VolumeInfo volumeInfo;
160 if( !_rawModel.getVolumeInfo( volumeInfo, range ))
162 LBERROR <<
"Can't get volume data" << std::endl;
166 glScalef( volumeInfo.volScaling.W,
167 volumeInfo.volScaling.H,
168 volumeInfo.volScaling.D );
171 glUseProgramObjectARB( _shaders.getProgram( ));
175 const uint32_t resolution = _rawModel.getResolution();
176 const double sliceDistance = 3.6 / ( resolution * _precision );
178 _putVolumeDataToShader( volumeInfo,
float( sliceDistance ),
179 invRotationM, taintColor, normalsQuality );
181 _sliceClipper.updatePerFrameInfo( modelviewM, modelviewITM,
182 sliceDistance, range );
185 glEnable( GL_BLEND );
186 glBlendFuncSeparateEXT( GL_ONE, GL_SRC_ALPHA, GL_ZERO, GL_SRC_ALPHA );
188 renderSlices( _sliceClipper );
190 glDisable( GL_BLEND );
193 glUseProgramObjectARB( 0 );
199 bool RawVolumeModelRenderer::loadShaders()
201 if( !_shaders.loadShaders( vertexShader_glsl, fragmentShader_glsl,
204 LBERROR <<
"Can't load glsl shaders" << std::endl;
User-defined log topics (65536)