-
Notifications
You must be signed in to change notification settings - Fork 23
/
rought_glsl.txt
executable file
·63 lines (56 loc) · 1.84 KB
/
rought_glsl.txt
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
//pref
Ambient|float|0.0|0.5|1
Diffuse|float|0.0|0.7|1
Specular|float|0.0|0.2|1
Shininess|float|1|60|120
Rough|float|0|0.1|1
Blinn-Phong shading with Lambertian diffuse. Copyright 2015 Chris Rorden, BSD2clause.|note
//vert
#version 330
layout(location = 0) in vec3 Vert;
layout(location = 3) in vec3 Norm;
layout(location = 6) in vec4 Clr;
out vec3 vN, vL, vV;
out vec4 vClr, vP;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
uniform float Rough = 0.1;
uniform vec3 LightPos = vec3(0.0, 20.0, 30.0); //LR, -DU+, -FN+
void main() {
vN = normalize((NormalMatrix * Norm));
vP = vec4(Vert, 1.0);
gl_Position = ModelViewProjectionMatrix * vec4(Vert, 1.0);
float rnd = fract(sin(gl_Position.x * 12.9898 + gl_Position.y * 78.233) * 43758.5453);
vec3 rnd3 = noise3(rnd) * Rough;
vN = normalize(vN + rnd3);
vL = normalize(LightPos);
vV = -vec3(ModelViewMatrix*vec4(Vert,1.0));
vClr = Clr;
}
//frag
#version 330
in vec4 vClr, vP;
in vec3 vN, vL, vV;
out vec4 color;
uniform float Ambient = 0.5;
uniform float Diffuse = 0.7;
uniform float Specular = 0.2;
uniform float Shininess = 60.0;
uniform vec4 ClipPlane = vec4(2.0, 0.0, 0.0, 0.0);
void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 l = normalize(vL);
vec3 n = normalize(vN);
vec3 h = normalize(l+normalize(vV));
vec3 a = vClr.rgb;
//float rnd = fract(sin(gl_FragCoord.x * 12.9898 + gl_FragCoord.y * 78.233) * 43758.5453);
//vec3 rnd3 = noise3(rnd);
//n = normalize(n + rnd3);
vec3 backcolor = Ambient*vec3(0.1+0.1+0.1) + a*abs(dot(n,l))*Diffuse;
vec3 d = a * dot(n,l) * Diffuse;
a *= Ambient;
float s = pow(max(0.0,dot(n,h)), Shininess) * Specular;
float backface = step(0.00, n.z);
color = vec4(mix(backcolor.rgb, a + d + s, backface), 1.0);
}