diff options
Diffstat (limited to 'js/lib/rdge/materials/plasma-material.js')
-rw-r--r-- | js/lib/rdge/materials/plasma-material.js | 199 |
1 files changed, 106 insertions, 93 deletions
diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 0b4923aa..15a1eef1 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -34,37 +35,37 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
34 | /////////////////////////////////////////////////////////////////////// | 35 | /////////////////////////////////////////////////////////////////////// |
35 | // Instance variables | 36 | // Instance variables |
36 | /////////////////////////////////////////////////////////////////////// | 37 | /////////////////////////////////////////////////////////////////////// |
37 | this._name = "Plasma"; | 38 | this._name = "Plasma"; |
38 | this._shaderName = "plasma"; | 39 | this._shaderName = "plasma"; |
39 | 40 | ||
40 | this._time = 0.0; | 41 | this._time = 0.0; |
41 | this._dTime = 0.01; | 42 | this._dTime = 0.01; |
42 | this._speed = 1.0; | 43 | this._speed = 1.0; |
43 | 44 | ||
44 | this._wave = 0.0; | 45 | this._wave = 0.0; |
45 | this._wave1 = 0.6; | 46 | this._wave1 = 0.6; |
46 | this._wave2 = 0.8; | 47 | this._wave2 = 0.8; |
47 | 48 | ||
48 | /////////////////////////////////////////////////////////////////////// | 49 | /////////////////////////////////////////////////////////////////////// |
49 | // Properties | 50 | // Properties |
50 | /////////////////////////////////////////////////////////////////////// | 51 | /////////////////////////////////////////////////////////////////////// |
51 | this._propNames = ["u_wave", "u_wave1", "u_wave2", "u_speed"]; | 52 | this._propNames = ["u_wave", "u_wave1", "u_wave2", "u_speed"]; |
52 | this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"]; | 53 | this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"]; |
53 | this._propTypes = ["float", "float", "float", "float"]; | 54 | this._propTypes = ["float", "float", "float", "float"]; |
54 | 55 | ||
55 | this._propValues = []; | 56 | this._propValues = []; |
56 | this._propValues[ this._propNames[0] ] = this._wave; | 57 | this._propValues[ this._propNames[0] ] = this._wave; |
57 | this._propValues[ this._propNames[1] ] = this._wave1; | 58 | this._propValues[ this._propNames[1] ] = this._wave1; |
58 | this._propValues[ this._propNames[2] ] = this._wave2; | 59 | this._propValues[ this._propNames[2] ] = this._wave2; |
59 | this._propValues[ this._propNames[3] ] = this._speed; | 60 | this._propValues[ this._propNames[3] ] = this._speed; |
60 | 61 | ||
61 | 62 | ||
62 | /////////////////////////////////////////////////////////////////////// | 63 | /////////////////////////////////////////////////////////////////////// |
63 | // Property Accessors | 64 | // Property Accessors |
64 | /////////////////////////////////////////////////////////////////////// | 65 | /////////////////////////////////////////////////////////////////////// |
65 | this.getShaderName = function() { return this._shaderName; }; | 66 | this.getShaderName = function() { return this._shaderName; }; |
66 | this.isAnimated = function() { return true; }; | 67 | this.isAnimated = function() { return true; }; |
67 | this.getShaderDef = function() { return plasmaShaderDef; }; | 68 | this.getShaderDef = function() { return plasmaShaderDef; }; |
68 | 69 | ||
69 | /////////////////////////////////////////////////////////////////////// | 70 | /////////////////////////////////////////////////////////////////////// |
70 | // Material Property Accessors | 71 | // Material Property Accessors |
@@ -73,82 +74,94 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
73 | /////////////////////////////////////////////////////////////////////// | 74 | /////////////////////////////////////////////////////////////////////// |
74 | // Methods | 75 | // Methods |
75 | /////////////////////////////////////////////////////////////////////// | 76 | /////////////////////////////////////////////////////////////////////// |
76 | // duplcate method requirde | 77 | // duplcate method requirde |
77 | 78 | ||
78 | this.init = function( world) | 79 | this.init = function( world) |
79 | { | 80 | { |
80 | this.setWorld( world ); | 81 | this.setWorld( world ); |
82 | |||
83 | // set up the shader | ||
84 | this._shader = new RDGE.jshader(); | ||
85 | this._shader.def = plasmaShaderDef; | ||
86 | this._shader.init(); | ||
81 | 87 | ||
82 | // set up the shader | 88 | // set the default value |
83 | this._shader = new RDGE.jshader(); | 89 | this._time = 0; |
84 | this._shader.def = plasmaShaderDef; | 90 | this._shader['default'].u_time.set( [this._time] ); |
85 | this._shader.init(); | ||
86 | 91 | ||
87 | // set the default value | 92 | // set up the material node |
88 | this._time = 0; | 93 | this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); |
89 | this._shader['default'].u_time.set( [this._time] ); | 94 | this._materialNode.setShader(this._shader); |
90 | 95 | ||
91 | // set up the material node | 96 | this._time = 0; |
92 | this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); | 97 | if (this._shader && this._shader['default']) { |
93 | this._materialNode.setShader(this._shader); | 98 | this._shader['default'].u_time.set( [this._time] ); |
99 | } | ||
94 | 100 | ||
95 | this._time = 0; | 101 | this.setShaderValues(); |
96 | if (this._shader && this._shader['default']) { | 102 | }; |
97 | this._shader['default'].u_time.set( [this._time] ); | ||
98 | } | ||
99 | 103 | ||
100 | this.setShaderValues(); | 104 | this.update = function( time ) { |
101 | }; | 105 | this._shader['default'].u_time.set( [this._time] ); |
106 | this._time += this._dTime; | ||
107 | }; | ||
102 | 108 | ||
103 | this.update = function( time ) { | 109 | this.resetToDefault = function() |
104 | this._shader['default'].u_time.set( [this._time] ); | 110 | { |
105 | this._time += this._dTime; | 111 | this._propValues[ this._propNames[0] ] = this._wave; |
106 | }; | 112 | this._propValues[ this._propNames[1] ] = this._wave1; |
113 | this._propValues[ this._propNames[2] ] = this._wave2; | ||
114 | this._propValues[ this._propNames[3] ] = this._speed; | ||
115 | |||
116 | var nProps = this._propNames.length; | ||
117 | for (var i=0; i<nProps; i++) | ||
118 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
119 | }; | ||
107 | }; | 120 | }; |
108 | 121 | ||
109 | /////////////////////////////////////////////////////////////////////////////////////// | 122 | /////////////////////////////////////////////////////////////////////////////////////// |
110 | // RDGE shader | 123 | // RDGE shader |
111 | 124 | ||
112 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 125 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
113 | var plasmaShaderDef = | 126 | var plasmaShaderDef = |
114 | {'shaders': | 127 | {'shaders': |
115 | { | 128 | { |
116 | 'defaultVShader':"assets/shaders/plasma.vert.glsl", | 129 | 'defaultVShader':"assets/shaders/plasma.vert.glsl", |
117 | 'defaultFShader':"assets/shaders/plasma.frag.glsl" | 130 | 'defaultFShader':"assets/shaders/plasma.frag.glsl" |
118 | }, | 131 | }, |
119 | 'techniques': | 132 | 'techniques': |
120 | { | 133 | { |
121 | 'default': | 134 | 'default': |
122 | [ | 135 | [ |
123 | { | 136 | { |
124 | 'vshader' : 'defaultVShader', | 137 | 'vshader' : 'defaultVShader', |
125 | 'fshader' : 'defaultFShader', | 138 | 'fshader' : 'defaultFShader', |
126 | // attributes | 139 | // attributes |
127 | 'attributes' : | 140 | 'attributes' : |
128 | { | 141 | { |
129 | 'vert' : { 'type' : 'vec3' }, | 142 | 'vert' : { 'type' : 'vec3' }, |
130 | 'normal' : { 'type' : 'vec3' }, | 143 | 'normal' : { 'type' : 'vec3' }, |
131 | 'texcoord' : { 'type' : 'vec2' } | 144 | 'texcoord' : { 'type' : 'vec2' } |
132 | }, | 145 | }, |
133 | // parameters | 146 | // parameters |
134 | 'params' : | 147 | 'params' : |
135 | { | 148 | { |
136 |