summaryrefslogtreecommitdiffstatshomepage
path: root/hlsl
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-04-18 20:25:28 +0200
committer ImJezze <jezze@gmx.net>2016-04-19 21:13:20 +0200
commit8ed3a7d94a65ee01bf1adce3ea8118c04d41a18d (patch)
treeef8996c9bae5d8498b45064924d0831a285e8434 /hlsl
parenta86983713dffcc926c50227a9e26091022bbc32c (diff)
Refactored distortion pass
- separated curvature parameter into distortion, cubic_distortion and distort_corner - distortion and cubic_distortion can be negative, to compensate each other - distort_corner is intependent from the image distortion
Diffstat (limited to 'hlsl')
-rw-r--r--hlsl/distortion.fx39
1 files changed, 28 insertions, 11 deletions
diff --git a/hlsl/distortion.fx b/hlsl/distortion.fx
index e33b8811ba5..f683397b17a 100644
--- a/hlsl/distortion.fx
+++ b/hlsl/distortion.fx
@@ -111,7 +111,9 @@ VS_OUTPUT vs_main(VS_INPUT Input)
// Distortion Pixel Shader
//-----------------------------------------------------------------------------
-uniform float CurvatureAmount = 0.0f;
+uniform float DistortionAmount = 0.0f; // k - quartic distortion coefficient
+uniform float CubicDistortionAmount = 0.0f; // kcube - cubic distortion modifier
+uniform float DistortCornerAmount = 0.0f;
uniform float RoundCornerAmount = 0.0f;
uniform float SmoothBorderAmount = 0.0f;
uniform float VignettingAmount = 0.0f;
@@ -195,13 +197,13 @@ float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount)
}
// www.francois-tarlier.com/blog/cubic-lens-distortion-shader/
-float2 GetDistortedCoords(float2 centerCoord, float amount)
+float2 GetDistortedCoords(float2 centerCoord, float amount, float amountCube)
{
// lens distortion coefficient
float k = amount;
// cubic distortion value
- float kcube = amount * 2.0f;
+ float kcube = amountCube;
// compute cubic distortion factor
float r2 = centerCoord.x * centerCoord.x + centerCoord.y * centerCoord.y;
@@ -210,7 +212,7 @@ float2 GetDistortedCoords(float2 centerCoord, float amount)
: 1.0f + r2 * (k + kcube * sqrt(r2));
// fit screen bounds
- f /= 1.0f + amount * 0.5f;
+ f /= 1.0f + amount * 0.25 + amountCube * 0.125f;
// apply cubic distortion factor
centerCoord *= f;
@@ -218,13 +220,13 @@ float2 GetDistortedCoords(float2 centerCoord, float amount)
return centerCoord;
}
-float2 GetCoords(float2 coord, float distortionAmount)
+float2 GetCoords(float2 coord, float distortionAmount, float cubicDistortionAmount)
{
// center coordinates
coord -= 0.5f;
// distort coordinates
- coord = GetDistortedCoords(coord, distortionAmount);
+ coord = GetDistortedCoords(coord, distortionAmount, cubicDistortionAmount);
// un-center coordinates
coord += 0.5f;
@@ -234,18 +236,33 @@ float2 GetCoords(float2 coord, float distortionAmount)
float4 ps_main(PS_INPUT Input) : COLOR
{
+ float distortionAmount = DistortionAmount;
+ float cubicDistortionAmount = CubicDistortionAmount > 0
+ ? CubicDistortionAmount * 1.1 // cubic distortion need to be a little higher to compensate the quartic distortion
+ : CubicDistortionAmount * 1.2; // negativ values even more
+
+ float2 TexelDims = 1.0f / TargetDims;
+
// Screen Curvature
- float2 TexCoord = GetCoords(Input.TexCoord, CurvatureAmount * 0.25f); // reduced amount
+ float2 TexCoord = GetCoords(Input.TexCoord, distortionAmount, cubicDistortionAmount);
+
+ // Corner Curvature
+ float2 CornerCoord = GetCoords(Input.TexCoord, DistortCornerAmount, 0.0f);
+
+ // clip border
+ clip(TexCoord < 0.0f - TexelDims || TexCoord > 1.0f + TexelDims ? -1 : 1);
float2 TexCoordCentered = TexCoord;
TexCoordCentered -= 0.5f;
+ float2 CornerCoordCentered = CornerCoord;
+ CornerCoordCentered -= 0.5f;
// Color
float4 BaseColor = tex2D(DiffuseSampler, TexCoord);
BaseColor.a = 1.0f;
// Vignetting Simulation
- float2 VignetteCoord = TexCoordCentered;
+ float2 VignetteCoord = CornerCoordCentered;
float VignetteFactor = GetVignetteFactor(VignetteCoord, VignettingAmount);
BaseColor.rgb *= VignetteFactor;
@@ -253,15 +270,15 @@ 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 = TexCoordCentered;
- float2 NoiseCoord = TexCoordCentered;
+ float2 SpotCoord = CornerCoordCentered;
+ float2 NoiseCoord = CornerCoordCentered;
float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount);
float NoiseFactor = GetNoiseFactor(SpotAddend, random(NoiseCoord));
BaseColor.rgb += SpotAddend * NoiseFactor * LightColor;
// Round Corners Simulation
- float2 RoundCornerCoord = TexCoordCentered;
+ float2 RoundCornerCoord = CornerCoordCentered;
float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount);
BaseColor.rgb *= roundCornerFactor;