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
6cc8c86c
Commit
6cc8c86c
authored
Feb 02, 2011
by
Sebastian Eichelbaum
Browse files
[CHANGE] - ribbon-like lighting implemented. Needs to be improved.
parent
f3412eb1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
25 deletions
+67
-25
src/modules/fiberDisplaySimple/WMFiberDisplaySimple.cpp
src/modules/fiberDisplaySimple/WMFiberDisplaySimple.cpp
+26
-11
src/modules/fiberDisplaySimple/WMFiberDisplaySimple.h
src/modules/fiberDisplaySimple/WMFiberDisplaySimple.h
+8
-12
src/modules/fiberDisplaySimple/shaders/WMFiberDisplaySimple-fragment.glsl
...rDisplaySimple/shaders/WMFiberDisplaySimple-fragment.glsl
+8
-2
src/modules/fiberDisplaySimple/shaders/WMFiberDisplaySimple-vertex.glsl
...berDisplaySimple/shaders/WMFiberDisplaySimple-vertex.glsl
+25
-0
No files found.
src/modules/fiberDisplaySimple/WMFiberDisplaySimple.cpp
View file @
6cc8c86c
...
...
@@ -101,7 +101,12 @@ void WMFiberDisplaySimple::properties()
m_clipPlaneDistance
->
removeConstraint
(
m_clipPlaneDistance
->
getMax
()
);
// there simply is no max.
m_tubeGroup
=
m_properties
->
addPropertyGroup
(
"Tube Rendering"
,
"If true, advanced fake-tube rendering is used."
);
m_useTubes
=
m_tubeGroup
->
addProperty
(
"Enable Tubes"
,
"If set, fake-tube rendering is used."
,
false
,
m_propCondition
);
m_tubeEnable
=
m_tubeGroup
->
addProperty
(
"Enable Tubes"
,
"If set, fake-tube rendering is used."
,
false
,
m_propCondition
);
m_tubeZoomable
=
m_tubeGroup
->
addProperty
(
"Zoomable"
,
"If set, fake-tube get thicker when zoomed in. If not set, they always keep the same "
"size in screen-space. This emulates standard OpenGL lines."
,
true
);
m_tubeSize
=
m_tubeGroup
->
addProperty
(
"Width"
,
"The size of the tubes."
,
2.0
);
m_tubeSize
->
setMin
(
0.10
);
m_tubeSize
->
setMax
(
25.0
);
// call WModule's initialization
WModule
::
properties
();
...
...
@@ -134,13 +139,22 @@ void WMFiberDisplaySimple::moduleMain()
{
// initialize clipping shader
m_shader
=
osg
::
ref_ptr
<
WGEShader
>
(
new
WGEShader
(
"WMFiberDisplaySimple"
,
m_localPath
)
);
m_clipPlanePointUniform
=
new
WGEPropertyUniform
<
WPropPosition
>
(
"u_planePoint"
,
m_clipPlanePoint
);
m_clipPlaneVectorUniform
=
new
WGEPropertyUniform
<
WPropPosition
>
(
"u_planeVector"
,
m_clipPlaneVector
);
m_clipPlaneDistanceUniform
=
new
WGEPropertyUniform
<
WPropDouble
>
(
"u_distance"
,
m_clipPlaneDistance
);
osg
::
ref_ptr
<
WGEPropertyUniform
<
WPropPosition
>
>
clipPlanePointUniform
=
new
WGEPropertyUniform
<
WPropPosition
>
(
"u_planePoint"
,
m_clipPlanePoint
);
osg
::
ref_ptr
<
WGEPropertyUniform
<
WPropPosition
>
>
clipPlaneVectorUniform
=
new
WGEPropertyUniform
<
WPropPosition
>
(
"u_planeVector"
,
m_clipPlaneVector
);
osg
::
ref_ptr
<
WGEPropertyUniform
<
WPropDouble
>
>
clipPlaneDistanceUniform
=
new
WGEPropertyUniform
<
WPropDouble
>
(
"u_distance"
,
m_clipPlaneDistance
);
m_shader
->
addPreprocessor
(
WGEShaderPreprocessor
::
SPtr
(
new
WGEShaderPropertyDefineOptions
<
WPropBool
>
(
m_clipPlaneEnabled
,
"CLIPPLANE_DISABLED"
,
"CLIPPLANE_ENABLED"
)
)
);
// init tube shader
m_shader
->
addPreprocessor
(
WGEShaderPreprocessor
::
SPtr
(
new
WGEShaderPropertyDefineOptions
<
WPropBool
>
(
m_tubeZoomable
,
"ZOOMABLE_DISABLED"
,
"ZOOMABLE_ENABLED"
)
)
);
osg
::
ref_ptr
<
WGEPropertyUniform
<
WPropDouble
>
>
tubeSizeUniform
=
new
WGEPropertyUniform
<
WPropDouble
>
(
"u_tubeSize"
,
m_tubeSize
);
// get notified about data changes
m_moduleState
.
setResetable
(
true
,
true
);
m_moduleState
.
add
(
m_fiberInput
->
getDataChangedCondition
()
);
...
...
@@ -154,9 +168,10 @@ void WMFiberDisplaySimple::moduleMain()
osg
::
StateSet
*
rootState
=
rootNode
->
getOrCreateStateSet
();
// do not forget to add the uniforms
rootState
->
addUniform
(
m_clipPlanePointUniform
);
rootState
->
addUniform
(
m_clipPlaneVectorUniform
);
rootState
->
addUniform
(
m_clipPlaneDistanceUniform
);
rootState
->
addUniform
(
clipPlanePointUniform
);
rootState
->
addUniform
(
clipPlaneVectorUniform
);
rootState
->
addUniform
(
clipPlaneDistanceUniform
);
rootState
->
addUniform
(
tubeSizeUniform
);
WKernel
::
getRunningKernel
()
->
getGraphicsEngine
()
->
getScene
()
->
insert
(
rootNode
);
// needed to observe the properties of the input connector data
...
...
@@ -261,7 +276,7 @@ osg::ref_ptr< osg::Node > WMFiberDisplaySimple::createClipPlane() const
osg
::
ref_ptr
<
osg
::
Vec4Array
>
planeColor
=
osg
::
ref_ptr
<
osg
::
Vec4Array
>
(
new
osg
::
Vec4Array
);
osg
::
ref_ptr
<
osg
::
Geometry
>
planeGeometry
=
osg
::
ref_ptr
<
osg
::
Geometry
>
(
new
osg
::
Geometry
);
// the plane vertices
planeColor
->
push_back
(
osg
::
Vec4
(
1.0
,
0.0
,
0.0
,
0.125
)
);
planeVertices
->
push_back
(
osg
::
Vec3
(
0.0
,
-
100.0
,
-
100.0
)
);
planeVertices
->
push_back
(
osg
::
Vec3
(
0.0
,
-
100.0
,
100.0
)
);
...
...
@@ -363,7 +378,7 @@ osg::ref_ptr< osg::Node > WMFiberDisplaySimple::createFiberGeode( boost::shared_
colors
->
push_back
(
color
);
tangents
->
push_back
(
tangent
);
if
(
m_
useTubes
->
get
()
)
if
(
m_
tubeEnable
->
get
()
)
{
vertices
->
push_back
(
vert
);
colors
->
push_back
(
color
);
...
...
@@ -379,7 +394,7 @@ osg::ref_ptr< osg::Node > WMFiberDisplaySimple::createFiberGeode( boost::shared_
}
// add the above line-strip
if
(
m_
useTubes
->
get
()
)
if
(
m_
tubeEnable
->
get
()
)
{
geometry
->
addPrimitiveSet
(
new
osg
::
DrawArrays
(
osg
::
PrimitiveSet
::
QUAD_STRIP
,
2
*
currentStart
,
2
*
len
)
);
}
...
...
@@ -397,7 +412,7 @@ osg::ref_ptr< osg::Node > WMFiberDisplaySimple::createFiberGeode( boost::shared_
geometry
->
setColorBinding
(
osg
::
Geometry
::
BIND_PER_VERTEX
);
geometry
->
setNormalArray
(
tangents
);
geometry
->
setNormalBinding
(
osg
::
Geometry
::
BIND_PER_VERTEX
);
if
(
m_
useTubes
->
get
()
)
// tex coords are only needed for fake-tubes
if
(
m_
tubeEnable
->
get
()
)
// tex coords are only needed for fake-tubes
{
geometry
->
setTexCoordArray
(
0
,
texcoords
);
}
...
...
src/modules/fiberDisplaySimple/WMFiberDisplaySimple.h
View file @
6cc8c86c
...
...
@@ -151,27 +151,23 @@ private:
/**
* Prop denoting whether to use tubes or line strips
*/
WPropBool
m_
useTubes
;
WPropBool
m_
tubeEnable
;
/**
*
G
ro
u
p
containing tube specific properties
*
P
rop
denoting whether tubes can be zoomed or not.
*/
WProp
Group
m_tube
Group
;
WProp
Bool
m_tube
Zoomable
;
/**
* Uniform for plane point.
* The size. The meaning somehow relates to tubeZoomable. If a tube is zoomable, the size is the smallest size in pixels on screen of totally
* zoomed out.
*/
osg
::
ref_ptr
<
WGEPropertyUniform
<
WPropPosition
>
>
m_clipPlanePointUniform
;
WPropDouble
m_tubeSize
;
/**
* Uniform for plane vector.
*/
osg
::
ref_ptr
<
WGEPropertyUniform
<
WPropPosition
>
>
m_clipPlaneVectorUniform
;
/**
* Uniform for plane distance.
* Group containing tube specific properties
*/
osg
::
ref_ptr
<
WGEPropertyUniform
<
WPropDouble
>
>
m_clipPlaneDistanceUniform
;
WPropGroup
m_tubeGroup
;
/**
* Update the transform node to provide an cue were the plane actually is.
...
...
src/modules/fiberDisplaySimple/shaders/WMFiberDisplaySimple-fragment.glsl
View file @
6cc8c86c
...
...
@@ -24,7 +24,7 @@
#version 120
#include "WGE
Texture
Tools.glsl"
#include "WGE
Shading
Tools.glsl"
/////////////////////////////////////////////////////////////////////////////
// Varyings
...
...
@@ -37,6 +37,11 @@
varying
float
dist
;
#endif
/**
* The surface normal. Needed for nice lighting.
*/
varying
vec3
v_normal
;
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
...
...
@@ -71,6 +76,7 @@ void main()
}
#endif
gl_FragColor
=
gl_Color
;
float
light
=
blinnPhongIlluminationIntensity
(
normalize
(
v_normal
)
);
gl_FragColor
=
vec4
(
vec3
(
(
1
.
5
-
gl_FragCoord
.
z
)
*
light
),
1
.
0
);
//gl_Color;
}
src/modules/fiberDisplaySimple/shaders/WMFiberDisplaySimple-vertex.glsl
View file @
6cc8c86c
...
...
@@ -35,6 +35,11 @@
varying
float
dist
;
#endif
/**
* The surface normal. Needed for nice lighting.
*/
varying
vec3
v_normal
;
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
...
...
@@ -49,6 +54,11 @@ uniform vec3 u_planePoint;
*/
uniform
vec3
u_planeVector
;
/**
* The size of the tube
*/
uniform
float
u_tubeSize
;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
...
...
@@ -83,10 +93,21 @@ void main()
// The view direction in world-space. In OpenGL this is always defined by this vector
vec3
view
=
vec3
(
0
.
0
,
0
.
0
,
-
1
.
0
);
#ifdef ZOOMABLE_ENABLED
// To avoid that the quad strip gets thinner and thinner when zooming in (or the other way around: to avoid the quad strip always occupies
// the same screen space), we need to calculate the zoom factor involved in OpenWalnut's current camera.
float
worldScale
=
length
(
(
gl_ModelViewMatrix
*
vec4
(
1
.
0
,
1
.
0
,
1
.
0
,
0
.
0
)
).
xyz
);
// worldScale now contains the scaling which is done by ModelView transformation (including the camera).
// With this, we can ensure that our offset (calculated later), which is of unit-length, is scaled acccording to the camera zoom. The
// additional uniform u_tubeSize allows the user to scale the tubes.
// We clamp the value to ensure a minimum width of the quadstrip of 1px on screen:
worldScale
=
clamp
(
u_tubeSize
*
worldScale
,
1
.
0
,
1000000
.
0
);
#else
// In this mode, the tubes should not be zoomed. Just use the user defined size here.
float
worldScale
=
clamp
(
u_tubeSize
,
1
.
0
,
1000000
.
0
);
#endif
// To enforce that each quad's normal points towards the user, we move the two vertex (which are at the same point currently) according to
// the direction stored in gl_MultiTexCoord0
vec3
offset
=
normalize
(
gl_MultiTexCoord0
.
s
*
cross
(
view
,
tangent
)
);
...
...
@@ -94,6 +115,10 @@ void main()
// Apply the offset and scale correctly.
vertex
.
xyz
+=
0
.
1
*
worldScale
*
offset
;
// with the tangent and the view vector we got the offset vector. We can noch get the normal using the tangent and the offset.
v_normal
=
cross
(
offset
,
tangent
);
v_normal
*=
sign
(
dot
(
v_normal
,
vec3
(
0
.
0
,
0
.
0
,
1
.
0
)
)
);
// Simply project the vertex afterwards
gl_Position
=
gl_ProjectionMatrix
*
vertex
;
gl_FrontColor
=
vec4
(
vec3
(
gl_MultiTexCoord0
.
s
),
1
.
0
);
...
...
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