/usr/share/openwalnut/shaders/WGEShadingTools.glsl is in libopenwalnut1 1.2.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | //---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#ifndef WGESHADINGTOOLS_GLSL
#define WGESHADINGTOOLS_GLSL
#version 120
/**
* A struct containing the needed light and material parameters commonly used in most shaders.
*
* \note This is for evaluating the phong equation for 1 channel only.
*/
struct wge_LightIntensityParameter
{
// These 4 parameters are similar to those in gl_MaterialParameters
float materialAmbient; //!< Material ambient intensity.
float materialDiffuse; //!< Material diffuse intensity.
float materialSpecular; //!< Material Specular intensity.
float materialShinines; //!< Material shinines factor
// These 4 parametes are a stripped down version of gl_LightSourceParameters
float lightDiffuse; //!< Light diffuse intensity.
float lightAmbient; //!< Light ambient intensity.
vec3 lightPosition; //!< Light position in world-space
vec3 viewDirection; //!< View direction vector. Well this actually is -vec3( 0.0, 0.0, -1.0 )
};
/**
* This variable contains the OpenWalnut default light. You should definitely use this for your lighting to obtain an identical look for all
* rendered images.
*/
wge_LightIntensityParameter wge_DefaultLightIntensity = wge_LightIntensityParameter(
0.2, // material ambient
0.75, // material diffuse
1.0, // material specular
100.0, // material shininess
1.0, // light diffuse
0.2, // light ambient
gl_LightSource[0].position.xyz, // light position
vec3( 0.0, 0.0, 1.0 ) // view direction
);
/**
* This variable contains the OpenWalnut default light. You should definitely use this for your lighting to obtain an identical look for all
* rendered images. This version looks a little bit more metallic.
*/
wge_LightIntensityParameter wge_DefaultLightIntensityLessDiffuse = wge_LightIntensityParameter(
0.2, // material ambient
0.35, // material diffuse
1.0, // material specular
100.0, // material shininess
1.0, // light diffuse
0.2, // light ambient
gl_LightSource[0].position.xyz, // light position
vec3( 0.0, 0.0, 1.0 ) // view direction
);
/**
* Function to calculate lighting based on "Real-Time Volume Graphics, p 119, chapter 5.4, Listing 5.1".
*
* \param ambient materials ambient color
* \param diffuse materials diffuse color
* \param specular materials specular color
* \param shininess material shininess
* \param lightColor the light color
* \param ambientLight the ambient light color
* \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 )
{
vec3 H = normalize( lightDir + viewDir );
// compute ambient term
vec3 ambientV = ambient * ambientLight;
// compute diffuse term
float diffuseLight = max( dot( lightDir, normalDir ), 0.0 );
vec3 diffuseV = diffuse * diffuseLight;
// compute specular term
float specularLight = pow( max( dot( H, normalDir ), 0.0 ), shininess );
if( diffuseLight <= 0.) specularLight = 0.;
vec3 specularV = specular * specularLight;
return vec4( ambientV + ( diffuseV + specularV ) * lightColor, 1.0 );
}
/**
* Function to calculate lighting intensity based 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
* the intensity.
*
* \param ambient materials ambient intensity
* \param diffuse materials diffuse intensity
* \param specular materials specular intensity
* \param shininess material shininess
* \param lightIntensity the light intensity
* \param ambientIntensity the ambient light intensity
* \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 )
{
vec3 H = normalize( lightDir + viewDir );
// compute ambient term
float ambientV = ambient * ambientIntensity;
// compute diffuse term
float diffuseLight = max( dot( lightDir, normalDir ), 0.0 );
float diffuseV = diffuse * diffuseLight;
// compute specular term
float specularLight = pow( max( dot( H, normalDir ), 0.0 ), shininess );
if( diffuseLight <= 0.) specularLight = 0.;
float specularV = specular * specularLight;
return ambientV + ( diffuseV + specularV ) * lightIntensity;
}
/**
* Function to calculate lighting intensity based 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
* the intensity.
*
* \param parameter the wge_LightIntensityParameter defining material and light
* \param normal the normal. Needs to be normalized.
*
* \return lighting intensity.
*/
float blinnPhongIlluminationIntensity( in wge_LightIntensityParameter parameter, in vec3 normal )
{
return blinnPhongIlluminationIntensity(
parameter.materialAmbient,
parameter.materialDiffuse,
parameter.materialSpecular,
parameter.materialShinines,
parameter.lightDiffuse,
parameter.lightAmbient,
normal,
parameter.viewDirection,
parameter.lightPosition
);
}
/**
* Function to calculate lighting intensity based 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
* the intensity. This uses the wge_DefaultLightIntensity.
*
* \param normal the normal. Must be normalized beforehand
*
* \return the light intensity
*/
float blinnPhongIlluminationIntensity( in vec3 normal )
{
return blinnPhongIlluminationIntensity( wge_DefaultLightIntensity, normal );
}
/**
* Calculates the gradient inside a luminance 3D texture at the specified position.
*
* \param sampler the texture sampler to use
* \param pos where in the texture
* \param stepsize the offset used in the kernel. Should be related to the nb. of voxels.
*
* \return the gradient
*/
vec3 getGradient( in sampler3D sampler, in vec3 pos, in float stepsize )
{
float valueXP = texture3D( sampler, pos + vec3( stepsize, 0.0, 0.0 ) ).r;
float valueXM = texture3D( sampler, pos - vec3( stepsize, 0.0, 0.0 ) ).r;
float valueYP = texture3D( sampler, pos + vec3( 0.0, stepsize, 0.0 ) ).r;
float valueYM = texture3D( sampler, pos - vec3( 0.0, stepsize, 0.0 ) ).r;
float valueZP = texture3D( sampler, pos + vec3( 0.0, 0.0, stepsize ) ).r;
float valueZM = texture3D( sampler, pos - vec3( 0.0, 0.0, stepsize ) ).r;
return vec3( valueXP - valueXM, valueYP - valueYM, valueZP - valueZM );
}
/**
* Calculates the gradient inside a luminance 3D texture at the specified position.
*
* \param sampler the texture sampler to use
* \param pos where in the texture
*
* \return the gradient
*/
vec3 getGradient( in sampler3D sampler, in vec3 pos )
{
// unfortunately the ATI driver does not allow default values for function arguments
return getGradient( sampler, pos, 0.005 );
}
/**
* Calculates the gradient in a luminance 3D texture at the specified position. Unlike getGradient, this switches the orientation of the gradient
* according to the viewing direction. This ensures, that the gradient always points towards the camera and therefore is useful as a normal.
*
* \param sampler the texture sampler to use
* \param pos where in the texture
* \param viewDir the direction from the camera to pos
* \param stepsize the offset used in the kernel. Should be related to the nb. of voxels.
*
* \return the gradient
*/
vec3 getGradientViewAligned( in sampler3D sampler, in vec3 pos, in vec3 viewDir, in float stepsize )
{
vec3 grad = getGradient( sampler, pos, stepsize );
return sign( dot( grad, -viewDir ) ) * grad;
}
/**
* Calculates the gradient in a luminance 3D texture at the specified position. Unlike getGradient, this switches the orientation of the gradient
* according to the viewing direction. This ensures, that the gradient always points towards the camera and therefore is useful as a normal.
*
* \param sampler the texture sampler to use
* \param pos where in the texture
* \param viewDir the direction from the camera to pos
*
* \return the gradient
*/
vec3 getGradientViewAligned( in sampler3D sampler, in vec3 pos, in vec3 viewDir )
{
// unfortunately the ATI driver does not allow default values for function arguments
return getGradientViewAligned( sampler, pos, viewDir, 0.005 );
}
/**
* Re-orient the specified vector to point towards the camera. This should be done AFTER modelview transformation.
*
* \param v the vector to re-orient
*
* \return the new vector. Only normalized if v was normalized.
*/
vec3 viewAlign( vec3 v )
{
return sign( dot( v, vec3( 0.0, 0.0, 1.0 ) ) ) * v;
}
#endif // WGESHADINGTOOLS_GLSL
|