diff options
author | Jose Antonio Marquez | 2012-03-06 11:18:30 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-03-06 11:18:30 -0800 |
commit | 3c4967fa93b3abc529fc404115707307ba72d5cd (patch) | |
tree | f3737db979727ee050f8b9c85ef994b0e6ddae27 /js/lib/rdge/materials/deform-material.js | |
parent | bee2df0d4da72677aaa2adae669ffdd4ac210dd6 (diff) | |
parent | 84332ab81c1b445195f1d9be8bbeae0725c8e758 (diff) | |
download | ninja-3c4967fa93b3abc529fc404115707307ba72d5cd.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into FileIO
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 | |||