diff options
Diffstat (limited to 'src/datavisualization/engine/shaders')
19 files changed, 174 insertions, 180 deletions
diff --git a/src/datavisualization/engine/shaders/ambient.frag b/src/datavisualization/engine/shaders/ambient.frag deleted file mode 100644 index 88f850f3..00000000 --- a/src/datavisualization/engine/shaders/ambient.frag +++ /dev/null @@ -1,32 +0,0 @@ -#version 120 - -uniform highp vec3 lightPosition_wrld; -uniform highp vec3 color_mdl; - -varying highp vec3 position_wrld; -varying highp vec3 normal_cmr; -varying highp vec3 eyeDirection_cmr; -varying highp vec3 lightDirection_cmr; - -void main() { - highp vec3 lightColor = vec3(1.0, 1.0, 1.0); - highp float lightPower = 10.0; - highp vec3 materialAmbientColor = vec3(0.5, 0.5, 0.5) * color_mdl; - highp vec3 materialSpecularColor = vec3(0.3, 0.3, 0.3) * color_mdl; - - highp float distance = length(lightPosition_wrld - position_wrld); - - highp vec3 n = normalize(normal_cmr); - highp vec3 l = normalize(lightDirection_cmr); - highp float cosTheta = clamp(dot(n, l), 0.0, 1.0); - - highp vec3 E = normalize(eyeDirection_cmr); - highp vec3 R = reflect(-l, n); - highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); - - gl_FragColor.rgb = - materialAmbientColor + - materialSpecularColor * lightColor * lightPower * pow(cosAlpha, 5) / (distance * distance); - gl_FragColor.a = 1.0; -} - diff --git a/src/datavisualization/engine/shaders/colorOnY.frag b/src/datavisualization/engine/shaders/colorOnY.frag index 80e54a61..caea959b 100644 --- a/src/datavisualization/engine/shaders/colorOnY.frag +++ b/src/datavisualization/engine/shaders/colorOnY.frag @@ -1,9 +1,11 @@ #version 120 uniform highp vec3 lightPosition_wrld; -uniform highp vec3 color_mdl; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform sampler2D textureSampler; +uniform highp float gradMin; +uniform highp float gradHeight; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; @@ -12,8 +14,8 @@ varying highp vec3 lightDirection_cmr; varying highp vec2 coords_mdl; void main() { - highp float heightMod = (coords_mdl.y * 0.3) + 0.7; // Add 30% black to the bottom - highp vec3 materialDiffuseColor = heightMod * color_mdl; + highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/colorOnY_ES2.frag b/src/datavisualization/engine/shaders/colorOnY_ES2.frag index aba52cfe..bb6e28c7 100644 --- a/src/datavisualization/engine/shaders/colorOnY_ES2.frag +++ b/src/datavisualization/engine/shaders/colorOnY_ES2.frag @@ -1,7 +1,9 @@ uniform highp vec3 lightPosition_wrld; -uniform highp vec3 color_mdl; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform sampler2D textureSampler; +uniform highp float gradMin; +uniform highp float gradHeight; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; @@ -10,8 +12,8 @@ varying highp vec3 lightDirection_cmr; varying highp vec2 coords_mdl; void main() { - highp float heightMod = (coords_mdl.y * 0.3) + 0.7; // Add 30% black to the bottom - highp vec3 materialDiffuseColor = heightMod * color_mdl; + highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/default.vert b/src/datavisualization/engine/shaders/default.vert index 14f77773..efb40862 100644 --- a/src/datavisualization/engine/shaders/default.vert +++ b/src/datavisualization/engine/shaders/default.vert @@ -1,5 +1,3 @@ -#version 120 - attribute highp vec3 vertexPosition_mdl; attribute highp vec2 vertexUV; attribute highp vec3 vertexNormal_mdl; diff --git a/src/datavisualization/engine/shaders/default_ES2.vert b/src/datavisualization/engine/shaders/default_ES2.vert deleted file mode 100644 index efb40862..00000000 --- a/src/datavisualization/engine/shaders/default_ES2.vert +++ /dev/null @@ -1,26 +0,0 @@ -attribute highp vec3 vertexPosition_mdl; -attribute highp vec2 vertexUV; -attribute highp vec3 vertexNormal_mdl; - -uniform highp mat4 MVP; -uniform highp mat4 V; -uniform highp mat4 M; -uniform highp mat4 itM; -uniform highp vec3 lightPosition_wrld; - -varying highp vec3 position_wrld; -varying highp vec3 normal_cmr; -varying highp vec3 eyeDirection_cmr; -varying highp vec3 lightDirection_cmr; -varying highp vec2 coords_mdl; - -void main() { - gl_Position = MVP * vec4(vertexPosition_mdl, 1.0); - coords_mdl = vertexPosition_mdl.xy; - position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz; - vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz; - eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr; - vec3 lightPosition_cmr = (V * vec4(lightPosition_wrld, 1.0)).xyz; - lightDirection_cmr = lightPosition_cmr + eyeDirection_cmr; - normal_cmr = (V * itM * vec4(vertexNormal_mdl, 0.0)).xyz; -} diff --git a/src/datavisualization/engine/shaders/selection.frag b/src/datavisualization/engine/shaders/plainColor.frag index 099c87a1..099c87a1 100644 --- a/src/datavisualization/engine/shaders/selection.frag +++ b/src/datavisualization/engine/shaders/plainColor.frag diff --git a/src/datavisualization/engine/shaders/selection.vert b/src/datavisualization/engine/shaders/plainColor.vert index 64d17e15..64d17e15 100644 --- a/src/datavisualization/engine/shaders/selection.vert +++ b/src/datavisualization/engine/shaders/plainColor.vert diff --git a/src/datavisualization/engine/shaders/surfaceGrid.vert b/src/datavisualization/engine/shaders/point_ES2.vert index 5582d633..b2dfdd7b 100644 --- a/src/datavisualization/engine/shaders/surfaceGrid.vert +++ b/src/datavisualization/engine/shaders/point_ES2.vert @@ -1,6 +1,8 @@ -attribute highp vec3 vertexPosition_mdl; uniform highp mat4 MVP; +attribute highp vec3 vertexPosition_mdl; + void main() { + gl_PointSize = 5.0; gl_Position = MVP * vec4(vertexPosition_mdl, 1.0); } diff --git a/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag b/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag index 68ba2368..9882cd92 100644 --- a/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag +++ b/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag @@ -3,8 +3,10 @@ uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; -uniform highp vec3 color_mdl; uniform highp sampler2DShadow shadowMap; +uniform sampler2D textureSampler; +uniform highp float gradMin; +uniform highp float gradHeight; varying highp vec4 shadowCoord; varying highp vec3 position_wrld; @@ -37,8 +39,8 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), }*/ void main() { - highp float heightMod = (coords_mdl.y * 0.3) + 0.7; // Add 30% black to the bottom - highp vec3 materialDiffuseColor = heightMod * color_mdl; + highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/surface.frag b/src/datavisualization/engine/shaders/surface.frag index 4b1357b1..576cc51f 100644 --- a/src/datavisualization/engine/shaders/surface.frag +++ b/src/datavisualization/engine/shaders/surface.frag @@ -1,6 +1,6 @@ #version 120 -varying highp vec3 coords_mdl; +varying highp vec2 coords_mdl; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; @@ -12,7 +12,7 @@ uniform highp float lightStrength; uniform highp float ambientStrength; void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.001) / 2.0); // 1000 pixel texture, we need a margin for 1/1000 rounding error + highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/surfaceFlat.frag b/src/datavisualization/engine/shaders/surfaceFlat.frag index 1f2a3822..fd42a289 100644 --- a/src/datavisualization/engine/shaders/surfaceFlat.frag +++ b/src/datavisualization/engine/shaders/surfaceFlat.frag @@ -14,7 +14,7 @@ uniform highp float lightStrength; uniform highp float ambientStrength; void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.001) / 2.0); // 1000 pixel texture, we need a margin for 1/1000 rounding error + highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/surfaceGrid.frag b/src/datavisualization/engine/shaders/surfaceGrid.frag deleted file mode 100644 index 1658b316..00000000 --- a/src/datavisualization/engine/shaders/surfaceGrid.frag +++ /dev/null @@ -1,6 +0,0 @@ -uniform highp vec3 color_mdl; - -void main() { - gl_FragColor.rgb = color_mdl; -} - diff --git a/src/datavisualization/engine/shaders/surfaceShadowFlat.frag b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag new file mode 100644 index 00000000..6341136e --- /dev/null +++ b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag @@ -0,0 +1,70 @@ +#version 120 + +#extension GL_EXT_gpu_shader4 : require + +varying highp vec3 coords_mdl; +varying highp vec3 position_wrld; +flat varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; + +uniform highp sampler2DShadow shadowMap; +uniform sampler2D textureSampler; +varying highp vec4 shadowCoord; +uniform highp vec3 lightPosition_wrld; +uniform highp float lightStrength; +uniform highp float ambientStrength; +uniform highp float shadowQuality; + +highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), + vec2(0.94558609, -0.76890725), + vec2(-0.094184101, -0.92938870), + vec2(0.34495938, 0.29387760), + vec2(-0.91588581, 0.45771432), + vec2(-0.81544232, -0.87912464), + vec2(-0.38277543, 0.27676845), + vec2(0.97484398, 0.75648379), + vec2(0.44323325, -0.97511554), + vec2(0.53742981, -0.47373420), + vec2(-0.26496911, -0.41893023), + vec2(0.79197514, 0.19090188), + vec2(-0.24188840, 0.99706507), + vec2(-0.81409955, 0.91437590), + vec2(0.19984126, 0.78641367), + vec2(0.14383161, -0.14100790)); + +void main() { + highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; + highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; + highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + + highp vec3 n = normalize(normal_cmr); + highp vec3 l = normalize(lightDirection_cmr); + highp float cosTheta = clamp(dot(n, l), 0.0, 1.0); + + highp vec3 E = normalize(eyeDirection_cmr); + highp vec3 R = reflect(-l, n); + highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); + + highp float bias = 0.005 * tan(acos(cosTheta)); + bias = clamp(bias, 0.0, 0.01); + + vec4 shadCoords = shadowCoord; + shadCoords.z -= bias; + + highp float visibility = 0.6; + for (int i = 0; i < 15; i++) { + vec4 shadCoordsPD = shadCoords; + shadCoordsPD.x += cos(poissonDisk[i].x) / shadowQuality; + shadCoordsPD.y += sin(poissonDisk[i].y) / shadowQuality; + visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; + } + + gl_FragColor.rgb = + visibility * (materialAmbientColor + + materialDiffuseColor * lightStrength * cosTheta + + materialSpecularColor * lightStrength * pow(cosAlpha, 10)); + gl_FragColor.a = 1.0; +} + diff --git a/src/datavisualization/engine/shaders/surface.vert b/src/datavisualization/engine/shaders/surfaceShadowFlat.vert index 28152abc..0a6e967f 100644 --- a/src/datavisualization/engine/shaders/surface.vert +++ b/src/datavisualization/engine/shaders/surfaceShadowFlat.vert @@ -1,3 +1,7 @@ +#version 120 + +#extension GL_EXT_gpu_shader4 : require + attribute highp vec3 vertexPosition_mdl; attribute highp vec3 vertexNormal_mdl; @@ -5,17 +9,25 @@ uniform highp mat4 MVP; uniform highp mat4 V; uniform highp mat4 M; uniform highp mat4 itM; +uniform highp mat4 depthMVP; uniform highp vec3 lightPosition_wrld; varying highp vec3 position_wrld; -varying highp vec3 normal_cmr; +flat varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; varying highp vec3 lightDirection_cmr; +varying highp vec4 shadowCoord; varying highp vec3 coords_mdl; +const highp mat4 bias = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + void main() { gl_Position = MVP * vec4(vertexPosition_mdl, 1.0); coords_mdl = vertexPosition_mdl; + shadowCoord = bias * depthMVP * vec4(vertexPosition_mdl, 1.0); position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz; vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz; eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr; diff --git a/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag new file mode 100644 index 00000000..755be3f1 --- /dev/null +++ b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag @@ -0,0 +1,68 @@ +#version 120 + +varying highp vec2 coords_mdl; +varying highp vec3 position_wrld; +varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; + +uniform highp sampler2DShadow shadowMap; +uniform sampler2D textureSampler; +varying highp vec4 shadowCoord; +uniform highp vec3 lightPosition_wrld; +uniform highp float lightStrength; +uniform highp float ambientStrength; +uniform highp float shadowQuality; + +highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), + vec2(0.94558609, -0.76890725), + vec2(-0.094184101, -0.92938870), + vec2(0.34495938, 0.29387760), + vec2(-0.91588581, 0.45771432), + vec2(-0.81544232, -0.87912464), + vec2(-0.38277543, 0.27676845), + vec2(0.97484398, 0.75648379), + vec2(0.44323325, -0.97511554), + vec2(0.53742981, -0.47373420), + vec2(-0.26496911, -0.41893023), + vec2(0.79197514, 0.19090188), + vec2(-0.24188840, 0.99706507), + vec2(-0.81409955, 0.91437590), + vec2(0.19984126, 0.78641367), + vec2(0.14383161, -0.14100790)); + +void main() { + highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; + highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; + highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + + highp vec3 n = normalize(normal_cmr); + highp vec3 l = normalize(lightDirection_cmr); + highp float cosTheta = clamp(dot(n, l), 0.0, 1.0); + + highp vec3 E = normalize(eyeDirection_cmr); + highp vec3 R = reflect(-l, n); + highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); + + highp float bias = 0.005 * tan(acos(cosTheta)); + bias = clamp(bias, 0.0, 0.01); + + vec4 shadCoords = shadowCoord; + shadCoords.z -= bias; + + highp float visibility = 0.6; + for (int i = 0; i < 15; i++) { + vec4 shadCoordsPD = shadCoords; + shadCoordsPD.x += cos(poissonDisk[i].x) / shadowQuality; + shadCoordsPD.y += sin(poissonDisk[i].y) / shadowQuality; + visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; + } + + gl_FragColor.rgb = + visibility * (materialAmbientColor + + materialDiffuseColor * lightStrength * cosTheta + + materialSpecularColor * lightStrength * pow(cosAlpha, 10)); + gl_FragColor.a = 1.0; +} + diff --git a/src/datavisualization/engine/shaders/surface_ES2.frag b/src/datavisualization/engine/shaders/surface_ES2.frag index 7f40ba4d..c7e75594 100644 --- a/src/datavisualization/engine/shaders/surface_ES2.frag +++ b/src/datavisualization/engine/shaders/surface_ES2.frag @@ -1,5 +1,5 @@ varying highp vec2 UV; -varying highp vec3 coords_mdl; +varying highp vec2 coords_mdl; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; @@ -11,7 +11,7 @@ uniform highp float lightStrength; uniform highp float ambientStrength; void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.001) / 2.0); // ~1000 pixel texture, we need a margin for 1/1000 rounding error + highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/texture.frag b/src/datavisualization/engine/shaders/texture.frag deleted file mode 100644 index a6d7b2eb..00000000 --- a/src/datavisualization/engine/shaders/texture.frag +++ /dev/null @@ -1,35 +0,0 @@ -#version 120 - -uniform highp vec3 lightPosition_wrld; -uniform highp vec3 color_mdl; -uniform highp float lightStrength; -uniform highp float ambientStrength; -uniform sampler2D textureSampler; - -varying highp vec2 UV; -varying highp vec3 position_wrld; -varying highp vec3 normal_cmr; -varying highp vec3 eyeDirection_cmr; -varying highp vec3 lightDirection_cmr; - -void main() { - highp vec3 materialDiffuseColor = texture2D(textureSampler, UV).rgb; - highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; - highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); - - highp float distance = length(lightPosition_wrld - position_wrld); - highp vec3 n = normalize(normal_cmr); - highp vec3 l = normalize(lightDirection_cmr); - highp float cosTheta = clamp(dot(n, l), 0.0, 1.0); - - highp vec3 E = normalize(eyeDirection_cmr); - highp vec3 R = reflect(-l, n); - highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); - - gl_FragColor.rgb = - materialAmbientColor + - materialDiffuseColor * lightStrength * (cosTheta * cosTheta) / distance + - materialSpecularColor * lightStrength * pow(cosAlpha, 10) / distance; - gl_FragColor.a = texture2D(textureSampler, UV).a; -} - diff --git a/src/datavisualization/engine/shaders/texture.vert b/src/datavisualization/engine/shaders/texture.vert deleted file mode 100644 index 01f922e0..00000000 --- a/src/datavisualization/engine/shaders/texture.vert +++ /dev/null @@ -1,26 +0,0 @@ -uniform highp mat4 MVP; -uniform highp mat4 V; -uniform highp mat4 M; -uniform highp mat4 itM; -uniform highp vec3 lightPosition_wrld; - -attribute highp vec3 vertexPosition_mdl; -attribute highp vec2 vertexUV; -attribute highp vec3 vertexNormal_mdl; - -varying highp vec2 UV; -varying highp vec3 position_wrld; -varying highp vec3 normal_cmr; -varying highp vec3 eyeDirection_cmr; -varying highp vec3 lightDirection_cmr; - -void main() { - gl_Position = MVP * vec4(vertexPosition_mdl, 1.0); - position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz; - vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz; - eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr; - vec3 lightPosition_cmr = (V * vec4(lightPosition_wrld, 1.0)).xyz; - lightDirection_cmr = lightPosition_cmr + eyeDirection_cmr; - normal_cmr = (V * itM * vec4(vertexNormal_mdl, 0.0)).xyz; - UV = vertexUV; -} diff --git a/src/datavisualization/engine/shaders/texture_ES2.frag b/src/datavisualization/engine/shaders/texture_ES2.frag deleted file mode 100644 index 58097ba5..00000000 --- a/src/datavisualization/engine/shaders/texture_ES2.frag +++ /dev/null @@ -1,37 +0,0 @@ -uniform highp vec3 lightPosition_wrld; -uniform highp vec3 color_mdl; -uniform highp float lightStrength; -uniform highp float ambientStrength; -uniform sampler2D textureSampler; - -varying highp vec2 UV; -varying highp vec3 position_wrld; -varying highp vec3 normal_cmr; -varying highp vec3 eyeDirection_cmr; -varying highp vec3 lightDirection_cmr; - -void main() { - highp vec3 materialDiffuseColor = texture2D(textureSampler, UV).rgb; - highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; - highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); - - highp float distance = length(lightPosition_wrld - position_wrld); - highp vec3 n = normalize(normal_cmr); - highp vec3 l = normalize(lightDirection_cmr); - highp float cosTheta = dot(n, l); - if (cosTheta < 0.0) cosTheta = 0.0; - else if (cosTheta > 1.0) cosTheta = 1.0; - - highp vec3 E = normalize(eyeDirection_cmr); - highp vec3 R = reflect(-l, n); - highp float cosAlpha = dot(E, R); - if (cosAlpha < 0.0) cosAlpha = 0.0; - else if (cosAlpha > 1.0) cosAlpha = 1.0; - - gl_FragColor.rgb = - materialAmbientColor + - materialDiffuseColor * lightStrength * (cosTheta * cosTheta) / distance + - materialSpecularColor * lightStrength * (cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha) / distance; - gl_FragColor.a = texture2D(textureSampler, UV).a; -} - |