aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/plasma-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/plasma-material.js')
-rw-r--r--js/lib/rdge/materials/plasma-material.js176
1 files changed, 94 insertions, 82 deletions
diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js
index 0b4923aa..14b6137a 100644
--- a/js/lib/rdge/materials/plasma-material.js
+++ b/js/lib/rdge/materials/plasma-material.js
@@ -34,37 +34,37 @@ var PlasmaMaterial = function PlasmaMaterial() {
34 /////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////
35 // Instance variables 35 // Instance variables
36 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
37 this._name = "Plasma"; 37 this._name = "Plasma";
38 this._shaderName = "plasma"; 38 this._shaderName = "plasma";
39 39
40 this._time = 0.0; 40 this._time = 0.0;
41 this._dTime = 0.01; 41 this._dTime = 0.01;
42 this._speed = 1.0; 42 this._speed = 1.0;
43 43
44 this._wave = 0.0; 44 this._wave = 0.0;
45 this._wave1 = 0.6; 45 this._wave1 = 0.6;
46 this._wave2 = 0.8; 46 this._wave2 = 0.8;
47 47
48 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
49 // Properties 49 // Properties
50 /////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////
51 this._propNames = ["u_wave", "u_wave1", "u_wave2", "u_speed"]; 51 this._propNames = ["u_wave", "u_wave1", "u_wave2", "u_speed"];
52 this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"]; 52 this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"];
53 this._propTypes = ["float", "float", "float", "float"]; 53 this._propTypes = ["float", "float", "float", "float"];
54 54
55 this._propValues = []; 55 this._propValues = [];
56 this._propValues[ this._propNames[0] ] = this._wave; 56 this._propValues[ this._propNames[0] ] = this._wave;
57 this._propValues[ this._propNames[1] ] = this._wave1; 57 this._propValues[ this._propNames[1] ] = this._wave1;
58 this._propValues[ this._propNames[2] ] = this._wave2; 58 this._propValues[ this._propNames[2] ] = this._wave2;
59 this._propValues[ this._propNames[3] ] = this._speed; 59 this._propValues[ this._propNames[3] ] = this._speed;
60 60
61 61
62 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
63 // Property Accessors 63 // Property Accessors
64 /////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////
65 this.getShaderName = function() { return this._shaderName; }; 65 this.getShaderName = function() { return this._shaderName; };
66 this.isAnimated = function() { return true; }; 66 this.isAnimated = function() { return true; };
67 this.getShaderDef = function() { return plasmaShaderDef; }; 67 this.getShaderDef = function() { return plasmaShaderDef; };
68 68
69 /////////////////////////////////////////////////////////////////////// 69 ///////////////////////////////////////////////////////////////////////
70 // Material Property Accessors 70 // Material Property Accessors
@@ -73,82 +73,94 @@ var PlasmaMaterial = function PlasmaMaterial() {
73 /////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////
74 // Methods 74 // Methods
75 /////////////////////////////////////////////////////////////////////// 75 ///////////////////////////////////////////////////////////////////////
76 // duplcate method requirde 76 // duplcate method requirde
77 77
78 this.init = function( world) 78 this.init = function( world)
79 { 79 {
80 this.setWorld( world ); 80 this.setWorld( world );
81
82 // set up the shader
83 this._shader = new RDGE.jshader();
84 this._shader.def = plasmaShaderDef;
85 this._shader.init();
81 86
82 // set up the shader 87 // set the default value
83 this._shader = new RDGE.jshader(); 88 this._time = 0;
84 this._shader.def = plasmaShaderDef; 89 this._shader['default'].u_time.set( [this._time] );
85 this._shader.init();
86 90
87 // set the default value 91 // set up the material node
88 this._time = 0; 92 this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID());
89 this._shader['default'].u_time.set( [this._time] ); 93 this._materialNode.setShader(this._shader);
90 94
91 // set up the material node 95 this._time = 0;
92 this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); 96 if (this._shader && this._shader['default']) {
93 this._materialNode.setShader(this._shader); 97 this._shader['default'].u_time.set( [this._time] );
98 }
94 99
95 this._time = 0; 100 this.setShaderValues();
96 if (this._shader && this._shader['default']) { 101 };
97 this._shader['default'].u_time.set( [this._time] );
98 }
99 102
100 this.setShaderValues(); 103 this.update = function( time ) {
101 }; 104 this._shader['default'].u_time.set( [this._time] );
105 this._time += this._dTime;
106 };
102 107
103 this.update = function( time ) { 108 this.resetToDefault = function()
104 this._shader['default'].u_time.set( [this._time] ); 109 {
105 this._time += this._dTime; 110 this._propValues[ this._propNames[0] ] = this._wave;
106 }; 111 this._propValues[ this._propNames[1] ] = this._wave1;
112 this._propValues[ this._propNames[2] ] = this._wave2;
113 this._propValues[ this._propNames[3] ] = this._speed;
114
115 var nProps = this._propNames.length;
116 for (var i=0; i<nProps; i++)
117 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
118};
107}; 119};
108 120
109/////////////////////////////////////////////////////////////////////////////////////// 121///////////////////////////////////////////////////////////////////////////////////////
110// RDGE shader 122// RDGE shader
111 123
112// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 124// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
113var plasmaShaderDef = 125var plasmaShaderDef =
114{'shaders': 126{'shaders':
115 { 127 {
116 'defaultVShader':"assets/shaders/plasma.vert.glsl", 128 'defaultVShader':"assets/shaders/plasma.vert.glsl",
117 'defaultFShader':"assets/shaders/plasma.frag.glsl" 129 'defaultFShader':"assets/shaders/plasma.frag.glsl"
118 }, 130 },
119 'techniques': 131 'techniques':
120 { 132 {
121 'default': 133 'default':
122 [ 134 [
123 { 135 {
124 'vshader' : 'defaultVShader', 136 'vshader' : 'defaultVShader',
125 'fshader' : 'defaultFShader', 137 'fshader' : 'defaultFShader',
126 // attributes 138 // attributes
127 'attributes' : 139 'attributes' :
128 { 140 {
129 'vert' : { 'type' : 'vec3' }, 141 'vert' : { 'type' : 'vec3' },
130 'normal' : { 'type' : 'vec3' }, 142 'normal' : { 'type' : 'vec3' },
131 'texcoord' : { 'type' : 'vec2' } 143 'texcoord' : { 'type' : 'vec2' }
132 }, 144 },
133 // parameters 145 // parameters
134 'params' : 146 'params' :
135 { 147 {
136 'u_time' : { 'type' : 'float' }, 148 'u_time' : { 'type' : 'float' },
137 'u_speed': { 'type' : 'float' }, 149 'u_speed': { 'type' : 'float' },
138 'u_wave' : { 'type' : 'float' }, 150 'u_wave' : { 'type' : 'float' },
139 'u_wave1': { 'type' : 'float' }, 151 'u_wave1': { 'type' : 'float' },
140 'u_wave2': { 'type' : 'float' } 152 'u_wave2': { 'type' : 'float' }
141 }, 153 },
142 154
143 // render states 155 // render states
144 'states' : 156 'states' :
145 { 157 {
146 'depthEnable' : true, 158 'depthEnable' : true,
147 'offset':[1.0, 0.1] 159 'offset':[1.0, 0.1]
148 } 160 }
149 } 161 }
150 ] 162 ]
151 } 163 }
152}; 164};
153 165
154PlasmaMaterial.prototype = new Material(); 166PlasmaMaterial.prototype = new Material();