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.js81
1 files changed, 74 insertions, 7 deletions
diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js
index 312ca1c1..fa844cc3 100644
--- a/js/lib/rdge/materials/flag-material.js
+++ b/js/lib/rdge/materials/flag-material.js
@@ -21,8 +21,9 @@ var FlagMaterial = function FlagMaterial() {
21 this._time = 0.0; 21 this._time = 0.0;
22 this._dTime = 0.1; 22 this._dTime = 0.1;
23 23
24 this._defaultWaveWidth = 1.0; 24 this._speed = 1.0;
25 this._defaultWaveHeight = 1.0; 25 this._waveWidth = 1.0;
26 this._waveHeight = 1.0;
26 27
27 this._hasVertexDeformation = true; 28 this._hasVertexDeformation = true;
28 29
@@ -31,14 +32,16 @@ var FlagMaterial = function FlagMaterial() {
31 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
32 // all defined in parent PulseMaterial.js 33 // all defined in parent PulseMaterial.js
33 // load the local default value 34 // load the local default value
34 this._propNames = ["texmap", "wavewidth", "waveheight" ]; 35 this._propNames = ["texmap", "wavewidth", "waveheight", "speed" ];
35 this._propLabels = ["Texture map", "Wave Width", "Wave Height" ]; 36 this._propLabels = ["Texture map", "Wave Width", "Wave Height", "Speed" ];
36 this._propTypes = ["file", "float", "float" ]; 37 this._propTypes = ["file", "float", "float", "float" ];
37 this._propValues = []; 38 this._propValues = [];
38 39
39 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 40 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
40 this._propValues[ this._propNames[1] ] = this._defaultWaveWidth; 41 this._propValues[ this._propNames[1] ] = this._waveWidth;
41 this._propValues[ this._propNames[2] ] = this._defaultWaveHeight; 42 this._propValues[ this._propNames[2] ] = this._waveHeight;
43 this._propValues[ this._propNames[3] ] = this._speed;
44
42 45
43 // a material can be animated or not. default is not. 46 // a material can be animated or not. default is not.
44 // Any material needing continuous rendering should override this method 47 // Any material needing continuous rendering should override this method
@@ -65,6 +68,68 @@ var FlagMaterial = function FlagMaterial() {
65 return newMat; 68 return newMat;
66 }; 69 };
67 70
71 this.setProperty = function( prop, value )
72 {
73 // make sure we have legitimate imput
74 var ok = this.validateProperty( prop, value );
75 if (!ok) {
76 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
77 }
78
79 switch (prop)
80 {
81 case "texmap":
82 this.setTextureMap(value);
83 break;
84
85 case "wavewidth":
86 this._waveWidth = value;
87 this._propValues[ this._propNames[1] ] = this._waveWidth;
88 this.updateParameters();
89 break;
90
91 case "waveheight":
92 this._waveHeight = value;
93 this._propValues[ this._propNames[2] ] = this._waveHeight;
94 this.updateParameters();
95 break;
96
97 case "speed":
98 this._speed = value;
99 this._propValues[ this._propNames[3] ] = this._speed;
100 this.updateParameters();
101 break;
102
103 case "color":
104 break;
105 }
106 };
107
108
109 this.updateParameters = function()
110 {
111 this._propValues[ this._propNames[1] ] = this._waveWidth;
112 this._propValues[ this._propNames[2] ] = this._waveHeight;
113 this._propValues[ this._propNames[3] ] = this._speed;
114
115 var material = this._materialNode;
116 if (material)
117 {
118 var technique = material.shaderProgram['default'];
119 var renderer = RDGE.globals.engine.getContext().renderer;
120 if (renderer && technique)
121 {
122
123 if (this._shader && this._shader['default']) {
124 this._shader['default'].u_speed.set( [this._speed] );
125 this._shader['default'].u_waveWidth.set( [this._waveWidth] );
126 this._shader['default'].u_waveHeight.set( [this._waveHeight] );
127 }
128 }
129 }
130 };
131
132
68 this.init = function( world ) 133 this.init = function( world )
69 { 134 {
70 // save the world 135 // save the world
@@ -91,6 +156,7 @@ var FlagMaterial = function FlagMaterial() {
91 this._glTex = new Texture( world, texMapName ); 156 this._glTex = new Texture( world, texMapName );
92 157
93 // set the shader values in the shader 158 // set the shader values in the shader
159 this.updateParameters();
94 this.updateTexture(); 160 this.updateTexture();
95 this.update( 0 ); 161 this.update( 0 );
96 } 162 }
@@ -125,6 +191,7 @@ var flagMaterialDef =
125 { 191 {
126 'u_tex0': { 'type' : 'tex2d' }, 192 'u_tex0': { 'type' : 'tex2d' },
127 'u_time' : { 'type' : 'float' }, 193 'u_time' : { 'type' : 'float' },
194 'u_speed' : { 'type' : 'float' },
128 'u_waveWidth' : { 'type' : 'float' }, 195 'u_waveWidth' : { 'type' : 'float' },
129 'u_waveHeight' : { 'type' : 'float' } 196 'u_waveHeight' : { 'type' : 'float' }
130 }, 197 },