aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/linear-gradient-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js214
1 files changed, 107 insertions, 107 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js
index 981bf9fd..d216a2c0 100755
--- a/js/lib/rdge/materials/linear-gradient-material.js
+++ b/js/lib/rdge/materials/linear-gradient-material.js
@@ -47,15 +47,15 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
47 this._colorStop2 = 0.3; 47 this._colorStop2 = 0.3;
48 this._colorStop3 = 0.6; 48 this._colorStop3 = 0.6;
49 this._colorStop4 = 1.0; 49 this._colorStop4 = 1.0;
50 // this._colorCount = 4; 50 // this._colorCount = 4;
51 this._angle = 0.0; // the shader takes [cos(a), sin(a)] 51 this._angle = 0.0; // the shader takes [cos(a), sin(a)]
52 52
53 this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; 53 this._textureTransform = [1,0,0, 0,1,0, 0,0,1];
54 54
55 /////////////////////////////////////////////////////////////////////// 55 ///////////////////////////////////////////////////////////////////////
56 // Property Accessors 56 // Property Accessors
57 /////////////////////////////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////
58 this.getShaderDef = function() { return linearGradientMaterialDef; } 58 this.getShaderDef = function() { return linearGradientMaterialDef; }
59 59
60 /////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////
61 // Material Property Accessors 61 // Material Property Accessors
@@ -95,13 +95,13 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
95 this._materialNode.setShader(this._shader); 95 this._materialNode.setShader(this._shader);
96 96
97 97
98 if (this._shader && this._shader['default']) 98 if (this._shader && this._shader['default'])
99 this._shader['default'].u_texTransform.set( this._textureTransform ); 99 this._shader['default'].u_texTransform.set( this._textureTransform );
100 100
101 101
102 // send the current values to the shader 102 // send the current values to the shader
103 this.setShaderValues(); 103 this.setShaderValues();
104 this.update( 0 ); 104 this.update( 0 );
105 }; 105 };
106}; 106};
107 107
@@ -111,107 +111,107 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
111// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 111// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
112var linearGradientMaterialDef = 112var linearGradientMaterialDef =
113{'shaders': 113{'shaders':
114 { 114 {
115 // shader file 115 // shader file
116 'defaultVShader':"assets/shaders/linearGradient.vert.glsl", 116 'defaultVShader':"assets/shaders/linearGradient.vert.glsl",
117 'defaultFShader':"assets/shaders/linearGradient.frag.glsl", 117 'defaultFShader':"assets/shaders/linearGradient.frag.glsl",
118 118
119 // this shader is inline 119 // this shader is inline
120 'dirLightVShader': "\ 120 'dirLightVShader': "\
121 uniform mat4 u_mvMatrix;\ 121 uniform mat4 u_mvMatrix;\
122 uniform mat4 u_normalMatrix;\ 122 uniform mat4 u_normalMatrix;\
123 uniform mat4 u_projMatrix;\ 123 uniform mat4 u_projMatrix;\
124 uniform mat4 u_worldMatrix;\ 124 uniform mat4 u_worldMatrix;\
125 attribute vec3 a_pos;\ 125 attribute vec3 a_pos;\
126 attribute vec3 a_nrm;\ 126 attribute vec3 a_nrm;\
127 varying vec3 vNormal;\ 127 varying vec3 vNormal;\
128 varying vec3 vPos;\ 128 varying vec3 vPos;\
129 void main() {\ 129 void main() {\
130 vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\ 130 vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\
131 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\ 131 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\
132 vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\ 132 vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\
133 }", 133 }",
134 'dirLightFShader': "\ 134 'dirLightFShader': "\
135 precision highp float;\ 135 precision highp float;\
136 uniform vec4 u_light1Diff;\ 136 uniform vec4 u_light1Diff;\
137 uniform vec3 u_light1Pos;\ 137 uniform vec3 u_light1Pos;\
138 uniform vec4 u_light2Diff;\ 138 uniform vec4 u_light2Diff;\
139 uniform vec3 u_light2Pos;\ 139 uniform vec3 u_light2Pos;\
140 varying vec3 vNormal;\ 140 varying vec3 vNormal;\
141 varying vec3 vPos;\ 141 varying vec3 vPos;\
142 void main() {\ 142 void main() {\
143 vec3 light1 = vec3(u_light1Pos.x - vPos.x, u_light1Pos.y - vPos.y, u_light1Pos.z - vPos.z);\ 143 vec3 light1 = vec3(u_light1Pos.x - vPos.x, u_light1Pos.y - vPos.y, u_light1Pos.z - vPos.z);\
144 vec3 light2 = vec3(u_light2Pos.x - vPos.x, u_light2Pos.y - vPos.y, u_light2Pos.z - vPos.z);\ 144 vec3 light2 = vec3(u_light2Pos.x - vPos.x, u_light2Pos.y - vPos.y, u_light2Pos.z - vPos.z);\
145 float t = 0.75;\ 145 float t = 0.75;\
146 float range = t*t;\ 146 float range = t*t;\
147 float alpha1 = max(0.0, 1.0 - ( (light1.x*light1.x)/range + (light1.y*light1.y)/range + (light1.z*light1.z)/range));\ 147 float alpha1 = max(0.0, 1.0 - ( (light1.x*light1.x)/range + (light1.y*light1.y)/range + (light1.z*light1.z)/range));\
148 float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\ 148 float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\
149 gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\ 149 gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\
150 }" 150 }"
151 }, 151 },
152 'techniques': 152 'techniques':
153 { 153 {
154 'default': 154 'default':
155 [ 155 [
156 { 156 {
157 'vshader' : 'defaultVShader', 157 'vshader' : 'defaultVShader',
158 'fshader' : 'defaultFShader', 158 'fshader' : 'defaultFShader',
159 // attributes 159 // attributes
160 'attributes' : 160 'attributes' :
161 { 161 {
162 'vert' : { 'type' : 'vec3' }, 162 'vert' : { 'type' : 'vec3' },
163 'normal' : { 'type' : 'vec3' }, 163 'normal' : { 'type' : 'vec3' },
164 'texcoord' : { 'type' : 'vec2' } 164 'texcoord' : { 'type' : 'vec2' }
165 }, 165 },
166 // parameters 166 // parameters
167 'params' : 167 'params' :
168 { 168 {
169 'u_color1' : { 'type' : 'vec4' }, 169 'u_color1' : { 'type' : 'vec4' },
170 'u_color2' : { 'type' : 'vec4' }, 170 'u_color2' : { 'type' : 'vec4' },
171 'u_color3' : { 'type' : 'vec4' }, 171 'u_color3' : { 'type' : 'vec4' },
172 'u_color4' : { 'type' : 'vec4' }, 172 'u_color4' : { 'type' : 'vec4' },
173 'u_colorStop1': { 'type' : 'float' }, 173 'u_colorStop1': { 'type' : 'float' },
174 'u_colorStop2': { 'type' : 'float' }, 174 'u_colorStop2': { 'type' : 'float' },
175 'u_colorStop3': { 'type' : 'float' }, 175 'u_colorStop3': { 'type' : 'float' },
176 'u_colorStop4': { 'type' : 'float' }, 176 'u_colorStop4': { 'type' : 'float' },
177 'u_cos_sin_angle': { 'type' : 'vec2' }, 177 'u_cos_sin_angle': { 'type' : 'vec2' },
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 182
183 // render states 183 // render states
184 'states' : 184 'states' :
185 { 185 {
186 'depthEnable' : true, 186 'depthEnable' : true,
187 'offset':[1.0, 0.1] 187 'offset':[1.0, 0.1]
188 } 188 }
189 }, 189 },
190 { // light pass 190 { // light pass
191 'vshader' : 'dirLightVShader', 191 'vshader' : 'dirLightVShader',
192 'fshader' : 'dirLightFShader', 192 'fshader' : 'dirLightFShader',
193 // attributes 193 // attributes
194 'attributes' : 194 'attributes' :
195 { 195 {
196 'a_pos' : { 'type' : 'vec3' }, 196 'a_pos' : { 'type' : 'vec3' },
197 'a_nrm' : { 'type' : 'vec3' } 197 'a_nrm' : { 'type' : 'vec3' }
198 }, 198 },
199 // parameters 199 // parameters
200 'params' : 200 'params' :
201 { 201 {
202 }, 202 },
203 203
204 // render states 204 // render states