diff options
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 218 |
1 files changed, 109 insertions, 109 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 137ced27..e1d31a42 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js | |||
@@ -47,15 +47,15 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
47 | this._colorStop2 = 0.3; | 47 | this._colorStop2 = 0.3; |
48 | this._colorStop3 = 0.6; | 48 | this._colorStop3 = 0.6; |
49 | this._colorStop4 = 1.0; | 49 | this._colorStop4 = 1.0; |
50 | // this._colorCount = 4; | 50 | // this._colorCount = 4; |
51 | this._angle = 0.0; // the shader takes [cos(a), sin(a)] | 51 | this._angle = 0.0; // the shader takes [cos(a), sin(a)] |
52 | 52 | ||
53 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; | 53 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; |
54 | 54 | ||
55 | /////////////////////////////////////////////////////////////////////// | 55 | /////////////////////////////////////////////////////////////////////// |
56 | // Property Accessors | 56 | // Property Accessors |
57 | /////////////////////////////////////////////////////////////////////// | 57 | /////////////////////////////////////////////////////////////////////// |
58 | this.getShaderDef = function() { return linearGradientMaterialDef; } | 58 | this.getShaderDef = function() { return linearGradientMaterialDef; } |
59 | 59 | ||
60 | /////////////////////////////////////////////////////////////////////// | 60 | /////////////////////////////////////////////////////////////////////// |
61 | // Material Property Accessors | 61 | // Material Property Accessors |
@@ -95,13 +95,13 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
95 | this._materialNode.setShader(this._shader); | 95 | this._materialNode.setShader(this._shader); |
96 | 96 | ||
97 | 97 | ||
98 | if (this._shader && this._shader['default']) | 98 | if (this._shader && this._shader['default']) |
99 | this._shader['default'].u_texTransform.set( this._textureTransform ); | 99 | this._shader['default'].u_texTransform.set( this._textureTransform ); |
100 | 100 | ||
101 | 101 | ||
102 | // send the current values to the shader | 102 | // send the current values to the shader |
103 | this.setShaderValues(); | 103 | this.setShaderValues(); |
104 | this.update( 0 ); | 104 | this.update( 0 ); |
105 | }; | 105 | }; |
106 | 106 | ||
107 | this.resetToDefault = function() | 107 | this.resetToDefault = function() |
@@ -177,111 +177,111 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
177 | 177 | ||
178 | /////////////////////////////////////////////////////////////////////////////////////// | 178 | /////////////////////////////////////////////////////////////////////////////////////// |
179 | // RDGE shader | 179 | // RDGE shader |
180 | 180 | ||
181 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 181 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
182 | var linearGradientMaterialDef = | 182 | var linearGradientMaterialDef = |
183 | {'shaders': | 183 | {'shaders': |
184 | { | 184 | { |
185 | // shader file | 185 | // shader file |
186 | 'defaultVShader':"assets/shaders/linearGradient.vert.glsl", | 186 | 'defaultVShader':"assets/shaders/linearGradient.vert.glsl", |
187 | 'defaultFShader':"assets/shaders/linearGradient.frag.glsl", | 187 | 'defaultFShader':"assets/shaders/linearGradient.frag.glsl", |
188 | 188 | ||
189 | // this shader is inline | 189 | // this shader is inline |
190 | 'dirLightVShader': "\ | 190 | 'dirLightVShader': "\ |
191 | uniform mat4 u_mvMatrix;\ | 191 | uniform mat4 u_mvMatrix;\ |
192 | uniform mat4 u_normalMatrix;\ | 192 | uniform mat4 u_normalMatrix;\ |
193 | uniform mat4 u_projMatrix;\ | 193 | uniform mat4 u_projMatrix;\ |
194 | uniform mat4 u_worldMatrix;\ | 194 | uniform mat4 u_worldMatrix;\ |
195 | attribute vec3 a_pos;\ | 195 | attribute vec3 a_pos;\ |
196 | attribute vec3 a_nrm;\ | 196 | attribute vec3 a_nrm;\ |
197 | varying vec3 vNormal;\ | 197 | varying vec3 vNormal;\ |
198 | varying vec3 vPos;\ | 198 | varying vec3 vPos;\ |
199 | void main() {\ | 199 | void main() {\ |
200 | vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\ | 200 | vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\ |
201 | gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\ | 201 | gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\ |
202 | vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\ | 202 | vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\ |
203 | }", | 203 | }", |
204 | 'dirLightFShader': "\ | 204 | 'dirLightFShader': "\ |
205 | precision highp float;\ | 205 | precision highp float;\ |
206 | uniform vec4 u_light1Diff;\ | 206 | uniform vec4 u_light1Diff;\ |
207 | uniform vec3 u_light1Pos;\ | 207 | uniform vec3 u_light1Pos;\ |
208 | uniform vec4 u_light2Diff;\ | 208 | uniform vec4 u_light2Diff;\ |
209 | uniform vec3 u_light2Pos;\ | 209 | uniform vec3 u_light2Pos;\ |
210 | varying vec3 vNormal;\ | 210 | varying vec3 vNormal;\ |
211 | varying vec3 vPos;\ | 211 | varying vec3 vPos;\ |
212 | void main() {\ | 212 | void main() {\ |
213 | vec3 light1 = vec3(u_light1Pos.x - vPos.x, u_light1Pos.y - vPos.y, u_light1Pos.z - vPos.z);\ | 213 | vec3 light1 = vec3(u_light1Pos.x - vPos.x, u_light1Pos.y - vPos.y, u_light1Pos.z - vPos.z);\ |
214 | vec3 light2 = vec3(u_light2Pos.x - vPos.x, u_light2Pos.y - vPos.y, u_light2Pos.z - vPos.z);\ | 214 | vec3 light2 = vec3(u_light2Pos.x - vPos.x, u_light2Pos.y - vPos.y, u_light2Pos.z - vPos.z);\ |
215 | float t = 0.75;\ | 215 | float t = 0.75;\ |
216 | float range = t*t;\ | 216 | float range = t*t;\ |
217 | float alpha1 = max(0.0, 1.0 - ( (light1.x*light1.x)/range + (light1.y*light1.y)/range + (light1.z*light1.z)/range));\ | 217 | float alpha1 = max(0.0, 1.0 - ( (light1.x*light1.x)/range + (light1.y*light1.y)/range + (light1.z*light1.z)/range));\ |
218 | float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\ | 218 | float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\ |
219 | gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\ | 219 | gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\ |
220 | }" | 220 | }" |
221 | }, | 221 | }, |
222 | 'techniques': | 222 | 'techniques': |
223 | { | 223 | { |
224 | 'default': | 224 | 'default': |
225 | [ | 225 | [ |
226 | { | 226 | { |
227 | 'vshader' : 'defaultVShader', | 227 | 'vshader' : 'defaultVShader', |
228 | 'fshader' : 'defaultFShader', | 228 | 'fshader' : 'defaultFShader', |
229 | // attributes | 229 | // attributes |
230 | 'attributes' : | 230 | 'attributes' : |
231 | { | 231 | { |
232 | 'vert' : { 'type' : 'vec3' }, | 232 | 'vert' : { 'type' : 'vec3' }, |
233 | 'normal' : { 'type' : 'vec3' }, | 233 | 'normal' : { 'type' : 'vec3' }, |
234 | 'texcoord' : { 'type' : 'vec2' } | 234 | 'texcoord' : { 'type' : 'vec2' } |
235 | }, | 235 | }, |
236 | // parameters | 236 | // parameters |
237 | 'params' : | 237 | 'params' : |
238 | { | 238 | { |
239 | 'u_color1' : { 'type' : 'vec4' }, | 239 | 'u_color1' : { 'type' : 'vec4' }, |
240 | 'u_color2' : { 'type' : 'vec4' }, | 240 | 'u_color2' : { 'type' : 'vec4' }, |
241 | 'u_color3' : { 'type' : 'vec4' }, | 241 | 'u_color3' : { 'type' : 'vec4' }, |
242 | 'u_color4' : { 'type' : 'vec4' }, | 242 | 'u_color4' : { 'type' : 'vec4' }, |
243 | 'u_colorStop1': { 'type' : 'float' }, | 243 | 'u_colorStop1': { 'type' : 'float' }, |
244 | 'u_colorStop2': { 'type' : 'float' }, | 244 | 'u_colorStop2': { 'type' : 'float' }, |
245 | 'u_colorStop3': { 'type' : 'float' }, | 245 | 'u_colorStop3': { 'type' : 'float' }, |
246 | 'u_colorStop4': { 'type' : 'float' }, | 246 | 'u_colorStop4': { 'type' : 'float' }, |
247 | 'u_cos_sin_angle': { 'type' : 'vec2' }, | 247 | 'u_cos_sin_angle': { 'type' : 'vec2' }, |
248 | 'u_texTransform': { 'type' : 'mat3' } | 248 | 'u_texTransform': { 'type' : 'mat3' } |
249 | //'u_colorCount': {'type' : 'int' } | 249 | //'u_colorCount': {'type' : 'int' } |
250 | 250 | ||
251 | }, | 251 | }, |
252 | 252 | ||
253 | // render states | 253 | // render states |
254 | 'states' : | 254 | 'states' : |
255 | { | 255 | { |
256 | 'depthEnable' : true, | 256 | 'depthEnable' : true, |
257 | 'offset':[1.0, 0.1] | 257 | 'offset':[1.0, 0.1] |
258 | } | 258 | } |
259 | }, | 259 | }, |
260 | { // light pass | 260 | { // light pass |
261 | 'vshader' : 'dirLightVShader', | 261 | 'vshader' : 'dirLightVShader', |
262 | 'fshader' : 'dirLightFShader', | 262 | 'fshader' : 'dirLightFShader', |
263 | // attributes | 263 | // attributes |
264 | 'attributes' : | 264 | 'attributes' : |
265 | { | 265 | { |
266 | 'a_pos' : { 'type' : 'vec3' }, | 266 | 'a_pos' : { 'type' : 'vec3' }, |
267 | 'a_nrm' : { 'type' : 'vec3' } | 267 | 'a_nrm' : { 'type' : 'vec3' } |
268 | }, | 268 | }, |
269 | // parameters |