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