aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/flag-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/flag-material.js')
-rw-r--r--js/lib/rdge/materials/flag-material.js148
1 files changed, 148 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js
new file mode 100644
index 00000000..8d4d1ee3
--- /dev/null
+++ b/js/lib/rdge/materials/flag-material.js
@@ -0,0 +1,148 @@
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
8var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
9var Texture = require("js/lib/rdge/texture").Texture;
10
11var FlagMaterial = function FlagMaterial() {
12 ///////////////////////////////////////////////////////////////////////
13 // Instance variables
14 ///////////////////////////////////////////////////////////////////////
15 this._name = "FlagMaterial";
16 this._shaderName = "flag";
17
18 this._texMap = 'assets/images/us_flag.png';
19
20 this._time = 0.0;
21 this._dTime = 0.1;
22
23 this._defaultWaveWidth = 1.0;
24 this._defaultWaveHeight = 1.0;
25
26 this._hasVertexDeformation = true;
27
28 ///////////////////////////////////////////////////////////////////////
29 // Properties
30 ///////////////////////////////////////////////////////////////////////
31 // all defined in parent PulseMaterial.js
32 // load the local default value
33 this._propNames = ["texmap", "wavewidth", "waveheight" ];
34 this._propLabels = ["Texture map", "Wave Width", "Wave Height" ];
35 this._propTypes = ["file", "float", "float" ];
36 this._propValues = [];
37
38 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
39 this._propValues[ this._propNames[1] ] = this._defaultWaveWidth;
40 this._propValues[ this._propNames[2] ] = this._defaultWaveHeight;
41
42 // a material can be animated or not. default is not.
43 // Any material needing continuous rendering should override this method
44 this.isAnimated = function() { return true; };
45
46 ///////////////////////////////////////////////////////////////////////
47 // Methods
48 ///////////////////////////////////////////////////////////////////////
49 // duplcate method requirde
50 this.dup = function( world ) {
51 // allocate a new uber material
52 var newMat = new FlagMaterial();
53
54 // copy over the current values;
55 var propNames = [], propValues = [], propTypes = [], propLabels = [];
56 this.getAllProperties( propNames, propValues, propTypes, propLabels);
57 var n = propNames.length;
58 for (var i=0; i<n; i++) {
59 newMat.setProperty( propNames[i], propValues[i] );
60 }
61
62 return newMat;
63 };
64
65 this.init = function( world )
66 {
67 // save the world
68 if (world) this.setWorld( world );
69
70 // set up the shader
71 this._shader = new jshader();
72 this._shader.def = flagMaterialDef;
73 this._shader.init();
74
75 // set up the material node
76 this._materialNode = createMaterialNode("flagMaterial" + "_" + world.generateUniqueNodeID());
77 this._materialNode.setShader(this._shader);
78
79 this._time = 0;
80 if (this._shader && this._shader['default']) {
81 this._shader['default'].u_time.set( [this._time] );
82 this._shader['default'].u_waveWidth.set( [this._propValues[ this._propNames[1] ]] );
83 this._shader['default'].u_waveHeight.set( [this._propValues[ this._propNames[2] ]] );
84 }
85
86 // set up the texture
87 var texMapName = this._propValues[this._propNames[0]];
88 this._glTex = new Texture( world, texMapName );
89
90 // set the shader values in the shader
91 this.updateTexture();
92 this.update( 0 );
93 }
94};
95
96///////////////////////////////////////////////////////////////////////////////////////
97// RDGE shader
98
99// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
100var flagMaterialDef =
101{'shaders':
102 {
103 'defaultVShader':"assets/shaders/Flag.vert.glsl",
104 'defaultFShader':"assets/shaders/Flag.frag.glsl"
105 },
106 'techniques':
107 {
108 'default':
109 [
110 {
111 'vshader' : 'defaultVShader',
112 'fshader' : 'defaultFShader',
113 // attributes
114 'attributes' :
115 {
116 'vert' : { 'type' : 'vec3' },
117 'normal' : { 'type' : 'vec3' },
118 'texcoord' : { 'type' : 'vec2' }
119 },
120 // parameters
121 'params' :
122 {
123 'u_tex0': { 'type' : 'tex2d' },
124 'u_time' : { 'type' : 'float' },
125 'u_waveWidth' : { 'type' : 'float' },
126 'u_waveHeight' : { 'type' : 'float' }
127 },
128
129 // render states
130 'states' :
131 {
132 'depthEnable' : true,
133 'offset':[1.0, 0.1]
134 }
135 }
136 ]
137 }
138};
139
140FlagMaterial.prototype = new PulseMaterial();
141
142if (typeof exports === "object") {
143 exports.FlagMaterial = FlagMaterial;
144}
145
146
147
148