source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/extras/shaders/ShaderFlares.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 3.8 KB
Line 
1/**
2 * @author mikael emtinger / http://gomo.se/
3 */
4
5THREE.ShaderFlares = {
6
7 'lensFlareVertexTexture': {
8
9 vertexShader: [
10
11 "uniform lowp int renderType;",
12
13 "uniform vec3 screenPosition;",
14 "uniform vec2 scale;",
15 "uniform float rotation;",
16
17 "uniform sampler2D occlusionMap;",
18
19 "attribute vec2 position;",
20 "attribute vec2 uv;",
21
22 "varying vec2 vUV;",
23 "varying float vVisibility;",
24
25 "void main() {",
26
27 "vUV = uv;",
28
29 "vec2 pos = position;",
30
31 "if( renderType == 2 ) {",
32
33 "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
34 "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
35 "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
36 "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
37 "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
38 "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
39 "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
40 "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
41 "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
42
43 "vVisibility = visibility.r / 9.0;",
44 "vVisibility *= 1.0 - visibility.g / 9.0;",
45 "vVisibility *= visibility.b / 9.0;",
46 "vVisibility *= 1.0 - visibility.a / 9.0;",
47
48 "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
49 "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
50
51 "}",
52
53 "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
54
55 "}"
56
57 ].join( "\n" ),
58
59 fragmentShader: [
60
61 "uniform lowp int renderType;",
62
63 "uniform sampler2D map;",
64 "uniform float opacity;",
65 "uniform vec3 color;",
66
67 "varying vec2 vUV;",
68 "varying float vVisibility;",
69
70 "void main() {",
71
72 // pink square
73
74 "if( renderType == 0 ) {",
75
76 "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
77
78 // restore
79
80 "} else if( renderType == 1 ) {",
81
82 "gl_FragColor = texture2D( map, vUV );",
83
84 // flare
85
86 "} else {",
87
88 "vec4 texture = texture2D( map, vUV );",
89 "texture.a *= opacity * vVisibility;",
90 "gl_FragColor = texture;",
91 "gl_FragColor.rgb *= color;",
92
93 "}",
94
95 "}"
96 ].join( "\n" )
97
98 },
99
100
101 'lensFlare': {
102
103 vertexShader: [
104
105 "uniform lowp int renderType;",
106
107 "uniform vec3 screenPosition;",
108 "uniform vec2 scale;",
109 "uniform float rotation;",
110
111 "attribute vec2 position;",
112 "attribute vec2 uv;",
113
114 "varying vec2 vUV;",
115
116 "void main() {",
117
118 "vUV = uv;",
119
120 "vec2 pos = position;",
121
122 "if( renderType == 2 ) {",
123
124 "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
125 "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
126
127 "}",
128
129 "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
130
131 "}"
132
133 ].join( "\n" ),
134
135 fragmentShader: [
136
137 "precision mediump float;",
138
139 "uniform lowp int renderType;",
140
141 "uniform sampler2D map;",
142 "uniform sampler2D occlusionMap;",
143 "uniform float opacity;",
144 "uniform vec3 color;",
145
146 "varying vec2 vUV;",
147
148 "void main() {",
149
150 // pink square
151
152 "if( renderType == 0 ) {",
153
154 "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
155
156 // restore
157
158 "} else if( renderType == 1 ) {",
159
160 "gl_FragColor = texture2D( map, vUV );",
161
162 // flare
163
164 "} else {",
165
166 "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
167 "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
168 "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
169 "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
170 "visibility = ( 1.0 - visibility / 4.0 );",
171
172 "vec4 texture = texture2D( map, vUV );",
173 "texture.a *= opacity * visibility;",
174 "gl_FragColor = texture;",
175 "gl_FragColor.rgb *= color;",
176
177 "}",
178
179 "}"
180
181 ].join( "\n" )
182
183 }
184
185};
Note: See TracBrowser for help on using the repository browser.