libobs: Improve low-resolution bilinear sampling
The issue with the current bilinear_lowres_scale effect is that it samples adjacent texels, disregarding the texel-to-pixel ratio. If the ratio is large, this can lead to aliasing. This change provides a fair set of texture samples across the entire pixel. The 8-sample pattern used here comes from Direct3D.master
parent
42c190f3d6
commit
fede4fb784
|
@ -1,12 +1,11 @@
|
|||
/*
|
||||
* bilinear low res scaling, samples 9 pixels of a larger image to scale to a
|
||||
* bilinear low res scaling, samples 8 pixels of a larger image to scale to a
|
||||
* low resolution image below half size
|
||||
*/
|
||||
|
||||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
uniform float4x4 color_matrix;
|
||||
uniform float2 base_dimension_i;
|
||||
|
||||
sampler_state textureSampler {
|
||||
Filter = Linear;
|
||||
|
@ -34,19 +33,24 @@ float4 pixel(float2 uv)
|
|||
|
||||
float4 DrawLowresBilinear(VertData v_in)
|
||||
{
|
||||
float2 stepxy = base_dimension_i;
|
||||
float4 out_color;
|
||||
float2 uv = v_in.uv;
|
||||
float2 stepxy = float2(ddx(uv.x), ddy(uv.y));
|
||||
float2 stepxy1 = stepxy * 0.0625;
|
||||
float2 stepxy3 = stepxy * 0.1875;
|
||||
float2 stepxy5 = stepxy * 0.3125;
|
||||
float2 stepxy7 = stepxy * 0.4375;
|
||||
|
||||
out_color = pixel(v_in.uv);
|
||||
out_color += pixel(v_in.uv + float2(-stepxy.x, -stepxy.y));
|
||||
out_color += pixel(v_in.uv + float2(-stepxy.x, 0.0));
|
||||
out_color += pixel(v_in.uv + float2(-stepxy.x, stepxy.y));
|
||||
out_color += pixel(v_in.uv + float2( 0.0, -stepxy.y));
|
||||
out_color += pixel(v_in.uv + float2( 0.0, stepxy.y));
|
||||
out_color += pixel(v_in.uv + float2( stepxy.x, -stepxy.y));
|
||||
out_color += pixel(v_in.uv + float2( stepxy.x, 0.0));
|
||||
out_color += pixel(v_in.uv + float2( stepxy.x, stepxy.y));
|
||||
return out_color / float4(9.0, 9.0, 9.0, 9.0);
|
||||
// Simulate Direct3D 8-sample pattern
|
||||
float4 out_color;
|
||||
out_color = pixel(uv + float2( stepxy1.x, -stepxy3.y));
|
||||
out_color += pixel(uv + float2(-stepxy1.x, stepxy3.y));
|
||||
out_color += pixel(uv + float2( stepxy5.x, stepxy1.y));
|
||||
out_color += pixel(uv + float2(-stepxy3.x, -stepxy5.y));
|
||||
out_color += pixel(uv + float2(-stepxy5.x, stepxy5.y));
|
||||
out_color += pixel(uv + float2(-stepxy7.x, -stepxy1.y));
|
||||
out_color += pixel(uv + float2( stepxy3.x, stepxy7.y));
|
||||
out_color += pixel(uv + float2( stepxy7.x, -stepxy7.y));
|
||||
return out_color * 0.125;
|
||||
}
|
||||
|
||||
float4 PSDrawLowresBilinearRGBA(VertData v_in) : TARGET
|
||||
|
|
Loading…
Reference in New Issue