diff options
author | 2015-11-17 19:37:56 +0100 | |
---|---|---|
committer | 2015-11-17 19:37:56 +0100 | |
commit | 8be53c28f0266af433076a6f5c1f1fa0abc70867 (patch) | |
tree | 5167ec845cdb853dddcbbafd84749308d3888095 /hlsl | |
parent | 5200f15ace282ad246bd38af900472db353ba241 (diff) |
Changed screen adjustment for HLSL
- screen adjustment (scale, offset) can now be handled by the respective
render API itself (default behavior is as before)
- D3D (if HLSL) is activated handles screen adjustment by itself within
the shader, which fixes the odd behavior of some effects (e.g. round
corners) when screen scale and offset is used
Diffstat (limited to 'hlsl')
-rw-r--r-- | hlsl/artwork_support/post.fx | 52 | ||||
-rw-r--r-- | hlsl/post.fx | 32 |
2 files changed, 78 insertions, 6 deletions
diff --git a/hlsl/artwork_support/post.fx b/hlsl/artwork_support/post.fx index f3d49d4dbaf..5fb864c3ef2 100644 --- a/hlsl/artwork_support/post.fx +++ b/hlsl/artwork_support/post.fx @@ -152,6 +152,9 @@ VS_OUTPUT vs_main(VS_INPUT Input) // Post-Processing Pixel Shader //----------------------------------------------------------------------------- +uniform float2 ScreenScale = float2(1.0f, 1.0f); +uniform float2 ScreenOffset = float2(0.0f, 0.0f); + uniform float ScanlineAlpha = 1.0f; uniform float ScanlineScale = 1.0f; uniform float ScanlineBrightScale = 1.0f; @@ -334,6 +337,34 @@ float2 GetCoords(float2 coord, float2 centerOffset, float distortionAmount) return coord; } +float2 GetAdjustedCoords(float2 coord, float2 centerOffset, float distortionAmount) +{ + float2 RatioCorrection = GetRatioCorrection(); + + // center coordinates + coord -= centerOffset; + + // apply ratio difference between screen and quad + coord /= RatioCorrection; + + // applay screen scale + coord /= ScreenScale; + + // distort coordinates + coord = GetDistortedCoords(coord, distortionAmount); + + // revert ratio difference between screen and quad + coord *= RatioCorrection; + + // un-center coordinates + coord += centerOffset; + + // apply screen offset + coord += (centerOffset * 2.0) * ScreenOffset; + + return coord; +} + float4 ps_main(PS_INPUT Input) : COLOR { float2 ScreenTexelDims = 1.0f / ScreenDims; @@ -345,8 +376,14 @@ float4 ps_main(PS_INPUT Input) : COLOR float2 ScreenCoord = Input.ScreenCoord / ScreenDims; ScreenCoord = GetCoords(ScreenCoord, float2(0.5f, 0.5f), CurvatureAmount); + float2 DistortionCoord = Input.TexCoord; + DistortionCoord = GetCoords(DistortionCoord, HalfSourceRect, CurvatureAmount); + float2 BaseCoord = Input.TexCoord; - BaseCoord = GetCoords(BaseCoord, HalfSourceRect, CurvatureAmount); + BaseCoord = GetAdjustedCoords(BaseCoord, HalfSourceRect, CurvatureAmount); + + float2 DistortionCoordCentered = DistortionCoord; + DistortionCoordCentered -= HalfSourceRect; float2 BaseCoordCentered = BaseCoord; BaseCoordCentered -= HalfSourceRect; @@ -354,6 +391,11 @@ float4 ps_main(PS_INPUT Input) : COLOR float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); BaseColor.a = 1.0f; + if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f) + { + BaseColor.rgb = 0.0f; + } + // Mask Simulation (may not affect bloom) if (!PrepareBloom) { @@ -431,7 +473,7 @@ float4 ps_main(PS_INPUT Input) : COLOR // Vignetting Simulation (may not affect bloom) if (!PrepareBloom) { - float2 VignetteCoord = BaseCoordCentered; + float2 VignetteCoord = DistortionCoordCentered; float VignetteFactor = GetVignetteFactor(VignetteCoord, VignettingAmount); Output.rgb *= VignetteFactor; @@ -442,8 +484,8 @@ float4 ps_main(PS_INPUT Input) : COLOR { float3 LightColor = float3(1.0f, 0.90f, 0.80f); - float2 SpotCoord = BaseCoordCentered; - float2 NoiseCoord = BaseCoordCentered; + float2 SpotCoord = DistortionCoordCentered; + float2 NoiseCoord = DistortionCoordCentered; float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount); float NoiseFactor = GetNoiseFactor(SpotAddend, random(NoiseCoord)); @@ -451,7 +493,7 @@ float4 ps_main(PS_INPUT Input) : COLOR } // Round Corners Simulation (may affect bloom) - float2 RoundCornerCoord = BaseCoordCentered; + float2 RoundCornerCoord = DistortionCoordCentered; float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount); Output.rgb *= roundCornerFactor; diff --git a/hlsl/post.fx b/hlsl/post.fx index b457b9687e2..7ab09b45ddb 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -77,6 +77,7 @@ bool xor(bool a, bool b) uniform float2 ScreenDims; // size of the window or fullscreen uniform float2 SourceDims; // size of the texture in power-of-two size +uniform float2 SourceRect; // size of the uv rectangle uniform float2 TargetDims; // size of the target surface uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size) @@ -124,6 +125,9 @@ VS_OUTPUT vs_main(VS_INPUT Input) // Post-Processing Pixel Shader //----------------------------------------------------------------------------- +uniform float2 ScreenScale = float2(1.0f, 1.0f); +uniform float2 ScreenOffset = float2(0.0f, 0.0f); + uniform float ScanlineAlpha = 1.0f; uniform float ScanlineScale = 1.0f; uniform float ScanlineBrightScale = 1.0f; @@ -138,17 +142,43 @@ uniform float2 ShadowUV = float2(0.25f, 0.25f); uniform float3 Power = float3(1.0f, 1.0f, 1.0f); uniform float3 Floor = float3(0.0f, 0.0f, 0.0f); +float2 GetAdjustedCoords(float2 coord, float2 centerOffset) +{ + // center coordinates + coord -= centerOffset; + + // apply screen scale + coord /= ScreenScale; + + // un-center coordinates + coord += centerOffset; + + // apply screen offset + coord += (centerOffset * 2.0) * ScreenOffset; + + return coord; +} + float4 ps_main(PS_INPUT Input) : COLOR { float2 ScreenTexelDims = 1.0f / ScreenDims; + float2 HalfSourceRect = PrepareVector + ? float2(0.5f, 0.5f) + : SourceRect * 0.5f; + float2 ScreenCoord = Input.ScreenCoord / ScreenDims; - float2 BaseCoord = Input.TexCoord; + float2 BaseCoord = GetAdjustedCoords(Input.TexCoord, HalfSourceRect); // Color float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); BaseColor.a = 1.0f; + if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f) + { + BaseColor.rgb = 0.0f; + } + // Mask Simulation (may not affect bloom) if (!PrepareBloom) { |