WMPointRenderer-fragment.glsl 3.79 KB
Newer Older
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
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------

#version 120

#extension GL_EXT_geometry_shader4 : enable

#include "WGEShadingTools.glsl"
#include "WGETextureTools.glsl"
#include "WGEPostprocessing.glsl"

/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////

/**
 * The normal in world-space
 */
varying vec3 v_normalWorld;

/**
 * The vertex coordinate in world-space
 */
varying vec3 v_vertex;

/**
 * The texture coordinates in [-1,1]
 */
varying vec3 v_texCoord;

/**
 * The scaling component of the modelview matrix.
 */
varying float v_worldScale;

/**
 * The radius of a sphere in world-space
 */
varying float v_worldSpaceRadius;

/**
 * The center point of the sphere
 */
varying vec3 v_centerPoint;

/**
 * Depth of the center point
 */
varying float v_centerVertexDepth;

/**
 * Deptj of the neareast point on the sphere towards the camera
 */
varying float v_nearestVertexDepth;

/**
 * Difference between nearest depth and center point depth
 */
varying float v_vertexDepthDiff;

/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////

/**
 * Main entry point of the fragment shader.
 */
void main()
{
    // create a sphere
    float r = 1.0 - ( ( v_texCoord.x * v_texCoord.x ) + ( v_texCoord.y * v_texCoord.y ) );
    if( r < 0.0 )
        discard;

    vec3 sphereSurf = v_vertex - v_centerPoint;
    sphereSurf.z += r * v_worldSpaceRadius;
    sphereSurf = normalize( sphereSurf );

    // lighting
113
    // NOTE: this is disabled as usually, we use a headlight, causing a specular highlight in the middle of each splat.
114 115 116 117
    // float light = blinnPhongIlluminationIntensity( wge_DefaultLightIntensity, sphereSurf );

    // finally set the color and depth
    wgeInitGBuffer();
118
    wge_FragColor = vec4( gl_Color.rgb * r , gl_Color.a );
119
    wge_FragNormal = textureNormalize( sphereSurf );
120
    wge_FragZoom = v_worldScale;
121
    wge_FragTangent = textureNormalize( vec3( 0.0, 1.0, 0.0 ) );
122 123
#ifdef DEPTHWRITE_ENABLED
    // we allow to disable depth write. This allows the GPU to disacard pixels before applying the fragment shader -> speedup
124
    gl_FragDepth = ( r * v_vertexDepthDiff ) + v_centerVertexDepth;
125
#endif
126 127
}