diff options
author | Jon Reid | 2012-03-06 14:15:18 -0800 |
---|---|---|
committer | Jon Reid | 2012-03-06 14:15:18 -0800 |
commit | 78d42c7cbf9205ed2e4faee1d8ddf02a4725edd3 (patch) | |
tree | c395b703f21431dcb4432c725f4c860431add61b /js/lib/rdge/materials/julia-material.js | |
parent | fa8b81d4f436c0b8564c8dcdd22d8dd6d5bccfaa (diff) | |
parent | 60bba95eaffa8b5c741c6c85fb84b327cd75d6c3 (diff) | |
download | ninja-78d42c7cbf9205ed2e4faee1d8ddf02a4725edd3.tar.gz |
Merge branch 'Timeline-uber' into timeline-serialized
Diffstat (limited to 'js/lib/rdge/materials/julia-material.js')
-rw-r--r-- | js/lib/rdge/materials/julia-material.js | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js new file mode 100644 index 00000000..07536f33 --- /dev/null +++ b/js/lib/rdge/materials/julia-material.js | |||
@@ -0,0 +1,136 @@ | |||
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 | |||
7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | ||
8 | |||
9 | var JuliaMaterial = function JuliaMaterial() { | ||
10 | /////////////////////////////////////////////////////////////////////// | ||
11 | // Instance variables | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | this._name = "JuliaMaterial"; | ||
14 | this._shaderName = "julia"; | ||
15 | |||
16 | this._texMap = 'assets/images/rocky-normal.jpg'; | ||
17 | |||
18 | this._time = 0.0; | ||
19 | this._dTime = 0.01; | ||
20 | |||
21 | /////////////////////////////////////////////////////////////////////// | ||
22 | // Properties | ||
23 | /////////////////////////////////////////////////////////////////////// | ||
24 | // no properties | ||
25 | this._propNames = []; | ||
26 | this._propLabels = []; | ||
27 | this._propTypes = []; | ||
28 | this._propValues = []; | ||
29 | |||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | // Methods | ||
32 | /////////////////////////////////////////////////////////////////////// | ||
33 | // duplcate method requirde | ||
34 | this.dup = function( world ) { | ||
35 | // allocate a new uber material | ||
36 | var newMat = new JuliaMaterial(); | ||
37 | |||
38 | // copy over the current values; | ||
39 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
40 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
41 | var n = propNames.length; | ||
42 | for (var i=0; i<n; i++) | ||
43 | newMat.setProperty( propNames[i], propValues[i] ); | ||
44 | |||
45 | return newMat; | ||
46 | }; | ||
47 | |||
48 | this.init = function( world ) { | ||
49 | // save the world | ||
50 | if (world) this.setWorld( world ); | ||
51 | |||
52 | // set up the shader | ||
53 | this._shader = new jshader(); | ||
54 | this._shader.def = JuliaMaterialDef; | ||
55 | this._shader.init(); | ||
56 | |||
57 | // set up the material node | ||
58 | this._materialNode = createMaterialNode("juliaMaterial"); | ||
59 | this._materialNode.setShader(this._shader); | ||
60 | |||
61 | this._time = 0; | ||
62 | if (this._shader && this._shader['default']) { | ||
63 | this._shader['default'].u_time.set( [this._time] ); | ||
64 | } | ||
65 | |||
66 | // set the shader values in the shader | ||
67 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | ||
68 | this.update( 0 ); | ||
69 | }; | ||
70 | |||
71 | this.update = function( time ) { | ||
72 | var material = this._materialNode; | ||
73 | if (material) { | ||
74 | var technique = material.shaderProgram['default']; | ||
75 | var renderer = g_Engine.getContext().renderer; | ||
76 | if (renderer && technique) { | ||
77 | if (this._shader && this._shader['default']) { | ||
78 | this._shader['default'].u_time.set( [this._time] ); | ||
79 | } | ||
80 | this._time = time; | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | /////////////////////////////////////////////////////////////////////////////////////// | ||
87 | // RDGE shader | ||
88 | |||
89 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
90 | var JuliaMaterialDef = | ||
91 | {'shaders': | ||
92 | { | ||
93 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
94 | 'defaultFShader':"assets/shaders/Julia.frag.glsl" | ||
95 | }, | ||
96 | 'techniques': | ||
97 | { | ||
98 | 'default': | ||
99 | [ | ||
100 | { | ||
101 | 'vshader' : 'defaultVShader', | ||
102 | 'fshader' : 'defaultFShader', | ||
103 | // attributes | ||
104 | 'attributes' : | ||
105 | { | ||
106 | 'vert' : { 'type' : 'vec3' }, | ||
107 | 'normal' : { 'type' : 'vec3' }, | ||
108 | 'texcoord' : { 'type' : 'vec2' } | ||
109 | }, | ||
110 | // parameters | ||
111 | 'params' : | ||
112 | { | ||
113 | 'u_tex0': { 'type' : 'tex2d' }, | ||
114 | 'u_time' : { 'type' : 'float' }, | ||
115 | 'u_resolution' : { 'type' : 'vec2' }, | ||
116 | }, | ||
117 | |||
118 | // render states | ||
119 | 'states' : | ||
120 | { | ||
121 | 'depthEnable' : true, | ||
122 | 'offset':[1.0, 0.1] | ||
123 | } | ||
124 | } | ||
125 | ] | ||
126 | } | ||
127 | }; | ||
128 | |||
129 | JuliaMaterial.prototype = new PulseMaterial(); | ||
130 | |||
131 | if (typeof exports === "object") { | ||
132 | exports.JuliaMaterial = JuliaMaterial; | ||
133 | } | ||
134 | |||
135 | |||
136 | |||