44 lines
1.1 KiB
GLSL
44 lines
1.1 KiB
GLSL
#version 450
|
||
|
||
layout (binding = 1) uniform sampler2D samplerColor;
|
||
|
||
layout (location = 0) in vec2 inUV;
|
||
layout (location = 1) in vec3 inNormal;
|
||
|
||
layout(push_constant) uniform PushConstants {
|
||
float zoom;
|
||
float r;
|
||
float g;
|
||
float b;
|
||
float radius;
|
||
float ux;
|
||
float uy;
|
||
} pushConstants;
|
||
|
||
|
||
layout (location = 0) out vec4 outFragColor;
|
||
|
||
void main()
|
||
{
|
||
// 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)
|
||
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;
|
||
}
|
||
|
||
} |