diff --git a/WickedEngine/imageHF.hlsli b/WickedEngine/imageHF.hlsli index 5469f234d..528937e18 100644 --- a/WickedEngine/imageHF.hlsli +++ b/WickedEngine/imageHF.hlsli @@ -9,12 +9,54 @@ TEXTURE2D(texture_background, float4, TEXSLOT_IMAGE_BACKGROUND); SAMPLERSTATE(Sampler, SSLOT_ONDEMAND0); +float Wedge2D(float2 v, float2 w) +{ + return v.x * w.y - v.y * w.x; +} + struct VertextoPixel { float4 pos : SV_POSITION; - float2 uv0 : TEXCOORD0; - float2 uv1 : TEXCOORD1; + float2 q : TEXCOORD3; + float2 b1 : TEXCOORD4; + float2 b2 : TEXCOORD5; + float2 b3 : TEXCOORD6; float4 uv_screen : TEXCOORD2; + + float4 compute_uvs() + { + // Quad interpolation: http://reedbeta.com/blog/quadrilateral-interpolation-part-2/ + + // Set up quadratic formula + float A = Wedge2D(b2, b3); + float B = Wedge2D(b3, q) - Wedge2D(b1, b2); + float C = Wedge2D(b1, q); + + // Solve for v + float2 uv; + if (abs(A) < 0.001) + { + // Linear form + uv.y = -C / B; + } + else + { + // Quadratic form. Take positive root for CCW winding with V-up + float discrim = B * B - 4 * A * C; + uv.y = 0.5 * (-B + sqrt(discrim)) / A; + } + + // Solve for u, using largest-magnitude component + float2 denom = b1 + uv.y * b3; + if (abs(denom.x) > abs(denom.y)) + uv.x = (q.x - b2.x * uv.y) / denom.x; + else + uv.x = (q.y - b2.y * uv.y) / denom.y; + + float2 uv0 = uv * xTexMulAdd.xy + xTexMulAdd.zw; + float2 uv1 = uv * xTexMulAdd2.xy + xTexMulAdd2.zw; + return float4(uv0, uv1); + } }; #endif // WI_IMAGE_HF diff --git a/WickedEngine/imagePS.hlsl b/WickedEngine/imagePS.hlsl index 1ac814624..b09a18f59 100644 --- a/WickedEngine/imagePS.hlsl +++ b/WickedEngine/imagePS.hlsl @@ -2,7 +2,8 @@ float4 main(VertextoPixel input) : SV_TARGET { - float4 color = texture_base.Sample(Sampler, input.uv0) * xColor; + float4 uvsets = input.compute_uvs(); + float4 color = texture_base.Sample(Sampler, uvsets.xy) * xColor; return color; -} \ No newline at end of file +} diff --git a/WickedEngine/imagePS_backgroundblur.hlsl b/WickedEngine/imagePS_backgroundblur.hlsl index 008f5856b..7515cb885 100644 --- a/WickedEngine/imagePS_backgroundblur.hlsl +++ b/WickedEngine/imagePS_backgroundblur.hlsl @@ -2,7 +2,8 @@ float4 main(VertextoPixel input) : SV_TARGET { - float4 color = texture_base.Sample(Sampler, input.uv0) * xColor; + float4 uvsets = input.compute_uvs(); + float4 color = texture_base.Sample(Sampler, uvsets.xy) * xColor; float3 background = texture_background.Sample(Sampler, (input.uv_screen.xy * float2(0.5f, -0.5f) + 0.5f) / input.uv_screen.w).rgb; return float4(lerp(background, color.rgb, color.a), 1); diff --git a/WickedEngine/imagePS_backgroundblur_masked.hlsl b/WickedEngine/imagePS_backgroundblur_masked.hlsl index 030df814d..f7855fa9b 100644 --- a/WickedEngine/imagePS_backgroundblur_masked.hlsl +++ b/WickedEngine/imagePS_backgroundblur_masked.hlsl @@ -2,9 +2,10 @@ float4 main(VertextoPixel input) : SV_TARGET { - float4 color = texture_base.Sample(Sampler, input.uv0) * xColor; + float4 uvsets = input.compute_uvs(); + float4 color = texture_base.Sample(Sampler, uvsets.xy) * xColor; float3 background = texture_background.Sample(Sampler, (input.uv_screen.xy * float2(0.5f, -0.5f) + 0.5f) / input.uv_screen.w).rgb; - float4 mask = texture_mask.Sample(Sampler, input.uv1); + float4 mask = texture_mask.Sample(Sampler, uvsets.zw); color *= mask; return float4(lerp(background, color.rgb, color.a), mask.a); diff --git a/WickedEngine/imagePS_masked.hlsl b/WickedEngine/imagePS_masked.hlsl index a89ac6317..b4bce5f13 100644 --- a/WickedEngine/imagePS_masked.hlsl +++ b/WickedEngine/imagePS_masked.hlsl @@ -2,9 +2,10 @@ float4 main(VertextoPixel input) : SV_TARGET { - float4 color = texture_base.Sample(Sampler, input.uv0) * xColor; + float4 uvsets = input.compute_uvs(); + float4 color = texture_base.Sample(Sampler, uvsets.xy) * xColor; - color *= texture_mask.Sample(Sampler, input.uv1); + color *= texture_mask.Sample(Sampler, uvsets.zw); return color; -} \ No newline at end of file +} diff --git a/WickedEngine/imagePS_separatenormalmap.hlsl b/WickedEngine/imagePS_separatenormalmap.hlsl index 1f6a1b47b..db9ca2072 100644 --- a/WickedEngine/imagePS_separatenormalmap.hlsl +++ b/WickedEngine/imagePS_separatenormalmap.hlsl @@ -2,11 +2,12 @@ float4 main(VertextoPixel input) : SV_TARGET { - float4 color = texture_base.Sample(Sampler, input.uv0); + float4 uvsets = input.compute_uvs(); + float4 color = texture_base.Sample(Sampler, uvsets.xy); color = 2 * color - 1; color *= xColor; return color; -} \ No newline at end of file +} diff --git a/WickedEngine/imagePS_separatenormalmap_bicubic.hlsl b/WickedEngine/imagePS_separatenormalmap_bicubic.hlsl index 086bf5e55..b2dc5b79f 100644 --- a/WickedEngine/imagePS_separatenormalmap_bicubic.hlsl +++ b/WickedEngine/imagePS_separatenormalmap_bicubic.hlsl @@ -2,11 +2,12 @@ float4 main(VertextoPixel input) : SV_TARGET { - float4 color = SampleTextureCatmullRom(texture_base, Sampler, input.uv0); + float4 uvsets = input.compute_uvs(); + float4 color = SampleTextureCatmullRom(texture_base, Sampler, uvsets.xy); color = 2 * color - 1; color *= xColor; return color; -} \ No newline at end of file +} diff --git a/WickedEngine/imageVS.hlsl b/WickedEngine/imageVS.hlsl index 26ff64809..4501da5ac 100644 --- a/WickedEngine/imageVS.hlsl +++ b/WickedEngine/imageVS.hlsl @@ -12,13 +12,14 @@ VertextoPixel main(uint vI : SV_VERTEXID) // 3--4 Out.pos = xCorners[vI]; - - Out.uv0 = float2(vI % 2, vI % 4 / 2); - Out.uv1 = Out.uv0; - Out.uv0 = Out.uv0 * xTexMulAdd.xy + xTexMulAdd.zw; - Out.uv1 = Out.uv1 * xTexMulAdd2.xy + xTexMulAdd2.zw; Out.uv_screen = Out.pos; + // Set up inverse bilinear interpolation + Out.q = Out.pos.xy - xCorners[0].xy; + Out.b1 = xCorners[1].xy - xCorners[0].xy; + Out.b2 = xCorners[2].xy - xCorners[0].xy; + Out.b3 = xCorners[0].xy - xCorners[1].xy - xCorners[2].xy + xCorners[3].xy; + return Out; } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index da7ba2a35..4c2c31db4 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates, breaking compatibility changes const int minor = 53; // minor bug fixes, alterations, refactors, updates - const int revision = 5; + const int revision = 6; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);