aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/mandel-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/mandel-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/mandel-material.js')
-rw-r--r--js/lib/rdge/materials/mandel-material.js147
1 files changed, 147 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js
new file mode 100644
index 00000000..07e009a2
--- /dev/null
+++ b/js/lib/rdge/materials/mandel-material.js
@@ -0,0 +1,147 @@
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 MandelMaterial = function MandelMaterial() {
10 ///////////////////////////////////////////////////////////////////////
11 // Instance variables
12 ///////////////////////////////////////////////////////////////////////
13 this._name = "MandelMaterial";
14 this._shaderName = "mandel";
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 // Material Property Accessors
32 ///////////////////////////////////////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////
35
36 this.isAnimated = function() {
37 return true;
38 };
39
40 ///////////////////////////////////////////////////////////////////////
41 // Methods
42 ///////////////////////////////////////////////////////////////////////
43 // duplcate method requirde
44 this.dup = function( world ) {
45 // allocate a new uber material
46 var newMat = new MandelMaterial();
47
48 // copy over the current values;
49 var propNames = [], propValues = [], propTypes = [], propLabels = [];
50 this.getAllProperties( propNames, propValues, propTypes, propLabels);
51 var n = propNames.length;
52 for (var i=0; i<n; i++) {
53 newMat.setProperty( propNames[i], propValues[i] );
54 }
55
56 return newMat;
57 };
58
59 this.init = function( world ) {
60 // save the world
61 if (world) this.setWorld( world );
62
63 // set up the shader
64 this._shader = new jshader();
65 this._shader.def = MandelMaterialDef;
66 this._shader.init();
67
68 // set up the material node
69 this._materialNode = createMaterialNode("mandelMaterial");
70 this._materialNode.setShader(this._shader);
71
72 this._time = 0;
73 if (this._shader && this._shader['default']) {
74 this._shader['default'].u_time.set( [this._time] );
75 }
76
77 // set the shader values in the shader
78 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
79 this.update( 0 );
80 };
81
82 this.update = function( time ) {
83 var material = this._materialNode;
84 if (material) {
85 var technique = material.shaderProgram['default'];
86 var renderer = g_Engine.getContext().renderer;
87 if (renderer && technique) {
88 if (this._shader && this._shader['default'])
89 this._shader['default'].u_time.set( [this._time] );
90 this._time = time;
91 }
92 }
93 }
94};
95
96///////////////////////////////////////////////////////////////////////////////////////
97// RDGE shader
98
99// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
100var MandelMaterialDef =
101{'shaders':
102 {
103 'defaultVShader':"assets/shaders/Basic.vert.glsl",
104 'defaultFShader':"assets/shaders/Mandel.frag.glsl"
105 },
106 'techniques':
107 {
108 'default':
109 [
110 {
111 'vshader' : 'defaultVShader',
112 'fshader' : 'defaultFShader',
113 // attributes
114 'attributes' :
115 {
116 'vert' : { 'type' : 'vec3' },
117 'normal' : { 'type' : 'vec3' },
118 'texcoord' : { 'type' : 'vec2' }
119 },
120 // parameters
121 'params' :
122 {
123 'u_tex0': { 'type' : 'tex2d' },
124 'u_time' : { 'type' : 'float' },
125 'u_resolution' : { 'type' : 'vec2' },
126 },
127
128 // render states
129 'states' :
130 {
131 'depthEnable' : true,
132 'offset':[1.0, 0.1]
133 }
134 }
135 ]
136 }
137};
138
139MandelMaterial.prototype = new PulseMaterial();
140
141if (typeof exports === "object") {
142 exports.MandelMaterial = MandelMaterial;
143}
144
145
146
147