GPUシェーダー管理を属性生成化
このコミットが含まれているのは:
8ファイル変更
+721
検索条件に一致するファイルはありません
@@ -0,0 +1,57 @@
|
||||
Texture2D source : register(t0);
|
||||
|
||||
cbuffer Parameters : register(b0)
|
||||
{
|
||||
float4 values[256];
|
||||
};
|
||||
|
||||
float get_value(uint index)
|
||||
{
|
||||
uint row = index >> 2;
|
||||
uint column = index & 3u;
|
||||
if (column == 0u)
|
||||
return values[row].x;
|
||||
if (column == 1u)
|
||||
return values[row].y;
|
||||
if (column == 2u)
|
||||
return values[row].z;
|
||||
return values[row].w;
|
||||
}
|
||||
|
||||
float convolve_channel(float value)
|
||||
{
|
||||
return floor(saturate(value) * 255.0) / 255.0;
|
||||
}
|
||||
|
||||
float4 convolve(float4 pos : SV_Position) : SV_Target
|
||||
{
|
||||
uint2 p = (uint2)floor(pos.xy);
|
||||
int width = (int)get_value(0u);
|
||||
int height = (int)get_value(1u);
|
||||
float divisor = get_value(2u);
|
||||
float offset = get_value(3u) / 255.0;
|
||||
int kernelSize = (int)get_value(4u);
|
||||
int half = (int)get_value(5u);
|
||||
float4 sum = 0.0;
|
||||
|
||||
for (int ky = 0; ky < kernelSize; ky++)
|
||||
{
|
||||
int sy = clamp((int)p.y + ky - half, 0, height - 1);
|
||||
for (int kx = 0; kx < kernelSize; kx++)
|
||||
{
|
||||
int sx = clamp((int)p.x + kx - half, 0, width - 1);
|
||||
float kv = get_value((uint)(8 + ky * kernelSize + kx));
|
||||
float4 sourceValue = source[uint2((uint)sx, (uint)sy)];
|
||||
float3 rgb = sourceValue.a <= 0.0 ? 0.0 : saturate(sourceValue.rgb / sourceValue.a);
|
||||
sum += float4(rgb, sourceValue.a) * kv;
|
||||
}
|
||||
}
|
||||
|
||||
float3 rgbOut = saturate(sum.rgb / divisor + offset);
|
||||
float alpha = saturate(sum.a / divisor + offset);
|
||||
return float4(
|
||||
convolve_channel(rgbOut.r * alpha),
|
||||
convolve_channel(rgbOut.g * alpha),
|
||||
convolve_channel(rgbOut.b * alpha),
|
||||
convolve_channel(alpha));
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
Texture2D source : register(t0);
|
||||
|
||||
cbuffer Parameters : register(b0)
|
||||
{
|
||||
float4 color;
|
||||
float4 rect;
|
||||
};
|
||||
|
||||
float4 fill_full(float4 pos : SV_Position) : SV_Target
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
float4 fill_partial(float4 pos : SV_Position) : SV_Target
|
||||
{
|
||||
uint2 p = (uint2)floor(pos.xy);
|
||||
uint4 r = (uint4)rect;
|
||||
if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w)
|
||||
return color;
|
||||
return source[p];
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
Texture2D source : register(t0);
|
||||
|
||||
cbuffer Parameters : register(b0)
|
||||
{
|
||||
float4 size;
|
||||
};
|
||||
|
||||
float channel(float value)
|
||||
{
|
||||
return floor(saturate(value) * 255.0) / 255.0;
|
||||
}
|
||||
|
||||
float4 resize_pack(float4 value)
|
||||
{
|
||||
return float4(channel(value.r), channel(value.g), channel(value.b), channel(value.a));
|
||||
}
|
||||
|
||||
float4 resize_nearest(float4 pos : SV_Position) : SV_Target
|
||||
{
|
||||
uint2 p = (uint2)floor(pos.xy);
|
||||
uint sourceWidth = (uint)size.x;
|
||||
uint sourceHeight = (uint)size.y;
|
||||
uint targetWidth = (uint)size.z;
|
||||
uint targetHeight = (uint)size.w;
|
||||
uint sx = min(((p.x * 2u + 1u) * sourceWidth) / (targetWidth * 2u), sourceWidth - 1u);
|
||||
uint sy = min(((p.y * 2u + 1u) * sourceHeight) / (targetHeight * 2u), sourceHeight - 1u);
|
||||
return source[uint2(sx, sy)];
|
||||
}
|
||||
|
||||
float4 resize_linear(float4 pos : SV_Position) : SV_Target
|
||||
{
|
||||
uint2 p = (uint2)floor(pos.xy);
|
||||
float sourceWidth = size.x;
|
||||
float sourceHeight = size.y;
|
||||
float targetWidth = size.z;
|
||||
float targetHeight = size.w;
|
||||
float u = (p.x + 0.5) * sourceWidth / targetWidth - 0.5;
|
||||
float v = (p.y + 0.5) * sourceHeight / targetHeight - 0.5;
|
||||
int x0 = (int)floor(u);
|
||||
int y0 = (int)floor(v);
|
||||
float tx = u - x0;
|
||||
float ty = v - y0;
|
||||
int maxX = (int)sourceWidth - 1;
|
||||
int maxY = (int)sourceHeight - 1;
|
||||
uint xA = (uint)clamp(x0, 0, maxX);
|
||||
uint yA = (uint)clamp(y0, 0, maxY);
|
||||
uint xB = (uint)clamp(x0 + 1, 0, maxX);
|
||||
uint yB = (uint)clamp(y0 + 1, 0, maxY);
|
||||
float4 c00 = source[uint2(xA, yA)];
|
||||
float4 c10 = source[uint2(xB, yA)];
|
||||
float4 c01 = source[uint2(xA, yB)];
|
||||
float4 c11 = source[uint2(xB, yB)];
|
||||
float4 top = c00 * (1.0 - tx) + c10 * tx;
|
||||
float4 bottom = c01 * (1.0 - tx) + c11 * tx;
|
||||
return resize_pack(top * (1.0 - ty) + bottom * ty);
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする