diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-09-10 11:42:13 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-09-10 12:04:24 +0300 |
commit | a28cdb72a4ea768a898ca07f0df0fa3c17c073a8 (patch) | |
tree | 0bafdcfa99fc783e9f5204539a8242bf6128d795 /src/datavisualization/engine/shaders/surface.frag | |
parent | f3e38983d77c72f3121c33a149a58fdf9c64158c (diff) |
Module renamed
Task-number: QTRD-2224
Change-Id: Iec18b6121809300b11d85445281d3c626c434f35
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization/engine/shaders/surface.frag')
-rw-r--r-- | src/datavisualization/engine/shaders/surface.frag | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/datavisualization/engine/shaders/surface.frag b/src/datavisualization/engine/shaders/surface.frag new file mode 100644 index 00000000..9fe7f45b --- /dev/null +++ b/src/datavisualization/engine/shaders/surface.frag @@ -0,0 +1,39 @@ +#version 120 + +varying highp vec2 UV; +varying highp vec3 coords_mdl; +varying highp vec3 position_wrld; +varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; + +uniform sampler2D textureSampler; +uniform highp vec3 lightPosition_wrld; +uniform highp float lightStrength; +uniform highp float ambientStrength; + +void main() { + highp vec2 gradientUV = vec2(0.5, (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 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 = materialDiffuseColor; + gl_FragColor.rgb = + materialAmbientColor + + materialDiffuseColor * lightStrength * pow(cosTheta, 2) / distance + + materialSpecularColor * lightStrength * pow(cosAlpha, 10) / distance; + gl_FragColor.a = 1.0; +// gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +} + |