aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/julia-material.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-12 16:25:28 -0700
committerNivesh Rajbhandari2012-03-12 16:25:28 -0700
commit5fb358d9e80a364d5f300d60b7a9fe0f773741e7 (patch)
tree2c4d5292b19c91697dffb542f369ec9dcb340f77 /js/lib/rdge/materials/julia-material.js
parent5f9b67be3b8bdb391d021103c6bcee6be2f6cdf4 (diff)
parent69d90467865a1384725b2301901be2180c5a841f (diff)
downloadninja-5fb358d9e80a364d5f300d60b7a9fe0f773741e7.tar.gz
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'js/lib/rdge/materials/julia-material.js')
-rw-r--r--js/lib/rdge/materials/julia-material.js136
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
7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
8
9var 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)
90var 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
129JuliaMaterial.prototype = new PulseMaterial();
130
131if (typeof exports === "object") {
132 exports.JuliaMaterial = JuliaMaterial;
133}
134
135
136