aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/pulse-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r--js/lib/rdge/materials/pulse-material.js189
1 files changed, 23 insertions, 166 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index 374a5eae..7c00b836 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -30,69 +30,30 @@ var PulseMaterial = function PulseMaterial()
30 this._time = 0.0; 30 this._time = 0.0;
31 this._dTime = 0.01; 31 this._dTime = 0.01;
32 32
33 this._xScale = 0.5;
34 this._yScale = 0.4;
35 this._speed = 1.0;
36
37 /////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////
38 // Property Accessors 34 // Property Accessors
39 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
40 this.getName = function() { return this._name; }; 36 this.isAnimated = function() { return true; };
41 this.getShaderName = function() { return this._shaderName; }; 37 this.getShaderDef = function() { return pulseMaterialDef; }
42
43 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null };
44 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
45
46 this.isAnimated = function() { return true; };
47 38
48 /////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////
49 // Material Property Accessors 40 // Material Property Accessors
50 /////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////
51 this._propNames = ["texmap", "xscale", "yscale", "speed" ]; 42
43 var u_tex0_index = 0,
44 u_xScale_index = 1,
45 u_yScale_index = 2,
46 u_speed_index = 3;
47
48 this._propNames = ["u_tex0", "u_xscale", "u_yscale", "u_speed" ];
52 this._propLabels = ["Texture map", "X Range", "Y Range", "Speed" ]; 49 this._propLabels = ["Texture map", "X Range", "Y Range", "Speed" ];
53 this._propTypes = ["file", "float", "float", "float"]; 50 this._propTypes = ["file", "float", "float", "float"];
54 this._propValues = []; 51 this._propValues = [];
55 52
56 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 53 this._propValues[ this._propNames[ u_tex0_index] ] = this._texMap.slice(0);
57 this._propValues[ this._propNames[1] ] = this._xScale; 54 this._propValues[ this._propNames[u_xScale_index] ] = 0.5;
58 this._propValues[ this._propNames[2] ] = this._yScale; 55 this._propValues[ this._propNames[u_yScale_index] ] = 0.4;
59 this._propValues[ this._propNames[3] ] = this._speed; 56 this._propValues[ this._propNames[ u_speed_index] ] = 1.0;
60
61 this.setProperty = function( prop, value ) {
62 // make sure we have legitimate imput
63 var ok = this.validateProperty( prop, value );
64 if (!ok && (prop != 'color')) {
65 console.log( "invalid property in Material:" + prop + " : " + value );
66 }
67
68 switch (prop)
69 {
70 case "texmap":
71 this.setTextureMap(value);
72 break;
73
74 case "speed":
75 this._speed = value;
76 this._propValues[ this._propNames[3] ] = this._speed;
77 this.updateParameters();
78 break;
79
80 case "xscale":
81 this._xScale = value;
82 this._propValues[ this._propNames[1] ] = this._xScale;
83 this.updateParameters();
84 break;
85
86 case "yscale":
87 this._yScale = value;
88 this._propValues[ this._propNames[2] ] = this._yScale;
89 this.updateParameters();
90 break;
91
92 case "color":
93 break;
94 }
95 };
96 /////////////////////////////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////
97 58
98 59
@@ -100,26 +61,9 @@ var PulseMaterial = function PulseMaterial()
100 // Methods 61 // Methods
101 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
102 // duplicate method required 63 // duplicate method required
103 this.dup = function( world ) {
104 // save the world
105 if (world) this.setWorld( world );
106
107 // get the current values;
108 var propNames = [], propValues = [], propTypes = [], propLabels = [];
109 this.getAllProperties(propNames, propValues, propTypes, propLabels);
110
111 // allocate a new material
112 var newMat = new PulseMaterial();
113
114 // copy over the current values;
115 var n = propNames.length;
116 for (var i = 0; i < n; i++)
117 newMat.setProperty(propNames[i], propValues[i]);
118
119 return newMat;
120 };
121 64
122 this.init = function( world ) { 65 this.init = function( world )
66 {
123 // save the world 67 // save the world
124 if (world) this.setWorld( world ); 68 if (world) this.setWorld( world );
125 69
@@ -140,67 +84,17 @@ var PulseMaterial = function PulseMaterial()
140 if (this._shader && this._shader['default']) { 84 if (this._shader && this._shader['default']) {
141 this._shader['default'].u_time.set( [this._time] ); 85 this._shader['default'].u_time.set( [this._time] );
142 } 86 }
143 this.updateParameters();
144 87
145 // set up the texture 88 // set up the texture
146 var texMapName = this._propValues[this._propNames[0]]; 89 //var texMapName = this._propValues[this._propNames[0]];
147 this._glTex = new Texture( world, texMapName ); 90 //this.setProperty( "u_tex0", texMapName );
148 91
149 // set the shader values in the shader 92 // set the shader values in the shader
150 this.updateTexture(); 93 this.setShaderValues();
151 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 94 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
152 this.update( 0 ); 95 this.update( 0 );
153 }; 96 };
154 97
155 this.updateParameters = function()
156 {
157 this._propValues[ this._propNames[1] ] = this._xScale;
158 this._propValues[ this._propNames[2] ] = this._yScale;
159 this._propValues[ this._propNames[3] ] = this._speed;
160
161 var material = this._materialNode;
162 if (material)
163 {
164 var technique = material.shaderProgram['default'];
165 var renderer = RDGE.globals.engine.getContext().renderer;
166 if (renderer && technique)
167 {
168
169 if (this._shader && this._shader['default']) {
170 this._shader['default'].u_speed.set( [this._speed] );
171 this._shader['default'].u_xscale.set( [this._xScale] );
172 this._shader['default'].u_yscale.set( [this._yScale] );
173 }
174 }
175 }
176 }
177
178 this.updateTexture = function() {
179
180 var texMapName = this._propValues[this._propNames[0]];
181 this._glTex = new Texture( this.getWorld(), texMapName );
182
183 var material = this._materialNode;
184 if (material) {
185 var technique = material.shaderProgram['default'];
186 var renderer = RDGE.globals.engine.getContext().renderer;
187 if (renderer && technique) {
188 var wrap = 'REPEAT', mips = true;
189 var tex;
190 if (this._glTex)
191 {
192 if (this._glTex.isAnimated())
193 this._glTex.render();
194 tex = this._glTex.getTexture();
195 }
196
197 if (tex) {
198 technique.u_tex0.set( tex );
199 }
200 }
201 }
202 };
203
204 this.update = function( time ) 98 this.update = function( time )
205 { 99 {
206 var material = this._materialNode; 100 var material = this._materialNode;
@@ -210,12 +104,13 @@ var PulseMaterial = function PulseMaterial()
210 var renderer = RDGE.globals.engine.getContext().renderer; 104 var renderer = RDGE.globals.engine.getContext().renderer;
211 if (renderer && technique) 105 if (renderer && technique)
212 { 106 {
213 if (this._glTex) 107 var glTex = this._glTextures["u_tex0"];
108 if (glTex)
214 { 109 {
215 //this.updateTexture(); 110 //this.updateTexture();
216 if (this._glTex.isAnimated()) 111 if (glTex.isAnimated())
217 this._glTex.render(); 112 glTex.render();
218 tex = this._glTex.getTexture(); 113 tex = glTex.getTexture();
219 if (tex) 114 if (tex)
220 technique.u_tex0.set( tex ); 115 technique.u_tex0.set( tex );