diff options
Diffstat (limited to 'js/lib/rdge/materials/julia-material.js')
-rw-r--r-- | js/lib/rdge/materials/julia-material.js | 49 |
1 files changed, 17 insertions, 32 deletions
diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js index 7aeec3dc..d89fa594 100644 --- a/js/lib/rdge/materials/julia-material.js +++ b/js/lib/rdge/materials/julia-material.js | |||
@@ -5,15 +5,16 @@ | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | 7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; |
8 | var Texture = require("js/lib/rdge/texture").Texture; | ||
8 | 9 | ||
9 | var JuliaMaterial = function JuliaMaterial() { | 10 | var JuliaMaterial = function JuliaMaterial() { |
10 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
11 | // Instance variables | 12 | // Instance variables |
12 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
13 | this._name = "JuliaMaterial"; | 14 | this._name = "Julia"; |
14 | this._shaderName = "julia"; | 15 | this._shaderName = "julia"; |
15 | 16 | ||
16 | this._texMap = 'assets/images/rocky-normal.jpg'; | 17 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; |
17 | 18 | ||
18 | this._time = 0.0; | 19 | this._time = 0.0; |
19 | this._dTime = 0.01; | 20 | this._dTime = 0.01; |
@@ -21,25 +22,22 @@ var JuliaMaterial = function JuliaMaterial() { | |||
21 | /////////////////////////////////////////////////////////////////////// | 22 | /////////////////////////////////////////////////////////////////////// |
22 | // Properties | 23 | // Properties |
23 | /////////////////////////////////////////////////////////////////////// | 24 | /////////////////////////////////////////////////////////////////////// |
24 | // properties inherited from PulseMaterial | 25 | var u_speed_index = 0; |
26 | this._propNames = [ "u_speed" ]; | ||
27 | this._propLabels = [ "Speed" ]; | ||
28 | this._propTypes = [ "float" ]; | ||
29 | this._propValues = []; | ||
30 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
31 | |||
32 | /////////////////////////////////////////////////////////////////////// | ||
33 | // Material Property Accessors | ||
34 | /////////////////////////////////////////////////////////////////////// | ||
35 | this.isAnimated = function() { return true; }; | ||
36 | this.getShaderDef = function() { return JuliaMaterialDef; } | ||
25 | 37 | ||
26 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
27 | // Methods | 39 | // Methods |
28 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
29 | // duplcate method requirde | ||
30 | this.dup = function( world ) { | ||
31 | // allocate a new uber material | ||
32 | var newMat = new JuliaMaterial(); | ||
33 | |||
34 | // copy over the current values; | ||
35 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
36 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
37 | var n = propNames.length; | ||
38 | for (var i=0; i<n; i++) | ||
39 | newMat.setProperty( propNames[i], propValues[i] ); | ||
40 | |||
41 | return newMat; | ||
42 | }; | ||
43 | 41 | ||
44 | this.init = function( world ) { | 42 | this.init = function( world ) { |
45 | // save the world | 43 | // save the world |
@@ -60,23 +58,10 @@ var JuliaMaterial = function JuliaMaterial() { | |||
60 | } | 58 | } |
61 | 59 | ||
62 | // set the shader values in the shader | 60 | // set the shader values in the shader |
61 | this.setShaderValues(); | ||
63 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | 62 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); |
64 | this.update( 0 ); | 63 | this.update( 0 ); |
65 | }; | 64 | }; |
66 | |||
67 | this.update = function( time ) { | ||
68 | var material = this._materialNode; | ||
69 | if (material) { | ||
70 | var technique = material.shaderProgram['default']; | ||
71 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
72 | if (renderer && technique) { | ||
73 | if (this._shader && this._shader['default']) { | ||
74 | this._shader['default'].u_time.set( [this._time] ); | ||
75 | } | ||
76 | this._time = time; | ||
77 | } | ||
78 | } | ||
79 | }; | ||
80 | } | 65 | } |
81 | 66 | ||
82 | /////////////////////////////////////////////////////////////////////////////////////// | 67 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -106,8 +91,8 @@ var JuliaMaterialDef = | |||
106 | // parameters | 91 | // parameters |
107 | 'params' : | 92 | 'params' : |
108 | { | 93 | { |
109 | 'u_tex0': { 'type' : 'tex2d' }, | ||
110 | 'u_time' : { 'type' : 'float' }, | 94 | 'u_time' : { 'type' : 'float' }, |
95 | 'u_speed' : { 'type' : 'float' }, | ||
111 | 'u_resolution' : { 'type' : 'vec2' }, | 96 | 'u_resolution' : { 'type' : 'vec2' }, |
112 | }, | 97 | }, |
113 | 98 | ||