diff options
Diffstat (limited to 'js/lib/rdge/materials/radial-gradient-material.js')
-rwxr-xr-x | js/lib/rdge/materials/radial-gradient-material.js | 170 |
1 files changed, 85 insertions, 85 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index 6a5a9e9a..f7e28083 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js | |||
@@ -47,17 +47,17 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
47 | this._defaultColorStop2 = 0.3; | 47 | this._defaultColorStop2 = 0.3; |
48 | this._defaultColorStop3 = 0.6; | 48 | this._defaultColorStop3 = 0.6; |
49 | this._defaultColorStop4 = 1.0; | 49 | this._defaultColorStop4 = 1.0; |
50 | // this._defaultColorCount = 4; | 50 | // this._defaultColorCount = 4; |
51 | 51 | ||
52 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; | 52 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; |
53 | 53 | ||
54 | /////////////////////////////////////////////////////////////////////// | 54 | /////////////////////////////////////////////////////////////////////// |
55 | // Property Accessors | 55 | // Property Accessors |
56 | /////////////////////////////////////////////////////////////////////// | 56 | /////////////////////////////////////////////////////////////////////// |
57 | 57 | ||
58 | 58 | ||
59 | this.isAnimated = function () { return false; }; | 59 | this.isAnimated = function () { return false; }; |
60 | this.getShaderDef = function() { return radialGradientMaterialDef; }; | 60 | this.getShaderDef = function() { return radialGradientMaterialDef; }; |
61 | 61 | ||
62 | /////////////////////////////////////////////////////////////////////// | 62 | /////////////////////////////////////////////////////////////////////// |
63 | // Material Property Accessors | 63 | // Material Property Accessors |
@@ -95,49 +95,49 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
95 | this._materialNode.setShader(this._shader); | 95 | this._materialNode.setShader(this._shader); |
96 | 96 | ||
97 | // set the shader values in the shader | 97 | // set the shader values in the shader |
98 | this._shader['default'].u_texTransform.set( this._textureTransform ); | 98 | this._shader['default'].u_texTransform.set( this._textureTransform ); |
99 | this.setShaderValues(); | 99 | this.setShaderValues(); |
100 | }; | 100 | }; |
101 | 101 | ||
102 | this.fitToPrimitive = function( prim ) | 102 | this.fitToPrimitive = function( prim ) |
103 | { | 103 | { |
104 | var bounds = ShapePrimitive.getBounds( prim ); | 104 | var bounds = ShapePrimitive.getBounds( prim ); |
105 | if (bounds) | 105 | if (bounds) |
106 | { | 106 | { |
107 | var dx = Math.abs( bounds[3] - bounds[0] ), | 107 | var dx = Math.abs( bounds[3] - bounds[0] ), |
108 | dy = Math.abs( bounds[4] - bounds[1] ); | 108 | dy = Math.abs( bounds[4] - bounds[1] ); |
109 | if (dy == 0) dy = 1.0; | 109 | if (dy == 0) dy = 1.0; |
110 | if (dx == 0) dx = 1.0; | 110 | if (dx == 0) dx = 1.0; |
111 | var xScale = 2.0, yScale = 2.0; | 111 | var xScale = 2.0, yScale = 2.0; |
112 | if (dx > dy) | 112 | if (dx > dy) |
113 | yScale *= dy/dx; | 113 | yScale *= dy/dx; |
114 | else | 114 | else |
115 | xScale *= dx/dy; | 115 | xScale *= dx/dy; |
116 | 116 | ||
117 | // build the matrix - the translation to the origin, the scale, | 117 | // build the matrix - the translation to the origin, the scale, |
118 | // and the translation back to the center (hard coded at (0.5, 0.5) for now). | 118 | // and the translation back to the center (hard coded at (0.5, 0.5) for now). |
119 | // the matrix is build directly instead of with matrix multiplications | 119 | // the matrix is build directly instead of with matrix multiplications |
120 | // for efficiency, not to mention that the multiplication function does | 120 | // for efficiency, not to mention that the multiplication function does |
121 | // not exist for mat3's. | 121 | // not exist for mat3's. |
122 | // the matrix as laid out below looks transposed - order is columnwise. | 122 | // the matrix as laid out below looks transposed - order is columnwise. |
123 | var xCtr = 0.5, yCtr = 0.5; | 123 | var xCtr = 0.5, yCtr = 0.5; |
124 | this._textureTransform = [ | 124 | this._textureTransform = [ |
125 | xScale, 0.0, 0.0, | 125 | xScale, 0.0, 0.0, |
126 | 0.0, yScale, 0.0, | 126 | 0.0, yScale, 0.0, |
127 | xCtr*(1-xScale), yCtr*(1 - yScale), 1.0 | 127 | xCtr*(1-xScale), yCtr*(1 - yScale), 1.0 |
128 | ]; | 128 | ]; |
129 | 129 | ||
130 | if (this._shader && this._shader['default']) | 130 | if (this._shader && this._shader['default']) |
131 | this._shader['default'].u_texTransform.set( this._textureTransform ); | 131 | this._shader['default'].u_texTransform.set( this._textureTransform ); |
132 | 132 | ||
133 | } | 133 | } |
134 | }; | 134 | }; |
135 | 135 | ||
136 | this.customExport = function( jObj ) | 136 | this.customExport = function( jObj ) |
137 | { | 137 | { |
138 | jObj.u_texTransform = this._textureTransform.slice(); | 138 | jObj.u_texTransform = this._textureTransform.slice(); |
139 | return jObj; | 139 | return jObj; |
140 | } | 140 | } |
141 | }; | 141 | }; |
142 | 142 | ||
143 | /////////////////////////////////////////////////////////////////////////////////////// | 143 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -146,48 +146,48 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
146 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 146 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
147 | var radialGradientMaterialDef = | 147 | var radialGradientMaterialDef = |
148 | { 'shaders': | 148 | { 'shaders': |
149 | { | 149 | { |
150 | 'defaultVShader': "assets/shaders/radialGradient.vert.glsl", | 150 | 'defaultVShader': "assets/shaders/radialGradient.vert.glsl", |
151 | 'defaultFShader': "assets/shaders/radialGradient.frag.glsl" | 151 | 'defaultFShader': "assets/shaders/radialGradient.frag.glsl" |
152 | }, | 152 | }, |
153 | 'techniques': | 153 | 'techniques': |
154 | { | 154 | { |
155 | 'default': | 155 | 'default': |
156 | [ | 156 | [ |
157 | { | 157 | { |
158 | 'vshader': 'defaultVShader', | 158 | 'vshader': 'defaultVShader', |
159 | 'fshader': 'defaultFShader', | 159 | 'fshader': 'defaultFShader', |
160 | // attributes | 160 | // attributes |
161 | 'attributes': | 161 | 'attributes': |
162 | { | 162 | { |
163 | 'vert': { 'type': 'vec3' }, | 163 | 'vert': { 'type': 'vec3' }, |
164 | 'normal': { 'type': 'vec3' }, | 164 | 'normal': { 'type': 'vec3' }, |
165 | 'texcoord': { 'type': 'vec2' } | 165 | 'texcoord': { 'type': 'vec2' } |
166 | }, | 166 | }, |
167 | // parameters | 167 | // parameters |
168 | 'params': | 168 | 'params': |
169 | { | 169 | { |
170 | 'u_color1': { 'type': 'vec4' }, | 170 | 'u_color1': { 'type': 'vec4' }, |
171 | 'u_color2': { 'type': 'vec4' }, | 171 | 'u_color2': { 'type': 'vec4' }, |
172 | 'u_color3': { 'type': 'vec4' }, | 172 | 'u_color3': { 'type': 'vec4' }, |
173 | 'u_color4': { 'type': 'vec4' }, | 173 | 'u_color4': { 'type': 'vec4' }, |
174 | 'u_colorStop1': { 'type': 'float' }, | 174 | 'u_colorStop1': { 'type': 'float' }, |
175 | 'u_colorStop2': { 'type': 'float' }, | 175 | 'u_colorStop2': { 'type': 'float' }, |
176 | 'u_colorStop3': { 'type': 'float' }, | 176 | 'u_colorStop3': { 'type': 'float' }, |
177 | 'u_colorStop4': { 'type': 'float' }, | 177 | 'u_colorStop4': { 'type': 'float' }, |
178 | 'u_texTransform': { 'type' : 'mat3' } | 178 | 'u_texTransform': { 'type' : 'mat3' } |
179 | //'u_colorCount': {'type' : 'int' } | 179 | //'u_colorCount': {'type' : 'int' } |
180 | }, | 180 | }, |
181 | 181 | ||
182 | // render states | 182 | // render states |
183 | 'states': | 183 | 'states': |
184 | { | 184 | { |
185 | 'depthEnable': true, | 185 | 'depthEnable': true, |
186 | 'offset': [1.0, 0.1] | 186 | 'offset': [1.0, 0.1] |
187 | } | 187 | } |
188 | } | 188 | } |
189 | ] | 189 | ] |
190 | } | 190 | } |
191 | }; | 191 | }; |
192 | 192 | ||
193 | RadialGradientMaterial.prototype = new Material(); | 193 | RadialGradientMaterial.prototype = new Material(); |