Commit ad7ce893 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

Merge branch '480-point-renderer-geometry-shader'

parents 40859320 508fac5e
......@@ -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
......
......@@ -90,6 +90,11 @@ varying float v_nearestVertexDepth;
*/
varying float v_vertexDepthDiff;
/**
* The color passed over from the geometry shader
*/
varying vec4 v_colorOut;
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
......@@ -103,7 +108,7 @@ varying float v_vertexDepthDiff;
*/
void main()
{
if( gl_Color.a == 0.0 )
if( v_colorOut.a == 0.0 )
discard;
// create a sphere
......@@ -121,7 +126,7 @@ void main()
// finally set the color and depth
wgeInitGBuffer();
wge_FragColor = vec4( gl_Color.rgb * r, gl_Color.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 ) );
......
......@@ -22,16 +22,19 @@
//
//---------------------------------------------------------------------------
#version 120
#extension GL_EXT_geometry_shader4 : enable
#version 150
#include "WGETransformationTools.glsl"
layout( points ) in;
layout( triangle_strip, max_vertices = 4 ) out;
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
uniform mat4 osg_ProjectionMatrix;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
......@@ -43,75 +46,77 @@
/**
* The point size
*/
varying in float v_pointSize[];
in float v_pointSize[];
/**
* The normal/tangent in scene-space
*/
varying in vec3 v_normal[];
in vec3 v_normal[];
/**
* Clip vertex if not 0.0
*/
varying in float v_clip[];
in float v_clip[];
/**
* Vertex in world space.
*/
varying in vec4 v_worldCenterVertex[];
in vec4 v_worldCenterVertex[];
/**
* The incoming color from the vertex shader.
*/
in vec4 v_colorIn[];
/**
* The vertex coordinates in world-space
*/
varying out vec3 v_vertex;
out vec3 v_vertex;
/**
* The texture coordinates in [-1,1]
*/
varying out vec3 v_texCoord;
out vec3 v_texCoord;
/**
* The radius of a sphere in world-space
*/
varying out float v_worldSpaceRadius;
out float v_worldSpaceRadius;
/**
* The center point of the sphere
*/
varying out vec3 v_centerPoint;
out vec3 v_centerPoint;
/**
* Vertex in world space.
*/
varying out vec4 v_worldVertex;
out vec4 v_worldVertex;
/**
* Depth of the center point
*/
varying out float v_centerVertexDepth;
out float v_centerVertexDepth;
/**
* Deptj of the neareast point on the sphere towards the camera
* Depth of the neareast point on the sphere towards the camera
*/
varying out float v_nearestVertexDepth;
out float v_nearestVertexDepth;
/**
* Difference between nearest depth and center point depth
*/
varying out float v_vertexDepthDiff;
out float v_vertexDepthDiff;
/**
* The world-space scaling factor
*/
varying out float v_worldScale;
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
out float v_worldScale;
/////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////
/**
* The output color of this primitive.
*/
out vec4 v_colorOut;
/**
* Main entry point of the geometry shader.
......@@ -125,14 +130,14 @@ void main()
}
// grab the info we got from the vertex array:
vec3 vertex = gl_PositionIn[0].xyz;
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 );
gl_FrontColor = gl_FrontColorIn[0];
v_colorOut = v_colorIn[0];
v_worldScale = getModelViewScale();
v_worldSpaceRadius = v_worldScale * v_pointSize[0];
......@@ -141,40 +146,38 @@ void main()
// 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 = gl_ProjectionMatrix * nearestVertex;
vec4 nearestVertexProjected = osg_ProjectionMatrix * nearestVertex;
v_nearestVertexDepth = ( 0.5 * nearestVertexProjected.z / nearestVertexProjected.w ) + 0.5;
// depth at the center point
vec4 centerVertex = vec4( v_centerPoint.xyz, 1.0 );
vec4 centerVertexProjected = gl_ProjectionMatrix * centerVertex;
vec4 centerVertexProjected = osg_ProjectionMatrix * centerVertex;
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 = gl_ProjectionMatrix * vec4( v_vertex, 1.0 );
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 = gl_ProjectionMatrix * vec4( v_vertex, 1.0 );
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 = gl_ProjectionMatrix * vec4( v_vertex, 1.0 );
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 = gl_ProjectionMatrix * vec4( v_vertex, 1.0 );
v_vertex = v_centerPoint + v_worldSpaceRadius * v_texCoord;
gl_Position = osg_ProjectionMatrix * vec4( v_vertex, 1.0 );
EmitVertex();
EndPrimitive();
}
......@@ -46,6 +46,8 @@ varying float v_clip;
varying float v_pointSize;
varying vec4 v_colorIn;
/**
* Vertex in world space.
*/
......@@ -77,7 +79,7 @@ void main()
#endif
// forward to geometry shader
gl_FrontColor = 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