aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/star-material.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-04-04 15:54:53 -0700
committerJose Antonio Marquez2012-04-04 15:54:53 -0700
commitc3022de5ba2e24737184dba7454233b165da0a20 (patch)
tree0bc6a2d433c577e13d598c3385bebaff8a226c86 /js/lib/rdge/materials/star-material.js
parente2ed78b699c3f2353bdf636629956c2a3ef319be (diff)
parente721a7c1009f298a1bd8fea583da14535e039880 (diff)
downloadninja-c3022de5ba2e24737184dba7454233b165da0a20.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into Document
Diffstat (limited to 'js/lib/rdge/materials/star-material.js')
-rw-r--r--js/lib/rdge/materials/star-material.js133
1 files changed, 66 insertions, 67 deletions
diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js
index d7d797e4..f3f4474d 100644
--- a/js/lib/rdge/materials/star-material.js
+++ b/js/lib/rdge/materials/star-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
7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; 7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
8 8
@@ -10,103 +10,102 @@ var StarMaterial = function StarMaterial() {
10 /////////////////////////////////////////////////////////////////////// 10 ///////////////////////////////////////////////////////////////////////
11 // Instance variables 11 // Instance variables
12 /////////////////////////////////////////////////////////////////////// 12 ///////////////////////////////////////////////////////////////////////
13 this._name = "StarMaterial"; 13 this._name = "StarMaterial";
14 this._shaderName = "star"; 14 this._shaderName = "star";
15 15
16 this._texMap = 'assets/images/rocky-normal.jpg'; 16 this._texMap = 'assets/images/rocky-normal.jpg';
17 17
18 this._time = 0.0; 18 this._time = 0.0;
19 this._dTime = 0.01; 19 this._dTime = 0.01;
20 20
21 /////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////
22 // Properties 22 // Properties
23 /////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////
24 // all defined in parent PulseMaterial.js 24 // all defined in parent PulseMaterial.js
25 // load the local default value 25 // load the local default value
26 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 26 this._propValues[this._propNames[0]] = this._texMap.slice(0);
27 27
28 /////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////
29 // Methods 29 // Methods
30 /////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////
31 // duplcate method requirde 31 // duplcate method requirde
32 this.dup = function( ) { 32 this.dup = function () {
33 // allocate a new uber material 33 // allocate a new uber material
34 var newMat = new StarMaterial(); 34 var newMat = new StarMaterial();
35 35
36 // copy over the current values; 36 // copy over the current values;
37 var propNames = [], propValues = [], propTypes = [], propLabels = []; 37 var propNames = [], propValues = [], propTypes = [], propLabels = [];
38 this.getAllProperties( propNames, propValues, propTypes, propLabels); 38 this.getAllProperties(propNames, propValues, propTypes, propLabels);
39 var n = propNames.length; 39 var n = propNames.length;
40 for (var i=0; i<n; i++) { 40 for (var i = 0; i < n; i++) {
41 newMat.setProperty( propNames[i], propValues[i] ); 41 newMat.setProperty(propNames[i], propValues[i]);
42 } 42 }
43 43
44 return newMat; 44 return newMat;
45 } ; 45 };
46 46
47 this.init = function( world ) 47 this.init = function (world) {
48 { 48 // save the world
49 // save the world 49 if (world) this.setWorld(world);
50 if (world) this.setWorld( world );
51 50
52 // set up the shader 51 // set up the shader
53 this._shader = new jshader(); 52 this._shader = new RDGE.jshader();
54 this._shader.def = starMaterialDef; 53 this._shader.def = starMaterialDef;
55 this._shader.init(); 54 this._shader.init();
56 55
57 // set up the material node 56 // set up the material node
58 this._materialNode = createMaterialNode("starMaterial" + "_" + world.generateUniqueNodeID()); 57 this._materialNode = RDGE.createMaterialNode("starMaterial" + "_" + world.generateUniqueNodeID());
59 this._materialNode.setShader(this._shader); 58 this._materialNode.setShader(this._shader);
60 59
61 this._time = 0; 60 this._time = 0;
62 if (this._shader && this._shader['default']) { 61 if (this._shader && this._shader['default']) {
63 this._shader['default'].u_time.set( [this._time] ); 62 this._shader['default'].u_time.set([this._time]);
64 } 63 }
65 64
66 // set the shader values in the shader 65 // set the shader values in the shader
67 this.updateTexture(); 66 this.updateTexture();
68 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 67 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
69 this.update( 0 ); 68 this.update(0);
70 } 69 };
71}; 70};
72 71
73/////////////////////////////////////////////////////////////////////////////////////// 72///////////////////////////////////////////////////////////////////////////////////////
74// RDGE shader 73// RDGE shader
75 74
76// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 75// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
77var starMaterialDef = 76var starMaterialDef =
78{'shaders': 77{ 'shaders':
79 { 78 {
80 'defaultVShader':"assets/shaders/Basic.vert.glsl", 79 'defaultVShader': "assets/shaders/Basic.vert.glsl",
81 'defaultFShader':"assets/shaders/Star.frag.glsl" 80 'defaultFShader': "assets/shaders/Star.frag.glsl"
82 }, 81 },
83 'techniques': 82 'techniques':
84 { 83 {
85 'default': 84 'default':
86 [ 85 [
87 { 86 {
88 'vshader' : 'defaultVShader', 87 'vshader': 'defaultVShader',
89 'fshader' : 'defaultFShader', 88 'fshader': 'defaultFShader',
90 // attributes 89 // attributes
91 'attributes' : 90 'attributes':
92 { 91 {
93 'vert' : { 'type' : 'vec3' }, 92 'vert': { 'type': 'vec3' },
94 'normal' : { 'type' : 'vec3' }, 93 'normal': { 'type': 'vec3' },
95 'texcoord' : { 'type' : 'vec2' } 94 'texcoord': { 'type': 'vec2' }
96 }, 95 },
97 // parameters 96 // parameters
98 'params' : 97 'params':
99 { 98 {
100 'u_tex0': { 'type' : 'tex2d' }, 99 'u_tex0': { 'type': 'tex2d' },
101 'u_time' : { 'type' : 'float' }, 100 'u_time': { 'type': 'float' },
102 'u_resolution' : { 'type' : 'vec2' } 101 'u_resolution': { 'type': 'vec2' }
103 }, 102 },
104 103
105 // render states 104 // render states
106 'states' : 105 'states':
107 { 106 {
108 'depthEnable' : true, 107 'depthEnable': true,
109 'offset':[1.0, 0.1] 108 'offset': [1.0, 0.1]
110 } 109 }
111 } 110 }
112 ] 111 ]