添加圆心遮罩

This commit is contained in:
xsl
2026-01-08 21:19:32 +08:00
parent b44162e6cb
commit 60b40bfd5f
11 changed files with 96 additions and 22 deletions
+28 -2
View File
@@ -9,7 +9,33 @@ layout(location = 0) out vec4 outColor;
// 纹理采样器
layout(binding = 0) uniform sampler2D texSampler;
layout(push_constant) uniform PushConstants {
float zoom;
float r;
float g;
float b;
float radius;
float ux;
float uy;
} pushConstants;
void main() {
// 采样纹理
outColor = texture(texSampler, inTexCoord);
// outFragColor = color;
// 获取当前片元的屏幕坐标(左下角为原点)
vec2 fragCoord = gl_FragCoord.xy;
// 屏幕中心(480x480 的中心是 (240, 240)
vec2 center = vec2(240.0, 240.0);
// 计算到中心的距离(欧氏距离,单位:像素)
float dist = length(fragCoord - center);
// 判断是否在半径之外
if (dist > pushConstants.radius) {
// 使用 push constant 中的 RGB 颜色(注意 alpha 设为 1.0
outColor = vec4(pushConstants.r, pushConstants.g, pushConstants.b, 1.0);
} else {
// 采样纹理
outColor = texture(texSampler, inTexCoord);
}
}
Binary file not shown.
+8 -2
View File
@@ -38,7 +38,13 @@ const vec2 texCoords[6] = vec2[6](
// 定义 Push Constant,只有一个 float
layout(push_constant) uniform PushConstants {
float myValue;
float zoom;
float r;
float g;
float b;
float radius;
float ux;
float uy;
} pushConstants;
@@ -48,7 +54,7 @@ layout(location = 0) out vec2 outTexCoord;
void main() {
// 获取顶点位置
vec2 position = positions[gl_VertexIndex];
position = position * pushConstants.myValue;
position = position * pushConstants.zoom;
// 设置输出位置(Vulkan使用不同的坐标系)
gl_Position = vec4(position, 0.0, 1.0);
Binary file not shown.
+24 -5
View File
@@ -6,7 +6,11 @@ layout (location = 0) in vec2 inUV;
layout (location = 1) in vec3 inNormal;
layout(push_constant) uniform PushConstants {
float myValue;
float zoom;
float r;
float g;
float b;
float radius;
float ux;
float uy;
} pushConstants;
@@ -16,10 +20,25 @@ layout (location = 0) out vec4 outFragColor;
void main()
{
vec2 pos = vec2(pushConstants.ux/4096.f, pushConstants.uy/2048.f);
vec2 uv = pos + vec2(inUV.x/8.f, inUV.y/4.f);
vec4 color = texture(samplerColor, uv);
// outFragColor = color;
// 获取当前片元的屏幕坐标(左下角为原点)
vec2 fragCoord = gl_FragCoord.xy;
outFragColor = color;
// 屏幕中心(480x480 的中心是 (240, 240)
vec2 center = vec2(240.0, 240.0);
// 计算到中心的距离(欧氏距离,单位:像素)
float dist = length(fragCoord - center);
// 判断是否在半径之外
if (dist > pushConstants.radius) {
// 使用 push constant 中的 RGB 颜色(注意 alpha 设为 1.0
outFragColor = vec4(pushConstants.r, pushConstants.g, pushConstants.b, 1.0);
} else {
vec2 pos = vec2(pushConstants.ux/4096.f, pushConstants.uy/2048.f);
vec2 uv = pos + vec2(inUV.x/8.f, inUV.y/4.f);
vec4 color = texture(samplerColor, uv);
outFragColor = color;
}
}
Binary file not shown.
+6 -2
View File
@@ -17,7 +17,11 @@ layout (location = 0) out vec2 outUV;
layout (location = 1) out vec3 outNormal;
layout(push_constant) uniform PushConstants {
float myValue;
float zoom;
float r;
float g;
float b;
float radius;
float ux;
float uy;
} pushConstants;
@@ -32,7 +36,7 @@ void main()
outUV = inUV;
vec2 position = vec2(inPos.xy*2 -1);
position = position * pushConstants.myValue;
position = position * pushConstants.zoom;
gl_Position = vec4(position, 0.5, 1.0);
vec4 pos = ubo.model * vec4(inPos, 1.0);
Binary file not shown.