aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge
diff options
context:
space:
mode:
authorhwc4872012-05-16 13:41:48 -0700
committerhwc4872012-05-16 13:41:48 -0700
commit1e649405d66f17d6acddb9055b181bba7ad70566 (patch)
treeb781fffc63773b17df8eb87a5e99f6ff7c1acb58 /js/lib/rdge
parent25a2e1c5eb21a18caccc7a9435d835a3f5e7f3a0 (diff)
downloadninja-1e649405d66f17d6acddb9055b181bba7ad70566.tar.gz
Exposing parameters in Water Material
Diffstat (limited to 'js/lib/rdge')
-rw-r--r--js/lib/rdge/materials/water-material.js172
1 files changed, 150 insertions, 22 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js
index 18a73915..1f0aa46e 100644
--- a/js/lib/rdge/materials/water-material.js
+++ b/js/lib/rdge/materials/water-material.js
@@ -23,14 +23,29 @@ var WaterMaterial = function WaterMaterial() {
23 23
24 this._time = 0.0; 24 this._time = 0.0;
25 this._dTime = 0.01; 25 this._dTime = 0.01;
26 this._emboss = 0.3;
27 this._delta = 20.0;
28 this._intensity = 3.0;
29
30 this._speed = 0.2;
26 31
27 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
28 // Properties 33 // Properties
29 /////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////
30 // all defined in parent PulseMaterial.js 35 // all defined in parent PulseMaterial.js
31 // load the local default value 36 // load the local default value
32 this._propValues = []; 37 //this._propValues = [];
33 this._propValues[this._propNames[0]] = this._texMap.slice(0); 38 //this._propValues[this._propNames[0]] = this._texMap.slice(0);
39 this._propNames = ["texmap", "emboss", "delta", "intensity", "speed"];
40 this._propLabels = ["Texture map", "Emboss", "Delta", "Intensity", "Speed"];
41 this._propTypes = ["file", "float", "float", "float", "float"];
42
43 this._propValues = [];
44 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
45 this._propValues[ this._propNames[1] ] = this._emboss;
46 this._propValues[ this._propNames[2] ] = this._delta;
47 this._propValues[ this._propNames[3] ] = this._intensity;
48 this._propValues[ this._propNames[4] ] = this._speed;
34 49
35 /////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////
36 // Methods 51 // Methods
@@ -52,32 +67,141 @@ var WaterMaterial = function WaterMaterial() {
52 return newMat; 67 return newMat;
53 }; 68 };
54 69
70 this.setProperty = function( prop, value ) {
71 // make sure we have legitimate imput
72 var ok = this.validateProperty( prop, value );
73 if (!ok) {
74 console.log( "invalid property in Water Material:" + prop + " : " + value );
75 }
76
77 switch (prop)
78 {
79 case "texmap":
80 this.setTextureMap(value);
81 break;
82
83 case "emboss":
84 this.setEmboss( value );
85 break;
86
87 case "delta":
88 this.setDelta( value );
89 break;
90
91 case "intensity":
92 this.setIntensity( value );
93 break;
94
95 case "speed":
96 this.setSpeed( value );
97 break;
98
99 case "color":
100 break;
101 }
102 };
103
55 this.init = function (world) { 104 this.init = function (world) {
56 // save the world 105 // save the world
57 if (world) this.setWorld(world); 106 if (world) this.setWorld(world);
107
108 // set up the shader
109 this._shader = new RDGE.jshader();
110 this._shader.def = waterMaterialDef;
111 this._shader.init();
112
113 // set up the material node
114 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID());
115 this._materialNode.setShader(this._shader);
116
117 this._time = 0;
118 if (this._shader && this._shader['default']) {
119 this._shader['default'].u_time.set([this._time]);
120
121 this._shader['default'].u_emboss.set( [this._emboss] );
122 this._shader['default'].u_delta.set( [this._delta] );
123 this._shader['default'].u_intensity.set( [this._intensity] );
124 this._shader['default'].u_speed.set( [this._speed] );
125 }
126
127 var texMapName = this._propValues[this._propNames[0]];
128 this._glTex = new Texture( world, texMapName );
129
130 // set the shader values in the shader
131 this.updateTexture();
132 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
133 this.update(0);
134 };
135
136 this.setTextureMap = function( texMapName )
137 {
138 this._texMap = texMapName.slice();
139 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
58 140
59 // set up the shader 141 this._glTex = new Texture( this.getWorld(), texMapName );
60 this._shader = new RDGE.jshader(); 142 this.updateTexture();
61 this._shader.def = waterMaterialDef; 143 }
62 this._shader.init();
63 144
64 // set up the material node 145 this.setEmboss = function( value )
65 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID()); 146 {
66 this._materialNode.setShader(this._shader); 147 this._emboss = value;
148 this._propValues[ "emboss" ] = value;
149
150 var material = this._materialNode;
151 if (material) {
152 var technique = material.shaderProgram['default'];
153 var renderer = RDGE.globals.engine.getContext().renderer;
154 if (renderer && technique) {
155 technique.u_emboss.set( [value] );
156 }
157 }
158 }
67 159
68 this._time = 0; 160 this.setIntensity = function( value )
69 if (this._shader && this._shader['default']) { 161 {
70 this._shader['default'].u_time.set([this._time]); 162 this._intensity = value;
71 } 163 this._propValues[ "intensity" ] = value;
164
165 var material = this._materialNode;
166 if (material) {
167 var technique = material.shaderProgram['default'];
168 var renderer = RDGE.globals.engine.getContext().renderer;
169 if (renderer && technique) {
170 technique.u_intensity.set( [value] );
171 console.log( "setting intensity to: " + value );
172 }
173 }
174 }
72 175
73 var texMapName = this._propValues[this._propNames[0]]; 176 this.setDelta = function( value )
74 this._glTex = new Texture( world, texMapName ); 177 {
178 this._delta = value;
179 this._propValues[ "delta" ] = value;
180
181 var material = this._materialNode;
182 if (material) {
183 var technique = material.shaderProgram['default'];
184 var renderer = RDGE.globals.engine.getContext().renderer;
185 if (renderer && technique) {
186 technique.u_delta.set( [value] );
187 }
188 }
189 }
75 190
76 // set the shader values in the shader 191 this.setSpeed = function( value )
77 this.updateTexture(); 192 {
78 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 193 this._speed = value;
79 this.update(0); 194 this._propValues[ "speed" ] = value;
80 }; 195
196 var material = this._materialNode;
197 if (material) {
198 var technique = material.shaderProgram['default'];
199 var renderer = RDGE.globals.engine.getContext().renderer;
200 if (renderer && technique) {
201 technique.u_speed.set( [value] );
202 }
203 }
204 }
81}; 205};
82 206
83/////////////////////////////////////////////////////////////////////////////////////// 207///////////////////////////////////////////////////////////////////////////////////////
@@ -109,6 +233,10 @@ var waterMaterialDef =
109 { 233 {
110 'u_tex0': { 'type': 'tex2d' }, 234 'u_tex0': { 'type': 'tex2d' },
111 'u_time': { 'type': 'float' }, 235 'u_time': { 'type': 'float' },
236 'u_emboss': { 'type': 'float' },
237 'u_delta': { 'type': 'float' },
238 'u_speed': { 'type': 'float' },
239 'u_intensity': { 'type': 'float' },
112 'u_resolution': { 'type': 'vec2' } 240 'u_resolution': { 'type': 'vec2' }
113 }, 241 },
114 242