Game Development Reference
In-Depth Information
At the lowest level, an SCNRenderer instance handles the core rendering of the layers and views. It is possible
to instantiate an SCNRenderer and pass an OpenGLContext context. Doing so provides more control over the
rendering. For example, you might want to realize advanced post-processing effects not by drawing directly to the
OpenGL framebuffer, but by drawing in a texture and processing that texture afterwards (using OpenGL Frame
Buffer Objects).
But just for simple tweaks like customizing the background or drawing an overlay, there is an easier approach
that involves taking advantage of the SCNSceneRendererDelegate protocol: both SCNView and SCNLayer implement
this protocol. The delegate on the client side can implement the following methods:
(void)renderer:(id <SCNSceneRenderer>)aRenderer willRenderScene:(SCNScene *)
scene atTime:(NSTimeInterval)time;
(void)renderer:(id <SCNSceneRenderer>)aRenderer didRenderScene:(SCNScene *)
scene atTime:(NSTimeInterval)time;
Typically, willRenderScene:atTime: is suitable to draw a custom background and didRenderScene:atTime: is a
good fit for an overlay.
Both SCNRenderer and SCNRendererDelegate operate at the scene level.
It is possible to replace and/or customize the rendering at the node level, such as for each SCNNode .
SCNNode owns a property called rendererDelegate , which expects to be assigned an SCNNodeRendererDelegate .
Once that is done, Scene Kit will no longer perform any rendering for this particular node, but will call the delegate
with the following method:
- (void)renderNode:(SCNNode *)node renderer:(SCNRenderer *)renderer arguments:(NSDictionary *)
arguments;
Even though no rendering is done, the scene graph is still evaluated, including the running animation. This
means that the delegate can access matrices being animated, take advantage of the whole scene graph structure, and
still be able to override the Scene Kit rendering with its own.
Relationship to COLLADA
It is well known that COLLADA is a dense specification allowing a lot of flexibility that makes supporting it
exhaustively quite challenging. It is also common knowledge that Apple delivers a simple but powerful set of
consistent graphic APIs for OS X developers (ImageKit, Core Image, Core Animation, etc.). Because Scene Kit is a
high-level Objective-C API, Apple has had to make choices regarding the set of supported and exposed COLLADA
features. While both COLLADA and Scene Kit provide a scene graph and common 3D entities such as nodes, cameras,
lights, and materials, there are many differences, including the following:
Scene Kit does not implement a stack of transforms; only one transform per node is
supported. The consequence is that animations with transformed nodes are typically flattened
before being imported into Scene Kit in order to satisfy this constraint.
Only one light, mesh, and camera are allowed per node. This limitation leads to a simpler API.
Scene Kit has added new properties to leverage features of its renderer, such as
litPerPixel to
specify whether lighting is performed at the pixel or at the vertex level.
Conclusion
This chapter provided information to get you started efficiently with Scene Kit. The reader is encouraged to explore
more advanced features such as parametric geometry (cubes, capsules, torus, 3D text, and more), custom shaders,
and access to imported geometry information (vertices and indices).
 
Search WWH ::




Custom Search