Commit 8f0756b0 authored by Michele Bosi's avatar Michele Bosi

Vivid: less reliance on "compatibililty" GL profile

parent 142d3513
......@@ -11,7 +11,9 @@
#version 150 compatibility
#pragma VL include /vivid/glsl/uniforms.glsl
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_Position = vl_ModelViewProjectionMatrix * gl_Vertex;
}
......@@ -11,7 +11,9 @@
#version 150 compatibility
#pragma VL include /vivid/glsl/uniforms.glsl
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_Position = vl_ModelViewProjectionMatrix * gl_Vertex;
}
......@@ -32,7 +32,7 @@ out vec3 N;
out vec4 Color;
void emitOutlineVertex(int i) {
gl_Position = ( gl_ProjectionMatrix * ( gl_ModelViewMatrix * gl_PositionIn[i] + vec4( 0, 0, vl_Vivid.outline.eyeOffset, 0 ) ) );
gl_Position = ( vl_ProjectionMatrix * ( vl_ModelViewMatrix * gl_PositionIn[i] + vec4( 0, 0, vl_Vivid.outline.eyeOffset, 0 ) ) );
gl_Position.z -= vl_Vivid.outline.clipOffset * gl_Position.w;
OP = gsOP[i];
......@@ -45,12 +45,12 @@ void emitOutlineVertex(int i) {
}
void outline() {
vec3 V0 = ( gl_ModelViewMatrix * gl_PositionIn[0] ).xyz;
vec3 V1 = ( gl_ModelViewMatrix * gl_PositionIn[1] ).xyz;
vec3 V2 = ( gl_ModelViewMatrix * gl_PositionIn[2] ).xyz;
vec3 V3 = ( gl_ModelViewMatrix * gl_PositionIn[3] ).xyz;
vec3 V4 = ( gl_ModelViewMatrix * gl_PositionIn[4] ).xyz;
vec3 V5 = ( gl_ModelViewMatrix * gl_PositionIn[5] ).xyz;
vec3 V0 = ( vl_ModelViewMatrix * gl_PositionIn[0] ).xyz;
vec3 V1 = ( vl_ModelViewMatrix * gl_PositionIn[1] ).xyz;
vec3 V2 = ( vl_ModelViewMatrix * gl_PositionIn[2] ).xyz;
vec3 V3 = ( vl_ModelViewMatrix * gl_PositionIn[3] ).xyz;
vec3 V4 = ( vl_ModelViewMatrix * gl_PositionIn[4] ).xyz;
vec3 V5 = ( vl_ModelViewMatrix * gl_PositionIn[5] ).xyz;
// polygon normals
// no need to normalize these
......@@ -93,9 +93,9 @@ void outline() {
}
void emitClipVertex(int i, int j, float t) {
// gl_Position = ( gl_ProjectionMatrix * ( gl_ModelViewMatrix * mix( gl_PositionIn[i], gl_PositionIn[j], t ) + vec4( 0, 0, vl_Vivid.outline.eyeOffset, 0 ) ) );
// gl_Position = ( vl_ProjectionMatrix * ( vl_ModelViewMatrix * mix( gl_PositionIn[i], gl_PositionIn[j], t ) + vec4( 0, 0, vl_Vivid.outline.eyeOffset, 0 ) ) );
// gl_Position.z -= vl_Vivid.outline.clipOffset * gl_Position.w;
gl_Position = gl_ModelViewProjectionMatrix * mix( gl_PositionIn[i], gl_PositionIn[j], t );
gl_Position = vl_ModelViewProjectionMatrix * mix( gl_PositionIn[i], gl_PositionIn[j], t );
OP = mix( gsOP[i], gsOP[j], t );
WP = mix( gsWP[i], gsWP[j], t );
......
......@@ -13,7 +13,9 @@
#version 150 compatibility
#pragma VL include /vivid/glsl/uniforms.glsl
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_Position = vl_ModelViewProjectionMatrix * gl_Vertex;
}
......@@ -199,13 +199,14 @@ vec4 ClippingStage( vec4 color )
vec4 FogStage( vec4 color )
{
float scale = 1.0 / ( vl_Vivid.fog.end - vl_Vivid.fog.start );
if ( vl_Vivid.fog.mode > 0 && color.a > 0 ) {
// Compute fog factor
float dist = length( CP.xyz );
float fog_factor = 0;
if ( vl_Vivid.fog.mode == 1 ) {
// Linear
fog_factor = ( vl_Vivid.fog.end - dist ) * vl_Vivid.fog.scale;
fog_factor = ( vl_Vivid.fog.end - dist ) * scale;
} else
if ( vl_Vivid.fog.mode == 2 ) {
// Exp
......
......@@ -23,11 +23,11 @@ out vec4 Color;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_Position = vl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
OP = gl_Vertex;
CP = gl_ModelViewMatrix * gl_Vertex;
CP = vl_ModelViewMatrix * gl_Vertex;
WP = vl_WorldMatrix * gl_Vertex;
N = normalize( gl_NormalMatrix * gl_Normal );
N = normalize( vl_NormalMatrix * gl_Normal );
Color = gl_Color;
}
......@@ -26,8 +26,8 @@ void main(void)
gl_Position = gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gsOP = gl_Vertex;
gsCP = gl_ModelViewMatrix * gl_Vertex;
gsCP = vl_ModelViewMatrix * gl_Vertex;
gsWP = vl_WorldMatrix * gl_Vertex;
gsN = normalize(gl_NormalMatrix * gl_Normal);
gsN = normalize(vl_NormalMatrix * gl_Normal);
gsColor = gl_Color;
}
......@@ -18,7 +18,7 @@ uniform mat4 vl_WorldMatrix;
uniform mat4 vl_ModelViewMatrix;
uniform mat4 vl_ProjectionMatrix;
uniform mat4 vl_ModelViewProjectionMatrix;
uniform mat4 vl_NormalMatrix;
uniform mat3 vl_NormalMatrix;
// Texture Mapping
......@@ -44,14 +44,14 @@ struct vl_MaterialParameters {
vec4 ambient;
vec4 emission;
float shininess;
}
};
struct vl_LightParameters {
vec4 position;
vec4 diffuse;
vec4 specular;
vec4 ambient;
}
};
// Smart Clip Stage
......
......@@ -68,7 +68,7 @@ vec4 computeFragColorDirect( vec3 pos )
float luminance = texture3D( volumeTexture, pos ).r;
#if 1
vec3 N = gl_NormalMatrix * ( texture3D( gradientTexture, pos ).xyz * 2.0 - 1.0 );
vec3 N = vl_NormalMatrix * ( texture3D( gradientTexture, pos ).xyz * 2.0 - 1.0 );
#else
vec3 a, b;
a.x = texture3D( volumeTexture, pos - vec3( gradientDelta.x, 0.0, 0.0 ) ).r;
......@@ -77,7 +77,7 @@ vec4 computeFragColorDirect( vec3 pos )
b.x = texture3D( volumeTexture, pos + vec3( gradientDelta.x, 0.0, 0.0 ) ).r;
b.y = texture3D( volumeTexture, pos + vec3( 0.0, gradientDelta.y, 0.0 ) ).r;
b.z = texture3D( volumeTexture, pos + vec3( 0.0, 0.0, gradientDelta.z ) ).r;
vec3 N = gl_NormalMatrix * normalize( a - b );
vec3 N = vl_NormalMatrix * normalize( a - b );
#endif
float lookup = transferFunctionDelta + ( 1.0 - 2.0 * transferFunctionDelta ) * luminance;
......@@ -101,7 +101,7 @@ vec4 computeFragColorIso( vec3 pos )
float luminance = texture3D( volumeTexture, pos ).r;
#if 1
vec3 N = gl_NormalMatrix * ( texture3D( gradientTexture, pos ).xyz * 2.0 - 1.0 );
vec3 N = vl_NormalMatrix * ( texture3D( gradientTexture, pos ).xyz * 2.0 - 1.0 );
#else
vec3 a, b;
a.x = texture3D( volumeTexture, pos - vec3( gradientDelta.x, 0.0, 0.0 ) ).r;
......@@ -110,7 +110,7 @@ vec4 computeFragColorIso( vec3 pos )
b.x = texture3D( volumeTexture, pos + vec3( gradientDelta.x, 0.0, 0.0 ) ).r;
b.y = texture3D( volumeTexture, pos + vec3( 0.0, gradientDelta.y, 0.0 ) ).r;
b.z = texture3D( volumeTexture, pos + vec3( 0.0, 0.0, gradientDelta.z ) ).r;
vec3 N = gl_NormalMatrix * normalize( a - b );
vec3 N = vl_NormalMatrix * normalize( a - b );
#endif
float lookup = transferFunctionDelta + ( 1.0 - 2.0 * transferFunctionDelta ) * luminance;
......@@ -163,7 +163,7 @@ void raycastIsosurface() {
// Depth test: must be done here!
vec3 ray_op = volumeBoxMin + (volumeBoxMax - volumeBoxMin) * ray_pos;
vec4 P = gl_ModelViewProjectionMatrix * vec4( ray_op, 1 );
vec4 P = vl_ModelViewProjectionMatrix * vec4( ray_op, 1 );
float z = ( P.z / P.w + 1.0 ) / 2.0;
if ( z > pixelDepth ) {
continue;
......@@ -215,7 +215,7 @@ void raycastDirect() {
// Don't compute the depth test if we know it's already visible
if ( ! visible ) {
vec3 ray_op = volumeBoxMin + (volumeBoxMax - volumeBoxMin) * ray_pos;
vec4 P = gl_ModelViewProjectionMatrix * vec4( ray_op, 1 );
vec4 P = vl_ModelViewProjectionMatrix * vec4( ray_op, 1 );
float z = ( P.z / P.w + 1.0 ) / 2.0;
if ( z > pixelDepth ) {
continue;
......@@ -260,7 +260,7 @@ void raycastMIP() {
// Don't compute the depth test if we know it's already visible
if ( ! visible ) {
vec3 ray_op = volumeBoxMin + (volumeBoxMax - volumeBoxMin) * ray_pos;
vec4 P = gl_ModelViewProjectionMatrix * vec4( ray_op, 1 );
vec4 P = vl_ModelViewProjectionMatrix * vec4( ray_op, 1 );
float z = ( P.z / P.w + 1.0 ) / 2.0;
if ( z < pixelDepth ) {
visible = true;
......
......@@ -13,15 +13,15 @@
#version 150 compatibility
// #pragma VL include /vivid/glsl/uniforms.glsl
#pragma VL include /vivid/glsl/uniforms.glsl
out vec3 CP; // camera-space vertex
out vec3 OP; // object-space vertex
void main()
{
gl_Position = ftransform();
gl_Position = vl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
CP = (gl_ModelViewMatrix * gl_Vertex).xyz;
CP = (vl_ModelViewMatrix * gl_Vertex).xyz;
OP = gl_Vertex.xyz;
}
......@@ -19,7 +19,7 @@
#version 150 compatibility
// #pragma VL include /vivid/glsl/uniforms.glsl
#pragma VL include /vivid/glsl/uniforms.glsl
// Automatic settings
......@@ -62,7 +62,7 @@ void main()
sample2.y = texture3D( volumeTexture, gl_TexCoord[0].xyz + vec3( 0.0, gradientDelta.y, 0.0 ) ).r;
sample1.z = texture3D( volumeTexture, gl_TexCoord[0].xyz - vec3( 0.0, 0.0, gradientDelta.z ) ).r;
sample2.z = texture3D( volumeTexture, gl_TexCoord[0].xyz + vec3( 0.0, 0.0, gradientDelta.z ) ).r;
vec3 N = gl_NormalMatrix * normalize( sample1 - sample2 );
vec3 N = vl_NormalMatrix * normalize( sample1 - sample2 );
// simple two-side lighting
......
......@@ -19,13 +19,13 @@
#version 150 compatibility
// #pragma VL include /vivid/glsl/uniforms.glsl
#pragma VL include /vivid/glsl/uniforms.glsl
out vec4 CP; // camera-space vertex
void main()
{
gl_Position = ftransform();
gl_Position = vl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
CP = gl_ModelViewMatrix * gl_Vertex;
CP = vl_ModelViewMatrix * gl_Vertex;
}
......@@ -240,6 +240,14 @@ public:
// Get, init or create the effect using incoming material settings if any
ref<Effect> fx1 = VividRendering::makeVividEffect( act->effect() );
act->setEffect( fx1.get() );
if ( fx1->shader()->getMaterial() ) {
Shader* sh = fx1->shader();
sh->gocUniform( "vl_Vivid.material.diffuse" )->setUniform( sh->getMaterial()->frontDiffuse() );
sh->gocUniform( "vl_Vivid.material.specular" )->setUniform( sh->getMaterial()->frontSpecular() );
sh->gocUniform( "vl_Vivid.material.ambient" )->setUniform( sh->getMaterial()->frontAmbient() );
sh->gocUniform( "vl_Vivid.material.emission" )->setUniform( sh->getMaterial()->frontEmission() );
sh->gocUniform( "vl_Vivid.material.shininess" )->setUniformF( sh->getMaterial()->frontShininess() );
}
//if ( ! fx1.get() ) {
// fx1 = new Effect;
......@@ -472,9 +480,10 @@ public:
ref<Effect> fx_box = VividRendering::makeVividEffect();
fx_box->shader()->gocLineWidth()->set( 3 );
fx_box->shader()->gocPolygonMode()->set( PM_LINE, PM_LINE );
fx_box->shader()->gocMaterial()->setFlatColor( vl::red );
fx_box->shader()->gocUniform( "vl_Vivid.enableLighting" )->setUniformI( 0 );
ref<Geometry> box_outline = vl::makeBox( volume_box );
box_outline->computeNormals();
box_outline->setColorArray( vl::red );
Actor* vol_box = mVividRendering->sceneManager()->tree()->addActor( box_outline.get(), fx_box.get(), mVividRendering->vividVolume()->volumeTransform() );
vol_box->setEnableMask( vl::Vivid::VividEnableMask );
vol_box->setObjectName( "Volume Box" );
......
......@@ -102,13 +102,11 @@ void ProjViewTransfCallback::updateMatrices(bool cam_changed, bool transf_change
if ( glsl_program->vl_NormalMatrix() != -1 )
{
// transpose of the inverse of the upper leftmost 3x3 of vl_ModelViewMatrix
mat4 normalmtx = modelview.as3x3();
normalmtx.invert();
normalmtx.transpose();
mat3 normalmtx = modelview.get3x3().invert().transpose();
#if VL_PIPELINE_PRECISION == 1
glUniformMatrix4fv( glsl_program->vl_NormalMatrix(), 1, GL_FALSE, normalmtx.ptr() ); VL_CHECK_OGL();
glUniformMatrix3fv( glsl_program->vl_NormalMatrix(), 1, GL_FALSE, normalmtx.ptr() ); VL_CHECK_OGL();
#elif VL_PIPELINE_PRECISION == 2
glUniformMatrix4fv( glsl_program->vl_NormalMatrix(), 1, GL_FALSE, ((fmat4)normalmtx).ptr() ); VL_CHECK_OGL();
glUniformMatrix3fv( glsl_program->vl_NormalMatrix(), 1, GL_FALSE, ((fmat4)normalmtx).ptr() ); VL_CHECK_OGL();
#endif
}
......
......@@ -316,21 +316,17 @@ bool VividRenderer::shadersReady() const {
//-------------------------------------------------------------------------------------------------
void VividRenderer::drawFullScreenQuad()
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
int current_glsl_program = -1;
glGetIntegerv(GL_CURRENT_PROGRAM, &current_glsl_program); VL_CHECK_OGL();
VL_CHECK( current_glsl_program != -1 );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
mat4 proj = mat4::getOrtho2D( 0.0, 1.0, 0.0, 1.0 );
glLoadMatrixf( proj.ptr() );
mFullScreenQuad->render( NULL, NULL, NULL, framebuffer()->openglContext() );
int vl_ModelViewProjectionMatrix = glGetUniformLocation(current_glsl_program, "vl_ModelViewProjectionMatrix");
VL_CHECK( vl_ModelViewProjectionMatrix != -1 );
glMatrixMode(GL_PROJECTION);
glPopMatrix();
mat4 proj = mat4::getOrtho2D( 0.0, 1.0, 0.0, 1.0 );
glUniformMatrix4fv( vl_ModelViewProjectionMatrix, 1, GL_FALSE, proj.ptr() ); VL_CHECK_OGL();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
mFullScreenQuad->render( NULL, NULL, NULL, framebuffer()->openglContext() );
}
//-------------------------------------------------------------------------------------------------
void VividRenderer::bindTexture( GLSLProgram* glsl, GLenum target, std::string texname, GLuint texid, int texunit )
......@@ -666,7 +662,7 @@ void VividRenderer::render2DOutlines(const RenderQueue* render_queue, Camera* ca
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
// Update legacy matrices
projViewTransfCallback()->updateMatrices( /*update_cm*/true, /*update_tr*/false, mShaderOutline2D.get(), camera, NULL );
projViewTransfCallback()->updateMatrices( /*update_cm*/true, /*update_tr*/false, NULL, camera, NULL );
for(int itok=0; itok < render_queue->size(); ++itok)
{
......@@ -716,8 +712,8 @@ void VividRenderer::render2DOutlines(const RenderQueue* render_queue, Camera* ca
// --------------- Transform setup ---------------
// Update matrices
projViewTransfCallback()->updateMatrices( /*update_cm*/false, /*update_tr*/true, mShaderOutline2D.get(), camera, actor->transform() );
// Update legacy matrices
projViewTransfCallback()->updateMatrices( /*update_cm*/false, /*update_tr*/true, NULL, camera, actor->transform() );
VL_CHECK_OGL()
......@@ -883,10 +879,6 @@ int VividRenderer::renderQueue(const RenderQueue* render_queue, GLSLProgram* cur
shader->getPointSize()->apply(0, NULL, opengl_context); VL_CHECK_OGL()
shader->getPolygonMode()->apply(0, NULL, opengl_context); VL_CHECK_OGL()
shader->getMaterial()->apply(0, NULL, opengl_context); VL_CHECK_OGL()
shader->getFog()->apply(0, NULL, opengl_context);
shader->getLight(0)->apply(0, camera, opengl_context); VL_CHECK_OGL()
shader->getLightModel()->apply(0, NULL, opengl_context);
if ( ! outline_on ) {
shader->getLineWidth()->apply(0, NULL, opengl_context);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment