diff options
Diffstat (limited to 'js/lib/rdge/materials/fly-material.js')
-rw-r--r-- | js/lib/rdge/materials/fly-material.js | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js new file mode 100644 index 00000000..8eadb3ab --- /dev/null +++ b/js/lib/rdge/materials/fly-material.js | |||
@@ -0,0 +1,119 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | ||
8 | |||
9 | var FlyMaterial = function FlyMaterial() { | ||
10 | /////////////////////////////////////////////////////////////////////// | ||
11 | // Instance variables | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | this._name = "FlyMaterial"; | ||
14 | this._shaderName = "fly"; | ||
15 | |||
16 | this._texMap = 'assets/images/rocky-normal.jpg'; | ||
17 | |||
18 | this._time = 0.0; | ||
19 | this._dTime = 0.01; | ||
20 | |||
21 | /////////////////////////////////////////////////////////////////////// | ||
22 | // Properties | ||
23 | /////////////////////////////////////////////////////////////////////// | ||
24 | // all defined in parent PulseMaterial.js | ||
25 | // load the local default value | ||
26 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | ||
27 | |||
28 | /////////////////////////////////////////////////////////////////////// | ||
29 | // Methods | ||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | // duplcate method requirde | ||
32 | this.dup = function( world ) { | ||
33 | // allocate a new uber material | ||
34 | var newMat = new FlyMaterial(); | ||
35 | |||
36 | // copy over the current values; | ||
37 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
38 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
39 | var n = propNames.length; | ||
40 | for (var i=0; i<n; i++) | ||
41 | newMat.setProperty( propNames[i], propValues[i] ); | ||
42 | |||
43 | return newMat; | ||
44 | }; | ||
45 | |||
46 | this.init = function( world ) { | ||
47 | // save the world | ||
48 | if (world) this.setWorld( world ); | ||
49 | |||
50 | // set up the shader | ||
51 | this._shader = new jshader(); | ||
52 | this._shader.def = flyMaterialDef; | ||
53 | this._shader.init(); | ||
54 | |||
55 | // set up the material node | ||
56 | this._materialNode = createMaterialNode("flyMaterial"); | ||
57 | this._materialNode.setShader(this._shader); | ||
58 | |||
59 | this._time = 0; | ||
60 | if (this._shader && this._shader['default']) { | ||
61 | this._shader['default'].u_time.set( [this._time] ); | ||
62 | } | ||
63 | |||
64 | // set the shader values in the shader | ||
65 | this.updateTexture(); | ||
66 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | ||
67 | this.update( 0 ); | ||
68 | } | ||
69 | }; | ||
70 | |||
71 | /////////////////////////////////////////////////////////////////////////////////////// | ||
72 | // RDGE shader | ||
73 | |||
74 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
75 | var flyMaterialDef = | ||
76 | {'shaders': | ||
77 | { | ||
78 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
79 | 'defaultFShader':"assets/shaders/Fly.frag.glsl" | ||
80 | }, | ||
81 | 'techniques': | ||
82 | { | ||
83 | 'default': | ||
84 | [ | ||
85 | { | ||
86 | 'vshader' : 'defaultVShader', | ||
87 | 'fshader' : 'defaultFShader', | ||
88 | // attributes | ||
89 | 'attributes' : | ||
90 | { | ||
91 | 'vert' : { 'type' : 'vec3' }, | ||
92 | 'normal' : { 'type' : 'vec3' }, | ||
93 | 'texcoord' : { 'type' : 'vec2' } | ||
94 | }, | ||
95 | // parameters | ||
96 | 'params' : | ||
97 | { | ||
98 | 'u_tex0': { 'type' : 'tex2d' }, | ||
99 | 'u_time' : { 'type' : 'float' }, | ||
100 | 'u_resolution' : { 'type' : 'vec2' }, | ||
101 | }, | ||
102 | |||
103 | // render states | ||
104 | 'states' : | ||
105 | { | ||
106 | 'depthEnable' : true, | ||
107 | 'offset':[1.0, 0.1] | ||
108 | } | ||
109 | } | ||
110 | ] | ||
111 | } | ||
112 | }; | ||
113 | |||
114 | FlyMaterial.prototype = new PulseMaterial(); | ||
115 | |||
116 | if (typeof exports === "object") { | ||
117 | exports.FlyMaterial = FlyMaterial; | ||
118 | } | ||
119 | |||