You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
tags: [computer graphics, physically based rendering, swift, ios, apple, mobile application development]
@@ -15,7 +15,7 @@ authors: [fabrizio_duroni]
15
15
16
16
---
17
17
18
-
SceneKit is one of the Apple framework I love the most. What is SceneKit? Let's see the definition from the
18
+
SceneKit is one of the framework inside the iOS SDK that I love the most. What is SceneKit? Let's see the definition from the
19
19
developer apple website:
20
20
21
21
>SceneKit combines a high-performance rendering engine with a descriptive API for import, manipulation, and rendering of 3D assets. Unlike lower-level APIs such as Metal and OpenGL that require you to implement in precise detail the rendering algorithms that display a scene, SceneKit requires only descriptions of your scene’s contents and the actions or animations you want it to perform.
@@ -30,13 +30,10 @@ In this post we will create a scene from scratch that uses the main PBR features
30
30
find inside SceneKit. At the end of this post you will be able to render the scene contained in the image below. So
31
31
it's time to start coding!!
32
32
33
-

33
+
{% include blog-lazy-image.html description="Physically based scene right" width="1500" height="682" src="/assets/images/posts/physically-based-rendering-scene-right.jpg" %}
34
34
35
-
The general approach used in the construction of the scene will be the following: for each main scene category
36
-
component we will create a class that encapsulate the creation of the corresponding `SCNNode`, the base SceneKit unit
37
-
element, and its setup to obtain the feature we want.
38
-
The first class we are going to create is the `Light` class that encapsulate the base features we need to set up the
39
-
light: position, rotation and generic color. Light in SceneKit are represented using the `SCNLight` class.
35
+
The general approach used in the construction of the scene will be the following: for each main scene category component we will create a class that encapsulate the creation of the corresponding `SCNNode`, the base SceneKit unit element, and its setup to obtain the feature we want.
36
+
The first class we are going to create is the `Light` class that encapsulate the base features we need to set up the light: position, rotation and generic color. Light in SceneKit are represented using the `SCNLight` class.
40
37
41
38
```swift
42
39
classLight {
@@ -84,7 +81,7 @@ We are now ready to create our `PhysicallyBasedLight` as an child of `Light` cla
84
81
be of type `.directional`, and we will customize its `intensity` and `temperature`. The intensity is the flux of the
85
82
light (again, go to check [my first post about physically based rendering](/2017/12/07/physically-base-rendering-introduction.html"physically based introduction post")
86
83
if you don't know what it is :stuck_out_tongue:), and the second one is the color temperature expressed in Kelvin
87
-
(remember: 6500 K corresponds to pure white sunlight). We also activate other interesting features: by setting
84
+
(remember: 6500 K corresponds to pure white sunlight). We activate other interesting features: by setting
88
85
`castsShadow` to `true` we activate the rendering of shadow using shadow mapping technique, and by setting
89
86
`orthographicScale` to `10` we extend a little bit the visible area of the scene from the light, so we are improving the
90
87
construction of the shadow map.
@@ -192,11 +189,11 @@ class Camera {
192
189
}
193
190
```
194
191
195
-
Now its time to think about the objects we want to display in the scene. For that reason we create a `Object` class
192
+
Now it's time to think about the objects we want to display in the scene. For that reason we create a `Object` class
196
193
that will represent each kind of object we want to show in the scene. Obviously as for the previous classes, also
197
194
the `Object` class will expose a `node` property of type `SCNNode` that represents our object in the scene. We define
198
195
this class with multiple initializer that let as create object instances using various configurations: init as an empty
199
-
object, init using a `SCNGeomtry` instance, using a mesh loaded as a `MDLObject` using the [Model I\O](https://developer.apple.com/documentation/modelio"Model I\O")
196
+
object, init using a `SCNGeometry` instance, using a mesh loaded as a `MDLObject` using the [Model I\O](https://developer.apple.com/documentation/modelio"Model I\O")
200
197
Apple framework. This framework let us import/export 3D models in a wide range of common available formats.
201
198
202
199
```swift
@@ -257,7 +254,7 @@ with a single property `material` of type `SCNMaterial`. On this material proper
257
254
*`normal.contents` property with an appropriate normal value.
258
255
*`ambientOcclusion.contents` property with an appropriate ambient occlusion value
259
256
260
-
As you can see, we have all the properties we discussed in my [introduction to physically based rendering](/2017/12/07/physically-base-rendering-introduction.html"physically based introduction post").
257
+
As you can see, we have all the properties we discussed in my [introduction to physically based rendering post](/2017/12/07/physically-base-rendering-introduction.html"physically based introduction post").
261
258
We have also other properties that help us improve the realism, especially with indirect lighting for what concern the
262
259
[ambient occlusion](https://en.wikipedia.org/wiki/Ambient_occlusion"ambient occlusion") (this property/technique is
263
260
not related to PBR but helps to improve the final rendering). Which kind of values accept this properties? As
@@ -290,7 +287,7 @@ class PhysicallyBasedMaterial {
290
287
291
288
Now it's time to construct our scene :relieved:!! We start by creating a new class `PhysicallyBasedScene`, subclass
292
289
of `SCNScene`. In this way we can customize the default initializer with the step needed to add all the element of
293
-
our scene, and also because in this way we have direct access to all the properties of `SCNScene`. We also define a
290
+
our scene, and also because in this way we have direct access to all the properties of `SCNScene`. We define a
294
291
protocol, `Scene`, that we will use to manage some gesture and animate the scene. So in the initializer we will call
295
292
three methods: `createCamera()` in which we will create the camera, `createLight()` in which we will create the
296
293
lights, `createObjects()` in which we will create the objects. NB: we need to define also the initializer with
@@ -445,7 +442,7 @@ The meshes are stored as [wavefront obj file](https://en.wikipedia.org/wiki/Wave
445
442
As you can see from the previous code, we use a class called `MeshLoader`. How does it work? It uses the [Model I/O](https://developer.apple.com/documentation/modelio"Model I/O")
446
443
Apple framework to load the obj file as a `MDLAsset` and then we extract the first `MDLObject`.
0 commit comments