Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertex Shader in SpriteKit

Tags:

sprite-kit

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

like image 242
Dave Avatar asked Oct 31 '22 07:10

Dave


1 Answers

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.)

like image 174
Warp Avatar answered Jan 04 '23 13:01

Warp