diff options
author | 2016-09-28 15:22:38 +0200 | |
---|---|---|
committer | 2016-09-28 15:30:43 +0200 | |
commit | ecf1e166fc6342ecf0664fe1d3af7aecb621c650 (patch) | |
tree | f75605582b1bc87ea3b6a2989d9867ea4ea93096 /hlsl | |
parent | 4727ff5e6a1e0aaa1d2b146b819250a6a83e8448 (diff) |
Fixed several small issues in HLSL/BGFX
* fixed target texture dimension when -intoverscan is used (this fixes the appereance of scanline and shadow mask)
* added target_scale and screen_count uniforms
* rounded corners now remain aligned with screen bounds when -intoverscan is used (single screen only)
Diffstat (limited to 'hlsl')
-rw-r--r-- | hlsl/distortion.fx | 75 | ||||
-rw-r--r-- | hlsl/post.fx | 22 | ||||
-rw-r--r-- | hlsl/prescale.fx | 1 | ||||
-rw-r--r-- | hlsl/primary.fx | 1 | ||||
-rw-r--r-- | hlsl/vector.fx | 8 |
5 files changed, 70 insertions, 37 deletions
diff --git a/hlsl/distortion.fx b/hlsl/distortion.fx index 3b7a9d592e3..c7128bccfef 100644 --- a/hlsl/distortion.fx +++ b/hlsl/distortion.fx @@ -86,7 +86,9 @@ float roundBox(float2 p, float2 b, float r) //----------------------------------------------------------------------------- uniform float2 ScreenDims; // size of the window or fullscreen +uniform int ScreenCount; uniform float2 TargetDims; // size of the target surface +uniform float2 TargetScale; uniform float2 QuadDims; // size of the screen quad VS_OUTPUT vs_main(VS_INPUT Input) @@ -170,7 +172,7 @@ float GetSpotAddend(float2 coord, float amount) return saturate(SigmoidSpot); } -float GetRoundCornerFactor(float2 coord, float2 bounds, float radiusAmount, float smoothAmount) +float GetBoundsFactor(float2 coord, float2 bounds, float radiusAmount, float smoothAmount) { // reduce smooth amount down to radius amount smoothAmount = min(smoothAmount, radiusAmount); @@ -216,7 +218,7 @@ float2 GetDistortedCoords(float2 centerCoord, float amount, float amountCube) return centerCoord; } -float2 GetCoords(float2 coord, float distortionAmount, float cubicDistortionAmount) +float2 GetTextureCoords(float2 coord, float distortionAmount, float cubicDistortionAmount) { // center coordinates coord -= 0.5f; @@ -230,35 +232,61 @@ float2 GetCoords(float2 coord, float distortionAmount, float cubicDistortionAmou return coord; } +float2 GetQuadCoords(float2 coord, float distortionAmount, float cubicDistortionAmount) +{ + // center coordinates + coord -= 0.5f; + + // keep coords inside of the quad bounds of a single screen + if (ScreenCount == 1) + { + // base-target dimensions (without oversampling) + float2 BaseTargetDims = TargetDims / TargetScale; + + // apply base-target/quad difference + coord *= BaseTargetDims / (SwapXY ? QuadDims.yx : QuadDims.xy); + } + + // distort coordinates + coord = GetDistortedCoords(coord, distortionAmount, cubicDistortionAmount); + + return coord; +} + float4 ps_main(PS_INPUT Input) : COLOR { + // image distortion float distortionAmount = DistortionAmount; float cubicDistortionAmount = CubicDistortionAmount > 0.0f ? CubicDistortionAmount * 1.1f // cubic distortion need to be a little higher to compensate the quartic distortion : CubicDistortionAmount * 1.2f; // negativ values even more + // corner distortion at least by the amount of the image distorition + float distortCornerAmount = max(DistortCornerAmount, DistortionAmount + CubicDistortionAmount); + + float roundCornerAmount = RoundCornerAmount * 0.5f; + float smoothBorderAmount = SmoothBorderAmount * 0.5f; + float2 TexelDims = 1.0f / TargetDims; - // Screen Curvature - float2 TexCoord = GetCoords(Input.TexCoord, distortionAmount, cubicDistortionAmount); + // base-target dimensions (without oversampling) + float2 BaseTargetDims = TargetDims / TargetScale; - // Corner Curvature - float2 CornerCoord = GetCoords(Input.TexCoord, DistortCornerAmount, 0.0f); + // Screen Texture Curvature + float2 BaseCoord = GetTextureCoords(Input.TexCoord, distortionAmount, cubicDistortionAmount); - // clip border - clip(TexCoord < 0.0f - TexelDims || TexCoord > 1.0f + TexelDims ? -1 : 1); + // Screen Quad Curvature + float2 QuadCoord = GetQuadCoords(Input.TexCoord, distortCornerAmount, 0.0f); - float2 TexCoordCentered = TexCoord; - TexCoordCentered -= 0.5f; - float2 CornerCoordCentered = CornerCoord; - CornerCoordCentered -= 0.5f; + // clip border + clip(BaseCoord < 0.0f - TexelDims || BaseCoord > 1.0f + TexelDims ? -1 : 1); // Color - float4 BaseColor = tex2D(DiffuseSampler, TexCoord); + float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); BaseColor.a = 1.0f; // Vignetting Simulation - float2 VignetteCoord = CornerCoordCentered; + float2 VignetteCoord = QuadCoord; float VignetteFactor = GetVignetteFactor(VignetteCoord, VignettingAmount); BaseColor.rgb *= VignetteFactor; @@ -266,20 +294,23 @@ float4 ps_main(PS_INPUT Input) : COLOR // Light Reflection Simulation float3 LightColor = float3(1.0f, 0.90f, 0.80f); // color temperature 5.000 Kelvin - float2 SpotCoord = CornerCoordCentered; - float2 NoiseCoord = CornerCoordCentered; + float2 SpotCoord = QuadCoord; + float2 NoiseCoord = QuadCoord; float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount); float NoiseFactor = GetNoiseFactor(SpotAddend, random(NoiseCoord)); BaseColor.rgb += SpotAddend * NoiseFactor * LightColor; // Round Corners Simulation - float2 RoundCornerCoord = CornerCoordCentered; - float2 RoundCornerBounds = SwapXY - ? QuadDims.yx - : QuadDims.xy; - - float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerBounds, RoundCornerAmount * 0.5f, SmoothBorderAmount * 0.5f); + float2 RoundCornerCoord = QuadCoord; + float2 RoundCornerBounds = ScreenCount == 1 + ? QuadDims // align corners to quad bounds of a single screen + : BaseTargetDims; // align corners to target bounds of multiple screens + RoundCornerBounds = SwapXY + ? RoundCornerBounds.yx + : RoundCornerBounds.xy; + + float roundCornerFactor = GetBoundsFactor(RoundCornerCoord, RoundCornerBounds, roundCornerAmount, smoothBorderAmount); BaseColor.rgb *= roundCornerFactor; return BaseColor; diff --git a/hlsl/post.fx b/hlsl/post.fx index 717c919d8a7..e6dda5a9474 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -76,6 +76,7 @@ static const float HalfPI = PI * 0.5f; uniform float2 ScreenDims; uniform float2 SourceDims; uniform float2 TargetDims; +uniform float2 TargetScale; uniform float2 QuadDims; uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size) @@ -158,17 +159,20 @@ float2 GetAdjustedCoords(float2 coord) return coord; } -float2 GetShadowCoord(float2 QuadCoord, float2 SourceCoord) +float2 GetShadowCoord(float2 TargetCoord, float2 SourceCoord) { - float2 QuadTexel = 1.0f / QuadDims; - float2 SourceTexel = 1.0f / SourceDims; + // base-target dimensions (without oversampling) + float2 BaseTargetDims = TargetDims / TargetScale; + BaseTargetDims = SwapXY + ? BaseTargetDims.yx + : BaseTargetDims.xy; float2 canvasCoord = ShadowTileMode == 0 - ? QuadCoord + ShadowUVOffset / QuadDims + ? TargetCoord + ShadowUVOffset / BaseTargetDims : SourceCoord + ShadowUVOffset / SourceDims; float2 canvasTexelDims = ShadowTileMode == 0 - ? QuadTexel - : SourceTexel; + ? 1.0f / BaseTargetDims + : 1.0f / SourceDims; float2 shadowDims = ShadowDims; float2 shadowUV = ShadowUV; @@ -204,15 +208,15 @@ float2 GetShadowCoord(float2 QuadCoord, float2 SourceCoord) float4 ps_main(PS_INPUT Input) : COLOR { float2 ScreenCoord = Input.ScreenCoord; - float2 TexCoord = GetAdjustedCoords(Input.TexCoord); + float2 BaseCoord = GetAdjustedCoords(Input.TexCoord); float2 SourceCoord = GetAdjustedCoords(Input.SourceCoord); // Color - float4 BaseColor = tex2D(DiffuseSampler, TexCoord); + float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); BaseColor.a = 1.0f; // clip border - clip(TexCoord < 0.0f || TexCoord > 1.0f ? -1 : 1); + clip(BaseCoord < 0.0f || BaseCoord > 1.0f ? -1 : 1); // Mask Simulation (may not affect bloom) if (!PrepareBloom && ShadowAlpha > 0.0f) diff --git a/hlsl/prescale.fx b/hlsl/prescale.fx index 2b48a2f9e5a..3f52c20b464 100644 --- a/hlsl/prescale.fx +++ b/hlsl/prescale.fx @@ -40,7 +40,6 @@ struct VS_INPUT float4 Position : POSITION; float4 Color : COLOR0; float2 TexCoord : TEXCOORD0; - float2 Unused : TEXCOORD1; }; struct PS_INPUT diff --git a/hlsl/primary.fx b/hlsl/primary.fx index 939d37e97dd..839ebbf8bf0 100644 --- a/hlsl/primary.fx +++ b/hlsl/primary.fx @@ -53,7 +53,6 @@ static const float Epsilon = 1.0e-7f; uniform float2 ScreenDims; uniform float2 TargetDims; -uniform float2 QuadDims; VS_OUTPUT vs_screen_main(VS_INPUT Input) { diff --git a/hlsl/vector.fx b/hlsl/vector.fx index 686b617bbd0..7de585fd3a0 100644 --- a/hlsl/vector.fx +++ b/hlsl/vector.fx @@ -46,7 +46,7 @@ float roundBox(float2 p, float2 b, float r) //----------------------------------------------------------------------------- uniform float2 ScreenDims; -uniform float2 QuadDims; +uniform float2 TargetDims; VS_OUTPUT vs_main(VS_INPUT Input) { @@ -76,7 +76,7 @@ uniform float LengthRatio; // Size at which fade is maximum uniform float LengthScale; // How much length affects the vector's fade uniform float BeamSmooth; -float GetRoundCornerFactor(float2 coord, float2 bounds, float radiusAmount, float smoothAmount) +float GetBoundsFactor(float2 coord, float2 bounds, float radiusAmount, float smoothAmount) { // reduce smooth amount down to radius amount smoothAmount = min(smoothAmount, radiusAmount); @@ -100,7 +100,7 @@ float GetRoundCornerFactor(float2 coord, float2 bounds, float radiusAmount, floa float4 ps_main(PS_INPUT Input) : COLOR { - float2 lineSize = Input.SizeInfo / max(QuadDims.x, QuadDims.y); // normalize + float2 lineSize = Input.SizeInfo / max(TargetDims.x, TargetDims.y); // normalize float lineLength = lineSize.x; float lineLengthRatio = LengthRatio; @@ -113,7 +113,7 @@ float4 ps_main(PS_INPUT Input) : COLOR float4 outColor = float4(timeLengthModulate, timeLengthModulate, timeLengthModulate, 1.0f); outColor *= Input.Color; - float RoundCornerFactor = GetRoundCornerFactor(Input.TexCoord - 0.5f, Input.SizeInfo, 1.0f, BeamSmooth); + float RoundCornerFactor = GetBoundsFactor(Input.TexCoord - 0.5f, Input.SizeInfo, 1.0f, BeamSmooth); outColor.rgb *= RoundCornerFactor; return outColor; |