This commit is contained in:
Ali 2022-05-09 20:01:32 +04:00
parent 609df3331f
commit 5ad827599b
2 changed files with 21 additions and 3 deletions

View File

@ -17,8 +17,19 @@ vertex Varyings wallpaperVertex(constant Vertex *verticies[[buffer(0)]], unsigne
return out;
}
fragment half4 wallpaperFragment(Varyings in[[stage_in]]) {
fragment half4 wallpaperFragment1(Varyings in[[stage_in]]) {
float4 out = float4(0.0, 1.0, 0.0, 1.0);
return half4(out);
}
fragment half4 wallpaperFragment(Varyings in[[stage_in]], constant uint2 &resolution[[buffer(0)]], constant float &time[[buffer(1)]]) {
half4 p = half4(in.position);
p.y = -p.y;
p.y /= resolution.y;
p.y += tan(time + tan(p.x) + sin(.2 * p.x));
float4 out = float4(0.0, (0.3 + (p.y < 0.0 ? 0.0 : 1.0 - p.y * 3.0)) * 0.2, 0.0, 1.0);
return half4(out);
}

View File

@ -17,6 +17,7 @@ import TelegramAnimatedStickerNode
import HierarchyTrackingLayer
import MetalKit
import HierarchyTrackingLayer
import simd
private final class NullActionClass: NSObject, CAAction {
static let shared = NullActionClass()
@ -247,13 +248,19 @@ final class MetalWallpaperBackgroundNode: ASDisplayNode, WallpaperBackgroundNode
var vertices: [Float] = [
-1.0, -1.0,
1.0, -1.0,
-1.0, animationOffset * 1.0,
1.0, animationOffset * 1.0
-1.0, 1.0,
1.0, 1.0
]
renderEncoder.setRenderPipelineState(self.renderPipelineState)
renderEncoder.setVertexBytes(&vertices, length: 4 * vertices.count, index: 0)
var resolution = simd_uint2(UInt32(drawable.texture.width), UInt32(drawable.texture.height))
renderEncoder.setFragmentBytes(&resolution, length: MemoryLayout<simd_uint2>.size * 2, index: 0)
var time = Float(timestamp) * 0.25
renderEncoder.setFragmentBytes(&time, length: 4, index: 1)
renderEncoder.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: 4, instanceCount: 1)