From 2b51baa1981fb445b938e64bdce539e58fe70264 Mon Sep 17 00:00:00 2001 From: Runt <qingingrunt2010@qq.com> Date: Sat, 26 Jul 2025 13:17:14 +0000 Subject: [PATCH] 小窗缩放, 相机转小窗显示 小窗旋转,相机画面旋转 关闭按钮优化 --- LiveProject/shader/Shaders.metal | 63 +++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/LiveProject/shader/Shaders.metal b/LiveProject/shader/Shaders.metal index e69de29..5151b97 100644 --- a/LiveProject/shader/Shaders.metal +++ b/LiveProject/shader/Shaders.metal @@ -0,0 +1,63 @@ +// +// Shaders.metal +// LiveProject +// +// Created by 倪路朋 on 6/27/25. +// + +#include <metal_stdlib> +using namespace metal; + +struct VertexOut { + float4 position [[position]]; + float2 texCoord; +}; + +struct Uniforms { + float2 textureSize; + float2 drawableSize; +}; + +vertex VertexOut vertex_main(uint vertexID [[vertex_id]], + constant Uniforms& uniforms [[buffer(0)]]) { + float4 positions[4] = { + float4(-1.0, -1.0, 0, 1), + float4( 1.0, -1.0, 0, 1), + float4(-1.0, 1.0, 0, 1), + float4( 1.0, 1.0, 0, 1) + }; + + float2 texCoords[4] = { + float2(0.0, 1.0), + float2(1.0, 1.0), + float2(0.0, 0.0), + float2(1.0, 0.0) + }; + + float texAspect = uniforms.textureSize.x / uniforms.textureSize.y; + float viewAspect = uniforms.drawableSize.x / uniforms.drawableSize.y; + + float scaleX = 1.0; + float scaleY = 1.0; + + if (texAspect > viewAspect) { + scaleY = viewAspect / texAspect; + } else { + scaleX = texAspect / viewAspect; + } + + VertexOut out; + float4 pos = positions[vertexID]; + pos.x *= scaleX; + pos.y *= scaleY; + + out.position = pos; + out.texCoord = texCoords[vertexID]; + return out; +} + +fragment float4 fragment_main(VertexOut in [[stage_in]], + texture2d<half> tex [[texture(0)]]) { + constexpr sampler s(filter::linear); + return float4(tex.sample(s, in.texCoord)); +} -- Gitblit v1.9.1