iOS 12和SKShader中不推荐使用OpenGL ES [英] OpenGL ES deprecated in iOS 12 and SKShader
问题描述
我对SpriteKit中的着色器的概念和用法非常陌生.
I am very new to the concept and use of shaders in SpriteKit.
我发现了本教程,该教程介绍了如何使用附加到Color Sprite的Custom Shader属性的自定义着色器文件Fractal.fsh渲染Mandelbrot分形.
I found this tutorial on how to render a Mandelbrot fractal with a custom shader file - Fractal.fsh - attached to a Color Sprite's Custom Shader property.
https://www.weheartswift.com/fractals-Xcode-6/
一切正常,我自以为是,学习SpriteKit中的OpenGL ES和自定义着色器将是一个有趣的练习.
It works fine and I thought to my self that learning about OpenGL ES and custom shaders in SpriteKit would be a fun exercise.
不过,根据Apple的说法,从iOS 12开始不推荐使用OpenGL ES.
According to Apple though, OpenGL ES is deprecated as of iOS 12.
我的问题是这个
这是否意味着到目前为止,SpriteKit中使用的自定义着色器应该用Metal编写?
Does this mean that custom shaders for use in SpriteKit should be written in Metal as of now?
我试图找出如何重写Metal中第一个链接中提到的fractal.fsh着色器代码的方法,但是我尚未-能够找到有关如何从OpenGL转换现有的自定义SKShader的资源. ES转换为金属.但是,我并不是要找人重写该代码以使用Metal,而只是指向正确方向的指针.
I have tried to figure out how to rewrite the fractal.fsh shader code, referred to in the first link, in Metal but I have not - yet - been able to find any resources on how to convert existing custom SKShader's from OpenGL ES to Metal. However, I am NOT looking for someone to rewrite that code to use Metal, only a pointer in the right direction.
更新: 根据@ Knight0fDragon的回答,我将尝试阐明我的问题:
UPDATE: Based on the answer from @Knight0fDragon I will try to clarify my question:
有关SKShader类的文档指出:
The documentation on the SKShader class states that:
"SKShader对象包含一个自定义OpenGL ES片段着色器."
"An SKShader object holds a custom OpenGL ES fragment shader."
https://developer.apple.com/documentation/spritekit/skshader
因此,如果SKShader对象包含自定义的OpenGL ES片段着色器,那么在不支持OpenGL ES的支持下它将保留什么内容?
So if a SKShader object holds a custom OpenGL ES fragment shader, what will it hold after the support for OpenGL ES is deprecated?
如果在iOS 12之前不能使用OpenGL ES,如何创建自定义片段着色器以在SpriteKit中使用呢? 首先,我认为可以将包含GLSL代码的* .fsh文件替换为包含等效金属代码的* .metal文件,但是这种评估显然太幼稚(因为我尝试过,因此无法将* .metal文件分配给Color Sprite的自定义着色器"属性)
How would one go on about creating a custom fragment shader to use in SpriteKit if one cannot use OpenGL ES as of iOS 12? First I thought that the *.fsh file containing the GLSL code could be replaced with a *.metal file containing equivalent metal code but that assessment was clearly too naive (because I tried and I couldn't assign the *.metal file to the Color Sprite's Custom Shader property)
推荐答案
From the documentation on "Executing Shaders in Metal and OpenGL ":
在支持该功能的设备上,您提供给SKShader的GLSL代码会自动转换为Metal着色语言并在Metal渲染器上运行.
On devices that support it, the GLSL code you provide to SKShader is automatically converted to Metal shading language and run on a Metal renderer.
因此,据我了解,SpriteKit将使用Metal作为可用的后端,并在编译它们时为您转换着色器.我没有找到直接在Metal中编写着色器的选项.
So, from my understanding, SpriteKit will use Metal as a backend where it is available and convert your shaders for you when compiling them. I did not find an option to directly write the shaders in Metal.
这篇关于iOS 12和SKShader中不推荐使用OpenGL ES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!