diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-05-21 09:58:28 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-05-21 10:05:47 +0300 |
commit | af20ce683e03ca6c43e80ac7ed6b294d2c2c3f80 (patch) | |
tree | 3a356ad2ff243d1ab34748208d0412304f446283 /src/datavis3d/engine/shaders | |
parent | ea73adef1477e8be3539edcb0523612be786ba8d (diff) |
Lighter shadows and beveled bar
Change-Id: I53c1d930c7f8de0a89c93a3aed3e35e45b9ee44e
Change-Id: I53c1d930c7f8de0a89c93a3aed3e35e45b9ee44e
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavis3d/engine/shaders')
-rw-r--r-- | src/datavis3d/engine/shaders/fragmentShadow | 64 | ||||
-rw-r--r-- | src/datavis3d/engine/shaders/fragmentShadowNoTex | 54 | ||||
-rw-r--r-- | src/datavis3d/engine/shaders/fragmentShadowNoTexColorOnY | 54 |
3 files changed, 9 insertions, 163 deletions
diff --git a/src/datavis3d/engine/shaders/fragmentShadow b/src/datavis3d/engine/shaders/fragmentShadow index 3a6ffc5a..5f3ee665 100644 --- a/src/datavis3d/engine/shaders/fragmentShadow +++ b/src/datavis3d/engine/shaders/fragmentShadow @@ -1,12 +1,10 @@ #version 120 -//#version 130 // use with version 1 uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp sampler2D textureSampler; -uniform highp sampler2DShadow shadowMap; // use with version 2 -//uniform highp sampler2D shadowMap; // use with version 1 +uniform highp sampler2DShadow shadowMap; varying highp vec4 shadowCoord; varying highp vec2 UV; @@ -38,62 +36,6 @@ const highp vec2 poissonDisk[16] = vec2[](vec2(-0.94201624, -0.39906216), return fract(sin(dot_product) * 43758.5453); }*/ -// Version 1: Causes self-shadowing, but shadows are smooth -/*void main() { - float shadowFactor = 1.0; // default to '1' meaning "no shadow" - //float epsilon = 0.01; // increase value to remove little artifacts - vec4 shadCoordsPD = shadowCoord; - shadCoordsPD.z += 0.005; - shadCoordsPD /= shadowCoord.w; - if (shadowCoord.w <= 0.0) { // ignore negative projection - shadowFactor = 1.0; - } else if (shadCoordsPD.x < 0.0 || shadCoordsPD.y < 0.0) { // outside light frustum, ignore - shadowFactor = 1.0; - } else if (shadCoordsPD.x >= 1.0 || shadCoordsPD.y >= 1.0) { // outside light frustum, ignore - shadowFactor = 1.0; - } else { - // This does not work perfectly. It causes self-shadowing, which we should get rid of. - // Requires at least #version 130 - float shadow = 0.0; - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(0, 0)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(-1, 1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(1, 1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(-1, -1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(1, -1)); - shadow *= 0.2; - shadowFactor = shadow; - //float shadow = texture2D(shadowMap, shadCoordsPD.xy).x; - //if (shadow + epsilon < shadCoordsPD.z) { - // shadowFactor = 0.0; - //} - } - // shadow is dark gray, other parts light gray - //gl_FragColor = vec4(0.8, 0.8, 0.8, 1.0) * shadowFactor;// + vec4(0.2, 0.2, 0.2, 1.0); - // simple shadows with no effect from light - //gl_FragColor = texture2D(textureSampler, UV) * shadowFactor; - - // shadows including effects from light - 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 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); - - // Shadow strength can be adjusted by using pow(shadowFactor, strength), but it causes self-shadowing issues that need to be solved - gl_FragColor.rgb = - shadowFactor * (materialAmbientColor + - materialDiffuseColor * lightStrength * cosTheta + - materialSpecularColor * lightStrength * pow(cosAlpha, 10)); - gl_FragColor.a = 1.0; -}*/ - -// Version 2: Shadows are a bit rugged (may be fixed with poisson disk?) void main() { highp vec3 materialDiffuseColor = texture2D(textureSampler, UV).rgb; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; @@ -116,12 +58,12 @@ void main() { // 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.2; + highp float visibility = 0.4; 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.05 * shadow2DProj(shadowMap, shadCoordsPD).r; + visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; } // stratified poisson; produces noise but hides pixel edges well /*for (int i = 0; i < 15; i++) { diff --git a/src/datavis3d/engine/shaders/fragmentShadowNoTex b/src/datavis3d/engine/shaders/fragmentShadowNoTex index a08b6b40..50f900ba 100644 --- a/src/datavis3d/engine/shaders/fragmentShadowNoTex +++ b/src/datavis3d/engine/shaders/fragmentShadowNoTex @@ -1,12 +1,10 @@ #version 120 -//#version 130 // use with version 1 uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp vec3 color_mdl; -uniform highp sampler2DShadow shadowMap; // use with version 2 -//uniform highp sampler2D shadowMap; // use with version 1 +uniform highp sampler2DShadow shadowMap; varying highp vec4 shadowCoord; varying highp vec2 UV; @@ -55,52 +53,6 @@ const highp vec2 poissonDisk[16] = vec2[](vec2(-0.94201624, -0.39906216), return fract(sin(dot_product) * 43758.5453); }*/ -// Version 1: Causes self-shadowing, but shadows are smooth -/*void main() { - float shadowFactor = 1.0; // default to '1' meaning "no shadow" - vec4 shadCoordsPD = shadowCoord; - shadCoordsPD.z += 0.005; - shadCoordsPD /= shadowCoord.w; - if (shadowCoord.w <= 0.0) { // ignore negative projection - shadowFactor = 1.0; - } else if (shadCoordsPD.x < 0.0 || shadCoordsPD.y < 0.0) { // outside light frustum, ignore - shadowFactor = 1.0; - } else if (shadCoordsPD.x >= 1.0 || shadCoordsPD.y >= 1.0) { // outside light frustum, ignore - shadowFactor = 1.0; - } else { - // This does not work perfectly. It causes self-shadowing, which we should get rid of. - // Requires at least #version 130 - float shadow = 0.0; - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(0, 0)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(-1, 1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(1, 1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(-1, -1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(1, -1)); - shadow *= 0.2; - shadowFactor = shadow; - } - - highp vec3 materialDiffuseColor = color_mdl.rgb; - 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); - - // Shadow strength can be adjusted by using pow(shadowFactor, strength), but it causes self-shadowing issues that need to be solved - gl_FragColor.rgb = - shadowFactor * (materialAmbientColor + - materialDiffuseColor * lightStrength * cosTheta + - materialSpecularColor * lightStrength * pow(cosAlpha, 20)); - gl_FragColor.a = 1.0; -}*/ - -// Version 2: Shadows are a bit rugged (may be fixed with poisson disk?) void main() { highp vec3 materialDiffuseColor = color_mdl.rgb; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; @@ -123,12 +75,12 @@ void main() { // 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.2; + highp float visibility = 0.4; 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.05 * shadow2DProj(shadowMap, shadCoordsPD).r; + visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; } // stratified poisson; produces noise but hides pixel edges well /*for (int i = 0; i < 15; i++) { diff --git a/src/datavis3d/engine/shaders/fragmentShadowNoTexColorOnY b/src/datavis3d/engine/shaders/fragmentShadowNoTexColorOnY index d208c5fd..75f0e6d3 100644 --- a/src/datavis3d/engine/shaders/fragmentShadowNoTexColorOnY +++ b/src/datavis3d/engine/shaders/fragmentShadowNoTexColorOnY @@ -1,12 +1,10 @@ #version 120 -//#version 130 // use with version 1 uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp vec3 color_mdl; -uniform highp sampler2DShadow shadowMap; // use with version 2 -//uniform highp sampler2D shadowMap; // use with version 1 +uniform highp sampler2DShadow shadowMap; varying highp vec4 shadowCoord; varying highp vec3 position_wrld; @@ -38,52 +36,6 @@ const highp vec2 poissonDisk[16] = vec2[](vec2(-0.94201624, -0.39906216), return fract(sin(dot_product) * 43758.5453); }*/ -// Version 1: Causes self-shadowing, but shadows are smooth -/*void main() { - float shadowFactor = 1.0; // default to '1' meaning "no shadow" - vec4 shadCoordsPD = shadowCoord; - shadCoordsPD.z += 0.005; - shadCoordsPD /= shadowCoord.w; - if (shadowCoord.w <= 0.0) { // ignore negative projection - shadowFactor = 1.0; - } else if (shadCoordsPD.x < 0.0 || shadCoordsPD.y < 0.0) { // outside light frustum, ignore - shadowFactor = 1.0; - } else if (shadCoordsPD.x >= 1.0 || shadCoordsPD.y >= 1.0) { // outside light frustum, ignore - shadowFactor = 1.0; - } else { - // This does not work perfectly. It causes self-shadowing, which we should get rid of. - // Requires at least #version 130 - float shadow = 0.0; - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(0, 0)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(-1, 1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(1, 1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(-1, -1)); - shadow += textureProjOffset(shadowMap, shadCoordsPD, ivec2(1, -1)); - shadow *= 0.2; - shadowFactor = shadow; - } - - highp vec3 materialDiffuseColor = vec3(coords_mdl.y * color_mdl.x, coords_mdl.y * color_mdl.y, coords_mdl.y * color_mdl.z); - 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); - - // Shadow strength can be adjusted by using pow(shadowFactor, strength), but it causes self-shadowing issues that need to be solved - gl_FragColor.rgb = - shadowFactor * (materialAmbientColor + - materialDiffuseColor * lightStrength * cosTheta + - materialSpecularColor * lightStrength * pow(cosAlpha, 20)); - gl_FragColor.a = 1.0; -}*/ - -// Version 2: Shadows are a bit rugged (may be fixed with poisson disk?) void main() { highp vec3 materialDiffuseColor = vec3(coords_mdl.y * color_mdl.x, coords_mdl.y * color_mdl.y, coords_mdl.y * color_mdl.z); highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; @@ -106,12 +58,12 @@ void main() { // 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.2; + highp float visibility = 0.4; 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.05 * shadow2DProj(shadowMap, shadCoordsPD).r; + visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; } /*for (int i = 0; i < 15; i++) { vec4 shadCoordsPD = shadCoords; |