]> gitweb.factorcode.org Git - factor.git/blob - extra/terrain/shaders/shaders.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / extra / terrain / shaders / shaders.factor
1 USING: multiline ;
2 IN: terrain.shaders
3
4 STRING: sky-vertex-shader
5
6 uniform float sky_theta;
7 varying vec3 direction;
8
9 void main()
10 {
11     vec4 v = vec4(gl_Vertex.xy, 1.0, 1.0);
12     gl_Position = v;
13
14     vec4 p = gl_ProjectionMatrixInverse * v;
15     p.z = -abs(p.z);
16
17     float s = sin(sky_theta), c = cos(sky_theta);
18     direction = mat3(1, 0, 0,  0, c, s,  0, -s, c)
19         * (gl_ModelViewMatrixInverse * vec4(p.xyz, 0.0)).xyz;
20 }
21
22 ;
23
24 STRING: sky-pixel-shader
25
26 uniform sampler2D sky;
27 uniform float sky_gradient, sky_theta;
28
29 const vec4 SKY_COLOR_A = vec4(0.25, 0.0, 0.5,  1.0),
30            SKY_COLOR_B = vec4(0.6,  0.5, 0.75, 1.0);
31
32 varying vec3 direction;
33
34 void main()
35 {
36     float t = texture2D(sky, normalize(direction.xyz).xy * 0.5 + vec2(0.5)).x + sky_gradient;
37     gl_FragColor = mix(SKY_COLOR_A, SKY_COLOR_B, sin(6.28*t));
38 }
39
40 ;
41
42 STRING: terrain-vertex-shader
43
44 uniform sampler2D heightmap;
45 uniform vec4 component_scale;
46
47 varying vec2 heightcoords;
48
49 float height(sampler2D map, vec2 coords)
50 {
51     vec4 v = texture2D(map, coords);
52     return dot(v, component_scale);
53 }
54
55 void main()
56 {
57     gl_Position = gl_ModelViewProjectionMatrix
58         * (gl_Vertex + vec4(0, height(heightmap, gl_Vertex.xz), 0, 0));
59     heightcoords = gl_Vertex.xz;
60 }
61
62 ;
63
64 STRING: terrain-pixel-shader
65
66 uniform sampler2D heightmap;
67 uniform vec4 component_scale;
68
69 varying vec2 heightcoords;
70
71 float height(sampler2D map, vec2 coords)
72 {
73     vec4 v = texture2D(map, coords);
74     return dot(v, component_scale);
75 }
76
77 void main()
78 {
79     gl_FragColor = texture2D(heightmap, heightcoords);
80 }
81
82 ;