Vertex Shader in SpriteKit

一个人想着一个人 提交于 2019-12-23 12:35:24

问题


Is it possible to run an openGL Shader Program with both vertex and fragment shaders in SpriteKit?

It seems only fragment Shaders are available.

SceneKit offers it via the SCNProgram class


回答1:


Actually vertex shaders are useful for much more than just transformations and projection. One of the most useful features is making calculations at each vertex, and then have the hardware interpolate the results, passing them to the fragment shader via 'varying' variables. (This is significantly more efficient than trying to calculate the interpolated values in the fragment shader itself.)

The simplest example is gouraud shading: You can calculate lighting in the vertex shader, and have the hardware interpolate these values, to be used in the fragment shader. This is much more efficient than calculating the lighting in the latter. (However, this is just a simplistic example. There are much more useful examples of this as well. Eg. many blurring shaders use this technique because it's much more efficient.)

The cocos2d library supports vertex shaders (and these techniques can be used with it.) So it's not like it's something that nobody uses.

There is probably no way of using vertex shaders currently in SpriteKit. You might have better luck by using SceneKit objects (which can be seamlessly embedded in a SpriteKit scene.)




回答2:


According to Apple's SKShader documentation it says this:

An SKShader object holds a custom OpenGL ES fragment shader. Shader objects are used to customize the drawing behavior of many different kinds of nodes in Sprite Kit.

Any other tutorial site that speaks about shaders with SpriteKit always refer to them being fragment shaders with no mention of vertex shaders.




回答3:


Vertex shader are mainly responsible for projecting 3D objects on 2D screens which is not needed for spritekit since it is a 2D engine.

The other uses of vertex shaders are to scale, transform and rotate objects which are all can be achieved from your spritekit code.

That may be the reason for not having them if they are really not there :)



来源:https://stackoverflow.com/questions/29597314/vertex-shader-in-spritekit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!