/usr/share/openwalnut/shaders/WGEPostprocessor-fragment.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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | //---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#ifndef WGEPOSTPROCESSOR_FRAGMENT_GLSL
#define WGEPOSTPROCESSOR_FRAGMENT_GLSL
#version 120
#include "WGEShadingTools.glsl"
#include "WGETextureTools.glsl"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Input-Texture Uniforms
// NOTE: do not put post-processor specific uniforms here!
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* The texture Unit for the original color field
*/
uniform sampler2D u_texture0Sampler;
/**
* The texture Unit for the Normal Map
*/
uniform sampler2D u_texture1Sampler;
/**
* The depth texture
*/
uniform sampler2D u_texture2Sampler;
/**
* The white-noise 3 channel texture: sampler
*/
uniform sampler2D u_texture3Sampler;
/**
* The white-noise 3 channel texture: size in x direction
*/
uniform int u_texture3SizeX;
/**
* Size of texture in pixels
*/
uniform int u_texture0SizeX;
/**
* Size of texture in pixels
*/
uniform int u_texture0SizeY;
/**
* Size of texture in pixels
*/
uniform int u_texture0SizeZ;
/**
* Offset to access the neighbouring pixel in a texture.
*/
float offsetX = 1.0 / u_texture0SizeX;
/**
* Offset to access the neighbouring pixel in a texture.
*/
float offsetY = 1.0 / u_texture0SizeY;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Varying
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Global Variables
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* The final color is stored in this global variable
*/
vec4 color = vec4( 1.0 );
/**
* If this value is used as in blend() and is 0.0 if no color has been set to the color variable. If it is 0.5, color has been set earlier. This
* is imply needed to properly blend the colors together without the need of a "initial"-color.
*/
float colorSet = 0.0; // is 0.5 if the color has been set earlier
/**
* The coordinate of the current pixel for texture lookup
*/
vec2 pixelCoord = gl_TexCoord[0].st;
/**
* This is needed for some swizzle tricks
*/
const vec2 zeroOneList = vec2( 1.0, 0.0 );
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Utility functions.
// * Get color at certain point
// * Get normal and depth at certain point
// * Blending utilities
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Returns the original unprocessed color value at the specified point
*
* \param where the pixel to grab
*
* \return the color
*/
vec4 getColor( in vec2 where )
{
return texture2D( u_texture0Sampler, where );
}
/**
* Returns the original unprocessed color value at the current pixel.
*
* \note GLSL does not officially allow default values for function arguments which is why we need this additional function.
*
* \return the color
*/
vec4 getColor()
{
return getColor( pixelCoord );
}
/**
* Grabs the normal at the specified point. The returned normal has been de-scaled to [-1,1] and normalized The w component is 1.
*
* \param where the pixel to grab
*
* \return the normal
*/
vec4 getNormal( in vec2 where )
{
return normalize( texture2DUnscaled( u_texture1Sampler, where, -1.0, 2.0 ).xyz ).xyzz * zeroOneList.xxxy + zeroOneList.yyyx;
}
/**
* Grabs the normal at the current pixel. The returned normal has been de-scaled to [-1,1]. The w component is 1.
*
* \note GLSL does not officially allow default values for function arguments which is why we need this additional function.
*
* \return the normal
*/
vec4 getNormal()
{
return getNormal( pixelCoord );
}
/**
* Grabs the depth at the specified point.
*
* \param where the position where to grab it.
*
* \return the depth
*/
float getDepth( in vec2 where )
{
return texture2D( u_texture2Sampler, where ).r;
}
/**
* Grabs the depth at the current pixel.
*
* \note GLSL does not officially allow default values for function arguments which is why we need this additional function.
*
* \return the depth
*/
float getDepth()
{
return getDepth( pixelCoord );
}
/**
* Blends the specified color to the current overall-color.
*
* \param newColor the new color to blend in.
*/
void blend( in vec4 newColor )
{
color = mix( color, newColor, 1.0 - colorSet );
colorSet = 0.5; // we definitely set the color.
}
/**
* Scales the current color with the specified scaling.
*
* \param f the scaling factor
*/
void blendScale( in float f )
{
color.rgb = mix( color.rgb * f, vec3( f ), 1.0 - ( 2.0 * colorSet ) );
colorSet = 0.5; // we definitely set the color.
}
/**
* Adds the specified color to the current color.
*
* \param newColor the color to add
*/
void blendAdd( in vec4 newColor )
{
color = mix( color + newColor, newColor, 1.0 - ( 2.0 * colorSet ) );
colorSet = 0.5; // we definitely set the color.
}
/**
* Adds the specified value as vec4 to the current color.
*
* \param f the scaling factor
*/
void blendAdd( in float f )
{
blendAdd( vec4( vec3( f ), 1.0 ) );
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Postprocessors
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Phong based Per-Pixel-Lighting.
*
* \param normal the surface normal. Normalized.
*
* \return the intensity.
*/
float getPPLPhong( vec3 normal )
{
// TODO(ebaum): provide properties/uniforms for the scaling factors here
return blinnPhongIlluminationIntensity(
0.2 , // material ambient
0.75, // material diffuse
0.5, // material specular
100.0, // shinines
1.0, // light diffuse
0.3, // light ambient
normal, // normal
vec4( 0.0, 0.0, 1.0, 1.0 ).xyz, // view direction // in world space, this always is the view-dir
gl_LightSource[0].position.xyz // light source position
);
}
/**
* Phong based Per-Pixel-Lighting based on the specified color.
*
* \return the new lighten color.
*/
float getPPLPhong()
{
return getPPLPhong( getNormal().xyz );
}
/**
* Apply laplace-filter to depth buffer. An edge is > 0.0.
*
* \return the edge
*/
float getEdge()
{
// TODO(ebaum): provide properties/uniforms for the scaling factors here
/////////////////////////////////////////////////////////////////////////////////////////////
// GETTING TEXELS
//
// Get surrounding texels; needed for ALL filters
/////////////////////////////////////////////////////////////////////////////////////////////
float edgec = getDepth( pixelCoord );
float edgebl = getDepth( pixelCoord + vec2( -offsetX, -offsetY ) );
float edgel = getDepth( pixelCoord + vec2( -offsetX, 0.0 ) );
float edgetl = getDepth( pixelCoord + vec2( -offsetX, offsetY ) );
float edget = getDepth( pixelCoord + vec2( 0.0, offsetY ) );
float edgetr = getDepth( pixelCoord + vec2( offsetX, offsetY ) );
float edger = getDepth( pixelCoord + vec2( offsetX, 0.0 ) );
float edgebr = getDepth( pixelCoord + vec2( offsetX, offsetY ) );
float edgeb = getDepth( pixelCoord + vec2( 0.0, -offsetY ) );
/////////////////////////////////////////////////////////////////////////////////////////////
// LAPLACE
//
// apply a standart laplace filter kernel
/////////////////////////////////////////////////////////////////////////////////////////////
// laplace filter kernel
float edge = 16.0 * abs(
0.0 * edgetl + 1.0 * edget + 0.0 * edgetr +
1.0 * edgel + -4.0 * edgec + 1.0 * edger +
0.0 * edgebl + 1.0 * edgeb + 0.0 * edgebr
);
// MPI Paper Hack, to make edges black and surrundings white
// return 1 - edge;
return edge;
}
/**
* Returns the gauss-smoothed color of the specified pixel from the input color texture.
*
* \param where the pixel to grab
*
* \return the color
*/
vec4 getGaussedColor( vec2 where )
{
// TODO(ebaum): provide properties/uniforms for the scaling factors here
// get the 8-neighbourhood
vec4 gaussedColorc = getColor( where );
vec4 gaussedColorbl = getColor( where + vec2( -offsetX, -offsetY ) );
vec4 gaussedColorl = getColor( where + vec2( -offsetX, 0.0 ) );
vec4 gaussedColortl = getColor( where + vec2( -offsetX, offsetY ) );
vec4 gaussedColort = getColor( where + vec2( 0.0, offsetY ) );
vec4 gaussedColortr = getColor( where + vec2( offsetX, offsetY ) );
vec4 gaussedColorr = getColor( where + vec2( offsetX, 0.0 ) );
vec4 gaussedColorbr = getColor( where + vec2( offsetX, offsetY ) );
vec4 gaussedColorb = getColor( where + vec2( 0.0, -offsetY ) );
// apply Gauss filter
vec4 gaussed = ( 1.0 / 16.0 ) * (
1.0 * gaussedColortl + 2.0 * gaussedColort + 1.0 * gaussedColortr +
2.0 * gaussedColorl + 4.0 * gaussedColorc + 2.0 * gaussedColorr +
1.0 * gaussedColorbl + 2.0 * gaussedColorb + 1.0 * gaussedColorbr );
return gaussed;
}
/**
* Returns the gauss-smoothed color of the current pixel from the input color texture.
*
* \return the color
*/
vec4 getGaussedColor()
{
return getGaussedColor( pixelCoord );
}
/**
* Returns the gauss-smoothed depth of the specified ixel from the input color texture.
*
* \param where the point to grab
*
* \return the gaussed depth
*/
float getGaussedDepth( vec2 where )
{
// TODO(ebaum): provide properties/uniforms for the scaling factors here
// get the 8-neighbourhood
float gaussedDepthc = getDepth( where );
float gaussedDepthbl = getDepth( where + vec2( -offsetX, -offsetY ) );
float gaussedDepthl = getDepth( where + vec2( -offsetX, 0.0 ) );
float gaussedDepthtl = getDepth( where + vec2( -offsetX, offsetY ) );
float gaussedDeptht = getDepth( where + vec2( 0.0, offsetY ) );
float gaussedDepthtr = getDepth( where + vec2( offsetX, offsetY ) );
float gaussedDepthr = getDepth( where + vec2( offsetX, 0.0 ) );
float gaussedDepthbr = getDepth( where + vec2( offsetX, offsetY ) );
float gaussedDepthb = getDepth( where + vec2( 0.0, -offsetY ) );
// apply Gauss filter
float gaussed = ( 1.0 / 16.0 ) * (
1.0 * gaussedDepthtl + 2.0 * gaussedDeptht + 1.0 * gaussedDepthtr +
2.0 * gaussedDepthl + 4.0 * gaussedDepthc + 2.0 * gaussedDepthr +
1.0 * gaussedDepthbl + 2.0 * gaussedDepthb + 1.0 * gaussedDepthbr );
return gaussed;
}
/**
* Returns the gauss-smoothed depth of the current pixel from the input depth texture.
*
* \return the gaussed depth
*/
float getGaussedDepth()
{
return getGaussedDepth( pixelCoord );
}
/**
* Calculate the cel-shading of a specified color. The number of colors is defined by the u_celShadingSamples uniform.
*
* \param inColor the color to shade
*
* \return the cel-shaded color
*/
vec4 getCelShading( vec4 inColor )
{
// TODO(ebaum): provide uniform for this
float samples = 5.0;
return vec4(
vec3( int( ( inColor * samples ).r ),
int( ( inColor * samples ).g ),
int( ( inColor * samples ).b ) ) / samples, inColor.a );
}
/**
* Calculate the cel-shading of the input color. The number of colors is defined by the u_celShadingSamples uniform.
*
* \return the cel-shaded color
*/
vec4 getCelShading()
{
return getCelShading( getColor() );
}
/**
* Returns a fade-out factor basing on pixel depth for the specified pixel
*
* \param where pixel coordinate
*
* \return the fade-out factor.
*/
float getDepthFading( vec2 where )
{
// TODO(ebaum): add uniforms for this limits
float invD = ( 1.0 - getDepth( where ) );
return smoothstep( 0.20, 0.5, invD );
}
/**
* Returns a fade-out factor basing on pixel depth for the current pixel.
*
* \return the fade-out factor.
*/
float getDepthFading()
{
return getDepthFading( pixelCoord );
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Main. Apply the specified post-processors.
*/
void main()
{
// don't do this stuff for background pixel
float depth = getDepth();
gl_FragDepth = depth;
if( depth > 0.99 )
{
discard;
}
// NOTE: Although the GLSL compiler might not be the most intelligent one, it will most probably be smart enough the reduce many texture
// fetch operations on the same sampler and same position to one fetch and provides the result in a variable. So it is not stupid to use
// getColor or getNormal or getDepth many times on the same u,v coordinate.
#ifdef WGE_POSTPROCESSOR_COLOR
blend( getColor() );
#endif
#ifdef WGE_POSTPROCESSOR_GAUSSEDCOLOR
blend( getGaussedColor() );
#endif
#ifdef WGE_POSTPROCESSOR_PPLPHONG
blendScale( getPPLPhong() );
#endif
#ifdef WGE_POSTPROCESSOR_CELSHADING
blend( getCelShading() );
#endif
#ifdef WGE_POSTPROCESSOR_DEPTHFADING
blendScale( getDepthFading() );
#endif
#ifdef WGE_POSTPROCESSOR_EDGE
blendAdd( getEdge() );
#endif
#ifdef WGE_POSTPROCESSOR_DEPTH
blendScale( depth );
#endif
#ifdef WGE_POSTPROCESSOR_GAUSSEDDEPTH
blendScale( getGaussedDepth() );
#endif
#ifdef WGE_POSTPROCESSOR_NORMAL
blend( getNormal() );
#endif
#ifdef WGE_POSTPROCESSOR_CUSTOM
vec4 customColor = vec4( 0.0 );
%WGEPostprocessor-CustomCode%
blend( customColor );
#endif
// output the depth and final color.
gl_FragColor = color;
}
#endif // WGEPOSTPROCESSOR_FRAGMENT_GLSL
|