aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/z-invert-material.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-06 10:58:25 -0800
committerValerio Virgillito2012-03-06 10:58:25 -0800
commit84332ab81c1b445195f1d9be8bbeae0725c8e758 (patch)
treee322baa1f98d4507ec255279198fa2284b2dff3c /js/lib/rdge/materials/z-invert-material.js
parent13f52cf0c74f53a919fa864f86669e8155f82961 (diff)
downloadninja-84332ab81c1b445195f1d9be8bbeae0725c8e758.tar.gz
Squashed commit of preload-fix into Master
- Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/z-invert-material.js')
-rw-r--r--js/lib/rdge/materials/z-invert-material.js125
1 files changed, 125 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/z-invert-material.js b/js/lib/rdge/materials/z-invert-material.js
new file mode 100644
index 00000000..051b724f
--- /dev/null
+++ b/js/lib/rdge/materials/z-invert-material.js
@@ -0,0 +1,125 @@
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
8var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
9
10var ZInvertMaterial = function ZInvertMaterial() {
11 ///////////////////////////////////////////////////////////////////////
12 // Instance variables
13 ///////////////////////////////////////////////////////////////////////
14 this._name = "ZInvertMaterial";
15 this._shaderName = "zinvert";
16
17 this._texMap = 'assets/images/rocky-normal.jpg';
18
19 this._time = 0.0;
20 this._dTime = 0.01;
21
22 ///////////////////////////////////////////////////////////////////////
23 // Properties
24 ///////////////////////////////////////////////////////////////////////
25 // all defined in parent PulseMaterial.js
26 // load the local default value
27 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
28
29 ///////////////////////////////////////////////////////////////////////
30 // Methods
31 ///////////////////////////////////////////////////////////////////////
32 // duplcate method requirde
33 this.dup = function( world ) {
34 // allocate a new uber material
35 var newMat = new ZInvertMaterial();
36
37 // copy over the current values;
38 var propNames = [], propValues = [], propTypes = [], propLabels = [];
39 this.getAllProperties( propNames, propValues, propTypes, propLabels);
40 var n = propNames.length;
41 for (var i=0; i<n; i++) {
42 newMat.setProperty( propNames[i], propValues[i] );
43 }
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 = zInvertMaterialDef;
55 this._shader.init();
56
57 // set up the material node
58 this._materialNode = createMaterialNode("zInvertMaterial");
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.updateTexture();
68 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
69 this.update( 0 );
70 }
71};
72
73///////////////////////////////////////////////////////////////////////////////////////
74// RDGE shader
75
76// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
77var zInvertMaterialDef =
78{'shaders':
79 {
80 'defaultVShader':"assets/shaders/Basic.vert.glsl",
81 'defaultFShader':"assets/shaders/ZInvert.frag.glsl"
82 },
83 'techniques':
84 {
85 'default':
86 [
87 {
88 'vshader' : 'defaultVShader',
89 'fshader' : 'defaultFShader',
90 // attributes
91 'attributes' :
92 {
93 'vert' : { 'type' : 'vec3' },
94 'normal' : { 'type' : 'vec3' },
95 'texcoord' : { 'type' : 'vec2' }
96 },
97 // parameters
98 'params' :
99 {
100 'u_tex0': { 'type' : 'tex2d' },
101 'u_time' : { 'type' : 'float' },
102 'u_resolution' : { 'type' : 'vec2' }
103 },
104
105 // render states
106 'states' :
107 {
108 'depthEnable' : true,
109 'offset':[1.0, 0.1]
110 }
111 }
112 ]
113 }
114};
115
116ZInvertMaterial.prototype = new PulseMaterial();
117
118if (typeof exports === "object") {
119 exports.ZInvertMaterial = ZInvertMaterial;
120}
121
122
123
124
125