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/star-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/star-material.js')
-rw-r--r-- | js/lib/rdge/materials/star-material.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js new file mode 100644 index 00000000..9c0f3172 --- /dev/null +++ b/js/lib/rdge/materials/star-material.js | |||
@@ -0,0 +1,124 @@ | |||
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 StarMaterial = function StarMaterial() { | ||
10 | /////////////////////////////////////////////////////////////////////// | ||
11 | // Instance variables | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | this._name = "StarMaterial"; | ||
14 | this._shaderName = "star"; | ||
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 | // Methods | ||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | // duplcate method requirde | ||
32 | this.dup = function( ) { | ||
33 | // allocate a new uber material | ||
34 | var newMat = new StarMaterial(); | ||
35 | |||
36 | // copy over the current values; | ||
37 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
38 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
39 | var n = propNames.length; | ||
40 | for (var i=0; i<n; i++) { | ||
41 | newMat.setProperty( propNames[i], propValues[i] ); | ||
42 | } | ||
43 | |||
44 | return newMat; | ||
45 | } ; | ||
46 | |||
47 | this.init = function( world ) | ||
48 | { | ||
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 = starMaterialDef; | ||
55 | this._shader.init(); | ||
56 | |||
57 | // set up the material node | ||
58 | this._materialNode = createMaterialNode("starMaterial"); | ||
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) | ||
77 | var starMaterialDef = | ||
78 | {'shaders': | ||
79 | { | ||
80 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
81 | 'defaultFShader':"assets/shaders/Star.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 | |||
116 | StarMaterial.prototype = new PulseMaterial(); | ||
117 | |||
118 | if (typeof exports === "object") { | ||
119 | exports.StarMaterial = StarMaterial; | ||
120 | } | ||
121 | |||
122 | |||
123 | |||
124 | |||