aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-material.js
diff options
context:
space:
mode:
authorEric Guzman2012-04-05 18:42:40 -0700
committerEric Guzman2012-04-05 18:42:40 -0700
commit8ff9dde2053e41d85bb27d9c91808a30e551a138 (patch)
tree8eec67d632d82d3052ed470096eda13fd50a55c8 /js/lib/rdge/materials/twist-material.js
parent4631d54ffb4942378835689e9f5d70ed95610822 (diff)
parent7656b6eac7aec59697c6cddbe2a507fe9e4aa187 (diff)
downloadninja-8ff9dde2053e41d85bb27d9c91808a30e551a138.tar.gz
Merge branch 'refs/heads/master' into CSSPanelUpdates
Diffstat (limited to 'js/lib/rdge/materials/twist-material.js')
-rw-r--r--js/lib/rdge/materials/twist-material.js161
1 files changed, 80 insertions, 81 deletions
diff --git a/js/lib/rdge/materials/twist-material.js b/js/lib/rdge/materials/twist-material.js
index 163c8a77..7fcca081 100644
--- a/js/lib/rdge/materials/twist-material.js
+++ b/js/lib/rdge/materials/twist-material.js
@@ -1,8 +1,8 @@
1/* <copyright> 1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2This 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/> 3No 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. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ 5</copyright> */
6 6
7 7
8var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; 8var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
@@ -12,116 +12,115 @@ var TwistMaterial = function TwistMaterial() {
12 /////////////////////////////////////////////////////////////////////// 12 ///////////////////////////////////////////////////////////////////////
13 // Instance variables 13 // Instance variables
14 /////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////
15 this._name = "TwistMaterial"; 15 this._name = "TwistMaterial";
16 this._shaderName = "twist"; 16 this._shaderName = "twist";
17 17
18 this._texMap = 'assets/images/rocky-normal.jpg'; 18 this._texMap = 'assets/images/rocky-normal.jpg';
19 19
20 this._time = 0.0; 20 this._time = 0.0;
21 this._dTime = 0.01; 21 this._dTime = 0.01;
22 22
23 /////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////
24 // Properties 24 // Properties
25 /////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////
26 // all defined in parent PulseMaterial.js 26 // all defined in parent PulseMaterial.js
27 // load the local default value 27 // load the local default value
28 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 28 this._propValues[this._propNames[0]] = this._texMap.slice(0);
29 29
30 /////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////
31 // Methods 31 // Methods
32 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
33 // duplcate method requirde 33 // duplcate method requirde
34 this.dup = function( world ) { 34 this.dup = function (world) {
35 // allocate a new uber material 35 // allocate a new uber material
36 var newMat = new TwistMaterial(); 36 var newMat = new TwistMaterial();
37 37
38 // copy over the current values; 38 // copy over the current values;
39 var propNames = [], propValues = [], propTypes = [], propLabels = []; 39 var propNames = [], propValues = [], propTypes = [], propLabels = [];
40 this.getAllProperties( propNames, propValues, propTypes, propLabels); 40 this.getAllProperties(propNames, propValues, propTypes, propLabels);
41 var n = propNames.length; 41 var n = propNames.length;
42 for (var i=0; i<n; i++) { 42 for (var i = 0; i < n; i++) {
43 newMat.setProperty( propNames[i], propValues[i] ); 43 newMat.setProperty(propNames[i], propValues[i]);
44 } 44 }
45 45
46 return newMat; 46 return newMat;
47 }; 47 };
48 48
49 this.init = function( world ) { 49 this.init = function (world) {
50 // save the world 50 // save the world
51 if (world) this.setWorld( world ); 51 if (world) this.setWorld(world);
52 52
53 // set up the shader 53 // set up the shader
54 this._shader = new jshader(); 54 this._shader = new RDGE.jshader();
55 this._shader.def = twistMaterialDef; 55 this._shader.def = twistMaterialDef;
56 this._shader.init(); 56 this._shader.init();
57 57
58 // set up the material node 58 // set up the material node
59 this._materialNode = createMaterialNode("twistMaterial" + "_" + world.generateUniqueNodeID()); 59 this._materialNode = RDGE.createMaterialNode("twistMaterial" + "_" + world.generateUniqueNodeID());
60 this._materialNode.setShader(this._shader); 60 this._materialNode.setShader(this._shader);
61 61
62 this._time = 0; 62 this._time = 0;
63 if (this._shader && this._shader['default']) { 63 if (this._shader && this._shader['default']) {
64 this._shader['default'].u_time.set( [this._time] ); 64 this._shader['default'].u_time.set([this._time]);
65 } 65 }
66 66
67 // set the shader values in the shader 67 // set the shader values in the shader
68 this.updateTexture(); 68 this.updateTexture();
69 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 69 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
70 this.update( 0 ); 70 this.update(0);
71 }; 71 };
72 72
73 this.update = function( time ) { 73 this.update = function (time) {
74 var material = this._materialNode; 74 var material = this._materialNode;
75 if (material) 75 if (material) {
76 { 76 var technique = material.shaderProgram['default'];
77 var technique = material.shaderProgram['default']; 77 var renderer = RDGE.globals.engine.getContext().renderer;
78 var renderer = g_Engine.getContext().renderer; 78 if (renderer && technique) {
79 if (renderer && technique) { 79 if (this._shader && this._shader['default'])
80 if (this._shader && this._shader['default']) 80 this._shader['default'].u_time.set([this._time]);
81 this._shader['default'].u_time.set( [this._time] ); 81 this._time = time;
82 this._time = time; 82 }
83 } 83 }
84 } 84 };
85 } 85};
86}
87 86
88/////////////////////////////////////////////////////////////////////////////////////// 87///////////////////////////////////////////////////////////////////////////////////////
89// RDGE shader 88// RDGE shader
90 89
91// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 90// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
92var twistMaterialDef = 91var twistMaterialDef =
93{'shaders': 92{ 'shaders':
94 { 93 {
95 'defaultVShader':"assets/shaders/Basic.vert.glsl", 94 'defaultVShader': "assets/shaders/Basic.vert.glsl",
96 'defaultFShader':"assets/shaders/Twist.frag.glsl" 95 'defaultFShader': "assets/shaders/Twist.frag.glsl"
97 }, 96 },
98 'techniques': 97 'techniques':
99 { 98 {
100 'default': 99 'default':
101 [ 100 [
102 { 101 {
103 'vshader' : 'defaultVShader', 102 'vshader': 'defaultVShader',
104 'fshader' : 'defaultFShader', 103 'fshader': 'defaultFShader',
105 // attributes 104 // attributes
106 'attributes' : 105 'attributes':
107 { 106 {
108 'vert' : { 'type' : 'vec3' }, 107 'vert': { 'type': 'vec3' },
109 'normal' : { 'type' : 'vec3' }, 108 'normal': { 'type': 'vec3' },
110 'texcoord' : { 'type' : 'vec2' } 109 'texcoord': { 'type': 'vec2' }
111 }, 110 },
112 // parameters 111 // parameters
113 'params' : 112 'params':
114 { 113 {
115 'u_tex0': { 'type' : 'tex2d' }, 114 'u_tex0': { 'type': 'tex2d' },
116 'u_time' : { 'type' : 'float' }, 115 'u_time': { 'type': 'float' },
117 'u_resolution' : { 'type' : 'vec2' } 116 'u_resolution': { 'type': 'vec2' }
118 }, 117 },
119 118
120 // render states 119 // render states
121 'states' : 120 'states':
122 { 121 {
123 'depthEnable' : true, 122 'depthEnable': true,
124 'offset':[1.0, 0.1] 123 'offset': [1.0, 0.1]
125 } 124 }
126 } 125 }
127 ] 126 ]