aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/shaders/Pulse.frag.glsl12
-rw-r--r--assets/shaders/plasma.frag.glsl16
-rw-r--r--js/lib/rdge/materials/plasma-material.js98
-rw-r--r--js/lib/rdge/materials/pulse-material.js208
4 files changed, 251 insertions, 83 deletions
diff --git a/assets/shaders/Pulse.frag.glsl b/assets/shaders/Pulse.frag.glsl
index b24c9bef..9aeb05c9 100644
--- a/assets/shaders/Pulse.frag.glsl
+++ b/assets/shaders/Pulse.frag.glsl
@@ -6,16 +6,22 @@ uniform float u_time;
6uniform vec2 u_resolution; 6uniform vec2 u_resolution;
7uniform sampler2D u_tex0; 7uniform sampler2D u_tex0;
8 8
9uniform float u_speed;
10uniform float u_xscale;
11uniform float u_yscale;
12
9void main(void) 13void main(void)
10{ 14{
11 vec2 halfres = u_resolution.xy/2.0; 15 vec2 halfres = u_resolution.xy/2.0;
12 vec2 cPos = gl_FragCoord.xy; 16 vec2 cPos = gl_FragCoord.xy;
13 17
14 cPos.x -= 0.5*halfres.x*sin(u_time/2.0)+0.3*halfres.x*cos(u_time)+halfres.x; 18 float time = u_time * u_speed;
15 cPos.y -= 0.4*halfres.y*sin(u_time/5.0)+0.3*halfres.y*cos(u_time)+halfres.y; 19
20 cPos.x -= u_xscale*halfres.x*sin(time/2.0)+0.3*halfres.x*cos(time)+halfres.x;
21 cPos.y -= u_yscale*halfres.y*sin(time/5.0)+0.3*halfres.y*cos(time)+halfres.y;
16 float cLength = length(cPos); 22 float cLength = length(cPos);
17 23
18 vec2 uv = gl_FragCoord.xy/u_resolution.xy+(cPos/cLength)*sin(cLength/30.0-u_time*10.0)/25.0; 24 vec2 uv = gl_FragCoord.xy/u_resolution.xy+(cPos/cLength)*sin(cLength/30.0-time*10.0)/25.0;
19 vec3 col = texture2D(u_tex0,uv).xyz*50.0/cLength; 25 vec3 col = texture2D(u_tex0,uv).xyz*50.0/cLength;
20 26
21 gl_FragColor = vec4(col,1.0); 27 gl_FragColor = vec4(col,1.0);
diff --git a/assets/shaders/plasma.frag.glsl b/assets/shaders/plasma.frag.glsl
index 248288a6..4a5ac3da 100644
--- a/assets/shaders/plasma.frag.glsl
+++ b/assets/shaders/plasma.frag.glsl
@@ -16,15 +16,21 @@ precision highp float;
16 16
17varying vec2 v_uv; 17varying vec2 v_uv;
18uniform float u_time; 18uniform float u_time;
19uniform vec4 color; 19
20uniform float u_wave;
21uniform float u_wave1;
22uniform float u_wave2;
23uniform float u_speed;
20 24
21void main(void) 25void main(void)
22{ 26{
23 float x = v_uv.x ; 27 float x = v_uv.x ;
24 float y = v_uv.y ; 28 float y = v_uv.y ;
25 float time = u_time; 29 float time = u_time*u_speed;
26 float wave = (cos(time + y / 0.2 + cos(x / 0.3 + cos((y / 0.1))))); 30
27 float wave1 = (sin(abs(wave + y/0.6))); 31 float wave = (cos(time + y / (u_wave+0.2) + cos(x / (u_wave+0.3) + cos((y / (u_wave+0.1))))));
28 float wave2 = (sin(abs(wave1 + y/0.8))); 32 float wave1 = (sin(abs(wave + y/u_wave1)));
33 float wave2 = (sin(abs(wave1 + y/u_wave2)));
34
29 gl_FragColor = vec4( abs(vec3(wave2,wave1,wave)),1.0); 35 gl_FragColor = vec4( abs(vec3(wave2,wave1,wave)),1.0);
30} 36}
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