heestand-xyz / PixelKit

Live Graphics in Swift & Metal
MIT License
885 stars 66 forks source link

Text generation? #6

Closed alyfreym closed 5 years ago

alyfreym commented 5 years ago

Hi, is it planned to add the function of generating text in the form of a texture using  Metal API?. What methods do you know for generating text using metal? I would be very happy if you gave an example. My goal is to overlay the effect of fire on the text. thanks for the answer

heestand-xyz commented 5 years ago

I don't know how to render text directly in metal, tho we got the TextPIX that renders in SpriteKit! http://pixelkit.net/docs/Classes/TextPIX.html

heestand-xyz commented 5 years ago

I've fixed the TextPIX in the latest version of PixelKit 0.6.5

heestand-xyz commented 5 years ago
Skärmavbild 2019-06-26 kl  19 38 39

Here's an example of text with fire:

let res = PIX.Res.cgSize(view.bounds.size) * PIX.Res.scale

let textPix = TextPIX(res: res)
textPix.text = "PixelKit"
textPix.font = .monospacedSystemFont(ofSize: 200, weight: .bold)

let noisePix = NoisePIX(res: res)
noisePix.colored = true
noisePix.zoom = 0.1

let feedPix = textPix._feed(0.8) { feedPix -> (PIX & PIXOut) in
    return feedPix._displace(with: noisePix, distance: 0.1)
}

let gradientPix = GradientPIX(res: res)
gradientPix.colorSteps = [
    ColorStep(0.0, .black),
    ColorStep(1 / 3, .red),
    ColorStep(2 / 3, .yellow),
    ColorStep(1.0, .white)
]

let lookup = LookupPIX()
lookup.inPixA = feedPix
lookup.inPixB = gradientPix

finalPix = lookup + textPix
finalPix.view.frame = view.bounds
view.addSubview(finalPix.view)
alyfreym commented 5 years ago

Omg, you saved me many hours, thanks!!!!