aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/MandelMaterial.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/helper-classes/RDGE/Materials/MandelMaterial.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/Materials/MandelMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/MandelMaterial.js147
1 files changed, 147 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/Materials/MandelMaterial.js b/js/helper-classes/RDGE/Materials/MandelMaterial.js
new file mode 100644
index 00000000..76083b76
--- /dev/null
+++ b/js/helper-classes/RDGE/Materials/MandelMaterial.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
7
8
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13function MandelMaterial()
14{
15 // initialize the inherited members
16 this.inheritedFrom = PulseMaterial;
17 this.inheritedFrom();
18
19 ///////////////////////////////////////////////////////////////////////
20 // Instance variables
21 ///////////////////////////////////////////////////////////////////////
22 this._name = "MandelMaterial";
23 this._shaderName = "mandel";
24
25 this._texMap = 'assets/images/rocky-normal.jpg';
26
27 this._time = 0.0;
28 this._dTime = 0.01;
29
30 ///////////////////////////////////////////////////////////////////////
31 // Properties
32 ///////////////////////////////////////////////////////////////////////
33 // no properties
34 this._propNames = [];
35 this._propLabels = [];
36 this._propTypes = [];
37 this._propValues = [];
38
39 ///////////////////////////////////////////////////////////////////////
40 // Material Property Accessors
41 ///////////////////////////////////////////////////////////////////////
42
43 ///////////////////////////////////////////////////////////////////////
44
45
46 ///////////////////////////////////////////////////////////////////////
47 // Methods
48 ///////////////////////////////////////////////////////////////////////
49 // duplcate method requirde
50 this.dup = function( world )
51 {
52 // allocate a new uber material
53 var newMat = new MandelMaterial();
54
55 // copy over the current values;
56 var propNames = [], propValues = [], propTypes = [], propLabels = [];
57 this.getAllProperties( propNames, propValues, propTypes, propLabels);
58 var n = propNames.length;
59 for (var i=0; i<n; i++)
60 newMat.setProperty( propNames[i], propValues[i] );
61
62 return newMat;
63 }
64
65 this.init = function( world )
66 {
67 // set up the shader
68 this._shader = new jshader();
69 this._shader.def = MandelMaterialDef;
70 this._shader.init();
71
72 // set up the material node
73 this._materialNode = createMaterialNode("mandelMaterial");
74 this._materialNode.setShader(this._shader);
75
76 this._time = 0;
77 if (this._shader && this._shader.default)
78 this._shader.default.u_time.set( [this._time] );
79
80 // set the shader values in the shader
81 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
82 this.update( 0 );
83 }
84
85 this.update = function( time )
86 {
87 var material = this._materialNode;
88 if (material)
89 {
90 var technique = material.shaderProgram.default;
91 var renderer = g_Engine.getContext().renderer;
92 if (renderer && technique)
93 {
94 if (this._shader && this._shader.default)
95 this._shader.default.u_time.set( [this._time] );
96 this._time = time;
97 }
98 }
99 }
100}
101
102///////////////////////////////////////////////////////////////////////////////////////
103// RDGE shader
104
105// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
106var MandelMaterialDef =
107{'shaders':
108 {
109 'defaultVShader':"assets/shaders/Basic.vert.glsl",
110 'defaultFShader':"assets/shaders/Mandel.frag.glsl"
111 },
112 'techniques':
113 {
114 'default':
115 [
116 {
117 'vshader' : 'defaultVShader',
118 'fshader' : 'defaultFShader',
119 // attributes
120 'attributes' :
121 {
122 'vert' : { 'type' : 'vec3' },
123 'normal' : { 'type' : 'vec3' },
124 'texcoord' : { 'type' : 'vec2' }
125 },
126 // parameters
127 'params' :
128 {
129 'u_tex0': { 'type' : 'tex2d' },
130 'u_time' : { 'type' : 'float' },
131 'u_resolution' : { 'type' : 'vec2' },
132 },
133
134 // render states
135 'states' :
136 {
137 'depthEnable' : true,
138 'offset':[1.0, 0.1]
139 },
140 },
141 ]
142 }
143};
144
145
146
147