diff options
author | Nivesh Rajbhandari | 2012-03-12 16:25:28 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-12 16:25:28 -0700 |
commit | 5fb358d9e80a364d5f300d60b7a9fe0f773741e7 (patch) | |
tree | 2c4d5292b19c91697dffb542f369ec9dcb340f77 /js/lib/rdge/materials/deform-material.js | |
parent | 5f9b67be3b8bdb391d021103c6bcee6be2f6cdf4 (diff) | |
parent | 69d90467865a1384725b2301901be2180c5a841f (diff) | |
download | ninja-5fb358d9e80a364d5f300d60b7a9fe0f773741e7.tar.gz |
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'js/lib/rdge/materials/deform-material.js')
-rw-r--r-- | js/lib/rdge/materials/deform-material.js | 127 |
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 | |||
7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | ||
8 | |||
9 | var 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) | ||
82 | var 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 | |||
121 | DeformMaterial.prototype = new PulseMaterial(); | ||
122 | |||
123 | if (typeof exports === "object") { | ||
124 | exports.DeformMaterial = DeformMaterial; | ||
125 | } | ||
126 | |||
127 | |||