aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/deform-material.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-06 14:09:44 -0800
committerNivesh Rajbhandari2012-03-06 14:09:44 -0800
commit792793cd3991032b4840ade67f98ae8eae2d30a0 (patch)
tree69d3df003d2bb58fa1ab562fbd1058ff91851f01 /js/lib/rdge/materials/deform-material.js
parent2346d8ab9db06573d8672c64988c46b6c672e015 (diff)
parent1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f (diff)
downloadninja-792793cd3991032b4840ade67f98ae8eae2d30a0.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/lib/rdge/materials/deform-material.js')
-rw-r--r--js/lib/rdge/materials/deform-material.js127
1 files changed, 127 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js
new file mode 100644
index 00000000..1e6af6ac
--- /dev/null
+++ b/js/lib/rdge/materials/deform-material.js
@@ -0,0 +1,127 @@
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 DeformMaterial = function DeformMaterial() {
10 ///////////////////////////////////////////////////////////////////////
11 // Instance variables
12 ///////////////////////////////////////////////////////////////////////
13 this._name = "DeformMaterial";
14 this._shaderName = "deform";
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 // all defined in parent PulseMaterial.js
25 // load the local default value
26 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
27
28 ///////////////////////////////////////////////////////////////////////
29 // Material Property Accessors
30 ///////////////////////////////////////////////////////////////////////
31
32 ///////////////////////////////////////////////////////////////////////
33
34
35 ///////////////////////////////////////////////////////////////////////
36 // Methods
37 ///////////////////////////////////////////////////////////////////////
38 // duplcate method requirde
39 this.dup = function( world ) {
40 // allocate a new uber material
41 var newMat = new DeformMaterial();
42
43 // copy over the current values;
44 var propNames = [], propValues = [], propTypes = [], propLabels = [];
45 this.getAllProperties( propNames, propValues, propTypes, propLabels);
46 var n = propNames.length;
47 for (var i=0; i<n; i++)
48 newMat.setProperty( propNames[i], propValues[i] );
49
50 return newMat;
51 };
52
53 this.init = function( world ) {
54 // save the world
55 if (world) this.setWorld( world );
56
57 // set up the shader
58 this._shader = new jshader();
59 this._shader.def = deformMaterialDef;
60 this._shader.init();
61
62 // set up the material node
63 this._materialNode = createMaterialNode("deformMaterial");
64 this._materialNode.setShader(this._shader);
65
66 this._time = 0;
67 if (this._shader && this._shader['default']) {
68 this._shader['default'].u_time.set( [this._time] );
69 }
70
71 // set the shader values in the shader
72 this.updateTexture();
73 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
74 this.update( 0 );
75 }
76};
77
78///////////////////////////////////////////////////////////////////////////////////////
79// RDGE shader
80
81// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
82var deformMaterialDef =
83{'shaders':
84 {
85 'defaultVShader':"assets/shaders/Basic.vert.glsl",
86 'defaultFShader':"assets/shaders/Deform.frag.glsl"
87 },
88 'techniques':
89 {
90 'default':
91 [
92 {
93 'vshader' : 'defaultVShader',
94 'fshader' : 'defaultFShader',
95 // attributes
96 'attributes' :
97 {
98 'vert' : { 'type' : 'vec3' },
99 'normal' : { 'type' : 'vec3' },
100 'texcoord' : { 'type' : 'vec2' }
101 },
102 // parameters
103 'params' :
104 {
105 'u_tex0': { 'type' : 'tex2d' },
106 'u_time' : { 'type' : 'float' },
107 'u_resolution' : { 'type' : 'vec2' }
108 },
109
110 // render states
111 'states' :
112 {
113 'depthEnable' : true,
114 'offset':[1.0, 0.1]
115 }
116 }
117 ]
118 }
119};
120
121DeformMaterial.prototype = new PulseMaterial();
122
123if (typeof exports === "object") {
124 exports.DeformMaterial = DeformMaterial;
125}
126
127