diff options
Diffstat (limited to 'js/lib/rdge/materials/star-material.js')
-rw-r--r-- | js/lib/rdge/materials/star-material.js | 110 |
1 files changed, 60 insertions, 50 deletions
diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js index 445f6023..34cca767 100644 --- a/js/lib/rdge/materials/star-material.js +++ b/js/lib/rdge/materials/star-material.js | |||
@@ -46,23 +46,23 @@ var StarMaterial = function StarMaterial() { | |||
46 | // array textures indexed by shader uniform name | 46 | // array textures indexed by shader uniform name |
47 | this._glTextures = []; | 47 | this._glTextures = []; |
48 | 48 | ||
49 | /////////////////////////////////////////////////////////////////////// | 49 | /////////////////////////////////////////////////////////////////////// |
50 | // Property Accessors | 50 | // Property Accessors |
51 | /////////////////////////////////////////////////////////////////////// | 51 | /////////////////////////////////////////////////////////////////////// |
52 | this.isAnimated = function() { return true; }; | 52 | this.isAnimated = function() { return true; }; |
53 | this.getShaderDef = function() { return starMaterialDef; } | 53 | this.getShaderDef = function() { return starMaterialDef; } |
54 | 54 | ||
55 | /////////////////////////////////////////////////////////////////////// | 55 | /////////////////////////////////////////////////////////////////////// |
56 | // Material Property Accessors | 56 | // Material Property Accessors |
57 | /////////////////////////////////////////////////////////////////////// | 57 | /////////////////////////////////////////////////////////////////////// |
58 | var u_tex0_index = 0, u_speed_index = 1; | 58 | var u_tex0_index = 0, u_speed_index = 1; |
59 | this._propNames = ["u_tex0", "u_speed" ]; | 59 | this._propNames = ["u_tex0", "u_speed" ]; |
60 | this._propLabels = ["Texture map", "Speed" ]; | 60 | this._propLabels = ["Texture map", "Speed" ]; |
61 | this._propTypes = ["file", "float" ]; | 61 | this._propTypes = ["file", "float" ]; |
62 | this._propValues = []; | 62 | this._propValues = []; |
63 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | 63 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); |
64 | this._propValues[this._propNames[u_speed_index]] = 1.0; | 64 | this._propValues[this._propNames[u_speed_index]] = 1.0; |
65 | /////////////////////////////////////////////////////////////////////// | 65 | /////////////////////////////////////////////////////////////////////// |
66 | 66 | ||
67 | /////////////////////////////////////////////////////////////////////// | 67 | /////////////////////////////////////////////////////////////////////// |
68 | // Methods | 68 | // Methods |
@@ -95,6 +95,16 @@ var StarMaterial = function StarMaterial() { | |||
95 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); | 95 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); |
96 | this.update(0); | 96 | this.update(0); |
97 | }; | 97 | }; |
98 | |||
99 | this.resetToDefault = function() | ||
100 | { | ||
101 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | ||
102 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
103 | |||
104 | var nProps = this._propNames.length; | ||
105 | for (var i=0; i<nProps; i++) | ||
106 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
107 | }; | ||
98 | }; | 108 | }; |
99 | 109 | ||
100 | /////////////////////////////////////////////////////////////////////////////////////// | 110 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -103,42 +113,42 @@ var StarMaterial = function StarMaterial() { | |||
103 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 113 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
104 | var starMaterialDef = | 114 | var starMaterialDef = |
105 | { 'shaders': | 115 | { 'shaders': |
106 | { | 116 | { |
107 | 'defaultVShader': "assets/shaders/Basic.vert.glsl", | 117 | 'defaultVShader': "assets/shaders/Basic.vert.glsl", |
108 | 'defaultFShader': "assets/shaders/Star.frag.glsl" | 118 | 'defaultFShader': "assets/shaders/Star.frag.glsl" |
109 | }, | 119 | }, |
110 | 'techniques': | 120 | 'techniques': |
111 | { | 121 | { |
112 | 'default': | 122 | 'default': |
113 | [ | 123 | [ |
114 | { | 124 | { |
115 | 'vshader': 'defaultVShader', | 125 | 'vshader': 'defaultVShader', |
116 | 'fshader': 'defaultFShader', | 126 | 'fshader': 'defaultFShader', |
117 | // attributes | 127 | // attributes |
118 | 'attributes': | 128 | 'attributes': |
119 | { | 129 | { |
120 | 'vert': { 'type': 'vec3' }, | 130 | 'vert': { 'type': 'vec3' }, |
121 | 'normal': { 'type': 'vec3' }, | 131 | 'normal': { 'type': 'vec3' }, |
122 | 'texcoord': { 'type': 'vec2' } | 132 | 'texcoord': { 'type': 'vec2' } |
123 | }, | 133 | }, |
124 | // parameters | 134 | // parameters |
125 | 'params': | 135 | 'params': |
126 | { | 136 | { |
127 | 'u_tex0': { 'type': 'tex2d' }, | 137 | 'u_tex0': { 'type': 'tex2d' }, |
128 | 'u_time': { 'type': 'float' }, | 138 | 'u_time': { 'type': 'float' }, |
129 | 'u_speed': { 'type': 'float' }, | 139 | 'u_speed': { 'type': 'float' }, |
130 | 'u_resolution': { 'type': 'vec2' } | 140 | 'u_resolution': { 'type': 'vec2' } |
131 | }, | 141 | }, |
132 | 142 | ||
133 | // render states | 143 | // render states |
134 | 'states': | 144 | 'states': |
135 | { | 145 | { |
136 | 'depthEnable': true, | 146 | 'depthEnable': true, |
137 | 'offset': [1.0, 0.1] | 147 | 'offset': [1.0, 0.1] |
138 | } | 148 | } |
139 | } | 149 | } |
140 | ] | 150 | ] |
141 | } | 151 | } |
142 | }; | 152 | }; |
143 | 153 | ||
144 | StarMaterial.prototype = new PulseMaterial(); | 154 | StarMaterial.prototype = new PulseMaterial(); |