summaryrefslogtreecommitdiff
path: root/shaders/humus-portals/1.shader_test
blob: feb080aa5659de18fe38dc92e486d92b28a9457a (plain)
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
[require]
GLSL >= 1.10

[fragment shader]
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 26


uniform sampler2D Base;
uniform sampler2D Bump;

uniform float invRadius;
uniform float ambient;

varying vec2 texCoord;
varying vec3 lightVec;
varying vec3 viewVec;

void main(){
	vec4 base = texture2D(Base, texCoord);
	vec3 bump = texture2D(Bump, texCoord).xyz * 2.0 - 1.0;

	bump = normalize(bump);

	float distSqr = dot(lightVec, lightVec);
	vec3 lVec = lightVec * inversesqrt(distSqr);

	float atten = clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0);
	float diffuse = clamp(dot(lVec, bump), 0.0, 1.0);

	float specular = pow(clamp(dot(reflect(normalize(-viewVec), bump), lVec), 0.0, 1.0), 16.0);
	
	gl_FragColor = ambient * base + (diffuse * base + 0.6 * specular) * atten;
}


[vertex shader]
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 0


varying vec2 texCoord;
varying vec3 lightVec;
varying vec3 viewVec;

uniform vec3 lightPos;
uniform vec3 camPos;

void main(){
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

	texCoord = gl_MultiTexCoord0.xy;

	vec3 lVec = lightPos - gl_Vertex.xyz;
	lightVec.x = dot(gl_MultiTexCoord1.xyz, lVec);
	lightVec.y = dot(gl_MultiTexCoord2.xyz, lVec);
	lightVec.z = dot(gl_MultiTexCoord3.xyz, lVec);

	vec3 vVec = camPos - gl_Vertex.xyz;
	viewVec.x = dot(gl_MultiTexCoord1.xyz, vVec);
	viewVec.y = dot(gl_MultiTexCoord2.xyz, vVec);
	viewVec.z = dot(gl_MultiTexCoord3.xyz, vVec);
}