image renderer quad interpolation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user