diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-01-27 13:10:44 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-01-27 13:13:58 +0200 |
commit | b368e57e59351736f9ad06834a743a7c1b49d368 (patch) | |
tree | 3b7d42569905d8cde0ca7571cd664428354a50dd /src/datavisualization/engine/shaders/shadow.frag | |
parent | eb3d0514ca886db33776522ea00f27b69bc86ad1 (diff) | |
parent | 05d06fbc61f07e400b519a9b020c2473398627c1 (diff) |
Merge branch 'develop'v1.0.0-beta1
Change-Id: I1c9a255eb8f30a24b665856d3711f0abe77c6ef4
Diffstat (limited to 'src/datavisualization/engine/shaders/shadow.frag')
-rw-r--r-- | src/datavisualization/engine/shaders/shadow.frag | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/src/datavisualization/engine/shaders/shadow.frag b/src/datavisualization/engine/shaders/shadow.frag index 5309b5bb..e2286dc5 100644 --- a/src/datavisualization/engine/shaders/shadow.frag +++ b/src/datavisualization/engine/shaders/shadow.frag @@ -5,6 +5,7 @@ uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp sampler2D textureSampler; uniform highp sampler2DShadow shadowMap; +uniform highp vec3 lightColor; varying highp vec4 shadowCoord; varying highp vec2 UV; @@ -30,16 +31,10 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), vec2(0.19984126, 0.78641367), vec2(0.14383161, -0.14100790)); -/*float random(vec3 seed, int i) { - vec4 seed4 = vec4(seed, i); - float dot_product = dot(seed4, vec4(12.9898, 78.233, 45.164, 94.673)); - return fract(sin(dot_product) * 43758.5453); -}*/ - void main() { highp vec3 materialDiffuseColor = texture2D(textureSampler, UV).rgb; - highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; - highp vec3 materialSpecularColor = vec3(0.2, 0.2, 0.2); + highp vec3 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor * 0.2; highp vec3 n = normalize(normal_cmr); highp vec3 l = normalize(lightDirection_cmr); @@ -54,10 +49,7 @@ void main() { vec4 shadCoords = shadowCoord; shadCoords.z -= bias; - // adjust shadow strength by increasing the multiplier and lowering the addition (their sum must be 1) - // direct method; needs large shadow texture to look good - //highp float visibility = 0.75 * shadow2DProj(shadowMap, shadCoords).r + 0.25; - // poisson disk sampling; smoothes edges + highp float visibility = 0.6; for (int i = 0; i < 15; i++) { vec4 shadCoordsPD = shadCoords; @@ -65,18 +57,11 @@ void main() { shadCoordsPD.y += sin(poissonDisk[i].y) / shadowQuality; visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; } - // stratified poisson; produces noise but hides pixel edges well - /*for (int i = 0; i < 15; i++) { - vec4 shadCoordsPD = shadCoords; - int index = int(16.0 * random(gl_FragCoord.xyy, i)); - shadCoordsPD.xy += poissonDisk[index] / 150.0; - visibility += 0.05 * shadow2DProj(shadowMap, shadCoordsPD).r; - } - */ gl_FragColor.rgb = - visibility * (materialAmbientColor + + (materialAmbientColor + materialDiffuseColor * lightStrength * cosTheta + materialSpecularColor * lightStrength * pow(cosAlpha, 10)); gl_FragColor.a = texture2D(textureSampler, UV).a; + gl_FragColor.rgb = visibility * clamp(gl_FragColor.rgb, 0.0, 1.0); } |