Commit 3aa922c4 authored by Alexander Wiebel's avatar Alexander Wiebel

[ADD #390] Style checking for glsl shaders

[STYLE #390] adapted all shaders to style
parent 599948cd
......@@ -285,6 +285,7 @@ ENDIF()
# noncolored if it is set to OFF
FILE( GLOB_RECURSE STYLE_CPP ${PROJECT_SOURCE_DIR}/*.cpp )
FILE( GLOB_RECURSE STYLE_H ${PROJECT_SOURCE_DIR}/*.h )
FILE( GLOB_RECURSE STYLE_GLSL ${PROJECT_SOURCE_DIR}/*.glsl )
# Set dirs to exclude from stylecheck
SET( EXCLUDE_DIRS "/ext/nifti/;/dataHandler/io/biosig/;/dataHandler/io/biosigWin/;/dataHandler/io/biosig/XMLParser/;/dataHandler/io/biosigWin/XMLParser/;/ext/libeep/avr/;/ext/libeep/cnt/;/ext/libeep/eep/;/common/platformDependent/visualStudio/;/modules/lic/fibernavigator/;/modules/lic/fantom/" )
FOREACH( dirname ${EXCLUDE_DIRS} )
......@@ -316,7 +317,7 @@ ELSE()
ENDIF()
FILE( WRITE ${PROJECT_BINARY_DIR}/brainlintlist "" )
FOREACH( fname ${STYLE_CPP} ${STYLE_H} )
FOREACH( fname ${STYLE_CPP} ${STYLE_H} ${STYLE_GLSL} )
FILE( APPEND ${PROJECT_BINARY_DIR}/brainlintlist "${fname}\n" )
ENDFOREACH()
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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/>.
//
//---------------------------------------------------------------------------
varying vec3 normal;
varying vec4 vertex;
varying vec3 halfvec;
const vec4 AMBIENT_BLACK = vec4(0.0, 0.0, 0.0, 1.0);
const vec4 DEFAULT_BLACK = vec4(0.0, 0.0, 0.0, 0.0);
const vec4 AMBIENT_BLACK = vec4( 0.0, 0.0, 0.0, 1.0 );
const vec4 DEFAULT_BLACK = vec4( 0.0, 0.0, 0.0, 0.0 );
void directionalLight( in int i, in vec3 normal, in float shininess,
inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
inout vec4 ambient, inout vec4 diffuse, inout vec4 specular )
{
float nDotVP;
float nDotHV;
float pf;
vec3 L = normalize (gl_LightSource[i].position.xyz - vertex.xyz);
vec3 H = normalize (L + halfvec.xyz);
vec3 L = normalize( gl_LightSource[i].position.xyz - vertex.xyz );
vec3 H = normalize( L + halfvec.xyz );
nDotVP = max(0.0, dot(normal, normalize((gl_LightSource[i].position.xyz))));
nDotHV = max(0.0, dot(normal, H));
nDotVP = max( 0.0, dot( normal, normalize( ( gl_LightSource[i].position.xyz ) ) ) );
nDotHV = max( 0.0, dot( normal, H ) );
if (nDotVP == 0.0)
if ( nDotVP == 0.0 )
pf = 0.0;
else
pf = pow(nDotHV, gl_FrontMaterial.shininess);
pf = pow( nDotHV, gl_FrontMaterial.shininess );
ambient += gl_LightSource[i].ambient;
diffuse += gl_LightSource[i].diffuse * nDotVP;
specular += gl_LightSource[i].specular * pf;
}
void calculateLighting(in vec3 N, in float shininess, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
void calculateLighting( in vec3 N, in float shininess, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular )
{
directionalLight(0, N, shininess, ambient, diffuse, specular);
directionalLight( 0, N, shininess, ambient, diffuse, specular );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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/>.
//
//---------------------------------------------------------------------------
varying vec3 normal;
varying vec4 vertex;
varying vec3 halfvec;
const vec4 AMBIENT_BLACK = vec4(0.0, 0.0, 0.0, 1.0);
const vec4 DEFAULT_BLACK = vec4(0.0, 0.0, 0.0, 0.0);
const vec4 AMBIENT_BLACK = vec4( 0.0, 0.0, 0.0, 1.0 );
const vec4 DEFAULT_BLACK = vec4( 0.0, 0.0, 0.0, 0.0 );
/**
* Computes normal and makes transformation to eye space.
......@@ -11,12 +35,12 @@ const vec4 DEFAULT_BLACK = vec4(0.0, 0.0, 0.0, 0.0);
void prepareLight()
{
// Calculate the normal
normal = normalize(gl_NormalMatrix * gl_Normal).xyz;
normal = normalize( gl_NormalMatrix * gl_Normal ).xyz;
// Transform the vertex position to eye space
vertex = vec4(gl_ModelViewMatrix * gl_Vertex);
vertex = vec4( gl_ModelViewMatrix * gl_Vertex );
vec3 L = normalize(gl_LightSource[0].position.xyz - vertex.xyz);
vec3 L = normalize( gl_LightSource[0].position.xyz - vertex.xyz );
halfvec = vec3(L + vec3(0.0, 0.0, 1.0));
halfvec = vec3( L + vec3( 0.0, 0.0, 1.0 ) );
}
/**
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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/>.
//
//---------------------------------------------------------------------------
/**
* Function to calculate lighting based on "Real-Time Volume Graphics, p 119, chapter 5.4, Listing 5.1".
*
* @param ambient materials ambient color
......@@ -10,33 +34,33 @@
* @param normalDir the normal
* @param viewDir viewing direction
* @param lightDir light direction
*
*
* @return the color.
*/
vec4 blinnPhongIllumination( vec3 ambient, vec3 diffuse, vec3 specular, float shininess,
vec3 lightColor, vec3 ambientLight,
vec3 normalDir, vec3 viewDir, vec3 lightDir )
vec4 blinnPhongIllumination( vec3 ambient, vec3 diffuse, vec3 specular, float shininess,
vec3 lightColor, vec3 ambientLight,
vec3 normalDir, vec3 viewDir, vec3 lightDir )
{
vec3 H = normalize( lightDir + viewDir );
// compute ambient term
vec3 ambientV = ambient * ambientLight;
// compute diffuse term
float diffuseLight = max(dot(lightDir, normalDir), 0.);
float diffuseLight = max( dot( lightDir, normalDir ), 0. );
vec3 diffuseV = diffuse * diffuseLight;
// compute specular term
float specularLight = pow(max(dot(H, normalDir), 0.), shininess);
float specularLight = pow( max( dot( H, normalDir ), 0. ), shininess );
if( diffuseLight <= 0.) specularLight = 0.;
vec3 specularV = specular * specularLight;
return vec4(ambientV + (diffuseV + specularV)*lightColor, 1.);
return vec4( ambientV + ( diffuseV + specularV ) * lightColor, 1. );
}
/**
/**
* @brief Function to calculate lighting intensitybased on "Real-Time Volume Graphics, p 119, chapter 5.4, Listing 5.1".
* It is basically the same as blinnPhongIllumination function above. But it is faster if you just need
* It is basically the same as blinnPhongIllumination function above. But it is faster if you just need
* the intensity.
*
* @param ambient materials ambient intensity
......@@ -48,27 +72,28 @@ vec4 blinnPhongIllumination( vec3 ambient, vec3 diffuse, vec3 specular, float sh
* @param normalDir the normal
* @param viewDir viewing direction
* @param lightDir light direction
*
*
* @return the light intensity.
*/
float blinnPhongIlluminationIntensity(float ambient, float diffuse, float specular, float shininess,
float lightIntensity, float ambientIntensity,
vec3 normalDir, vec3 viewDir, vec3 lightDir )
float blinnPhongIlluminationIntensity( float ambient, float diffuse, float specular,
float shininess,
float lightIntensity, float ambientIntensity,
vec3 normalDir, vec3 viewDir, vec3 lightDir )
{
vec3 H = normalize( lightDir + viewDir );
// compute ambient term
float ambientV = ambient * ambientIntensity;
// compute diffuse term
float diffuseLight = max(dot(lightDir, normalDir), 0.);
float diffuseLight = max( dot( lightDir, normalDir ), 0. );
float diffuseV = diffuse * diffuseLight;
// compute specular term
float specularLight = pow(max(dot(H, normalDir), 0.), shininess);
float specularLight = pow( max( dot( H, normalDir ), 0. ), shininess );
if( diffuseLight <= 0.) specularLight = 0.;
float specularV = specular * specularLight;
return ambientV + (diffuseV + specularV)*lightIntensity;
return ambientV + ( diffuseV + specularV ) * lightIntensity;
}
......@@ -25,9 +25,9 @@
/**
* 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 )
......@@ -37,29 +37,29 @@ vec3 project( vec4 point )
// 2: scale to screen space and [0,1]
pointProjected.x /= pointProjected.w;
pointProjected.x = pointProjected.x * 0.5 + 0.5 ;
pointProjected.x = pointProjected.x * 0.5 + 0.5;
pointProjected.y /= pointProjected.w;
pointProjected.y = pointProjected.y * 0.5 + 0.5 ;
pointProjected.y = pointProjected.y * 0.5 + 0.5;
pointProjected.z /= pointProjected.w;
pointProjected.z = pointProjected.z * 0.5 + 0.5 ;
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
*
*
* \return the projected vector in unscaled screen-space ( [-1,1] per component )
*/
vec3 projectVector( vec4 vector )
{
vec4 base = vec4( 0.0, 0.0, 0.0, 1.0 );
vec4 diff = vector;
vec4 diffP=gl_ModelViewProjectionMatrix * diff;
vec4 baseP=gl_ModelViewProjectionMatrix * base;
vec4 diffP = gl_ModelViewProjectionMatrix * diff;
vec4 baseP = gl_ModelViewProjectionMatrix * base;
// scale by w
diffP.x /= diffP.w;
......@@ -75,9 +75,9 @@ vec3 projectVector( vec4 vector )
/**
* 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.
......@@ -90,9 +90,9 @@ vec3 projectVector( vec3 vector )
/**
* 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
......@@ -103,11 +103,11 @@ vec3 project( vec3 point )
}
/**
* This function transforms a point which is in world space, to a point in the local coordinate system of the object
* 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
*/
vec4 worldToLocal( vec4 point )
......@@ -116,11 +116,11 @@ vec4 worldToLocal( vec4 point )
}
/**
* This function transforms a point which is in world space, to a point in the local coordinate system of the object
* 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
......@@ -131,12 +131,12 @@ vec4 worldToLocal( vec3 point )
}
/**
* This function transforms a vector which is in world space, to a point in the local coordinate system of the object
* 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 )
......@@ -145,12 +145,12 @@ vec4 worldToLocal( vec4 point1, vec4 point2 )
}
/**
* This function transforms a vector which is in world space, to a point in the local coordinate system of the object
* 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
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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/>.
//
//---------------------------------------------------------------------------
//
// This makes threshold lying between min and max to lie between 0 and 1
// where 0 correspond to min and 1 to max
// where 0 corresponds to min and 1 to max
//
float scaleZeroOne( in float threshold, in float min, in float max )
{
......
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
varying vec3 tangentR3; // Tangent vector in world space
varying float s_param; // s parameter of texture [-1..1]
varying float tangent_dot_view;
......@@ -28,37 +52,40 @@ float lookupTex()
if ( col1.r < threshold )
{
discard;
discard;
}
else
{
return col1.r;
}
}
/*
/**
* simple fragment shader that does rendering of tubes with diffuse illumination
*/
void main()
{
vec3 color;
vec3 color;
if ( useTexture )
{
float value = lookupTex();
colorMap(color.rgb, value, cMap );
}
else
{
color = abs(normalize(myColor.rgb));
}
if ( useTexture )
{
float value = lookupTex();
colorMap( color.rgb, value, cMap );
}
else
{
color = abs( normalize( myColor.rgb ) );
}
vec3 view = vec3(0., 0., -1.);
float view_dot_normal = sqrt(1. - s_param * s_param) + .1;
vec3 view = vec3( 0., 0., -1. );
float view_dot_normal = sqrt( 1. - s_param * s_param ) + .1;
gl_FragColor.rgb = clamp(view_dot_normal * (color + 0.15 * pow( view_dot_normal, 10.) *
pow(tangent_dot_view, 10.) * vec3(1., 1., 1.)), 0., 1.); //< set the color of this fragment (i.e. pixel)
// set the color of this fragment (i.e. pixel)
gl_FragColor.rgb = clamp( view_dot_normal
* ( color + 0.15 * pow( view_dot_normal, 10. )
* pow( tangent_dot_view, 10. )
* vec3( 1., 1., 1. ) ), 0., 1. );
gl_FragColor.a = myColor.a;
gl_FragColor.a = myColor.a;
}
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
varying float tangent_dot_view;
varying vec3 tangentR3;
varying float s_param;
......@@ -8,29 +32,29 @@ varying vec4 VaryingTexCoord0;
void main()
{
VaryingTexCoord0 = gl_Vertex;
gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; //< make clipping planes work
vec3 tangent;
gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; //< make clipping planes work
vec3 tangent;
float thickness = 0.01 * u_thickness/ 100.;
float thickness = 0.01 * u_thickness/ 100.;
tangentR3 = gl_Normal;
tangent = (gl_ModelViewProjectionMatrix * vec4(gl_Normal,0.)).xyz; //< transform our tangent vector
s_param = gl_MultiTexCoord0.x; //< store texture coordinate for shader
tangentR3 = gl_Normal;
tangent = ( gl_ModelViewProjectionMatrix * vec4( gl_Normal, 0. ) ).xyz; //< transform our tangent vector
s_param = gl_MultiTexCoord0.x; //< store texture coordinate for shader
vec3 offsetNN = cross( normalize(tangent.xyz), vec3(0.,0.,-1.));
vec3 offset = normalize(offsetNN);
tangent_dot_view = length(offsetNN);
vec3 offsetNN = cross( normalize( tangent.xyz ), vec3( 0., 0., -1. ) );
vec3 offset = normalize( offsetNN );
tangent_dot_view = length( offsetNN );
vec4 pos = ftransform(); //< transform position to eye space
vec4 pos = ftransform(); //< transform position to eye space
offset.x *= thickness;
offset.y *= thickness;
offset.x *= thickness;
offset.y *= thickness;
pos.xyz += offset * (s_param); //< add offset in y-direction (eye-space)
pos.xyz += offset * ( s_param ); //< add offset in y-direction (eye-space)
myColor = gl_Color;
myColor = gl_Color;
gl_Position = pos; //< store final position
gl_Position = pos; //< store final position
}
//---------------------------------------------------------------------------
//
// 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.