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