Commit 508fac5e authored by Robin Eschbach's avatar Robin Eschbach
Browse files

[FIX #490] version of included geometry shader

parent 9de22440
......@@ -83,6 +83,8 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
m_View->getCamera()->setGraphicsContext( m_GraphicsWindow.get() );
m_View->getCamera()->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms( true );
m_mouseLocationHandler = new WMouseLocationHandler( name );
m_View->addEventHandler( m_mouseLocationHandler );
......
......@@ -25,7 +25,10 @@
#ifndef WGETRANSFORMATIONTOOLS_GLSL
#define WGETRANSFORMATIONTOOLS_GLSL
#version 120
#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
......@@ -38,7 +41,7 @@
vec3 project( vec4 point )
{
// 1: project
vec4 pointProjected = gl_ModelViewProjectionMatrix * point;
vec4 pointProjected = osg_ModelViewProjectionMatrix * point;
// 2: scale to screen space and [0,1]
pointProjected.x /= pointProjected.w;
......@@ -63,7 +66,7 @@ vec3 projectVector( vec4 vector )
vec4 vec = vector;
vec.w = 0.0; // ensure w is zero
vec4 vecP = gl_ModelViewProjectionMatrix * vec;
vec4 vecP = osg_ModelViewProjectionMatrix * vec;
return vecP.xyz;
}
......@@ -108,7 +111,7 @@ vec3 project( vec3 point )
*/
vec4 worldToLocal( vec4 point )
{
return gl_ModelViewMatrixInverse * point;
return inverse( osg_ModelViewMatrix ) * point;
}
/**
......@@ -165,7 +168,7 @@ vec4 worldToLocal( vec3 point1, vec3 point2 )
*/
float getModelViewScale()
{
return length( ( gl_ModelViewMatrix * normalize( vec4( 1.0, 1.0, 1.0, 0.0 ) ) ).xyz );
return length( ( osg_ModelViewMatrix * normalize( vec4( 1.0, 1.0, 1.0, 0.0 ) ) ).xyz );
}
#endif // WGETRANSFORMATIONTOOLS_GLSL
......
......@@ -123,9 +123,6 @@ void WMPointRenderer::moduleMain()
m_properties->addProperty( postNode->getProperties() );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( postNode );
osg::State* state = WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCamera()->getGraphicsContext()->getState();
state->setUseModelViewAndProjectionUniforms( true );
// load the GLSL shader:
m_shader = new WGEShader( "WMPointRenderer", m_localPath );
// set geometry shader options
......
......@@ -90,7 +90,10 @@ varying float v_nearestVertexDepth;
*/
varying float v_vertexDepthDiff;
varying vec4 fColor;
/**
* The color passed over from the geometry shader
*/
varying vec4 v_colorOut;
/////////////////////////////////////////////////////////////////////////////
// Variables
......@@ -105,7 +108,7 @@ varying vec4 fColor;
*/
void main()
{
if( fColor.a == 0.0 )
if( v_colorOut.a == 0.0 )
discard;
// create a sphere
......@@ -123,7 +126,7 @@ void main()
// finally set the color and depth
wgeInitGBuffer();
wge_FragColor = vec4( fColor.rgb * r, fColor.a );
wge_FragColor = vec4( v_colorOut.rgb * r, v_colorOut.a );
wge_FragNormal = textureNormalize( sphereSurf );
wge_FragZoom = v_worldScale;
wge_FragTangent = textureNormalize( vec3( 0.0, 1.0, 0.0 ) );
......
......@@ -24,76 +24,156 @@
#version 150
//#include "WGETransformationTools.glsl"
#include "WGETransformationTools.glsl"
layout( points ) in;
layout( triangle_strip, max_vertices = 4 ) out;
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
uniform mat4 osg_ProjectionMatrix;
uniform mat4 osg_ModelViewMatrix;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
/**
* The point size
*/
in float v_pointSize[];
/**
* The normal/tangent in scene-space
*/
in vec3 v_normal[];
/**
* Clip vertex if not 0.0
*/
in float v_clip[];
/**
* Vertex in world space.
*/
in vec4 v_worldCenterVertex[];
in vec4 vColor[];
/**
* The incoming color from the vertex shader.
*/
in vec4 v_colorIn[];
/**
* The vertex coordinates in world-space
*/
out vec3 v_vertex;
/**
* The texture coordinates in [-1,1]
*/
out vec3 v_texCoord;
/**
* The radius of a sphere in world-space
*/
out float v_worldSpaceRadius;
/**
* The center point of the sphere
*/
out vec3 v_centerPoint;
/**
* Vertex in world space.
*/
out vec4 v_worldVertex;
/**
* Depth of the center point
*/
out float v_centerVertexDepth;
/**
* Depth of the neareast point on the sphere towards the camera
*/
out float v_nearestVertexDepth;
/**
* Difference between nearest depth and center point depth
*/
out float v_vertexDepthDiff;
/**
* The world-space scaling factor
*/
out float v_worldScale;
out vec4 fColor;
/**
* The output color of this primitive.
*/
out vec4 v_colorOut;
/**
* Main entry point of the geometry shader.
*/
void main()
{
// clip whole sprite
if( v_clip[0] != 0.0 )
{
return;
}
// grab the info we got from the vertex array:
vec3 vertex = gl_in[0].gl_Position.xyz;
// the plane of the sprite is determined by the tangent ond two orthogonal vectors a and b
// NOTE: the 1.0 corresponds to a radius of 1 (unit-sphere)
vec3 a = vec3( 0.0, 1.0, 0.0 );
vec3 b = vec3( 1.0, 0.0, 0.0 );
fColor = vColor[0];
v_colorOut = v_colorIn[0];
// World scale problem because of include
v_worldScale = 1.0;
v_worldScale = getModelViewScale();
v_worldSpaceRadius = v_worldScale * v_pointSize[0];
v_centerPoint = vertex;
v_worldVertex = v_worldCenterVertex[0];
// calculate the depth using the point on the sphere most near to the cam
vec4 nearestVertex = vec4( v_centerPoint.xy, v_centerPoint.z - v_worldSpaceRadius, 1.0 );
vec4 nearestVertexProjected = osg_ProjectionMatrix * nearestVertex;
v_nearestVertexDepth = ( 0.5 * nearestVertexProjected.z / nearestVertexProjected.w ) + 0.5;
vec4 centerVertex = vec4( v_centerPoint.xyz, 1.0 );
vec4 centerVertexProjected = osg_ProjectionMatrix * centerVertex;
v_centerVertexDepth = ( 0.5 * centerVertexProjected.z / centerVertexProjected.w ) * 0.5;
v_centerVertexDepth = ( 0.5 * centerVertexProjected.z / centerVertexProjected.w ) + 0.5;
v_vertexDepthDiff = v_centerVertexDepth - v_nearestVertexDepth;
// vertex 1
v_texCoord = ( -a ) + ( -b );
v_vertex = v_centerPoint + v_worldSpaceRadius * v_texCoord;
gl_Position = osg_ProjectionMatrix * vec4( v_vertex, 1.0 );
EmitVertex();
// vertex 2
v_texCoord = ( -a ) + ( +b );
v_vertex = v_centerPoint + v_worldSpaceRadius * v_texCoord;
gl_Position = osg_ProjectionMatrix * vec4( v_vertex, 1.0 );
EmitVertex();
// vertex 3
v_texCoord = ( +a ) + ( -b );
v_vertex = v_centerPoint + v_worldSpaceRadius * v_texCoord;
gl_Position = osg_ProjectionMatrix * vec4( v_vertex, 1.0 );
EmitVertex();
// vertex 4
v_texCoord = ( +a ) + ( +b );
v_vertex = v_centerPoint + v_worldSpaceRadius * v_texCoord;
gl_Position = osg_ProjectionMatrix * vec4( v_vertex, 1.0 );
......
......@@ -46,7 +46,7 @@ varying float v_clip;
varying float v_pointSize;
varying vec4 vColor;
varying vec4 v_colorIn;
/**
* Vertex in world space.
......@@ -79,7 +79,7 @@ void main()
#endif
// forward to geometry shader
vColor = gl_Color;
v_colorIn = gl_Color;
gl_Position = gl_ModelViewMatrix * gl_Vertex;
v_worldCenterVertex = gl_Vertex;
......
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