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.js133
1 files changed, 133 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..a8c319e4
--- /dev/null
+++ b/js/lib/rdge/materials/flag-material.js
@@ -0,0 +1,133 @@
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 Material = require("js/lib/rdge/materials/material").Material;
9var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
10var Texture = require("js/lib/rdge/texture").Texture;
11
12var FlagMaterial = function FlagMaterial() {
13 ///////////////////////////////////////////////////////////////////////
14 // Instance variables
15 ///////////////////////////////////////////////////////////////////////
16 this._name = "FlagMaterial";
17 this._shaderName = "flag";
18
19 this._texMap = 'assets/images/us_flag.png';
20
21 this._time = 0.0;
22 this._dTime = 0.1;
23
24 this._speed = 1.0;
25 this._waveWidth = 1.0;
26 this._waveHeight = 1.0;
27
28 this._hasVertexDeformation = true;
29
30 ///////////////////////////////////////////////////////////////////////
31 // Properties
32 ///////////////////////////////////////////////////////////////////////
33 // all defined in parent PulseMaterial.js
34 // load the local default value
35 this._propNames = ["u_tex0", "u_waveWidth", "u_waveHeight", "u_speed" ];
36 this._propLabels = ["Texture map", "Wave Width", "Wave Height", "Speed" ];
37 this._propTypes = ["file", "float", "float", "float" ];
38 this._propValues = [];
39
40 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
41 this._propValues[ this._propNames[1] ] = this._waveWidth;
42 this._propValues[ this._propNames[2] ] = this._waveHeight;
43 this._propValues[ this._propNames[3] ] = this._speed;
44
45
46 // a material can be animated or not. default is not.
47 // Any material needing continuous rendering should override this method
48 this.isAnimated = function() { return true; };
49 this.getShaderDef = function() { return flagMaterialDef; }
50
51 ///////////////////////////////////////////////////////////////////////
52 // Methods
53 ///////////////////////////////////////////////////////////////////////
54 // duplcate method requirde
55
56 this.init = function( world )
57 {
58 // save the world
59 if (world) this.setWorld( world );
60
61 // set up the shader
62 this._shader = new RDGE.jshader();
63 this._shader.def = flagMaterialDef;
64 this._shader.init();
65
66 // set up the material node
67 this._materialNode = RDGE.createMaterialNode("flagMaterial" + "_" + world.generateUniqueNodeID());
68 this._materialNode.setShader(this._shader);
69
70 this._time = 0;
71 if (this._shader && this._shader['default'])
72 this._shader['default'].u_time.set( [this._time] );
73
74 // set the shader values in the shader
75 this.setShaderValues();
76 this.update( 0 );
77 }
78};
79
80///////////////////////////////////////////////////////////////////////////////////////
81// RDGE shader
82
83// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
84var flagMaterialDef =
85{'shaders':
86 {
87 'defaultVShader':"assets/shaders/Flag.vert.glsl",
88 'defaultFShader':"assets/shaders/Flag.frag.glsl"
89 },
90 'techniques':
91 {
92 'default':
93 [
94 {
95 'vshader' : 'defaultVShader',
96 'fshader' : 'defaultFShader',
97 // attributes
98 'attributes' :
99 {
100 'vert' : { 'type' : 'vec3' },
101 'normal' : { 'type' : 'vec3' },
102 'texcoord' : { 'type' : 'vec2' }
103 },
104 // parameters
105 'params' :
106 {
107 'u_tex0': { 'type' : 'tex2d' },
108 'u_time' : { 'type' : 'float' },
109 'u_speed' : { 'type' : 'float' },
110 'u_waveWidth' : { 'type' : 'float' },
111 'u_waveHeight' : { 'type' : 'float' }
112 },
113
114 // render states
115 'states' :
116 {
117 'depthEnable' : true,
118 'offset':[1.0, 0.1]
119 }
120 }
121 ]
122 }
123};
124
125FlagMaterial.prototype = new PulseMaterial();
126
127if (typeof exports === "object") {
128 exports.FlagMaterial = FlagMaterial;
129}
130
131
132
133