Commit 293a0e3d authored by Robin Eschbach's avatar Robin Eschbach
Browse files

[FIX #479] geometry include throwing errors for other shaders due to version mismatch

parent cadd69cd
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGETRANSFORMATIONTOOLS_GLSL
#define WGETRANSFORMATIONTOOLS_GLSL
#version 150
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat4 osg_ModelViewMatrix;
/**
* Projects a given point to screen-space, where (0,0) is the lower left corner and (1,1) the upper right. The Depth
* is stored in the returned vector's Z value.
*
* \param point the point to project
*
* \return the projected point, the Z value is the depth
*/
vec3 project( vec4 point )
{
// 1: project
vec4 pointProjected = osg_ModelViewProjectionMatrix * point;
// 2: scale to screen space and [0,1]
pointProjected.x /= pointProjected.w;
pointProjected.x = pointProjected.x * 0.5 + 0.5;
pointProjected.y /= pointProjected.w;
pointProjected.y = pointProjected.y * 0.5 + 0.5;
pointProjected.z /= pointProjected.w;
pointProjected.z = pointProjected.z * 0.5 + 0.5;
return pointProjected.xyz;
}
/**
* Projects a given vector to screen-space. It does not scale the final vector to [0,1] as project() would have done.
*
* \param vector the vector to project, the w component needs to be zero.
*
* \return the projected vector in unscaled screen-space ( [-1,1] per component )
*/
vec3 projectVector( vec4 vector )
{
vec4 vec = vector;
vec.w = 0.0; // ensure w is zero
vec4 vecP = osg_ModelViewProjectionMatrix * vec;
return vecP.xyz;
}
/**
* Projects a given vector to screen-space. It does not scale the final vector to [0,1] as project() would have done.
*
* \param vector the vector to project
*
* \return the projected vector in unscaled screen-space ( [-1,1] per component )
*
* \note This assumes the homogeneous coordinate to be 1.
*/
vec3 projectVector( vec3 vector )
{
return projectVector( vec4( vector, 1.0 ) );
}
/**
* Projects a given point to screen-space, where (0,0) is the lower left corner and (1,1) the upper right. The Depth
* is stored in the returned vector's Z value.
*
* \param point the point to project
*
* \return the projected point, the Z value is the depth
*
* \note This projects a vec3 by applying 1.0 to the homogeneous coordinate
*/
vec3 project( vec3 point )
{
return project( vec4( point, 1.0 ) );
}
/**
* This function transforms a point which is in world space, to a point in the local coordinate system of the object
* currently getting rendered.
* \note you can use this method with point.w == 0.0 for vector projection too.
*
* \param point the point in world coordinates
*
* \return the point in local coordinates
*/
vec4 worldToLocal( vec4 point )
{
return inverse( osg_ModelViewMatrix ) * point;
}
/**
* This function transforms a point which is in world space, to a point in the local coordinate system of the object
* currently getting rendered.
*
* \param point the point in world coordinates
*
* \return the point in local coordinates
*
* \note This assumes the homogeneous part to be 1.0
*/
vec4 worldToLocal( vec3 point )
{
return worldToLocal( vec4( point, 1.0 ) );
}
/**
* This function transforms a vector which is in world space, to a point in the local coordinate system of the object
* currently getting rendered.
*
* \param point1 the vector point in world coordinates
* \param point2 the vector direction point in world coordinates
*
* \return the vector in local coordinates
*/
vec4 worldToLocal( vec4 point1, vec4 point2 )
{
return worldToLocal( point1 - point2 );
}
/**
* This function transforms a vector which is in world space, to a point in the local coordinate system of the object
* currently getting rendered.
*
* \param point1 the vector point in world coordinates
* \param point2 the vector direction point in world coordinates
*
* \return the vector in local coordinates
*
* \note This assumes the homogeneous part to be 1.0
*/
vec4 worldToLocal( vec3 point1, vec3 point2 )
{
return worldToLocal( vec4( point1 - point2, 0.0 ) );
}
/**
* This calculates the scaling factor of the modelview matrix. It transforms a vec4( 1.0, 1.0, 1.0, 0.0 ) vector and returns its length,
* representing the scaling. This is mostly useful for screen-space based approaches which need some hint about zooming to provide consistent
* look for all zoom levels.
*
* \return ModelView zoom
*/
float getModelViewScale()
{
return length( ( osg_ModelViewMatrix * normalize( vec4( 1.0, 1.0, 1.0, 0.0 ) ) ).xyz );
}
#endif // WGETRANSFORMATIONTOOLS_GLSL
......@@ -25,10 +25,7 @@
#ifndef WGETRANSFORMATIONTOOLS_GLSL
#define WGETRANSFORMATIONTOOLS_GLSL
#version 150
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat4 osg_ModelViewMatrix;
#version 120
/**
* Projects a given point to screen-space, where (0,0) is the lower left corner and (1,1) the upper right. The Depth
......@@ -41,7 +38,7 @@ uniform mat4 osg_ModelViewMatrix;
vec3 project( vec4 point )
{
// 1: project
vec4 pointProjected = osg_ModelViewProjectionMatrix * point;
vec4 pointProjected = gl_ModelViewProjectionMatrix * point;
// 2: scale to screen space and [0,1]
pointProjected.x /= pointProjected.w;
......@@ -66,7 +63,7 @@ vec3 projectVector( vec4 vector )
vec4 vec = vector;
vec.w = 0.0; // ensure w is zero
vec4 vecP = osg_ModelViewProjectionMatrix * vec;
vec4 vecP = gl_ModelViewProjectionMatrix * vec;
return vecP.xyz;
}
......@@ -111,7 +108,7 @@ vec3 project( vec3 point )
*/
vec4 worldToLocal( vec4 point )
{
return inverse( osg_ModelViewMatrix ) * point;
return gl_ModelViewMatrixInverse * point;
}
/**
......@@ -168,8 +165,7 @@ vec4 worldToLocal( vec3 point1, vec3 point2 )
*/
float getModelViewScale()
{
return length( ( osg_ModelViewMatrix * normalize( vec4( 1.0, 1.0, 1.0, 0.0 ) ) ).xyz );
return length( ( gl_ModelViewMatrix * normalize( vec4( 1.0, 1.0, 1.0, 0.0 ) ) ).xyz );
}
#endif // WGETRANSFORMATIONTOOLS_GLSL
......@@ -75,6 +75,16 @@ varying float v_worldScale;
*/
varying vec4 v_clusterColor;
/**
* The color coming from the geometry shader
*/
varying vec4 v_colorOut;
/**
* The coordinates of the texture
*/
varying vec4 v_texCoord;
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
......@@ -89,7 +99,7 @@ varying vec4 v_clusterColor;
void main()
{
// it should be round
float c = ( gl_TexCoord[0].x * gl_TexCoord[0].x ) + ( gl_TexCoord[0].y * gl_TexCoord[0].y );
float c = ( v_texCoord.x * v_texCoord.x ) + ( v_texCoord.y * v_texCoord.y );
// clip everything outside the sphere
float outside = 1.0 - step( 1.0, c );
......@@ -103,16 +113,16 @@ void main()
#endif
// calculate some kind of "round" depth value
// NOTE: gl_TexCoord[0].w is 0.0 if the front of the cap is seen
vec3 v = v_vertex.xyz + ( 1.0 - gl_TexCoord[0].w ) * ( normal ) * ( 1.0 - c );
// NOTE: v_texCoord.w is 0.0 if the front of the cap is seen
vec3 v = v_vertex.xyz + ( 1.0 - v_texCoord.w ) * ( normal ) * ( 1.0 - c );
// apply standard projection:
vec4 vProj = gl_ProjectionMatrix * vec4( v.xyz, 1.0 );
float depth = ( 0.5 * vProj.z / vProj.w ) + 0.5;
float w = gl_TexCoord[0].w * ( 1.0 - abs( gl_TexCoord[0].x ) ) + ( 1.0 - gl_TexCoord[0].w );
float w = v_texCoord.w * ( 1.0 - abs( v_texCoord.x ) ) + ( 1.0 - v_texCoord.w );
// apply colormapping to the input color
vec4 finalColor = gl_Color;
vec4 finalColor = v_colorOut;
// use secondary color only if bitfield filtering is active
#ifdef BITFIELD_ENABLED
......@@ -120,7 +130,7 @@ void main()
// finalColor = mix( v_clusterColor, gl_Color, u_roiFilterColorOverride );
// FIXME_ somehow, the secondary color array does not arrive at the vertex shader although it is bound. We make endcaps transparent in the
// case
finalColor = mix( vec4( 0.0 ), gl_Color, u_roiFilterColorOverride );
finalColor = mix( vec4( 0.0 ), v_colorOut, u_roiFilterColorOverride );
#endif
#endif
......
......@@ -22,16 +22,21 @@
//
//---------------------------------------------------------------------------
#version 120
#version 150
#extension GL_EXT_geometry_shader4 : enable
#include "WGETransformationTools-geometry.glsl"
#include "WGETransformationTools.glsl"
layout( points ) in;
layout( triangle_strip, max_vertices = 4 ) out;
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
uniform mat4 osg_ModelViewMatrix
uniform mat4 osg_ProjectionMatrix
/**
* A point on the plane.
*/
......@@ -63,37 +68,52 @@ uniform float u_tubeSize;
/**
* The normal/tangent in scene-space
*/
varying in vec3 v_normal[];
in vec3 v_normal[];
/**
* The normal/tangent in scene-space
*/
varying in float v_discard[];
in float v_discard[];
/**
* Second color array
*/
varying in vec4 v_secondaryColor[];
in vec4 v_secondaryColor[];
/**
* The Color passed from the vertex shader
*/
in vec4 v_colorIn[];
/**
* The output normal for the fragment shader in world-space
*/
varying out vec3 v_normalWorld;
out vec3 v_normalWorld;
/**
* The vertex coordinates in world-space
*/
varying out vec4 v_vertex;
out vec4 v_vertex;
/**
* The scaling component of the modelview matrix.
*/
varying out float v_worldScale;
out float v_worldScale;
/**
* This varying carries the current cluster color.
*/
varying out vec4 v_clusterColor;
out vec4 v_clusterColor;
/**
* The color of this primitive
*/
out vec4 v_colorOut;
/**
* The texture coordinates
*/
out vec4 v_texCoord;
/////////////////////////////////////////////////////////////////////////////
// Variables
......@@ -120,7 +140,7 @@ void main()
// define the plane
vec3 n = normalize( u_planeVector );
float d = dot( u_planePoint, n );
float dist = dot( gl_PositionIn[0].xyz, n ) - d;
float dist = dot( gl_in[0].gl_Position.xyz, n ) - d;
if( abs( dist ) >= u_distance )
{
......@@ -139,48 +159,48 @@ void main()
// grab the info we got from the vertex array:
vec3 tangent = normalize( v_normal[0] );
vec4 vertex = gl_PositionIn[0];
vec4 vertex = gl_in[0].gl_Position;
// camera view direction
vec3 view = normalize( ( gl_ModelViewMatrixInverse * vec4( 0.0, 0.0, -1.0, 0.0 ) ).xyz );
vec3 view = normalize( ( inverse( osg_ModelViewMatrix ) * vec4( 0.0, 0.0, -1.0, 0.0 ) ).xyz );
float angle = step( 0.0, sign( dot( view, tangent ) ) );
// the plane of the sprite is determined by the tangent ond two orthogonal vectors a and b
vec4 a = 0.2 * u_tubeSize * vec4( normalize( cross( tangent, view ) ), 0.0 );
vec4 b = 0.2 * u_tubeSize * vec4( normalize( cross( tangent, a.xyz ) ), 0.0 );
gl_FrontColor = gl_FrontColorIn[0];
v_colorOut = v_colorIn[0];
v_clusterColor = v_secondaryColor[0];
// create the quad
v_normalWorld = ( gl_ModelViewMatrix * vec4( v_normal[0], 0.0 ) ).xyz;
v_normalWorld = ( osg_ModelViewMatrix * vec4( v_normal[0], 0.0 ) ).xyz;
// let it point towards the camera
v_normalWorld *= sign( dot( normalize( v_normalWorld ), vec3( 0.0, 0.0, 1.0 ) ) );
v_worldScale = getModelViewScale();
// vertex 1
gl_TexCoord[0] = vec4( -1.0, -1.0, 0.0, angle );
v_vertex = gl_ModelViewMatrix * ( vertex + ( -0.5 * a ) + ( -0.5 * b ) );
gl_Position = gl_ProjectionMatrix * v_vertex;
v_texCoord = vec4( -1.0, -1.0, 0.0, angle );
v_vertex = osg_ModelViewMatrix * ( vertex + ( -0.5 * a ) + ( -0.5 * b ) );
gl_Position = osg_ProjectionMatrix * v_vertex;
EmitVertex();
// vertex 2
gl_TexCoord[0] = vec4( -1.0, 1.0, 0.0, angle );
v_vertex = gl_ModelViewMatrix * ( vertex + ( -0.5 * a ) + ( 0.5 * b ) );
gl_Position = gl_ProjectionMatrix * v_vertex;
v_texCoord = vec4( -1.0, 1.0, 0.0, angle );
v_vertex = osg_ModelViewMatrix * ( vertex + ( -0.5 * a ) + ( 0.5 * b ) );
gl_Position = osg_ProjectionMatrix * v_vertex;
EmitVertex();
// vertex 3
gl_TexCoord[0] = vec4( 1.0, -1.0, 0.0, angle );
v_vertex = gl_ModelViewMatrix * ( vertex + ( 0.5 * a ) + ( -0.5 * b ) );
gl_Position = gl_ProjectionMatrix * v_vertex;
v_texCoord = vec4( 1.0, -1.0, 0.0, angle );
v_vertex = osg_ModelViewMatrix * ( vertex + ( 0.5 * a ) + ( -0.5 * b ) );
gl_Position = osg_ProjectionMatrix * v_vertex;
EmitVertex();
// vertex 4
gl_TexCoord[0] = vec4( 1.0, 1.0, 0.0, angle );
v_vertex = gl_ModelViewMatrix * ( vertex + ( 0.5 * a ) + ( 0.5 * b ) );
gl_Position = gl_ProjectionMatrix * v_vertex;
v_texCoord = vec4( 1.0, 1.0, 0.0, angle );
v_vertex = osg_ModelViewMatrix * ( vertex + ( 0.5 * a ) + ( 0.5 * b ) );
gl_Position = osg_ProjectionMatrix * v_vertex;
EmitVertex();
EndPrimitive();
......
......@@ -79,6 +79,11 @@ varying float v_worldScale;
*/
varying vec4 v_clusterColor;
/**
* The color passed to the geometry shader.
*/
varying vec4 v_colorIn;
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
......@@ -106,7 +111,7 @@ void main()
// forward to geometry shader
v_normal = gl_Normal;
gl_FrontColor = gl_Color;
v_colorIn = gl_Color;
gl_Position = gl_Vertex;
}
......@@ -24,7 +24,7 @@
#version 150
#include "WGETransformationTools.glsl"
#include "WGETransformationTools-geometry.glsl"
layout( points ) in;
layout( triangle_strip, max_vertices = 4 ) out;
......
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