Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
ad7ce893
Commit
ad7ce893
authored
Jun 21, 2021
by
Alexander Wiebel
Browse files
Merge branch '480-point-renderer-geometry-shader'
parents
40859320
508fac5e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
46 deletions
+61
-46
src/core/graphicsEngine/WGEViewer.cpp
src/core/graphicsEngine/WGEViewer.cpp
+2
-0
src/core/graphicsEngine/shaders/shaders/WGETransformationTools.glsl
...raphicsEngine/shaders/shaders/WGETransformationTools.glsl
+8
-5
src/modules/pointRenderer/shaders/WMPointRenderer-fragment.glsl
...dules/pointRenderer/shaders/WMPointRenderer-fragment.glsl
+7
-2
src/modules/pointRenderer/shaders/WMPointRenderer-geometry.glsl
...dules/pointRenderer/shaders/WMPointRenderer-geometry.glsl
+41
-38
src/modules/pointRenderer/shaders/WMPointRenderer-vertex.glsl
...modules/pointRenderer/shaders/WMPointRenderer-vertex.glsl
+3
-1
No files found.
src/core/graphicsEngine/WGEViewer.cpp
View file @
ad7ce893
...
...
@@ -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
);
...
...
src/core/graphicsEngine/shaders/shaders/WGETransformationTools.glsl
View file @
ad7ce893
...
...
@@ -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
=
g
l
_ModelViewProjectionMatrix
*
point
;
vec4
pointProjected
=
os
g_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
=
g
l
_ModelViewProjectionMatrix
*
vec
;
vec4
vecP
=
os
g_ModelViewProjectionMatrix
*
vec
;
return
vecP
.
xyz
;
}
...
...
@@ -108,7 +111,7 @@ vec3 project( vec3 point )
*/
vec4
worldToLocal
(
vec4
point
)
{
return
g
l
_ModelViewMatrix
Inverse
*
point
;
return
inverse
(
os
g_ModelViewMatrix
)
*
point
;
}
/**
...
...
@@ -165,7 +168,7 @@ vec4 worldToLocal( vec3 point1, vec3 point2 )
*/
float
getModelViewScale
()
{
return
length
(
(
g
l
_ModelViewMatrix
*
normalize
(
vec4
(
1
.
0
,
1
.
0
,
1
.
0
,
0
.
0
)
)
).
xyz
);
return
length
(
(
os
g_ModelViewMatrix
*
normalize
(
vec4
(
1
.
0
,
1
.
0
,
1
.
0
,
0
.
0
)
)
).
xyz
);
}
#endif // WGETRANSFORMATIONTOOLS_GLSL
...
...
src/modules/pointRenderer/shaders/WMPointRenderer-fragment.glsl
View file @
ad7ce893
...
...
@@ -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_C
olor
.
a
==
0
.
0
)
if
(
v_c
olor
Out
.
a
==
0
.
0
)
discard
;
// create a sphere
...
...
@@ -121,7 +126,7 @@ void main()
// finally set the color and depth
wgeInitGBuffer
();
wge_FragColor
=
vec4
(
gl_C
olor
.
rgb
*
r
,
gl_C
olor
.
a
);
wge_FragColor
=
vec4
(
v_c
olor
Out
.
rgb
*
r
,
v_c
olor
Out
.
a
);
wge_FragNormal
=
textureNormalize
(
sphereSurf
);
wge_FragZoom
=
v_worldScale
;
wge_FragTangent
=
textureNormalize
(
vec3
(
0
.
0
,
1
.
0
,
0
.
0
)
);
...
...
src/modules/pointRenderer/shaders/WMPointRenderer-geometry.glsl
View file @
ad7ce893
...
...
@@ -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
;
/**
* Dept
j
of the neareast point on the sphere towards the camera
* Dept
h
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_Position
In
[
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_FrontC
olorIn
[
0
];
v_colorOut
=
v_c
olorIn
[
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
=
g
l
_ProjectionMatrix
*
nearestVertex
;
vec4
nearestVertexProjected
=
os
g_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
=
g
l
_ProjectionMatrix
*
centerVertex
;
vec4
centerVertexProjected
=
os
g_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
=
g
l
_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
v_vertex
=
v_centerPoint
+
v_worldSpaceRadius
*
v_texCoord
;
gl_Position
=
os
g_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
EmitVertex
();
// vertex 2
v_texCoord
=
(
-
a
)
+
(
+
b
);
v_vertex
=
(
v_centerPoint
+
v_worldSpaceRadius
*
v_texCoord
)
;
gl_Position
=
g
l
_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
v_vertex
=
v_centerPoint
+
v_worldSpaceRadius
*
v_texCoord
;
gl_Position
=
os
g_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
EmitVertex
();
// vertex 3
v_texCoord
=
(
+
a
)
+
(
-
b
);
v_vertex
=
(
v_centerPoint
+
v_worldSpaceRadius
*
v_texCoord
)
;
gl_Position
=
g
l
_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
v_vertex
=
v_centerPoint
+
v_worldSpaceRadius
*
v_texCoord
;
gl_Position
=
os
g_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
EmitVertex
();
// vertex 4
v_texCoord
=
(
+
a
)
+
(
+
b
);
v_vertex
=
(
v_centerPoint
+
v_worldSpaceRadius
*
v_texCoord
)
;
gl_Position
=
g
l
_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
v_vertex
=
v_centerPoint
+
v_worldSpaceRadius
*
v_texCoord
;
gl_Position
=
os
g_ProjectionMatrix
*
vec4
(
v_vertex
,
1
.
0
);
EmitVertex
();
EndPrimitive
();
}
src/modules/pointRenderer/shaders/WMPointRenderer-vertex.glsl
View file @
ad7ce893
...
...
@@ -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_FrontC
olor
=
gl_Color
;
v_c
olor
In
=
gl_Color
;
gl_Position
=
gl_ModelViewMatrix
*
gl_Vertex
;
v_worldCenterVertex
=
gl_Vertex
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment