refmod_test

diff sdr.ps.glsl @ 0:b469e6a72636

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 18 Feb 2016 23:15:43 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sdr.ps.glsl	Thu Feb 18 23:15:43 2016 +0200
     1.3 @@ -0,0 +1,58 @@
     1.4 +#version 110
     1.5 +
     1.6 +varying vec3 pos, normal;
     1.7 +
     1.8 +uniform float rough, specularity, ior;
     1.9 +uniform float dif_sdr, spec_sdr;
    1.10 +
    1.11 +#define DSDR_LAMBERT	0.0
    1.12 +#define DSDR_OREN_NAYAR	1.0
    1.13 +
    1.14 +#define SSDR_PHONG		0.0
    1.15 +#define SSDR_BLINN		1.0
    1.16 +#define SSDR_COOK_TORR	2.0
    1.17 +
    1.18 +#define EQ(a, b)	(abs((a) - (b)) < 0.5)
    1.19 +
    1.20 +float lambert(vec3 norm, vec3 ldir);
    1.21 +float oren_nayar(vec3 view, vec3 norm, vec3 ldir, float rough);
    1.22 +
    1.23 +float phong(vec3 view, vec3 norm, vec3 ldir, float spow);
    1.24 +float blinn(vec3 norm, vec3 hvec, float spow);
    1.25 +float cook_torrance(vec3 view, vec3 norm, vec3 ldir, vec3 hvec, float rough, float ior);
    1.26 +
    1.27 +void main()
    1.28 +{
    1.29 +	vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
    1.30 +	float idiff, ispec;
    1.31 +
    1.32 +	vec3 view = -normalize(pos);
    1.33 +	vec3 norm = normalize(normal);
    1.34 +	vec3 ldir = normalize(gl_LightSource[0].position.xyz - pos);
    1.35 +
    1.36 +	if(EQ(dif_sdr, DSDR_LAMBERT)) {
    1.37 +		idiff = lambert(norm, ldir);
    1.38 +	} else if(EQ(dif_sdr, DSDR_OREN_NAYAR)) {
    1.39 +		idiff = oren_nayar(view, norm, ldir, rough);
    1.40 +	} else {
    1.41 +		idiff = 0.0;
    1.42 +	}
    1.43 +
    1.44 +	vec4 mcolor = gl_FrontMaterial.diffuse;
    1.45 +
    1.46 +	if(EQ(spec_sdr, SSDR_PHONG)) {
    1.47 +		ispec = phong(view, norm, ldir, gl_FrontMaterial.shininess);
    1.48 +		color = mcolor * idiff + vec4(specularity, specularity, specularity, 1.0) * ispec;
    1.49 +	} else if(EQ(spec_sdr, SSDR_BLINN)) {
    1.50 +		ispec = blinn(norm, gl_LightSource[0].halfVector.xyz, gl_FrontMaterial.shininess);
    1.51 +		color = mcolor * idiff + vec4(specularity, specularity, specularity, 1.0) * ispec;
    1.52 +	} else if(EQ(spec_sdr, SSDR_COOK_TORR)) {
    1.53 +		ispec = cook_torrance(view, norm, ldir, gl_LightSource[0].halfVector.xyz, rough, ior);
    1.54 +		color = specularity * ispec * mcolor + (1.0 - specularity) * idiff * mcolor;
    1.55 +	} else {
    1.56 +		color = vec4(1.0, 0.0, 0.0, 1.0);
    1.57 +	}
    1.58 +	color.a = 1.0;
    1.59 +
    1.60 +	gl_FragColor = color;
    1.61 +}