From 0dd6c14507f19f9fd834194fb70da5bb8070902a Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 22 Aug 2013 22:05:30 +0900 Subject: [PATCH] disabled soft map shadow due to quality issue --- ChangeLog | 2 ++ Resources/Shaders/Shadow/MapSoft.fs | 45 ++++++++++++++++++++--------- Sources/Draw/GLShadowShader.cpp | 2 +- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 392eefc2..08d1c961 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,5 +38,7 @@ * volumetric fog * lens flare + * disabled soft map shadow due to quality issue + diff --git a/Resources/Shaders/Shadow/MapSoft.fs b/Resources/Shaders/Shadow/MapSoft.fs index 1a73eb73..f727ec19 100644 --- a/Resources/Shaders/Shadow/MapSoft.fs +++ b/Resources/Shaders/Shadow/MapSoft.fs @@ -8,13 +8,14 @@ uniform sampler2D mapShadowTexture; varying vec3 mapShadowCoord; -vec2 MapSoft_BlockSample(vec2 sample, float depth) { +vec3 MapSoft_BlockSample(vec2 sample, float depth, + float shiftedDepth) { const float factor = 1. / 512.; float val = texture2D(mapShadowTexture, sample.xy * factor).w; - float distance = depth - val; + float distance = shiftedDepth - val; float weight = step(0., distance); - weight = clamp(distance*100000., 0., 1.); - return vec2(distance, 1.) * weight; + weight = clamp(distance*255. - 1., 0., 1.); + return vec3(distance, 1., step(0., shiftedDepth - val)) * weight; } float VisibilityOfSunLight_Map() { @@ -32,21 +33,22 @@ float VisibilityOfSunLight_Map() { // blocker distance estimation vec4 distSampPos = vec4(iPosShifted, iPosShifted + sampShift); - vec2 samp1 = MapSoft_BlockSample(distSampPos.xy, depth); - vec2 samp2 = MapSoft_BlockSample(distSampPos.zy, depth); - vec2 samp3 = MapSoft_BlockSample(distSampPos.xw, depth); - vec2 samp4 = MapSoft_BlockSample(distSampPos.zw, depth); - vec2 distWeighted1 = samp1; + float depthShifted = depth + sampShift.y / 255.; + vec3 samp1 = MapSoft_BlockSample(distSampPos.xy, depth, depth); + vec3 samp2 = MapSoft_BlockSample(distSampPos.zy, depth, depth); + vec3 samp3 = MapSoft_BlockSample(distSampPos.xw, depth, depthShifted); + vec3 samp4 = MapSoft_BlockSample(distSampPos.zw, depth, depthShifted); + vec3 distWeighted1 = samp1; distWeighted1 = mix(distWeighted1, samp2, fracPosHSAbs.x); - vec2 distWeighted2 = samp3; + vec3 distWeighted2 = samp3; distWeighted2 = mix(distWeighted2, samp4, fracPosHSAbs.x); - vec2 distWeighted3 = mix(distWeighted1, distWeighted2, + vec3 distWeighted3 = mix(distWeighted1, distWeighted2, fracPosHSAbs.y); distWeighted3.x /= distWeighted3.y + 1.e-10; @@ -60,9 +62,26 @@ float VisibilityOfSunLight_Map() { vec2 blurWeight = 0.5 - (0.5 - fracPosHSAbs) / blur; blurWeight = max(blurWeight, 0.); - float val1 = mix(samp1.y, samp2.y, blurWeight.x); - float val2 = mix(samp3.y, samp4.y, blurWeight.x); + float val1 = mix(samp1.z, samp2.z, blurWeight.x); + float val2 = mix(samp3.z, samp4.z, blurWeight.x); float val = 1. - mix(val1, val2, blurWeight.y); + // --- sharp shadow + vec4 sharpCol = texture2D(mapShadowTexture, floor(mapShadowCoord.xy) / 512.); + float sharpVal = sharpCol.w; + + // side shadow? + if(sharpCol.x > .499) { + sharpVal -= fract(mapShadowCoord.y) / 255.; + } + + float dist = sharpVal - mapShadowCoord.z + 0.001; + sharpVal = step(0., dist); + + float sharpWeight = clamp(4. + dist * 200., 0., 1.); + sharpVal = mix(1., sharpVal, sharpWeight); + + val *= sharpVal; + return val; } \ No newline at end of file diff --git a/Sources/Draw/GLShadowShader.cpp b/Sources/Draw/GLShadowShader.cpp index 15818083..9fae5bdd 100644 --- a/Sources/Draw/GLShadowShader.cpp +++ b/Sources/Draw/GLShadowShader.cpp @@ -50,7 +50,7 @@ namespace spades { shaders.push_back(r->RegisterShader("Shaders/Shadow/Common.fs")); shaders.push_back(r->RegisterShader("Shaders/Shadow/Common.vs")); - if(r_mapSoftShadow){ + if(r_mapSoftShadow && false){ shaders.push_back(r->RegisterShader("Shaders/Shadow/MapSoft.fs")); shaders.push_back(r->RegisterShader("Shaders/Shadow/MapSoft.vs"));