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