From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- assets/shaders/Basic.vert.glsl | 6 +- assets/shaders/BasicTex.frag.glsl | 2 +- assets/shaders/Cloud.frag.glsl | 6 +- assets/shaders/Cloud.vert.glsl | 28 +-- assets/shaders/Flag.vert.glsl | 22 +- assets/shaders/Taper.vert.glsl | 152 ++++++------ assets/shaders/TwistVert.frag.glsl | 8 +- assets/shaders/TwistVert.vert.glsl | 84 +++---- assets/shaders/linearGradient.frag.glsl | 68 +++--- assets/shaders/linearGradient.vert.glsl | 30 +-- assets/shaders/radialGradient.frag.glsl | 70 +++--- assets/shaders/radialGradient.vert.glsl | 8 +- assets/shaders/test_fshader.glsl | 18 +- assets/shaders/test_fshader_full.glsl | 8 +- assets/shaders/test_vshader.glsl | 60 ++--- assets/shaders/ub_fshader.glsl | 414 ++++++++++++++++---------------- assets/shaders/ub_vshader.glsl | 232 +++++++++--------- 17 files changed, 608 insertions(+), 608 deletions(-) (limited to 'assets/shaders') diff --git a/assets/shaders/Basic.vert.glsl b/assets/shaders/Basic.vert.glsl index ae454411..80b2f088 100755 --- a/assets/shaders/Basic.vert.glsl +++ b/assets/shaders/Basic.vert.glsl @@ -39,7 +39,7 @@ attribute vec3 a_pos; attribute vec2 texcoord; // varying -varying vec2 v_texCoord0; +varying vec2 v_texCoord0; // matrix uniforms uniform mat4 u_mvMatrix; @@ -48,6 +48,6 @@ uniform mat4 u_worldMatrix; void main(void) { - v_texCoord0 = texcoord; - gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ; + v_texCoord0 = texcoord; + gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ; } diff --git a/assets/shaders/BasicTex.frag.glsl b/assets/shaders/BasicTex.frag.glsl index 4fee288d..d89e2ead 100644 --- a/assets/shaders/BasicTex.frag.glsl +++ b/assets/shaders/BasicTex.frag.glsl @@ -35,7 +35,7 @@ precision highp float; uniform sampler2D u_tex0; -varying vec2 v_texCoord0; +varying vec2 v_texCoord0; void main() { diff --git a/assets/shaders/Cloud.frag.glsl b/assets/shaders/Cloud.frag.glsl index 85a43699..dc984191 100644 --- a/assets/shaders/Cloud.frag.glsl +++ b/assets/shaders/Cloud.frag.glsl @@ -36,12 +36,12 @@ precision highp float; uniform sampler2D u_tex0; uniform float u_surfaceAlpha; -varying vec2 v_texCoord0; +varying vec2 v_texCoord0; void main() { - vec4 c = texture2D(u_tex0, v_texCoord0); - gl_FragColor = c; + vec4 c = texture2D(u_tex0, v_texCoord0); + gl_FragColor = c; } diff --git a/assets/shaders/Cloud.vert.glsl b/assets/shaders/Cloud.vert.glsl index 95c14132..c709bc27 100644 --- a/assets/shaders/Cloud.vert.glsl +++ b/assets/shaders/Cloud.vert.glsl @@ -34,7 +34,7 @@ precision highp float; #endif // attributes -attribute vec3 a_pos; +attribute vec3 a_pos; attribute vec2 texcoord; // uniforms @@ -48,7 +48,7 @@ uniform mat4 u_mvMatrix; uniform mat4 u_projMatrix; // varying -varying vec2 v_texCoord0; +varying vec2 v_texCoord0; // constants const float zSpeed = 10.0; @@ -57,19 +57,19 @@ const float zSpeed = 10.0; void main() { // Transform position - vec4 pos = vec4(a_pos,1); + vec4 pos = vec4(a_pos,1); - float dz = u_time*zSpeed; - float n = floor( dz/(u_zmax-u_zmin) ); - dz -= n*(u_zmax - u_zmin); - float z = pos.z + dz; - if (z > u_zmax) - { - z = u_zmin + (z - u_zmax); - } - pos.z = z; + float dz = u_time*zSpeed; + float n = floor( dz/(u_zmax-u_zmin) ); + dz -= n*(u_zmax - u_zmin); + float z = pos.z + dz; + if (z > u_zmax) + { + z = u_zmin + (z - u_zmax); + } + pos.z = z; - gl_Position = u_projMatrix * u_mvMatrix * pos; - + gl_Position = u_projMatrix * u_mvMatrix * pos; + v_texCoord0 = texcoord; } diff --git a/assets/shaders/Flag.vert.glsl b/assets/shaders/Flag.vert.glsl index fe3ff722..49eaaccb 100644 --- a/assets/shaders/Flag.vert.glsl +++ b/assets/shaders/Flag.vert.glsl @@ -55,21 +55,21 @@ varying vec2 v_uv; void main() { - float time = u_time * u_speed; - const float pi = 3.14159; - float angle = time; + float time = u_time * u_speed; + const float pi = 3.14159; + float angle = time; v_uv = texcoord; - float x = 2.0*pi*texcoord.x/u_waveWidth; - float y = 2.0*pi*texcoord.y; + float x = 2.0*pi*texcoord.x/u_waveWidth; + float y = 2.0*pi*texcoord.y; vec3 v = a_pos; - v.z = sin( x + angle ); - v.z += sin( 0.2*y + angle); - v.z *= u_waveHeight; - v.z -= 2.0*u_waveHeight; - v.z *= x * 0.09; - + v.z = sin( x + angle ); + v.z += sin( 0.2*y + angle); + v.z *= u_waveHeight; + v.z -= 2.0*u_waveHeight; + v.z *= x * 0.09; + gl_Position = u_projMatrix * u_mvMatrix * vec4(v,1.0) ; } diff --git a/assets/shaders/Taper.vert.glsl b/assets/shaders/Taper.vert.glsl index 5fe173b2..e55aeede 100644 --- a/assets/shaders/Taper.vert.glsl +++ b/assets/shaders/Taper.vert.glsl @@ -60,85 +60,85 @@ varying vec4 v_color; float TaperAmount( float param ) { - // Bezier coordinates of the X coordinate. - // Adjust these to get tighter or looser - float tightness = 0.8; - - float x0, y0, x1, y1, x2, y2; - float t; - if (param < 0.5) - { - t = 2.0*param; - x0 = 0.0; y0 = 0.0; - x1 = tightness; y1 = 0.0; - x2 = 1.0; y2 = 0.5; - } - else - { - t = (param - 0.5)*2.0; - x0 = 0.0; y0 = 0.5; - x1 = 1.0 - tightness; y1 = 1.0; - x2 = 1.0; y2 = 1.0; - } - - float a = x0 - 2.0*x1 + x2; - float b = 2.0*(x1 - x0); - float c = x0 - t; - - float descr = sqrt( b*b - 4.0*a*c ); - float denom = 2.0*a; - float n1 = (-b + descr)/denom; - float n2 = (-b - descr)/denom; - if ((n1 >= 0.0) || (n1 <= 1.0)) t = n1; - else if ((n2 >= 0.0) || (n2 <= 1.0)) t = n2; - else - t = 0.0; - - float ya = y0 + t*(y1 - y0); - float yb = y1 + t*(y2 - y1); - float yc = ya + t*(yb - ya); - - return yc; + // Bezier coordinates of the X coordinate. + // Adjust these to get tighter or looser + float tightness = 0.8; + + float x0, y0, x1, y1, x2, y2; + float t; + if (param < 0.5) + { + t = 2.0*param; + x0 = 0.0; y0 = 0.0; + x1 = tightness; y1 = 0.0; + x2 = 1.0; y2 = 0.5; + } + else + { + t = (param - 0.5)*2.0; + x0 = 0.0; y0 = 0.5; + x1 = 1.0 - tightness; y1 = 1.0; + x2 = 1.0; y2 = 1.0; + } + + float a = x0 - 2.0*x1 + x2; + float b = 2.0*(x1 - x0); + float c = x0 - t; + + float descr = sqrt( b*b - 4.0*a*c ); + float denom = 2.0*a; + float n1 = (-b + descr)/denom; + float n2 = (-b - descr)/denom; + if ((n1 >= 0.0) || (n1 <= 1.0)) t = n1; + else if ((n2 >= 0.0) || (n2 <= 1.0)) t = n2; + else + t = 0.0; + + float ya = y0 + t*(y1 - y0); + float yb = y1 + t*(y2 - y1); + float yc = ya + t*(yb - ya); + + return yc; } void main(void) { - vec3 pos = vert; - vec2 uv = texcoord; - - - float limit1 = u_limit1, - limit2 = u_limit2, - limit3 = u_limit2; - - v_color = vec4(texcoord.x, texcoord.y, 0, 1); - if ((uv.x > u_limit1) && (uv.x < u_limit3)) - { - float t; - if (uv.x < u_limit2) - { - t = (uv.x - u_limit1)/(u_limit2 - u_limit1); - } - else - { - t = 1.0 - (uv.x - u_limit2)/(u_limit3 - u_limit2); - } - t = TaperAmount( t ); - - float maxVal; - if (pos.y > u_center) - { - maxVal = u_maxVal; - } - else - { - maxVal = u_minVal; - } - - float yFrac = (pos.y - u_center)/(maxVal-u_center); - pos.y = pos.y - yFrac * (maxVal - u_center)*t*u_taperAmount; - } - - gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ; + vec3 pos = vert; + vec2 uv = texcoord; + + + float limit1 = u_limit1, + limit2 = u_limit2, + limit3 = u_limit2; + + v_color = vec4(texcoord.x, texcoord.y, 0, 1); + if ((uv.x > u_limit1) && (uv.x < u_limit3)) + { + float t; + if (uv.x < u_limit2) + { + t = (uv.x - u_limit1)/(u_limit2 - u_limit1); + } + else + { + t = 1.0 - (uv.x - u_limit2)/(u_limit3 - u_limit2); + } + t = TaperAmount( t ); + + float maxVal; + if (pos.y > u_center) + { + maxVal = u_maxVal; + } + else + { + maxVal = u_minVal; + } + + float yFrac = (pos.y - u_center)/(maxVal-u_center); + pos.y = pos.y - yFrac * (maxVal - u_center)*t*u_taperAmount; + } + + gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ; } diff --git a/assets/shaders/TwistVert.frag.glsl b/assets/shaders/TwistVert.frag.glsl index 22104e4e..545d4f51 100644 --- a/assets/shaders/TwistVert.frag.glsl +++ b/assets/shaders/TwistVert.frag.glsl @@ -46,10 +46,10 @@ varying vec2 v_texcoord; void main() { vec3 col; - if (v_zNormal >= 0.0) - col = texture2D(u_tex0, v_texcoord).xyz; - else - col = texture2D(u_tex1, v_texcoord).xyz; + if (v_zNormal >= 0.0) + col = texture2D(u_tex0, v_texcoord).xyz; + else + col = texture2D(u_tex1, v_texcoord).xyz; gl_FragColor = vec4(col, 1.0); } diff --git a/assets/shaders/TwistVert.vert.glsl b/assets/shaders/TwistVert.vert.glsl index 94d22020..6db4210f 100644 --- a/assets/shaders/TwistVert.vert.glsl +++ b/assets/shaders/TwistVert.vert.glsl @@ -64,51 +64,51 @@ varying vec2 v_texcoord; float GetAngle( float t ) { - float angle= 0.0; - if (t < u_limit2) - { - if (t < u_limit1) - { - angle = u_twistAmount; - } - else - { - angle = (t - u_limit2)/(u_limit1 - u_limit2)*u_twistAmount; - } - } - - return angle; + float angle= 0.0; + if (t < u_limit2) + { + if (t < u_limit1) + { + angle = u_twistAmount; + } + else + { + angle = (t - u_limit2)/(u_limit1 - u_limit2)*u_twistAmount; + } + } + + return angle; } void main(void) { - vec3 pos = vert; - vec2 uv = texcoord; - v_texcoord = texcoord; - - v_zNormal = 1.0; - if (uv.x < u_limit2) - { - float angle = GetAngle( uv.x ); - float cs = cos(angle), sn = sin(angle); - - vec3 ctrPt = pos; - float y = pos.y*cs - pos.z*sn; // + u_center; - pos.z = pos.y*sn + pos.z*cs; - pos.y = y; - - // rotate the normal - mat3 rotMat = mat3( vec3( 1.0, 0.0, 0.0 ), vec3( 0.0, cs, sn ), vec3( 0.0, -sn, cs ) ); - vec3 pt0 = ctrPt, pt1 = vec3(ctrPt.x, ctrPt.y+1.0, ctrPt.z), pt2 = vec3( ctrPt.x+1.0, ctrPt.y, ctrPt.z); - pt0 = rotMat * pt0; pt1 = rotMat * pt1; - angle = GetAngle(1.0); - cs = cos(angle); sn = sin(angle); - rotMat = mat3( vec3( 1.0, 0.0, 0.0 ), vec3( 0.0, cs, sn ), vec3( 0.0, -sn, cs ) ); - pt2 = rotMat * pt2; - vec4 nrm = vec4( cross(pt1-pt0, pt2-pt0), 1.0 ); - v_zNormal = -nrm.z; - } - - gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ; + vec3 pos = vert; + vec2 uv = texcoord; + v_texcoord = texcoord; + + v_zNormal = 1.0; + if (uv.x < u_limit2) + { + float angle = GetAngle( uv.x ); + float cs = cos(angle), sn = sin(angle); + + vec3 ctrPt = pos; + float y = pos.y*cs - pos.z*sn; // + u_center; + pos.z = pos.y*sn + pos.z*cs; + pos.y = y; + + // rotate the normal + mat3 rotMat = mat3( vec3( 1.0, 0.0, 0.0 ), vec3( 0.0, cs, sn ), vec3( 0.0, -sn, cs ) ); + vec3 pt0 = ctrPt, pt1 = vec3(ctrPt.x, ctrPt.y+1.0, ctrPt.z), pt2 = vec3( ctrPt.x+1.0, ctrPt.y, ctrPt.z); + pt0 = rotMat * pt0; pt1 = rotMat * pt1; + angle = GetAngle(1.0); + cs = cos(angle); sn = sin(angle); + rotMat = mat3( vec3( 1.0, 0.0, 0.0 ), vec3( 0.0, cs, sn ), vec3( 0.0, -sn, cs ) ); + pt2 = rotMat * pt2; + vec4 nrm = vec4( cross(pt1-pt0, pt2-pt0), 1.0 ); + v_zNormal = -nrm.z; + } + + gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ; } diff --git a/assets/shaders/linearGradient.frag.glsl b/assets/shaders/linearGradient.frag.glsl index 111dffbd..56a55d86 100755 --- a/assets/shaders/linearGradient.frag.glsl +++ b/assets/shaders/linearGradient.frag.glsl @@ -33,44 +33,44 @@ precision highp float; #endif -uniform vec4 u_color1; -uniform vec4 u_color2; -uniform vec4 u_color3; -uniform vec4 u_color4; -uniform float u_colorStop1; -uniform float u_colorStop2; -uniform float u_colorStop3; -uniform float u_colorStop4; -uniform vec2 u_cos_sin_angle; -//uniform int u_colorCount; // currently using 4 +uniform vec4 u_color1; +uniform vec4 u_color2; +uniform vec4 u_color3; +uniform vec4 u_color4; +uniform float u_colorStop1; +uniform float u_colorStop2; +uniform float u_colorStop3; +uniform float u_colorStop4; +uniform vec2 u_cos_sin_angle; +//uniform int u_colorCount; // currently using 4 -varying vec2 v_uv; +varying vec2 v_uv; void main(void) { - float t = dot(v_uv, u_cos_sin_angle); + float t = dot(v_uv, u_cos_sin_angle); - vec4 color; - if (t < u_colorStop1) - color = u_color1; - else if (t < u_colorStop2) - { - float tLocal = (t - u_colorStop1)/(u_colorStop2 - u_colorStop1); - color = mix(u_color1,u_color2,tLocal); - } - else if (t < u_colorStop3) - { - float tLocal = (t - u_colorStop2)/(u_colorStop3 - u_colorStop2); - color = mix(u_color2,u_color3,tLocal); - } - else if (t < u_colorStop4) - { - float tLocal = (t - u_colorStop3)/(u_colorStop4 - u_colorStop3); - color = mix(u_color3,u_color4,tLocal); - } - else - color = u_color4; + vec4 color; + if (t < u_colorStop1) + color = u_color1; + else if (t < u_colorStop2) + { + float tLocal = (t - u_colorStop1)/(u_colorStop2 - u_colorStop1); + color = mix(u_color1,u_color2,tLocal); + } + else if (t < u_colorStop3) + { + float tLocal = (t - u_colorStop2)/(u_colorStop3 - u_colorStop2); + color = mix(u_color2,u_color3,tLocal); + } + else if (t < u_colorStop4) + { + float tLocal = (t - u_colorStop3)/(u_colorStop4 - u_colorStop3); + color = mix(u_color3,u_color4,tLocal); + } + else + color = u_color4; - gl_FragColor =color; -} + gl_FragColor =color; +} diff --git a/assets/shaders/linearGradient.vert.glsl b/assets/shaders/linearGradient.vert.glsl index 165c2646..fcdc5e96 100755 --- a/assets/shaders/linearGradient.vert.glsl +++ b/assets/shaders/linearGradient.vert.glsl @@ -51,25 +51,25 @@ uniform mat4 u_normalMatrix; uniform mat4 u_projMatrix; uniform mat4 u_worldMatrix; -uniform vec4 u_color1; -uniform vec4 u_color2; -uniform vec4 u_color3; -uniform vec4 u_color4; -uniform float u_colorStop1; -uniform float u_colorStop2; -uniform float u_colorStop3; -uniform float u_colorStop4; -uniform vec2 u_cos_sin_angle; -//uniform int u_colorCount; // currently using 4 +uniform vec4 u_color1; +uniform vec4 u_color2; +uniform vec4 u_color3; +uniform vec4 u_color4; +uniform float u_colorStop1; +uniform float u_colorStop2; +uniform float u_colorStop3; +uniform float u_colorStop4; +uniform vec2 u_cos_sin_angle; +//uniform int u_colorCount; // currently using 4 uniform mat3 u_texTransform; -varying vec2 v_uv; +varying vec2 v_uv; void main(void) { - gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; - //v_uv = texcoord; - vec3 tmp = u_texTransform * vec3( texcoord, 1.0); - v_uv = tmp.xy; + gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; + //v_uv = texcoord; + vec3 tmp = u_texTransform * vec3( texcoord, 1.0); + v_uv = tmp.xy; } diff --git a/assets/shaders/radialGradient.frag.glsl b/assets/shaders/radialGradient.frag.glsl index 1544e457..b78e38bb 100644 --- a/assets/shaders/radialGradient.frag.glsl +++ b/assets/shaders/radialGradient.frag.glsl @@ -32,44 +32,44 @@ POSSIBILITY OF SUCH DAMAGE. precision highp float; #endif -uniform vec4 u_color1; -uniform vec4 u_color2; -uniform vec4 u_color3; -uniform vec4 u_color4; -uniform float u_colorStop1; -uniform float u_colorStop2; -uniform float u_colorStop3; -uniform float u_colorStop4; -uniform vec2 u_cos_sin_angle; -//uniform int u_colorCount; // currently using all 4 - -varying vec2 v_uv; +uniform vec4 u_color1; +uniform vec4 u_color2; +uniform vec4 u_color3; +uniform vec4 u_color4; +uniform float u_colorStop1; +uniform float u_colorStop2; +uniform float u_colorStop3; +uniform float u_colorStop4; +uniform vec2 u_cos_sin_angle; +//uniform int u_colorCount; // currently using all 4 + +varying vec2 v_uv; void main(void) { - vec2 pt = vec2( v_uv.x - 0.5, v_uv.y - 0.5); - float t = sqrt( dot(pt, pt) ); + vec2 pt = vec2( v_uv.x - 0.5, v_uv.y - 0.5); + float t = sqrt( dot(pt, pt) ); - vec4 color; - if (t < u_colorStop1) - color = u_color1; - else if (t < u_colorStop2) - { - float tLocal = (t - u_colorStop1)/(u_colorStop2 - u_colorStop1); - color = mix(u_color1,u_color2,tLocal); - } - else if (t < u_colorStop3) - { - float tLocal = (t - u_colorStop2)/(u_colorStop3 - u_colorStop2); - color = mix(u_color2,u_color3,tLocal); - } - else if (t < u_colorStop4) - { - float tLocal = (t - u_colorStop3)/(u_colorStop4 - u_colorStop3); - color = mix(u_color3,u_color4,tLocal); - } - else - color = u_color4; + vec4 color; + if (t < u_colorStop1) + color = u_color1; + else if (t < u_colorStop2) + { + float tLocal = (t - u_colorStop1)/(u_colorStop2 - u_colorStop1); + color = mix(u_color1,u_color2,tLocal); + } + else if (t < u_colorStop3) + { + float tLocal = (t - u_colorStop2)/(u_colorStop3 - u_colorStop2); + color = mix(u_color2,u_color3,tLocal); + } + else if (t < u_colorStop4) + { + float tLocal = (t - u_colorStop3)/(u_colorStop4 - u_colorStop3); + color = mix(u_color3,u_color4,tLocal); + } + else + color = u_color4; - gl_FragColor = color; + gl_FragColor = color; } diff --git a/assets/shaders/radialGradient.vert.glsl b/assets/shaders/radialGradient.vert.glsl index eea365c6..06f26ae0 100644 --- a/assets/shaders/radialGradient.vert.glsl +++ b/assets/shaders/radialGradient.vert.glsl @@ -44,11 +44,11 @@ uniform mat4 u_mvMatrix; uniform mat4 u_projMatrix; uniform mat3 u_texTransform; -varying vec2 v_uv; +varying vec2 v_uv; void main(void) { - gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; - vec3 tmp = u_texTransform * vec3( texcoord, 1.0); - v_uv = tmp.xy; + gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; + vec3 tmp = u_texTransform * vec3( texcoord, 1.0); + v_uv = tmp.xy; } diff --git a/assets/shaders/test_fshader.glsl b/assets/shaders/test_fshader.glsl index d2b3bd40..1fa78e44 100755 --- a/assets/shaders/test_fshader.glsl +++ b/assets/shaders/test_fshader.glsl @@ -40,7 +40,7 @@ uniform vec4 u_light0Amb; // diffuse map uniform sampler2D u_colMap; -// environment map +// environment map uniform sampler2D envMap; // normal map @@ -72,12 +72,12 @@ varying float vDiffuseIntensity; void main() { - vec4 rgba_depth = texture2D(depthMap, vShadowCoord.xy/vShadowCoord.w, -32.0); - const vec4 bit_shift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0); - float dist = vShadowCoord.w/200.0; - float d = dot(rgba_depth, bit_shift); - float shadowCoef = (dist > d + 0.00779) ? (0.6) : (1.0); - + vec4 rgba_depth = texture2D(depthMap, vShadowCoord.xy/vShadowCoord.w, -32.0); + const vec4 bit_shift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0); + float dist = vShadowCoord.w/200.0; + float d = dot(rgba_depth, bit_shift); + float shadowCoef = (dist > d + 0.00779) ? (0.6) : (1.0); + vec4 colMapTexel = vec4(0); if (u_renderGlow <= 0.5) { colMapTexel = vec4(texture2D(u_colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); @@ -120,7 +120,7 @@ void main() vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel)*shadowCoef; if (u_renderGlow <= 0.5) { - diffuse *= u_light0Diff; + diffuse *= u_light0Diff; } vec4 specular = 2.0 * pf * envMapTexel; @@ -138,7 +138,7 @@ void main() vec4 colMapTexel = vec4(texture2D(u_colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); // // normal mapping - vec3 normal = normalize(vNormal.xyz); + vec3 normal = normalize(vNormal.xyz); // vec3 mapNormal = texture2D(u_normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; // mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); // diff --git a/assets/shaders/test_fshader_full.glsl b/assets/shaders/test_fshader_full.glsl index ae7d45b2..5fcc280b 100755 --- a/assets/shaders/test_fshader_full.glsl +++ b/assets/shaders/test_fshader_full.glsl @@ -41,7 +41,7 @@ uniform vec4 u_lightAmb; // diffuse map uniform sampler2D colMap; -// environment map +// environment map uniform sampler2D envMap; // normal map @@ -90,15 +90,15 @@ void main() float pf; if(diffuseIntensity == 0.0) - pf = 0.0; + pf = 0.0; else - pf = pow(specularModifier, 76.0); + pf = pow(specularModifier, 76.0); vec4 ambient = u_matAmbient * u_lightAmb; vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel); if (u_renderGlow <= 0.5) - diffuse *= u_lightDiff * diffuseIntensity * attenuation; + diffuse *= u_lightDiff * diffuseIntensity * attenuation; vec4 specular = 2.0 * pf * envMapTexel; diff --git a/assets/shaders/test_vshader.glsl b/assets/shaders/test_vshader.glsl index 8bf9ee74..69015b78 100755 --- a/assets/shaders/test_vshader.glsl +++ b/assets/shaders/test_vshader.glsl @@ -46,8 +46,8 @@ uniform mat4 u_vShadowLight; uniform vec3 u_lightPos; // varyings -varying vec4 vNormal; // w = texcoord.x -varying vec4 vECPos; // w = texcoord.y +varying vec4 vNormal; // w = texcoord.x +varying vec4 vECPos; // w = texcoord.y varying vec3 vEyePos; varying vec4 vShadowCoord; varying vec2 vEnvTexCoord; @@ -56,18 +56,18 @@ varying float vDiffuseIntensity; #ifdef PC void main() { - vNormal.w = texcoord.x; - vECPos.w = texcoord.y; + vNormal.w = texcoord.x; + vECPos.w = texcoord.y; vEyePos = u_eye; -// position normals and vert - vECPos.xyz = (u_mvMatrix*vec4(vert, 1.0)).xyz; - vNormal.xyz = (u_normalMatrix*vec4(normal, 0.0)).xyz; +// position normals and vert + vECPos.xyz = (u_mvMatrix*vec4(vert, 1.0)).xyz; + vNormal.xyz = (u_normalMatrix*vec4(normal, 0.0)).xyz; -// pass along the geo - gl_Position = u_projMatrix * vec4(vECPos.xyz, 1.0); - - mat4 shadowMat = u_shadowBiasMatrix*u_projMatrix*u_vShadowLight*u_worldMatrix; +// pass along the geo + gl_Position = u_projMatrix * vec4(vECPos.xyz, 1.0); + + mat4 shadowMat = u_shadowBiasMatrix*u_projMatrix*u_vShadowLight*u_worldMatrix; vShadowCoord = shadowMat * vec4(vert, 1.0); } #endif @@ -76,31 +76,31 @@ void main() void main() { - vNormal.w = texcoord.x; - vECPos.w = texcoord.y; + vNormal.w = texcoord.x; + vECPos.w = texcoord.y; vEyePos = u_eye; -// position normals and vert - vECPos.xyz = (u_mvMatrix*vec4(vert, 1.0)).xyz; - vNormal.xyz = (u_normalMatrix*vec4(normal, 0.0)).xyz; +// position normals and vert + vECPos.xyz = (u_mvMatrix*vec4(vert, 1.0)).xyz; + vNormal.xyz = (u_normalMatrix*vec4(normal, 0.0)).xyz; -// pass along the geo - gl_Position = u_projMatrix * vec4(vECPos.xyz, 1.0); - - //mat4 shadowMat = u_shadowBiasMatrix*u_projMatrix*u_vShadowLight*u_worldMatrix; +// pass along the geo + gl_Position = u_projMatrix * vec4(vECPos.xyz, 1.0); + + //mat4 shadowMat = u_shadowBiasMatrix*u_projMatrix*u_vShadowLight*u_worldMatrix; //vShadowCoord = shadowMat * vec4(vert, 1.0); // normal mapping - vec3 normal = normalize(vNormal.xyz); - - // create envmap coordinates - vec3 r = reflect( vec3(vECPos.xyz - u_eye.xyz), normal); - float m = 2.0 * length(r); - vEnvTexCoord = vec2(r.x/m + 0.5, r.y/m + 0.5); - - vec3 lightDirection = normalize(u_lightPos - vECPos.xyz); - vDiffuseIntensity = max(0.0, dot(normal, lightDirection)); - + vec3 normal = normalize(vNormal.xyz); + + // create envmap coordinates + vec3 r = reflect( vec3(vECPos.xyz - u_eye.xyz), normal); + float m = 2.0 * length(r); + vEnvTexCoord = vec2(r.x/m + 0.5, r.y/m + 0.5); + + vec3 lightDirection = normalize(u_lightPos - vECPos.xyz); + vDiffuseIntensity = max(0.0, dot(normal, lightDirection)); + } #endif diff --git a/assets/shaders/ub_fshader.glsl b/assets/shaders/ub_fshader.glsl index e4e0e2d3..840a97b6 100755 --- a/assets/shaders/ub_fshader.glsl +++ b/assets/shaders/ub_fshader.glsl @@ -30,257 +30,257 @@ POSSIBILITY OF SUCH DAMAGE. // defines #if defined( GL_ES ) - precision highp float; + precision highp float; #endif uniform mat4 u_viewMatrix; #if defined( MATERIAL ) - uniform vec4 u_ambientColor; - uniform vec4 u_diffuseColor; - uniform vec4 u_specularColor; - uniform float u_specularPower; + uniform vec4 u_ambientColor; + uniform vec4 u_diffuseColor; + uniform vec4 u_specularColor; + uniform float u_specularPower; #endif #if defined( LIGHTING ) - varying vec3 v_normal; - #if defined( LIGHT_0 ) -// uniform int u_light0Type; - uniform vec3 u_light0Pos; - uniform vec3 u_light0Dir; - uniform vec3 u_light0Atten; - uniform vec2 u_light0Spot; - uniform vec4 u_light0Color; - uniform vec4 u_light0Specular; - varying vec3 v_light0Dir; - varying vec3 v_light0SpotDir; - #endif + varying vec3 v_normal; + #if defined( LIGHT_0 ) +// uniform int u_light0Type; + uniform vec3 u_light0Pos; + uniform vec3 u_light0Dir; + uniform vec3 u_light0Atten; + uniform vec2 u_light0Spot; + uniform vec4 u_light0Color; + uniform vec4 u_light0Specular; + varying vec3 v_light0Dir; + varying vec3 v_light0SpotDir; + #endif - #if defined( LIGHT_1 ) -// uniform int u_light1Type; - uniform vec3 u_light1Pos; - uniform vec3 u_light1Dir; - uniform vec3 u_light1Atten; - uniform vec2 u_light1Spot; - uniform vec4 u_light1Color; - uniform vec4 u_light1Specular; - varying vec3 v_light1Dir; - varying vec3 v_light1SpotDir; - #endif + #if defined( LIGHT_1 ) +// uniform int u_light1Type; + uniform vec3 u_light1Pos; + uniform vec3 u_light1Dir; + uniform vec3 u_light1Atten; + uniform vec2 u_light1Spot; + uniform vec4 u_light1Color; + uniform vec4 u_light1Specular; + varying vec3 v_light1Dir; + varying vec3 v_light1SpotDir; + #endif - #if defined( LIGHT_2 ) -// uniform int u_light2Type; - uniform vec3 u_light2Pos; - uniform vec3 u_light2Dir; - uniform vec3 u_light2Atten; - uniform vec2 u_light2Spot; - uniform vec4 u_light2Color; - uniform vec4 u_light2Specular; - varying vec3 v_light2Dir; - varying vec3 v_light2SpotDir; - #endif + #if defined( LIGHT_2 ) +// uniform int u_light2Type; + uniform vec3 u_light2Pos; + uniform vec3 u_light2Dir; + uniform vec3 u_light2Atten; + uniform vec2 u_light2Spot; + uniform vec4 u_light2Color; + uniform vec4 u_light2Specular; + varying vec3 v_light2Dir; + varying vec3 v_light2SpotDir; + #endif - #if defined( LIGHT_3 ) -// uniform int u_light3Type; - uniform vec3 u_light3Pos; - uniform vec3 u_light3Dir; - uniform vec3 u_light3Atten; - uniform vec2 u_light3Spot; - uniform vec4 u_light3Color; - uniform vec4 u_light3Specular; - varying vec3 v_light3Dir; - varying vec3 v_light3SpotDir; - #endif + #if defined( LIGHT_3 ) +// uniform int u_light3Type; + uniform vec3 u_light3Pos; + uniform vec3 u_light3Dir; + uniform vec3 u_light3Atten; + uniform vec2 u_light3Spot; + uniform vec4 u_light3Color; + uniform vec4 u_light3Specular; + varying vec3 v_light3Dir; + varying vec3 v_light3SpotDir; + #endif #endif #if defined( ENVIRONMENT_MAP ) - uniform float u_envReflection; + uniform float u_envReflection; #endif uniform vec3 u_eye; -uniform sampler2D s_diffuseMap; -uniform sampler2D s_normalMap; -uniform sampler2D s_envMap; -uniform sampler2D s_specMap; +uniform sampler2D s_diffuseMap; +uniform sampler2D s_normalMap; +uniform sampler2D s_envMap; +uniform sampler2D s_specMap; varying vec3 v_mvPos; varying vec3 v_eyeDir; varying vec2 v_texcoord; void main() { - // these are the four principle color elements making up the final fragment equation. - vec4 a = vec4(0.0,0.0,0.0,0.0); // ambient contribution - vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution - vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution - vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution - + // these are the four principle color elements making up the final fragment equation. + vec4 a = vec4(0.0,0.0,0.0,0.0); // ambient contribution + vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution + vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution + vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution + #if defined( MATERIAL ) - a += u_ambientColor; - d += u_diffuseColor; + a += u_ambientColor; + d += u_diffuseColor; #endif #if defined( DIFFUSE_MAP ) - d *= texture2D(s_diffuseMap, v_texcoord); + d *= texture2D(s_diffuseMap, v_texcoord); #endif #if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) - vec3 normal = normalize( v_normal ); + vec3 normal = normalize( v_normal ); #endif - + #if defined( LIGHTING ) - #if defined( NORMAL_MAP ) - vec4 normalMap = texture2D(s_normalMap, v_texcoord); - normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 ); - normal = normalize(normalMap.x*vec3(normal.z, 0.0, normal.x) + vec3(0.0, normalMap.y, 0.0) + normalMap.z*normal); - #endif // NORMAL_MAP + #if defined( NORMAL_MAP ) + vec4 normalMap = texture2D(s_normalMap, v_texcoord); + normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 ); + normal = normalize(normalMap.x*vec3(normal.z, 0.0, normal.x) + vec3(0.0, normalMap.y, 0.0) + normalMap.z*normal); + #endif // NORMAL_MAP - #if defined( LIGHT_0 ) - { - // diffuse lighting - float ldist = length( v_light0Dir.xyz ); - vec3 ldir = v_light0Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_0 > 0 ) - atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); - #if (LIGHT_0 == 2) - float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light0Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light0Color; + #if defined( LIGHT_0 ) + { + // diffuse lighting + float ldist = length( v_light0Dir.xyz ); + vec3 ldir = v_light0Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_0 > 0 ) + atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); + #if (LIGHT_0 == 2) + float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light0Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light0Color; - #if defined( LIGHT_0_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light0Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light0Specular); - #endif - } - #endif // LIGHT_0 - - #if defined( LIGHT_1 ) - { - // diffuse lighting - float ldist = length( v_light1Dir.xyz ); - vec3 ldir = v_light1Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_1 > 0 ) - atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) ); - #if (LIGHT_1 == 2) - float spotAngle = dot( ldir, normalize( v_light1SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light1Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light1Color; + #if defined( LIGHT_0_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light0Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light0Specular); + #endif + } + #endif // LIGHT_0 + + #if defined( LIGHT_1 ) + { + // diffuse lighting + float ldist = length( v_light1Dir.xyz ); + vec3 ldir = v_light1Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_1 > 0 ) + atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) ); + #if (LIGHT_1 == 2) + float spotAngle = dot( ldir, normalize( v_light1SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light1Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light1Color; - #if defined( LIGHT_1_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light1Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light1Specular); - #endif - } - #endif // LIGHT_1 - - #if defined( LIGHT_2 ) - { - // diffuse lighting - float ldist = length( v_light2Dir.xyz ); - vec3 ldir = v_light2Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_2 > 0 ) - atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) ); - #if (LIGHT_2 == 2) - float spotAngle = dot( ldir, normalize( v_light2SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light2Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light2Color; + #if defined( LIGHT_1_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light1Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light1Specular); + #endif + } + #endif // LIGHT_1 + + #if defined( LIGHT_2 ) + { + // diffuse lighting + float ldist = length( v_light2Dir.xyz ); + vec3 ldir = v_light2Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_2 > 0 ) + atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) ); + #if (LIGHT_2 == 2) + float spotAngle = dot( ldir, normalize( v_light2SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light2Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light2Color; - #if defined( LIGHT_2_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light2Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular); - #endif - } - #endif // LIGHT_2 - - #if defined( LIGHT_3 ) - { - // diffuse lighting - float ldist = length( v_light3Dir.xyz ); - vec3 ldir = v_light3Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_3 > 0 ) - atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) ); - #if (LIGHT_3 == 2) - float spotAngle = dot( ldir, normalize( v_light3SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light3Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light3Spot.y ) / ( u_light3Spot.x - u_light3Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light3Color; + #if defined( LIGHT_2_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light2Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular); + #endif + } + #endif // LIGHT_2 + + #if defined( LIGHT_3 ) + { + // diffuse lighting + float ldist = length( v_light3Dir.xyz ); + vec3 ldir = v_light3Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_3 > 0 ) + atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) ); + #if (LIGHT_3 == 2) + float spotAngle = dot( ldir, normalize( v_light3SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light3Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light3Spot.y ) / ( u_light3Spot.x - u_light3Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light3Color; - #if defined( LIGHT_3_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light3Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light3Specular); - #endif - } - #endif // LIGHT_3 + #if defined( LIGHT_3_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light3Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light3Specular); + #endif + } + #endif // LIGHT_3 #endif // LIGHTING #if defined( SPECULAR ) && defined( SPECULAR_MAP ) - vec4 specMapColor = texture2D(s_specMap, v_texcoord); - s *= specMapColor; + vec4 specMapColor = texture2D(s_specMap, v_texcoord); + s *= specMapColor; #endif #if defined( ENVIRONMENT_MAP ) - vec3 r = reflect( normalize( vec3(0.0,0.0,1.0) ), normal ); - float m = 2.0 * length(r); - vec4 envMapColor = texture2D(s_envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)) * u_envReflection; - - #if defined( GLOSS_MAP ) - // this is an option to modulate the alpha channel of the specular map with the environment - // map (i.e. - gloss mapping). - envMapColor *= specMapColor.a; - #endif - - s += envMapColor; + vec3 r = reflect( normalize( vec3(0.0,0.0,1.0) ), normal ); + float m = 2.0 * length(r); + vec4 envMapColor = texture2D(s_envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)) * u_envReflection; + + #if defined( GLOSS_MAP ) + // this is an option to modulate the alpha channel of the specular map with the environment + // map (i.e. - gloss mapping). + envMapColor *= specMapColor.a; + #endif + + s += envMapColor; #endif gl_FragColor = ( a + l ) * d + s; diff --git a/assets/shaders/ub_vshader.glsl b/assets/shaders/ub_vshader.glsl index a559d844..da8a8660 100755 --- a/assets/shaders/ub_vshader.glsl +++ b/assets/shaders/ub_vshader.glsl @@ -44,65 +44,65 @@ uniform vec3 u_eye; // attributes #if defined( MATERIAL ) - uniform vec4 u_ambientColor; - uniform vec4 u_diffuseColor; - uniform vec4 u_specularColor; - uniform float u_specularPower; + uniform vec4 u_ambientColor; + uniform vec4 u_diffuseColor; + uniform vec4 u_specularColor; + uniform float u_specularPower; #endif #if defined( LIGHTING ) - varying vec3 v_normal; - #if defined( LIGHT_0 ) - uniform int u_light0Type; - uniform vec3 u_light0Pos; - uniform vec3 u_light0Dir; - uniform vec3 u_light0Atten; - uniform vec2 u_light0Spot; - uniform vec4 u_light0Color; - uniform vec4 u_light0Specular; - varying vec3 v_light0Dir; - varying vec3 v_light0SpotDir; - #endif - - #if defined( LIGHT_1 ) - uniform int u_light1Type; - uniform vec3 u_light1Pos; - uniform vec3 u_light1Dir; - uniform vec3 u_light1Atten; - uniform vec2 u_light1Spot; - uniform vec3 u_light1Color; - uniform vec4 u_light1Specular; - varying vec3 v_light1Dir; - varying vec3 v_light1SpotDir; - #endif - - #if defined( LIGHT_2 ) - uniform int u_light2Type; // 0 - dir, 1 - point, 2 - spot - uniform vec3 u_light2Pos; - uniform vec3 u_light2Dir; - uniform vec3 u_light2Atten; - uniform vec2 u_light2Spot; // 0 - spot light cutoff angle, 1 - spot light exponent - uniform vec3 u_light2Color; - uniform vec4 u_light2Specular; - varying vec3 v_light2Dir; - varying vec3 v_light2SpotDir; - #endif - - #if defined( LIGHT_3 ) - uniform int u_light3Type; - uniform vec3 u_light3Pos; - uniform vec3 u_light3Dir; - uniform vec3 u_light3Atten; - uniform vec2 u_light3Spot; - uniform vec3 u_light3Color; - uniform vec4 u_light3Specular; - varying vec3 v_light3Dir; - varying vec3 v_light3SpotDir; - #endif + varying vec3 v_normal; + #if defined( LIGHT_0 ) + uniform int u_light0Type; + uniform vec3 u_light0Pos; + uniform vec3 u_light0Dir; + uniform vec3 u_light0Atten; + uniform vec2 u_light0Spot; + uniform vec4 u_light0Color; + uniform vec4 u_light0Specular; + varying vec3 v_light0Dir; + varying vec3 v_light0SpotDir; + #endif + + #if defined( LIGHT_1 ) + uniform int u_light1Type; + uniform vec3 u_light1Pos; + uniform vec3 u_light1Dir; + uniform vec3 u_light1Atten; + uniform vec2 u_light1Spot; + uniform vec3 u_light1Color; + uniform vec4 u_light1Specular; + varying vec3 v_light1Dir; + varying vec3 v_light1SpotDir; + #endif + + #if defined( LIGHT_2 ) + uniform int u_light2Type; // 0 - dir, 1 - point, 2 - spot + uniform vec3 u_light2Pos; + uniform vec3 u_light2Dir; + uniform vec3 u_light2Atten; + uniform vec2 u_light2Spot; // 0 - spot light cutoff angle, 1 - spot light exponent + uniform vec3 u_light2Color; + uniform vec4 u_light2Specular; + varying vec3 v_light2Dir; + varying vec3 v_light2SpotDir; + #endif + + #if defined( LIGHT_3 ) + uniform int u_light3Type; + uniform vec3 u_light3Pos; + uniform vec3 u_light3Dir; + uniform vec3 u_light3Atten; + uniform vec2 u_light3Spot; + uniform vec3 u_light3Color; + uniform vec4 u_light3Specular; + varying vec3 v_light3Dir; + varying vec3 v_light3SpotDir; + #endif #endif #if defined( ENVIRONMENT_MAP ) - uniform float u_envReflection; + uniform float u_envReflection; #endif varying vec3 v_mvPos; @@ -111,76 +111,76 @@ varying vec2 v_texcoord; #if defined( PC ) void main() { - // position normals and vert - v_mvPos = ( u_mvMatrix * vec4( a_pos, 1.0 ) ).xyz; + // position normals and vert + v_mvPos = ( u_mvMatrix * vec4( a_pos, 1.0 ) ).xyz; - v_texcoord = (u_uvMatrix * vec4(a_texcoord, 0, 1.0)).xy; + v_texcoord = (u_uvMatrix * vec4(a_texcoord, 0, 1.0)).xy; #if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAP ) ) - v_normal = ( u_normalMatrix * vec4( a_normal, 0.0 ) ).xyz; + v_normal = ( u_normalMatrix * vec4( a_normal, 0.0 ) ).xyz; #endif #if defined( LIGHTING ) - v_eyeDir = vec3(-u_viewMatrix[3][0], -u_viewMatrix[3][1], -u_viewMatrix[3][2]); - #if defined( LIGHT_0 ) - { - vec3 lpos = ( u_viewMatrix * vec4( u_light0Pos, 1.0 ) ).xyz; - - #if ( LIGHT_0 == 0 ) - v_light0Dir = ( u_viewMatrix * vec4( -u_light0Dir, 0.0 ) ).xyz; - #else - v_light0Dir = lpos - v_mvPos; - #if ( LIGHT_0 == 2 ) - v_light0SpotDir = (u_viewMatrix * vec4( -u_light0Dir, 0.0 )).xyz; - #endif // ( LIGHT_0 == 2 ) - #endif // ( LIGHT_0 == 0 ) - } - #endif // defined( LIGHT_0 ) - #if defined( LIGHT_1 ) - { - vec3 lpos = ( u_viewMatrix * vec4( u_light1Pos, 1.0 ) ).xyz; - - #if ( LIGHT_1 == 0 ) - v_light1Dir = ( u_viewMatrix * vec4( -u_light1Dir, 0.0 ) ).xyz; - #else - v_light1Dir = lpos - v_mvPos; - #if ( LIGHT_1 == 2 ) - v_light1SpotDir = (u_viewMatrix * vec4( -u_light1Dir, 0.0 )).xyz; - #endif // ( LIGHT_1 == 2 ) - #endif // ( LIGHT_1 == 0 ) - } - #endif // defined( LIGHT_1 ) - #if defined( LIGHT_2 ) - { - vec3 lpos = ( u_viewMatrix * vec4( u_light2Pos, 1.0 ) ).xyz; - - #if ( LIGHT_2 == 0 ) - v_light2Dir = ( u_viewMatrix * vec4( -u_light2Dir, 0.0 ) ).xyz; - #else - v_light2Dir = lpos - v_mvPos; - #if ( LIGHT_2 == 2 ) - v_light2SpotDir = (u_viewMatrix * vec4( -u_light2Dir, 0.0 )).xyz; - #endif // ( LIGHT_2 == 2 ) - #endif // ( LIGHT_2 == 0 ) - } - #endif // defined( LIGHT_2 ) - #if defined( LIGHT_3 ) - { - vec3 lpos = ( u_viewMatrix * vec4( u_light3Pos, 1.0 ) ).xyz; - - #if ( LIGHT_3 == 0 ) - v_light3Dir = ( u_viewMatrix * vec4( -u_light3Dir, 0.0 ) ).xyz; - #else - v_light3Dir = lpos - v_mvPos; - #if ( LIGHT_3 == 2 ) - v_light3SpotDir = (u_viewMatrix * vec4( -u_light3Dir, 0.0 )).xyz; - #endif // ( LIGHT_3 == 2 ) - #endif // ( LIGHT_3 == 0 ) - } - #endif // defined( LIGHT_3 ) + v_eyeDir = vec3(-u_viewMatrix[3][0], -u_viewMatrix[3][1], -u_viewMatrix[3][2]); + #if defined( LIGHT_0 ) + { + vec3 lpos = ( u_viewMatrix * vec4( u_light0Pos, 1.0 ) ).xyz; + + #if ( LIGHT_0 == 0 ) + v_light0Dir = ( u_viewMatrix * vec4( -u_light0Dir, 0.0 ) ).xyz; + #else + v_light0Dir = lpos - v_mvPos; + #if ( LIGHT_0 == 2 ) + v_light0SpotDir = (u_viewMatrix * vec4( -u_light0Dir, 0.0 )).xyz; + #endif // ( LIGHT_0 == 2 ) + #endif // ( LIGHT_0 == 0 ) + } + #endif // defined( LIGHT_0 ) + #if defined( LIGHT_1 ) + { + vec3 lpos = ( u_viewMatrix * vec4( u_light1Pos, 1.0 ) ).xyz; + + #if ( LIGHT_1 == 0 ) + v_light1Dir = ( u_viewMatrix * vec4( -u_light1Dir, 0.0 ) ).xyz; + #else + v_light1Dir = lpos - v_mvPos; + #if ( LIGHT_1 == 2 ) + v_light1SpotDir = (u_viewMatrix * vec4( -u_light1Dir, 0.0 )).xyz; + #endif // ( LIGHT_1 == 2 ) + #endif // ( LIGHT_1 == 0 ) + } + #endif // defined( LIGHT_1 ) + #if defined( LIGHT_2 ) + { + vec3 lpos = ( u_viewMatrix * vec4( u_light2Pos, 1.0 ) ).xyz; + + #if ( LIGHT_2 == 0 ) + v_light2Dir = ( u_viewMatrix * vec4( -u_light2Dir, 0.0 ) ).xyz; + #else + v_light2Dir = lpos - v_mvPos; + #if ( LIGHT_2 == 2 ) + v_light2SpotDir = (u_viewMatrix * vec4( -u_light2Dir, 0.0 )).xyz; + #endif // ( LIGHT_2 == 2 ) + #endif // ( LIGHT_2 == 0 ) + } + #endif // defined( LIGHT_2 ) + #if defined( LIGHT_3 ) + { + vec3 lpos = ( u_viewMatrix * vec4( u_light3Pos, 1.0 ) ).xyz; + + #if ( LIGHT_3 == 0 ) + v_light3Dir = ( u_viewMatrix * vec4( -u_light3Dir, 0.0 ) ).xyz; + #else + v_light3Dir = lpos - v_mvPos; + #if ( LIGHT_3 == 2 ) + v_light3SpotDir = (u_viewMatrix * vec4( -u_light3Dir, 0.0 )).xyz; + #endif // ( LIGHT_3 == 2 ) + #endif // ( LIGHT_3 == 0 ) + } + #endif // defined( LIGHT_3 ) #endif // defined( LIGHTING ) - // pass along the geo - gl_Position = u_projMatrix * vec4(v_mvPos, 1.0); + // pass along the geo + gl_Position = u_projMatrix * vec4(v_mvPos, 1.0); } #endif -- cgit v1.2.3