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.js132
1 files changed, 132 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js
new file mode 100644
index 00000000..9ecc2b48
--- /dev/null
+++ b/js/lib/rdge/materials/plasma-material.js
@@ -0,0 +1,132 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
7var Material = require("js/lib/rdge/materials/material").Material;
8
9var PlasmaMaterial = function PlasmaMaterial() {
10 ///////////////////////////////////////////////////////////////////////
11 // Instance variables
12 ///////////////////////////////////////////////////////////////////////
13 this._name = "PlasmaMaterial";
14 this._shaderName = "plasma";
15
16 this._time = 0.0;
17 this._dTime = 0.01;
18 this._speed = 1.0;
19
20 this._color = [1,0,0,1];
21
22
23 ///////////////////////////////////////////////////////////////////////
24 // Property Accessors
25 ///////////////////////////////////////////////////////////////////////
26 this.getShaderName = function() { return this._shaderName; };
27
28 this.isAnimated = function() { return true; };
29
30 ///////////////////////////////////////////////////////////////////////
31 // Material Property Accessors
32 ///////////////////////////////////////////////////////////////////////
33 this._propNames = ["color"];
34 this._propLabels = ["Color"];
35 this._propTypes = ["color"];
36 this._propValues = [];
37
38 this._propValues[ this._propNames[0] ] = this._color;
39
40 this.setProperty = function( prop, value ) {
41 // make sure we have legitimate imput
42 if (this.validateProperty( prop, value )) {
43 this._color = value.slice(0);
44 this._shader['default'][prop].set(value);
45 }
46 };
47 ///////////////////////////////////////////////////////////////////////
48
49 ///////////////////////////////////////////////////////////////////////
50 // Methods
51 ///////////////////////////////////////////////////////////////////////
52 // duplcate method requirde
53 this.dup = function() {
54 return new PlasmaMaterial();
55 };
56
57 this.init = function() {
58 // set up the shader
59 this._shader = new jshader();
60 this._shader.def = plasmaShaderDef;
61 this._shader.init();
62
63 // set the default value
64 this._time = 0;
65 this._shader['default'].u_time = this._time;
66 this.setProperty( "color", [this._time, 0, 0, 1] );
67
68 // set up the material node
69 this._materialNode = createMaterialNode("plasmaMaterial");
70 this._materialNode.setShader(this._shader);
71 };
72
73 this.update = function( time ) {
74 this._shader['default'].u_time = this._time;
75 var color = this.getProperty( "color" );
76 color[0] = this._time;
77 this.setProperty( "color", color );
78 //console.log( "update color to: " + color );
79 this._time += this._dTime;
80 }
81
82};
83
84///////////////////////////////////////////////////////////////////////////////////////
85// RDGE shader
86
87// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
88var plasmaShaderDef =
89{'shaders':
90 {
91 'defaultVShader':"assets/shaders/plasma.vert.glsl",
92 'defaultFShader':"assets/shaders/plasma.frag.glsl"
93 },
94 'techniques':
95 {
96 'default':
97 [
98 {
99 'vshader' : 'defaultVShader',
100 'fshader' : 'defaultFShader',
101 // attributes
102 'attributes' :
103 {
104 'vert' : { 'type' : 'vec3' },
105 'normal' : { 'type' : 'vec3' },
106 'texcoord' : { 'type' : 'vec2' }
107 },
108 // parameters
109 'params' :
110 {
111 'u_time' : { 'type' : 'float' },
112 'color' : { 'type' : 'vec4' }
113 },
114
115 // render states
116 'states' :
117 {
118 'depthEnable' : true,
119 'offset':[1.0, 0.1]
120 }
121 }
122 ]
123 }
124};
125
126PlasmaMaterial.prototype = new Material();
127
128if (typeof exports === "object") {
129 exports.PlasmaMaterial = PlasmaMaterial;
130}
131
132