File: reflexion_lines.frag

package info (click to toggle)
meshlab 2022.02%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,348 kB
  • sloc: cpp: 536,635; ansic: 27,783; sh: 539; makefile: 36
file content (62 lines) | stat: -rw-r--r-- 3,142 bytes parent folder | download | duplicates (7)
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
/****************************************************************************
* MeshLab                                                           o o     *
* An extendible mesh processor                                    o     o   *
*                                                                _   O  _   *
* Copyright(C) 2005, 2009                                          \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* This program is free software; you can redistribute it and/or modify      *
* it under the terms of the GNU General Public License as published by      *
* the Free Software Foundation; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* This program 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 General Public License (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/
//
// reflexion_lines.vert: Fragment shader for rendering with reflexion lines
//
// author: Gael Guennebaud
//

varying vec3 EyePos;
varying vec3 Normal;

uniform float ScaleFactor;
uniform float Smoothing;
uniform float Shading;

float arcSinus(float x) {
	return x * (1.0 + x*x * ((1.0/6.0) + x*x * ((3.0/40.0) + (15.0/336.0)*x*x)));
}

void main (void)
{
    vec4 color;

    vec3 reflexionVector;
    vec3 n = normalize(Normal);
    vec3 viewVec = normalize(EyePos);
    reflexionVector = viewVec.xyz - 2.0*n*dot(n,viewVec.xyz);
    reflexionVector.z += 1.0;
    reflexionVector.z = 0.5/sqrt(dot(reflexionVector,reflexionVector));
    reflexionVector.xy = (reflexionVector.xy*reflexionVector.z) + 0.5;
    reflexionVector *= 2.0;
//    color = vec4(clamp(0.5 + Smoothing * sin(2.0 * 3.1428 * reflexionVector.x*ScaleFactor), 0.0, 1.0),
//			clamp(0.5 + Smoothing * sin(2.0 * 3.1428 * reflexionVector.y*ScaleFactor), 0.0, 1.0),
//			clamp(0.5 + Smoothing * sin(2.0 * 3.1428 * reflexionVector.z*ScaleFactor), 0.0, 1.0),
//			1.0);
	
	float sharpness = 1.0/arcSinus(Smoothing*fwidth(reflexionVector.x)*2.0*ScaleFactor);
    color = vec4(clamp(0.5 + sharpness * sin(2.0 * 3.1428 * reflexionVector.x*ScaleFactor), 0.0, 1.0));
    color.a = 1.0;
    gl_FragColor = vec4(vec3(sharpness), 1.0);
	gl_FragColor = clamp(dot(gl_LightSource[0].position.xyz, n)*Shading + (1.0-Shading), 0.0, 1.0) * min(color, vec4(1.0,1.0,1.0,1.0));
}