mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-28 14:23:01 +00:00
88cc142afb
End goal of this is to be an anisotropic filtering purely on the GPU without any actual mipmaps in the graphics subsystem. The basic idea behind it is that we can create all possible mipmaps in a twice as big texture as the original and then can efficiently render it no matter the GPU features as it will only consume one sampler. The texture that it outputs will have both horizontal, vertical and full mipmaps in it. Horizontal mipmaps reduce Width, Vertical mipmaps reduce Height and full mipmaps reduce both. This means that LoD levels are both possible in the X and Y direction, allowing for much greater precision mipmapping on all GPUs. This is a temporary solution until we can directly copy updated textures to a mipmap level.
49 lines
863 B
Text
49 lines
863 B
Text
uniform matrix4 ViewProj;
|
|
|
|
uniform texture2d image;
|
|
uniform float2 imageTexel;
|
|
uniform int layer;
|
|
|
|
sampler_state textureSampler {
|
|
Filter = Point;
|
|
AddressU = Clamp;
|
|
AddressV = Clamp;
|
|
};
|
|
|
|
struct VertDataIn {
|
|
float4 pos : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct VertDataOut {
|
|
float4 pos : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
VertDataOut VSDefault(VertDataIn v_in)
|
|
{
|
|
VertDataOut vert_out;
|
|
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
|
|
vert_out.uv = v_in.uv;
|
|
return vert_out;
|
|
}
|
|
|
|
float4 PSAverage(VertDataOut v_in) : TARGET
|
|
{
|
|
float4 rgba = 0;
|
|
for (float x = -1; x <= 1; x++) {
|
|
for (float y = -1; y <= 1; y++) {
|
|
rgba += image.Sample(textureSampler, v_in.uv + vec2(x,y) * imageTexel + imageTexel);
|
|
}
|
|
}
|
|
return rgba / 9.0;
|
|
}
|
|
|
|
technique Draw
|
|
{
|
|
pass
|
|
{
|
|
vertex_shader = VSDefault(v_in);
|
|
pixel_shader = PSAverage(v_in);
|
|
}
|
|
}
|