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, 72 insertions, 61 deletions
diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js
index 445f6023..26aa66aa 100644
--- a/js/lib/rdge/materials/star-material.js
+++ b/js/lib/rdge/materials/star-material.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -46,23 +47,23 @@ var StarMaterial = function StarMaterial() {
46 // array textures indexed by shader uniform name 47 // array textures indexed by shader uniform name
47 this._glTextures = []; 48 this._glTextures = [];
48 49
49 /////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////
50 // Property Accessors 51 // Property Accessors
51 /////////////////////////////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////
52 this.isAnimated = function() { return true; }; 53 this.isAnimated = function() { return true; };
53 this.getShaderDef = function() { return starMaterialDef; } 54 this.getShaderDef = function() { return starMaterialDef; }
54 55
55 /////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////
56 // Material Property Accessors 57 // Material Property Accessors
57 /////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////
58 var u_tex0_index = 0, u_speed_index = 1; 59 var u_tex0_index = 0, u_speed_index = 1;
59 this._propNames = ["u_tex0", "u_speed" ]; 60 this._propNames = ["u_tex0", "u_speed" ];
60 this._propLabels = ["Texture map", "Speed" ]; 61 this._propLabels = ["Texture map", "Speed" ];
61 this._propTypes = ["file", "float" ]; 62 this._propTypes = ["file", "float" ];
62 this._propValues = []; 63 this._propValues = [];
63 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); 64 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0);
64 this._propValues[this._propNames[u_speed_index]] = 1.0; 65 this._propValues[this._propNames[u_speed_index]] = 1.0;
65 /////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////
66 67
67 /////////////////////////////////////////////////////////////////////// 68 ///////////////////////////////////////////////////////////////////////
68 // Methods 69 // Methods
@@ -95,6 +96,16 @@ var StarMaterial = function StarMaterial() {
95 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 96 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
96 this.update(0); 97 this.update(0);
97 }; 98 };
99
100 this.resetToDefault = function()
101 {
102 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0);
103 this._propValues[this._propNames[u_speed_index]] = 1.0;
104
105 var nProps = this._propNames.length;
106 for (var i=0; i<nProps; i++)
107 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
108 };
98}; 109};
99 110
100/////////////////////////////////////////////////////////////////////////////////////// 111///////////////////////////////////////////////////////////////////////////////////////
@@ -103,42 +114,42 @@ var StarMaterial = function StarMaterial() {
103// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 114// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
104var starMaterialDef = 115var starMaterialDef =
105{ 'shaders': 116{ 'shaders':
106 { 117 {
107 'defaultVShader': "assets/shaders/Basic.vert.glsl", 118 'defaultVShader': "assets/shaders/Basic.vert.glsl",
108 'defaultFShader': "assets/shaders/Star.frag.glsl" 119 'defaultFShader': "assets/shaders/Star.frag.glsl"
109 }, 120 },
110 'techniques': 121 'techniques':
111 { 122 {
112 'default': 123 'default':
113 [ 124 [
114 { 125 {
115 'vshader': 'defaultVShader', 126 'vshader': 'defaultVShader',
116 'fshader': 'defaultFShader', 127 'fshader': 'defaultFShader',
117 // attributes 128 // attributes
118 'attributes': 129 'attributes':
119 { 130 {
120 'vert': { 'type': 'vec3' }, 131 'vert': { 'type': 'vec3' },
121 'normal': { 'type': 'vec3' }, 132 'normal': { 'type': 'vec3' },
122 'texcoord': { 'type': 'vec2' } 133 'texcoord': { 'type': 'vec2' }
123 }, 134 },
124 // parameters 135 // parameters
125 'params': 136 'params':
126 { 137 {
127 'u_tex0': { 'type': 'tex2d' }, 138 'u_tex0': { 'type': 'tex2d' },
128 'u_time': { 'type': 'float' }, 139 'u_time': { 'type': 'float' },
129 'u_speed': { 'type': 'float' }, 140 'u_speed': { 'type': 'float' },
130 'u_resolution': { 'type': 'vec2' } 141 'u_resolution': { 'type': 'vec2' }
131 }, 142 },
132 143
133 // render states 144 // render states
134 'states': 145 'states':
135 { 146 {
136 'depthEnable': true, 147 'depthEnable': true,
137 'offset': [1.0, 0.1] 148 'offset': [1.0, 0.1]
138 } 149 }
139 } 150 }
140 ] 151 ]
141 } 152 }
142}; 153};
143 154
144StarMaterial.prototype = new PulseMaterial(); 155StarMaterial.prototype = new PulseMaterial();