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