diff options
Diffstat (limited to 'hlsl')
-rw-r--r-- | hlsl/bloom.fx | 22 | ||||
-rw-r--r-- | hlsl/downsample.fx | 21 | ||||
-rw-r--r-- | hlsl/post.fx | 38 |
3 files changed, 44 insertions, 37 deletions
diff --git a/hlsl/bloom.fx b/hlsl/bloom.fx index 1ee152adfec..47cc04c47ed 100644 --- a/hlsl/bloom.fx +++ b/hlsl/bloom.fx @@ -202,8 +202,9 @@ float random(float2 seed) uniform float2 ScreenDims; uniform float2 TargetDims; -uniform float2 SourceRect; +uniform float2 SourceDims; +// level dimensions not necessary anymore? uniform float2 Level0Size; uniform float4 Level12Size; uniform float4 Level34Size; @@ -211,6 +212,8 @@ uniform float4 Level56Size; uniform float4 Level78Size; uniform float4 Level9ASize; +uniform bool VectorScreen = false; + VS_OUTPUT vs_main(VS_INPUT Input) { VS_OUTPUT Output = (VS_OUTPUT)0; @@ -226,12 +229,17 @@ VS_OUTPUT vs_main(VS_INPUT Input) float2 TexCoord = Input.Position.xy / ScreenDims; TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) - Output.TexCoord0 = TexCoord; - Output.TexCoord12 = TexCoord.xyxy + (0.5f / Level12Size); - Output.TexCoord34 = TexCoord.xyxy + (0.5f / Level34Size); - Output.TexCoord56 = TexCoord.xyxy + (0.5f / Level56Size); - Output.TexCoord78 = TexCoord.xyxy + (0.5f / Level78Size); - Output.TexCoord9A = TexCoord.xyxy + (0.5f / Level9ASize); + Output.TexCoord0 = TexCoord.xy; // + (0.5f / Level0Size); + + TexCoord += VectorScreen + ? 0.5f / TargetDims.xy + : 0.5f / SourceDims.xy; + + Output.TexCoord12 = TexCoord.xyxy; // + (0.5f / Level12Size); + Output.TexCoord34 = TexCoord.xyxy; // + (0.5f / Level34Size); + Output.TexCoord56 = TexCoord.xyxy; // + (0.5f / Level56Size); + Output.TexCoord78 = TexCoord.xyxy; // + (0.5f / Level78Size); + Output.TexCoord9A = TexCoord.xyxy; // + (0.5f / Level9ASize); return Output; } diff --git a/hlsl/downsample.fx b/hlsl/downsample.fx index 3afcdc703dd..fad2ef8341f 100644 --- a/hlsl/downsample.fx +++ b/hlsl/downsample.fx @@ -57,6 +57,8 @@ uniform float2 SourceDims; uniform float2 SourceRect; uniform float2 QuadDims; +uniform int BloomLevel; + uniform bool VectorScreen; static const float2 Coord0Offset = float2(-0.5f, -0.5f); @@ -68,9 +70,7 @@ VS_OUTPUT vs_main(VS_INPUT Input) { VS_OUTPUT Output = (VS_OUTPUT)0; - float2 TargetTexelDims = 1.0f / TargetDims; - float2 ScreenTexelDims = 1.0f / ScreenDims; - float2 SourceTexelDims = 1.0f / SourceDims; + float2 HalfTargetTexelDims = 0.5f / TargetDims; Output.Position = float4(Input.Position.xyz, 1.0f); Output.Position.xy /= ScreenDims; @@ -83,17 +83,10 @@ VS_OUTPUT vs_main(VS_INPUT Input) float2 TexCoord = Input.Position.xy / ScreenDims; TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) - float2 VectorTexelOffset = ScreenTexelDims * -0.5; - float2 RasterTexelOffset = SourceTexelDims * (0.5f * SourceRect) * (1.0f - (QuadDims / ScreenDims)); - - TexCoord += VectorScreen - ? VectorTexelOffset - : RasterTexelOffset; - - Output.TexCoord01.xy = TexCoord + Coord0Offset * TargetTexelDims; - Output.TexCoord01.zw = TexCoord + Coord1Offset * TargetTexelDims; - Output.TexCoord23.xy = TexCoord + Coord2Offset * TargetTexelDims; - Output.TexCoord23.zw = TexCoord + Coord3Offset * TargetTexelDims; + Output.TexCoord01.xy = TexCoord + Coord0Offset * HalfTargetTexelDims; + Output.TexCoord01.zw = TexCoord + Coord1Offset * HalfTargetTexelDims; + Output.TexCoord23.xy = TexCoord + Coord2Offset * HalfTargetTexelDims; + Output.TexCoord23.zw = TexCoord + Coord3Offset * HalfTargetTexelDims; return Output; } diff --git a/hlsl/post.fx b/hlsl/post.fx index d972926f629..01d83d435ff 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -97,17 +97,14 @@ VS_OUTPUT vs_main(VS_INPUT Input) Output.Position.xy *= 2.0f; // zoom Output.TexCoord = Input.Position.xy / ScreenDims; - Output.TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) - Output.SourceCoord = Input.TexCoord; + Output.TexCoord += PrepareBloom + ? 0.0f / TargetDims // use half texel offset (DX9) to do the blur for first bloom layer + : 0.5f / TargetDims; // fix half texel offset correction (DX9) - float2 ScreenCoordOffset = ShadowUVOffset; - ScreenCoordOffset = SwapXY - ? ShadowUVOffset.yx - : ShadowUVOffset.xy; + Output.SourceCoord = Input.TexCoord; Output.ScreenCoord = Input.Position.xy / ScreenDims; - Output.ScreenCoord += ScreenCoordOffset / ScreenDims; Output.Color = Input.Color; @@ -173,22 +170,31 @@ float4 ps_main(PS_INPUT Input) : COLOR float4 BaseColor = tex2D(DiffuseSampler, TexCoord); BaseColor.a = 1.0f; - clip(TexCoord < 0.0f || TexCoord > 1.0f ? -1 : 1); + // keep border + if (!PrepareBloom) + { + // clip border + clip(TexCoord < 0.0f || TexCoord > 1.0f ? -1 : 1); + } // Mask Simulation (may not affect bloom) if (!PrepareBloom && ShadowAlpha > 0.0f) { + float2 shadowUVOffset = ShadowUVOffset; + shadowUVOffset = SwapXY + ? ShadowUVOffset.yx + : ShadowUVOffset.xy; + float2 shadowDims = ShadowDims; shadowDims = SwapXY ? shadowDims.yx : shadowDims.xy; float2 shadowUV = ShadowUV; - // shadowUV = SwapXY - // ? shadowUV.yx - // : shadowUV.xy; - float2 screenCoord = ShadowTileMode == 0 ? ScreenCoord : SourceCoord; + float2 screenCoord = ShadowTileMode == 0 + ? ScreenCoord + shadowUVOffset / ScreenDims + : SourceCoord + shadowUVOffset / SourceDims; screenCoord = SwapXY ? screenCoord.yx : screenCoord.xy; @@ -198,17 +204,17 @@ float4 ps_main(PS_INPUT Input) : COLOR ? shadowCount.yx : shadowCount.xy; - float2 shadowTile = (ShadowTileMode == 0 ? ScreenTexelDims : SourceTexelDims) * shadowCount; + float2 shadowTile = ShadowTileMode == 0 + ? ScreenTexelDims * shadowCount + : SourceTexelDims * shadowCount; shadowTile = SwapXY ? shadowTile.yx : shadowTile.xy; float2 ShadowFrac = frac(screenCoord / shadowTile); + float2 ShadowCoord = (ShadowFrac * shadowUV); ShadowCoord += 0.5f / shadowDims; // half texel offset - // ShadowCoord = SwapXY - // ? ShadowCoord.yx - // : ShadowCoord.xy; float4 ShadowColor = tex2D(ShadowSampler, ShadowCoord); float3 ShadowMaskColor = lerp(1.0f, ShadowColor.rgb, ShadowAlpha); |