propane 0.8.0-java → 0.9.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -1
  3. data/README.md +1 -1
  4. data/lib/propane/app.rb +56 -55
  5. data/lib/propane/creators/sketch_writer.rb +7 -3
  6. data/lib/propane/helper_methods.rb +40 -29
  7. data/lib/propane/runner.rb +3 -2
  8. data/lib/propane/version.rb +1 -1
  9. data/pom.rb +1 -1
  10. data/pom.xml +1 -1
  11. data/vendors/Rakefile +31 -1
  12. metadata +2 -59
  13. data/examples/data_path/Rakefile +0 -32
  14. data/examples/data_path/bw_shader.rb +0 -47
  15. data/examples/data_path/data/Texture01.jpg +0 -0
  16. data/examples/data_path/data/Texture02.jpg +0 -0
  17. data/examples/data_path/data/Univers45.vlw +0 -0
  18. data/examples/data_path/data/bwfrag.glsl +0 -23
  19. data/examples/data_path/data/displaceFrag.glsl +0 -8
  20. data/examples/data_path/data/displaceVert.glsl +0 -201
  21. data/examples/data_path/data/lachoy.jpg +0 -0
  22. data/examples/data_path/data/landscape.glsl +0 -352
  23. data/examples/data_path/data/monjori.glsl +0 -30
  24. data/examples/data_path/data/moon.jpg +0 -0
  25. data/examples/data_path/data/sea.jpg +0 -0
  26. data/examples/data_path/edge_detection.rb +0 -49
  27. data/examples/data_path/glsl_heightmap_noise.rb +0 -125
  28. data/examples/data_path/kinetic_type.rb +0 -79
  29. data/examples/data_path/landscape.rb +0 -34
  30. data/examples/data_path/linear_image.rb +0 -51
  31. data/examples/data_path/monjori.rb +0 -35
  32. data/examples/regular/Rakefile +0 -30
  33. data/examples/regular/arcball_box.rb +0 -28
  34. data/examples/regular/arcball_constrain.rb +0 -29
  35. data/examples/regular/bezier_playground.rb +0 -206
  36. data/examples/regular/circle_collision.rb +0 -118
  37. data/examples/regular/colors_two.rb +0 -60
  38. data/examples/regular/creating_colors.rb +0 -64
  39. data/examples/regular/drawolver.rb +0 -93
  40. data/examples/regular/elegant_ball.rb +0 -159
  41. data/examples/regular/empathy.rb +0 -80
  42. data/examples/regular/fern.rb +0 -57
  43. data/examples/regular/fibonacci_sphere.rb +0 -91
  44. data/examples/regular/flight_patterns.rb +0 -64
  45. data/examples/regular/fractions.rb +0 -32
  46. data/examples/regular/grapher.rb +0 -40
  47. data/examples/regular/gravity.rb +0 -120
  48. data/examples/regular/grey_circles.rb +0 -28
  49. data/examples/regular/jwishy.rb +0 -99
  50. data/examples/regular/letters.rb +0 -42
  51. data/examples/regular/lib/boundary.rb +0 -38
  52. data/examples/regular/lib/particle.rb +0 -77
  53. data/examples/regular/lib/particle_system.rb +0 -111
  54. data/examples/regular/lib/rain_drops.rb +0 -54
  55. data/examples/regular/liquidy.rb +0 -41
  56. data/examples/regular/mouse_button_demo.rb +0 -32
  57. data/examples/regular/polyhedrons.rb +0 -249
  58. data/examples/regular/raining.rb +0 -60
  59. data/examples/regular/ribbon_doodle.rb +0 -89
  60. data/examples/regular/select_file.rb +0 -32
  61. data/examples/regular/select_image.rb +0 -40
  62. data/examples/regular/slider_demo.rb +0 -61
  63. data/examples/regular/slider_example.rb +0 -53
  64. data/examples/regular/slider_simple.rb +0 -47
  65. data/examples/regular/tree.rb +0 -76
  66. data/examples/regular/vector_math.rb +0 -37
  67. data/examples/regular/words.rb +0 -41
  68. data/lib/propane/helpers/string_extra.rb +0 -45
  69. data/lib/propane/underscorer.rb +0 -19
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: java
6
6
  authors:
7
7
  - filib
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-01 00:00:00.000000000 Z
12
+ date: 2016-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arcball
@@ -45,61 +45,6 @@ files:
45
45
  - README.md
46
46
  - Rakefile
47
47
  - bin/propane
48
- - examples/data_path/Rakefile
49
- - examples/data_path/bw_shader.rb
50
- - examples/data_path/data/Texture01.jpg
51
- - examples/data_path/data/Texture02.jpg
52
- - examples/data_path/data/Univers45.vlw
53
- - examples/data_path/data/bwfrag.glsl
54
- - examples/data_path/data/displaceFrag.glsl
55
- - examples/data_path/data/displaceVert.glsl
56
- - examples/data_path/data/lachoy.jpg
57
- - examples/data_path/data/landscape.glsl
58
- - examples/data_path/data/monjori.glsl
59
- - examples/data_path/data/moon.jpg
60
- - examples/data_path/data/sea.jpg
61
- - examples/data_path/edge_detection.rb
62
- - examples/data_path/glsl_heightmap_noise.rb
63
- - examples/data_path/kinetic_type.rb
64
- - examples/data_path/landscape.rb
65
- - examples/data_path/linear_image.rb
66
- - examples/data_path/monjori.rb
67
- - examples/regular/Rakefile
68
- - examples/regular/arcball_box.rb
69
- - examples/regular/arcball_constrain.rb
70
- - examples/regular/bezier_playground.rb
71
- - examples/regular/circle_collision.rb
72
- - examples/regular/colors_two.rb
73
- - examples/regular/creating_colors.rb
74
- - examples/regular/drawolver.rb
75
- - examples/regular/elegant_ball.rb
76
- - examples/regular/empathy.rb
77
- - examples/regular/fern.rb
78
- - examples/regular/fibonacci_sphere.rb
79
- - examples/regular/flight_patterns.rb
80
- - examples/regular/fractions.rb
81
- - examples/regular/grapher.rb
82
- - examples/regular/gravity.rb
83
- - examples/regular/grey_circles.rb
84
- - examples/regular/jwishy.rb
85
- - examples/regular/letters.rb
86
- - examples/regular/lib/boundary.rb
87
- - examples/regular/lib/particle.rb
88
- - examples/regular/lib/particle_system.rb
89
- - examples/regular/lib/rain_drops.rb
90
- - examples/regular/liquidy.rb
91
- - examples/regular/mouse_button_demo.rb
92
- - examples/regular/polyhedrons.rb
93
- - examples/regular/raining.rb
94
- - examples/regular/ribbon_doodle.rb
95
- - examples/regular/select_file.rb
96
- - examples/regular/select_image.rb
97
- - examples/regular/slider_demo.rb
98
- - examples/regular/slider_example.rb
99
- - examples/regular/slider_simple.rb
100
- - examples/regular/tree.rb
101
- - examples/regular/vector_math.rb
102
- - examples/regular/words.rb
103
48
  - lib/PROCESSING_LICENSE.txt
104
49
  - lib/core-2.2.1.jar
105
50
  - lib/export.txt
@@ -115,10 +60,8 @@ files:
115
60
  - lib/propane/creators/sketch_writer.rb
116
61
  - lib/propane/helper_methods.rb
117
62
  - lib/propane/helpers/numeric.rb
118
- - lib/propane/helpers/string_extra.rb
119
63
  - lib/propane/library_loader.rb
120
64
  - lib/propane/runner.rb
121
- - lib/propane/underscorer.rb
122
65
  - lib/propane/version.rb
123
66
  - library/boids/boids.rb
124
67
  - library/control_panel/control_panel.rb
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- # Simple demo Rakefile to autorun samples in current directory
4
- # NB: If using atom install build and build-rake packages to run from atom
5
-
6
- SAMPLES_DIR = './'
7
-
8
- desc 'run demo'
9
- task default: [:demo]
10
-
11
- desc 'demo'
12
- task :demo do
13
- samples_list.shuffle.each { |sample| run_sample sample }
14
- end
15
-
16
- def samples_list
17
- files = []
18
- Dir.chdir(SAMPLES_DIR)
19
- Dir.glob('*.rb').each do |file|
20
- files << File.join(SAMPLES_DIR, file)
21
- end
22
- return files
23
- end
24
-
25
- def run_sample(sample_name)
26
- puts "Running #{sample_name}...quit to run next sample"
27
- open("|jruby #{sample_name}", 'r') do |io|
28
- while l = io.gets
29
- puts(l.chop)
30
- end
31
- end
32
- end
@@ -1,47 +0,0 @@
1
- #!/usr/bin/env jruby -v -W2
2
- require 'propane'
3
-
4
- class BwShader < Propane::App
5
- # Texture from Jason Liebig's FLICKR collection of vintage labels and wrappers:
6
- # http://www.flickr.com/photos/jasonliebigstuff/3739263136/in/photostream/
7
-
8
- attr_reader :label, :can, :angle, :bw_shader
9
-
10
- def setup
11
- size(640, 360, P3D)
12
- @label = load_image(File.expand_path('./data/lachoy.jpg'))
13
- @can = create_can(100, 200, 32, label)
14
- @bw_shader = load_shader(File.expand_path('./data/bwfrag.glsl'))
15
- @angle = 0
16
- end
17
-
18
- def draw
19
- background(0)
20
- shader(bw_shader)
21
- translate(width/2, height/2)
22
- rotate_y(angle)
23
- shape(can)
24
- @angle += 0.01
25
- end
26
-
27
- def create_can(r, h, detail, tex)
28
- texture_mode(NORMAL)
29
- sh = create_shape
30
- sh.begin_shape(QUAD_STRIP)
31
- sh.no_stroke
32
- sh.texture(tex)
33
- (0..detail).each do |i|
34
- angle = TAU / detail
35
- x = sin(i * angle)
36
- z = cos(i * angle)
37
- u = i.to_f / detail
38
- sh.normal(x, 0, z)
39
- sh.vertex(x * r, -h/2, z * r, u, 0)
40
- sh.vertex(x * r, +h/2, z * r, u, 1)
41
- end
42
- sh.end_shape
43
- sh
44
- end
45
- end
46
-
47
- BwShader.new title: 'Black & White Shader'
@@ -1,23 +0,0 @@
1
- #ifdef GL_ES
2
- precision mediump float;
3
- precision mediump int;
4
- #endif
5
-
6
- #define PROCESSING_TEXTURE_SHADER
7
-
8
- uniform sampler2D texture;
9
-
10
- varying vec4 vertColor;
11
- varying vec4 vertTexCoord;
12
-
13
- const vec4 lumcoeff = vec4(0.299, 0.587, 0.114, 0);
14
-
15
- void main() {
16
- vec4 col = texture2D(texture, vertTexCoord.st);
17
- float lum = dot(col, lumcoeff);
18
- if (0.5 < lum) {
19
- gl_FragColor = vertColor;
20
- } else {
21
- gl_FragColor = vec4(0, 0, 0, 1);
22
- }
23
- }
@@ -1,8 +0,0 @@
1
-
2
- uniform sampler2D colorMap;
3
-
4
- varying vec4 vertTexCoord;
5
-
6
- void main() {
7
- gl_FragColor = texture2D(colorMap, vertTexCoord.st);
8
- }
@@ -1,201 +0,0 @@
1
-
2
- #define PROCESSING_TEXLIGHT_SHADER
3
-
4
- uniform mat4 modelview;
5
- uniform mat4 transform;
6
- uniform mat3 normalMatrix;
7
- uniform mat4 texMatrix;
8
-
9
- uniform int lightCount;
10
- uniform vec4 lightPosition[8];
11
- uniform vec3 lightNormal[8];
12
- uniform vec3 lightAmbient[8];
13
- uniform vec3 lightDiffuse[8];
14
- uniform vec3 lightSpecular[8];
15
- uniform vec3 lightFalloff[8];
16
- uniform vec2 lightSpot[8];
17
-
18
- attribute vec4 vertex;
19
- attribute vec4 color;
20
- attribute vec3 normal;
21
- attribute vec2 texCoord;
22
-
23
- attribute vec4 ambient;
24
- attribute vec4 specular;
25
- attribute vec4 emissive;
26
- attribute float shininess;
27
-
28
- varying vec4 vertColor;
29
- varying vec4 vertTexCoord;
30
-
31
- const float zero_float = 0.0;
32
- const float one_float = 1.0;
33
- const vec3 zero_vec3 = vec3(0);
34
-
35
- uniform float displaceStrength;
36
- uniform float time;
37
-
38
- float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
39
- vec3 lpv = lightPos - vertPos;
40
- vec3 dist = vec3(one_float);
41
- dist.z = dot(lpv, lpv);
42
- dist.y = sqrt(dist.z);
43
- return one_float / dot(dist, coeff);
44
- }
45
-
46
- float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
47
- vec3 lpv = normalize(lightPos - vertPos);
48
- vec3 nln = -one_float * lightNorm;
49
- float spotCos = dot(nln, lpv);
50
- return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
51
- }
52
-
53
- float lambertFactor(vec3 lightDir, vec3 vecNormal) {
54
- return max(zero_float, dot(lightDir, vecNormal));
55
- }
56
-
57
- float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
58
- vec3 np = normalize(vertPos);
59
- vec3 ldp = normalize(lightDir - np);
60
- return pow(max(zero_float, dot(ldp, vecNormal)), shine);
61
- }
62
-
63
- // Source code for GLSL Perlin noise courtesy of:
64
- // https://github.com/ashima/webgl-noise/wiki
65
-
66
- vec3 mod289(vec3 x) {
67
- return x - floor(x * (1.0 / 289.0)) * 289.0;
68
- }
69
-
70
- vec2 mod289(vec2 x) {
71
- return x - floor(x * (1.0 / 289.0)) * 289.0;
72
- }
73
-
74
- vec3 permute(vec3 x) {
75
- return mod289(((x*34.0)+1.0)*x);
76
- }
77
-
78
- float snoise(vec2 v)
79
- {
80
- const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
81
- 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
82
- -0.577350269189626, // -1.0 + 2.0 * C.x
83
- 0.024390243902439); // 1.0 / 41.0
84
- // First corner
85
- vec2 i = floor(v + dot(v, C.yy) );
86
- vec2 x0 = v - i + dot(i, C.xx);
87
-
88
- // Other corners
89
- vec2 i1;
90
- //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
91
- //i1.y = 1.0 - i1.x;
92
- i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
93
- // x0 = x0 - 0.0 + 0.0 * C.xx ;
94
- // x1 = x0 - i1 + 1.0 * C.xx ;
95
- // x2 = x0 - 1.0 + 2.0 * C.xx ;
96
- vec4 x12 = x0.xyxy + C.xxzz;
97
- x12.xy -= i1;
98
-
99
- // Permutations
100
- i = mod289(i); // Avoid truncation effects in permutation
101
- vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
102
- + i.x + vec3(0.0, i1.x, 1.0 ));
103
-
104
- vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
105
- m = m*m ;
106
- m = m*m ;
107
-
108
- // Gradients: 41 points uniformly over a line, mapped onto a diamond.
109
- // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
110
-
111
- vec3 x = 2.0 * fract(p * C.www) - 1.0;
112
- vec3 h = abs(x) - 0.5;
113
- vec3 ox = floor(x + 0.5);
114
- vec3 a0 = x - ox;
115
-
116
- // Normalise gradients implicitly by scaling m
117
- // Approximation of: m *= inversesqrt( a0*a0 + h*h );
118
- m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
119
-
120
- // Compute final noise value at P
121
- vec3 g;
122
- g.x = a0.x * x0.x + h.x * x0.y;
123
- g.yz = a0.yz * x12.xz + h.yz * x12.yw;
124
- return 130.0 * dot(m, g);
125
- }
126
-
127
- void main() {
128
- // Calculating texture coordinates, with r and q set both to one
129
- vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
130
-
131
- vec2 p = texCoord; // put coordinates into vec2 p for convenience
132
- p.x += time; // add time to make the noise and the subsequent displacement move
133
- float df = snoise( p ); // create displacement float value from shader-based 2D Perlin noise
134
- vec4 newVertexPos = vertex + vec4(normal * df * displaceStrength, 0.0); // regular vertex position + direction * displacementMap * displaceStrength
135
-
136
- // Vertex in clip coordinates
137
- gl_Position = transform * newVertexPos;
138
-
139
- // Vertex in eye coordinates
140
- vec3 ecVertex = vec3(modelview * vertex);
141
-
142
- // Normal vector in eye coordinates
143
- vec3 ecNormal = normalize(normalMatrix * normal);
144
-
145
- if (dot(-one_float * ecVertex, ecNormal) < zero_float) {
146
- // If normal is away from camera, choose its opposite.
147
- // If we add backface culling, this will be backfacing
148
- ecNormal *= -one_float;
149
- }
150
-
151
- // Light calculations
152
- vec3 totalAmbient = vec3(0, 0, 0);
153
- vec3 totalDiffuse = vec3(0, 0, 0);
154
- vec3 totalSpecular = vec3(0, 0, 0);
155
- for (int i = 0; i < 8; i++) {
156
- if (lightCount == i) break;
157
-
158
- vec3 lightPos = lightPosition[i].xyz;
159
- bool isDir = zero_float < lightPosition[i].w;
160
- float spotCos = lightSpot[i].x;
161
- float spotExp = lightSpot[i].y;
162
-
163
- vec3 lightDir;
164
- float falloff;
165
- float spotf;
166
-
167
- if (isDir) {
168
- falloff = one_float;
169
- lightDir = -one_float * lightNormal[i];
170
- } else {
171
- falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
172
- lightDir = normalize(lightPos - ecVertex);
173
- }
174
-
175
- spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
176
- spotCos, spotExp)
177
- : one_float;
178
-
179
- if (any(greaterThan(lightAmbient[i], zero_vec3))) {
180
- totalAmbient += lightAmbient[i] * falloff;
181
- }
182
-
183
- if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
184
- totalDiffuse += lightDiffuse[i] * falloff * spotf *
185
- lambertFactor(lightDir, ecNormal);
186
- }
187
-
188
- if (any(greaterThan(lightSpecular[i], zero_vec3))) {
189
- totalSpecular += lightSpecular[i] * falloff * spotf *
190
- blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
191
- }
192
- }
193
-
194
- // Calculating final color as result of all lights (plus emissive term).
195
- // Transparency is determined exclusively by the diffuse component.
196
- vertColor = vec4(totalAmbient, 0) * ambient +
197
- vec4(totalDiffuse, 1) * color +
198
- vec4(totalSpecular, 0) * specular +
199
- vec4(emissive.rgb, 0);
200
-
201
- }
@@ -1,352 +0,0 @@
1
- // Elevated shader
2
- // https://www.shadertoy.com/view/MdX3Rr by inigo quilez
3
-
4
- // Created by inigo quilez - iq/2013
5
- // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
6
-
7
- // Processing port by Raphaël de Courville.
8
-
9
- #ifdef GL_ES
10
- precision highp float;
11
- #endif
12
-
13
- // Type of shader expected by Processing
14
- #define PROCESSING_COLOR_SHADER
15
-
16
- // Processing specific input
17
- uniform float time;
18
- uniform vec2 resolution;
19
- uniform vec2 mouse;
20
-
21
- // Layer between Processing and Shadertoy uniforms
22
- vec3 iResolution = vec3(resolution,0.0);
23
- float iGlobalTime = time;
24
- vec4 iMouse = vec4(mouse,0.0,0.0); // zw would normally be the click status
25
-
26
- // ------- Below is the unmodified Shadertoy code ----------
27
- // Created by inigo quilez - iq/2013
28
- // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
29
-
30
- //stereo thanks to Croqueteer
31
- //#define STEREO
32
-
33
- mat3 m = mat3( 0.00, 0.80, 0.60,
34
- -0.80, 0.36, -0.48,
35
- -0.60, -0.48, 0.64 );
36
-
37
- float hash( float n )
38
- {
39
- return fract(sin(n)*43758.5453123);
40
- }
41
-
42
-
43
- float noise( in vec3 x )
44
- {
45
- vec3 p = floor(x);
46
- vec3 f = fract(x);
47
-
48
- f = f*f*(3.0-2.0*f);
49
-
50
- float n = p.x + p.y*57.0 + 113.0*p.z;
51
-
52
- float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
53
- mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
54
- mix(mix( hash(n+113.0), hash(n+114.0),f.x),
55
- mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
56
- return res;
57
- }
58
-
59
-
60
-
61
-
62
- vec3 noised( in vec2 x )
63
- {
64
- vec2 p = floor(x);
65
- vec2 f = fract(x);
66
-
67
- vec2 u = f*f*(3.0-2.0*f);
68
-
69
- float n = p.x + p.y*57.0;
70
-
71
- float a = hash(n+ 0.0);
72
- float b = hash(n+ 1.0);
73
- float c = hash(n+ 57.0);
74
- float d = hash(n+ 58.0);
75
- return vec3(a+(b-a)*u.x+(c-a)*u.y+(a-b-c+d)*u.x*u.y,
76
- 30.0*f*f*(f*(f-2.0)+1.0)*(vec2(b-a,c-a)+(a-b-c+d)*u.yx));
77
-
78
- }
79
-
80
- float noise( in vec2 x )
81
- {
82
- vec2 p = floor(x);
83
- vec2 f = fract(x);
84
-
85
- f = f*f*(3.0-2.0*f);
86
-
87
- float n = p.x + p.y*57.0;
88
-
89
- float res = mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
90
- mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
91
-
92
- return res;
93
- }
94
-
95
- float fbm( vec3 p )
96
- {
97
- float f = 0.0;
98
-
99
- f += 0.5000*noise( p ); p = m*p*2.02;
100
- f += 0.2500*noise( p ); p = m*p*2.03;
101
- f += 0.1250*noise( p ); p = m*p*2.01;
102
- f += 0.0625*noise( p );
103
-
104
- return f/0.9375;
105
- }
106
-
107
- mat2 m2 = mat2(1.6,-1.2,1.2,1.6);
108
-
109
- float fbm( vec2 p )
110
- {
111
- float f = 0.0;
112
-
113
- f += 0.5000*noise( p ); p = m2*p*2.02;
114
- f += 0.2500*noise( p ); p = m2*p*2.03;
115
- f += 0.1250*noise( p ); p = m2*p*2.01;
116
- f += 0.0625*noise( p );
117
-
118
- return f/0.9375;
119
- }
120
-
121
- float terrain( in vec2 x )
122
- {
123
- vec2 p = x*0.003;
124
- float a = 0.0;
125
- float b = 1.0;
126
- vec2 d = vec2(0.0);
127
- for(int i=0;i<5; i++)
128
- {
129
- vec3 n = noised(p);
130
- d += n.yz;
131
- a += b*n.x/(1.0+dot(d,d));
132
- b *= 0.5;
133
- p=mat2(1.6,-1.2,1.2,1.6)*p;
134
- }
135
-
136
- return 140.0*a;
137
- }
138
-
139
- float terrain2( in vec2 x )
140
- {
141
- vec2 p = x*0.003;
142
- float a = 0.0;
143
- float b = 1.0;
144
- vec2 d = vec2(0.0);
145
- for(int i=0;i<14; i++)
146
- {
147
- vec3 n = noised(p);
148
- d += n.yz;
149
- a += b*n.x/(1.0+dot(d,d));
150
- b *= 0.5;
151
- p=m2*p;
152
- }
153
-
154
- return 140.0*a;
155
- }
156
-
157
-
158
- float map( in vec3 p )
159
- {
160
- float h = terrain(p.xz);
161
-
162
- float ss = 0.03;
163
- float hh = h*ss;
164
- float fh = fract(hh);
165
- float ih = floor(hh);
166
- fh = mix( sqrt(fh), fh, smoothstep(50.0,140.0,h) );
167
- h = (ih+fh)/ss;
168
-
169
- return p.y - h;
170
- }
171
-
172
- float map2( in vec3 p )
173
- {
174
- float h = terrain2(p.xz);
175
-
176
-
177
- float ss = 0.03;
178
- float hh = h*ss;
179
- float fh = fract(hh);
180
- float ih = floor(hh);
181
- fh = mix( sqrt(fh), fh, smoothstep(50.0,140.0,h) );
182
- h = (ih+fh)/ss;
183
-
184
- return p.y - h;
185
- }
186
-
187
- bool jinteresct(in vec3 rO, in vec3 rD, out float resT )
188
- {
189
- float h = 0.0;
190
- float t = 0.0;
191
- for( int j=0; j<120; j++ )
192
- {
193
- //if( t>2000.0 ) break;
194
-
195
- vec3 p = rO + t*rD;
196
- if( p.y>300.0 ) break;
197
- h = map( p );
198
-
199
- if( h<0.1 )
200
- {
201
- resT = t;
202
- return true;
203
- }
204
- t += max(0.1,0.5*h);
205
-
206
- }
207
-
208
- if( h<5.0 )
209
- {
210
- resT = t;
211
- return true;
212
- }
213
- return false;
214
- }
215
-
216
- float sinteresct(in vec3 rO, in vec3 rD )
217
- {
218
- float res = 1.0;
219
- float t = 0.0;
220
- for( int j=0; j<50; j++ )
221
- {
222
- //if( t>1000.0 ) break;
223
- vec3 p = rO + t*rD;
224
-
225
- float h = map( p );
226
-
227
- if( h<0.1 )
228
- {
229
- return 0.0;
230
- }
231
- res = min( res, 16.0*h/t );
232
- t += h;
233
-
234
- }
235
-
236
- return clamp( res, 0.0, 1.0 );
237
- }
238
-
239
- vec3 calcNormal( in vec3 pos, float t )
240
- {
241
- float e = 0.001;
242
- e = 0.001*t;
243
- vec3 eps = vec3(e,0.0,0.0);
244
- vec3 nor;
245
- nor.x = map2(pos+eps.xyy) - map2(pos-eps.xyy);
246
- nor.y = map2(pos+eps.yxy) - map2(pos-eps.yxy);
247
- nor.z = map2(pos+eps.yyx) - map2(pos-eps.yyx);
248
- return normalize(nor);
249
- }
250
-
251
- vec3 camPath( float time )
252
- {
253
- vec2 p = 600.0*vec2( cos(1.4+0.37*time),
254
- cos(3.2+0.31*time) );
255
-
256
- return vec3( p.x, 0.0, p.y );
257
- }
258
-
259
- void main(void)
260
- {
261
- vec2 xy = -1.0 + 2.0*gl_FragCoord.xy / iResolution.xy;
262
-
263
- vec2 s = xy*vec2(1.75,1.0);
264
-
265
- #ifdef STEREO
266
- float isCyan = mod(gl_FragCoord.x + mod(gl_FragCoord.y,2.0),2.0);
267
- #endif
268
-
269
- float time = iGlobalTime*.15;
270
-
271
- vec3 light1 = normalize( vec3( 0.4, 0.22, 0.6 ) );
272
- vec3 light2 = vec3( -0.707, 0.000, -0.707 );
273
-
274
-
275
- vec3 campos = camPath( time );
276
- vec3 camtar = camPath( time + 3.0 );
277
- campos.y = terrain( campos.xz ) + 15.0;
278
- camtar.y = campos.y*0.5;
279
-
280
- float roll = 0.1*cos(0.1*time);
281
- vec3 cw = normalize(camtar-campos);
282
- vec3 cp = vec3(sin(roll), cos(roll),0.0);
283
- vec3 cu = normalize(cross(cw,cp));
284
- vec3 cv = normalize(cross(cu,cw));
285
- vec3 rd = normalize( s.x*cu + s.y*cv + 1.6*cw );
286
-
287
- #ifdef STEREO
288
- campos += 2.0*cu*isCyan; // move camera to the right - the rd vector is still good
289
- #endif
290
-
291
- float sundot = clamp(dot(rd,light1),0.0,1.0);
292
- vec3 col;
293
- float t;
294
- if( !jinteresct(campos,rd,t) )
295
- {
296
- col = 0.9*vec3(0.97,.99,1.0)*(1.0-0.3*rd.y);
297
- col += 0.2*vec3(0.8,0.7,0.5)*pow( sundot, 4.0 );
298
- }
299
- else
300
- {
301
- vec3 pos = campos + t*rd;
302
-
303
- vec3 nor = calcNormal( pos, t );
304
-
305
- float dif1 = clamp( dot( light1, nor ), 0.0, 1.0 );
306
- float dif2 = clamp( 0.2 + 0.8*dot( light2, nor ), 0.0, 1.0 );
307
- float sh = 1.0;
308
- if( dif1>0.001 )
309
- sh = sinteresct(pos+light1*20.0,light1);
310
-
311
- vec3 dif1v = vec3(dif1);
312
- dif1v *= vec3( sh, sh*sh*0.5+0.5*sh, sh*sh );
313
-
314
- float r = noise( 7.0*pos.xz );
315
-
316
- col = (r*0.25+0.75)*0.9*mix( vec3(0.10,0.05,0.03), vec3(0.13,0.10,0.08), clamp(terrain2( vec2(pos.x,pos.y*48.0))/200.0,0.0,1.0) );
317
- col = mix( col, 0.17*vec3(0.5,.23,0.04)*(0.50+0.50*r),smoothstep(0.70,0.9,nor.y) );
318
- col = mix( col, 0.10*vec3(0.2,.30,0.00)*(0.25+0.75*r),smoothstep(0.95,1.0,nor.y) );
319
- col *= 0.75;
320
- // snow
321
- #if 1
322
- float h = smoothstep(55.0,80.0,pos.y + 25.0*fbm(0.01*pos.xz) );
323
- float e = smoothstep(1.0-0.5*h,1.0-0.1*h,nor.y);
324
- float o = 0.3 + 0.7*smoothstep(0.0,0.1,nor.x+h*h);
325
- float s = h*e*o;
326
- s = smoothstep( 0.1, 0.9, s );
327
- col = mix( col, 0.4*vec3(0.6,0.65,0.7), s );
328
- #endif
329
-
330
-
331
- vec3 brdf = 2.0*vec3(0.17,0.19,0.20)*clamp(nor.y,0.0,1.0);
332
- brdf += 6.0*vec3(1.00,0.95,0.80)*dif1v;
333
- brdf += 2.0*vec3(0.20,0.20,0.20)*dif2;
334
-
335
- col *= brdf;
336
-
337
- float fo = 1.0-exp(-pow(0.0015*t,1.5));
338
- vec3 fco = vec3(0.7) + 0.6*vec3(0.8,0.7,0.5)*pow( sundot, 4.0 );
339
- col = mix( col, fco, fo );
340
- }
341
-
342
- col = sqrt(col);
343
-
344
- vec2 uv = xy*0.5+0.5;
345
- col *= 0.7 + 0.3*pow(16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y),0.1);
346
-
347
- #ifdef STEREO
348
- col *= vec3( isCyan, 1.0-isCyan, 1.0-isCyan );
349
- #endif
350
-
351
- gl_FragColor=vec4(col,1.0);
352
- }