diff options
Diffstat (limited to 'js/lib/rdge/materials')
-rw-r--r-- | js/lib/rdge/materials/plasma-material.js | 98 | ||||
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 208 |
2 files changed, 231 insertions, 75 deletions
diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 02172a6b..1db207d6 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js | |||
@@ -17,6 +17,23 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
17 | this._dTime = 0.01; | 17 | this._dTime = 0.01; |
18 | this._speed = 1.0; | 18 | this._speed = 1.0; |
19 | 19 | ||
20 | this._wave = 0.0; | ||
21 | this._wave1 = 0.6; | ||
22 | this._wave2 = 0.8; | ||
23 | |||
24 | /////////////////////////////////////////////////////////////////////// | ||
25 | // Properties | ||
26 | /////////////////////////////////////////////////////////////////////// | ||
27 | this._propNames = ["wave", "wave1", "wave2", "speed"]; | ||
28 | this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"]; | ||
29 | this._propTypes = ["float", "float", "float", "float"]; | ||
30 | |||
31 | this._propValues = []; | ||
32 | this._propValues[ this._propNames[0] ] = this._wave; | ||
33 | this._propValues[ this._propNames[1] ] = this._wave1; | ||
34 | this._propValues[ this._propNames[2] ] = this._wave2; | ||
35 | this._propValues[ this._propNames[3] ] = this._speed; | ||
36 | |||
20 | 37 | ||
21 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
22 | // Property Accessors | 39 | // Property Accessors |
@@ -28,10 +45,51 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
28 | /////////////////////////////////////////////////////////////////////// | 45 | /////////////////////////////////////////////////////////////////////// |
29 | // Material Property Accessors | 46 | // Material Property Accessors |
30 | /////////////////////////////////////////////////////////////////////// | 47 | /////////////////////////////////////////////////////////////////////// |
48 | // duplcate method requirde | ||
49 | this.dup = function (world) { | ||
50 | // get the current values; | ||
51 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
52 | this.getAllProperties(propNames, propValues, propTypes, propLabels); | ||
53 | |||
54 | // allocate a new material | ||
55 | var newMat = new PlasmaMaterial(); | ||
56 | |||
57 | // copy over the current values; | ||
58 | var n = propNames.length; | ||
59 | for (var i = 0; i < n; i++) | ||
60 | newMat.setProperty(propNames[i], propValues[i]); | ||
61 | |||
62 | return newMat; | ||
63 | }; | ||
31 | 64 | ||
32 | this.setProperty = function( prop, value ) | 65 | this.setProperty = function( prop, value ) |
33 | { | 66 | { |
34 | // plasma has no properties | 67 | // make sure we have legitimate imput |
68 | var ok = this.validateProperty( prop, value ); | ||
69 | if (!ok) { | ||
70 | console.log( "invalid property in Water Material:" + prop + " : " + value ); | ||
71 | } | ||
72 | |||
73 | switch (prop) | ||
74 | { | ||
75 | case "wave": | ||
76 | this._wave = value; | ||
77 | break; | ||
78 | |||
79 | case "wave1": | ||
80 | this._wave1 = value; | ||
81 | break; | ||
82 | |||
83 | case "wave2": | ||
84 | this._wave2 = value; | ||
85 | break; | ||
86 | |||
87 | case "speed": | ||
88 | this._speed = value; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | this.updateParameters(); | ||
35 | }; | 93 | }; |
36 | 94 | ||
37 | /////////////////////////////////////////////////////////////////////// | 95 | /////////////////////////////////////////////////////////////////////// |
@@ -56,12 +114,37 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
56 | // set the default value | 114 | // set the default value |
57 | this._time = 0; | 115 | this._time = 0; |
58 | this._shader['default'].u_time.set( [this._time] ); | 116 | this._shader['default'].u_time.set( [this._time] ); |
117 | this._shader['default'].u_speed.set( [this._speed] ); | ||
118 | |||
119 | this._shader['default'].u_wave.set( [this._wave] ); | ||
120 | this._shader['default'].u_wave1.set( [this._wave1] ); | ||
121 | this._shader['default'].u_wave2.set( [this._wave2] ); | ||
59 | 122 | ||
60 | // set up the material node | 123 | // set up the material node |
61 | this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); | 124 | this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); |
62 | this._materialNode.setShader(this._shader); | 125 | this._materialNode.setShader(this._shader); |
63 | }; | 126 | }; |
64 | 127 | ||
128 | this.updateParameters = function() | ||
129 | { | ||
130 | this._propValues[ this._propNames[0] ] = this._wave; | ||
131 | this._propValues[ this._propNames[1] ] = this._wave1; | ||
132 | this._propValues[ this._propNames[2] ] = this._wave2; | ||
133 | this._propValues[ this._propNames[3] ] = this._speed; | ||
134 | |||
135 | var material = this._materialNode; | ||
136 | if (material) { | ||
137 | var technique = material.shaderProgram['default']; | ||
138 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
139 | if (renderer && technique) { | ||
140 | technique.u_wave.set( [this._wave] ); | ||
141 | technique.u_wave1.set( [this._wave1] ); | ||
142 | technique.u_wave2.set( [this._wave2] ); | ||
143 | technique.u_speed.set( [this._speed] ); | ||
144 | } | ||
145 | } | ||
146 | }; | ||
147 | |||
65 | this.update = function( time ) { | 148 | this.update = function( time ) { |
66 | this._shader['default'].u_time.set( [this._time] ); | 149 | this._shader['default'].u_time.set( [this._time] ); |
67 | this._time += this._dTime; | 150 | this._time += this._dTime; |
@@ -74,7 +157,10 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
74 | 'material' : this.getShaderName(), | 157 | 'material' : this.getShaderName(), |
75 | 'name' : this.getName(), | 158 | 'name' : this.getName(), |
76 | 'speed' : this._speed, | 159 | 'speed' : this._speed, |
77 | 'dTime' : this._dTime | 160 | 'dTime' : this._dTime, |
161 | 'wave' : this._wave, | ||
162 | 'wave1' : this._wave1, | ||
163 | 'wave2' : this._wave2 | ||
78 | }; | 164 | }; |
79 | 165 | ||
80 | return jObj; | 166 | return jObj; |
@@ -84,6 +170,10 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
84 | { | 170 | { |
85 | this._speed = jObj.speed; | 171 | this._speed = jObj.speed; |
86 | this._dTime = jObj.dTime; | 172 | this._dTime = jObj.dTime; |
173 | |||
174 | this._wave = jObj.wave; | ||
175 | this._wave1 = jObj.wave1; | ||
176 | this._wave2 = jObj.wave2; | ||
87 | }; | 177 | }; |
88 | }; | 178 | }; |
89 | 179 | ||
@@ -115,6 +205,10 @@ var plasmaShaderDef = | |||
115 | 'params' : | 205 | 'params' : |
116 | { | 206 | { |
117 | 'u_time' : { 'type' : 'float' }, | 207 | 'u_time' : { 'type' : 'float' }, |
208 | 'u_speed': { 'type' : 'float' }, | ||
209 | 'u_wave' : { 'type' : 'float' }, | ||
210 | 'u_wave1': { 'type' : 'float' }, | ||
211 | 'u_wave2': { 'type' : 'float' } | ||
118 | }, | 212 | }, |
119 | 213 | ||
120 | // render states | 214 | // render states |
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index c2969501..56c10f21 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js | |||
@@ -13,28 +13,30 @@ var Texture = require("js/lib/rdge/texture").Texture; | |||
13 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
14 | var PulseMaterial = function PulseMaterial() | 14 | var PulseMaterial = function PulseMaterial() |
15 | { | 15 | { |
16 | var MaterialLibrary = require("js/models/materials-model").MaterialsModel; | 16 | var MaterialLibrary = require("js/models/materials-model").MaterialsModel; |
17 | 17 | ||
18 | // initialize the inherited members | 18 | // initialize the inherited members |
19 | this.inheritedFrom = Material; | 19 | this.inheritedFrom = Material; |
20 | this.inheritedFrom(); | 20 | this.inheritedFrom(); |
21 | 21 | ||
22 | /////////////////////////////////////////////////////////////////////// | 22 | /////////////////////////////////////////////////////////////////////// |
23 | // Instance variables | 23 | // Instance variables |
24 | /////////////////////////////////////////////////////////////////////// | 24 | /////////////////////////////////////////////////////////////////////// |
25 | this._name = "PulseMaterial"; | 25 | this._name = "PulseMaterial"; |
26 | this._shaderName = "pulse"; | 26 | this._shaderName = "pulse"; |
27 | 27 | ||
28 | this._texMap = 'assets/images/cubelight.png'; | 28 | this._texMap = 'assets/images/cubelight.png'; |
29 | //this._texMap = 'assets/images/cloud10.png'; | ||
30 | //this._texMap = 'texture'; | ||
31 | 29 | ||
32 | this._time = 0.0; | 30 | this._time = 0.0; |
33 | this._dTime = 0.01; | 31 | this._dTime = 0.01; |
34 | 32 | ||
35 | /////////////////////////////////////////////////////////////////////// | 33 | this._xScale = 0.5; |
36 | // Property Accessors | 34 | this._yScale = 0.4; |
37 | /////////////////////////////////////////////////////////////////////// | 35 | this._speed = 1.0; |
36 | |||
37 | /////////////////////////////////////////////////////////////////////// | ||
38 | // Property Accessors | ||
39 | /////////////////////////////////////////////////////////////////////// | ||
38 | this.getName = function() { return this._name; }; | 40 | this.getName = function() { return this._name; }; |
39 | this.getShaderName = function() { return this._shaderName; }; | 41 | this.getShaderName = function() { return this._shaderName; }; |
40 | 42 | ||
@@ -43,22 +45,25 @@ var Pu |