refmod_test

view sdr.ps.glsl @ 1:7e911c994ef2

should work on mac now
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 18 Feb 2016 23:21:49 +0200
parents
children
line source
1 #version 110
3 varying vec3 pos, normal;
5 uniform float rough, specularity, ior;
6 uniform float dif_sdr, spec_sdr;
8 #define DSDR_LAMBERT 0.0
9 #define DSDR_OREN_NAYAR 1.0
11 #define SSDR_PHONG 0.0
12 #define SSDR_BLINN 1.0
13 #define SSDR_COOK_TORR 2.0
15 #define EQ(a, b) (abs((a) - (b)) < 0.5)
17 float lambert(vec3 norm, vec3 ldir);
18 float oren_nayar(vec3 view, vec3 norm, vec3 ldir, float rough);
20 float phong(vec3 view, vec3 norm, vec3 ldir, float spow);
21 float blinn(vec3 norm, vec3 hvec, float spow);
22 float cook_torrance(vec3 view, vec3 norm, vec3 ldir, vec3 hvec, float rough, float ior);
24 void main()
25 {
26 vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
27 float idiff, ispec;
29 vec3 view = -normalize(pos);
30 vec3 norm = normalize(normal);
31 vec3 ldir = normalize(gl_LightSource[0].position.xyz - pos);
33 if(EQ(dif_sdr, DSDR_LAMBERT)) {
34 idiff = lambert(norm, ldir);
35 } else if(EQ(dif_sdr, DSDR_OREN_NAYAR)) {
36 idiff = oren_nayar(view, norm, ldir, rough);
37 } else {
38 idiff = 0.0;
39 }
41 vec4 mcolor = gl_FrontMaterial.diffuse;
43 if(EQ(spec_sdr, SSDR_PHONG)) {
44 ispec = phong(view, norm, ldir, gl_FrontMaterial.shininess);
45 color = mcolor * idiff + vec4(specularity, specularity, specularity, 1.0) * ispec;
46 } else if(EQ(spec_sdr, SSDR_BLINN)) {
47 ispec = blinn(norm, gl_LightSource[0].halfVector.xyz, gl_FrontMaterial.shininess);
48 color = mcolor * idiff + vec4(specularity, specularity, specularity, 1.0) * ispec;
49 } else if(EQ(spec_sdr, SSDR_COOK_TORR)) {
50 ispec = cook_torrance(view, norm, ldir, gl_LightSource[0].halfVector.xyz, rough, ior);
51 color = specularity * ispec * mcolor + (1.0 - specularity) * idiff * mcolor;
52 } else {
53 color = vec4(1.0, 0.0, 0.0, 1.0);
54 }
55 color.a = 1.0;
57 gl_FragColor = color;
58 }