Skip to content

Commit

Permalink
added PBR materials, and updated screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjarne Lundgren authored and Bjarne Lundgren committed Jun 24, 2017
1 parent 554b8ac commit bf6d19d
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 23 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions AR-TicTacToe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
0633C8D91EF9108C00F6A311 /* GameState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0633C8D81EF9108C00F6A311 /* GameState.swift */; };
0633C8DB1EF910CB00F6A311 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0633C8DA1EF910CB00F6A311 /* Extensions.swift */; };
0633C8DD1EF910D900F6A311 /* Board.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0633C8DC1EF910D900F6A311 /* Board.swift */; };
708A9ACA1EFEFF4700D010B9 /* Media.scnassets in Resources */ = {isa = PBXBuildFile; fileRef = 708A9AC91EFEFF4700D010B9 /* Media.scnassets */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -32,6 +33,8 @@
0633C8D81EF9108C00F6A311 /* GameState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameState.swift; sourceTree = "<group>"; };
0633C8DA1EF910CB00F6A311 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
0633C8DC1EF910D900F6A311 /* Board.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Board.swift; sourceTree = "<group>"; };
708A9A921EFEF94700D010B9 /* media_sources.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = media_sources.txt; sourceTree = "<group>"; };
708A9AC91EFEFF4700D010B9 /* Media.scnassets */ = {isa = PBXFileReference; lastKnownFileType = wrapper.scnassets; path = Media.scnassets; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -75,6 +78,8 @@
0633C8D81EF9108C00F6A311 /* GameState.swift */,
0633C8DA1EF910CB00F6A311 /* Extensions.swift */,
0633C8DC1EF910D900F6A311 /* Board.swift */,
708A9A921EFEF94700D010B9 /* media_sources.txt */,
708A9AC91EFEFF4700D010B9 /* Media.scnassets */,
);
path = "AR-TicTacToe";
sourceTree = "<group>";
Expand Down Expand Up @@ -137,6 +142,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
708A9ACA1EFEFF4700D010B9 /* Media.scnassets in Resources */,
0633C8C91EF90F6600F6A311 /* LaunchScreen.storyboard in Resources */,
0633C8C61EF90F6600F6A311 /* Assets.xcassets in Resources */,
0633C8C41EF90F6600F6A311 /* Main.storyboard in Resources */,
Expand Down
Binary file not shown.
Binary file added AR-TicTacToe/.DS_Store
Binary file not shown.
24 changes: 8 additions & 16 deletions AR-TicTacToe/Board.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,19 @@ class Board {
let geometry = SCNBox(width: width,
height: height,
length: length,
chamferRadius: 0)
geometry.firstMaterial!.diffuse.contents = UIColor.darkGray
geometry.firstMaterial!.specular.contents = UIColor.white

let vgeometry = SCNBox(width: width,
height: height,
length: length,
chamferRadius: 0)
vgeometry.firstMaterial!.diffuse.contents = UIColor.darkGray
vgeometry.firstMaterial!.specular.contents = UIColor.white



chamferRadius: height * 0.1)
geometry.firstMaterial?.lightingModel = .physicallyBased
geometry.firstMaterial?.diffuse.contents = UIImage(named: "Media.scnassets/scuffed-plastic2-alb.png")
geometry.firstMaterial?.roughness.contents = UIImage(named: "Media.scnassets/scuffed-plastic-rough.png")
geometry.firstMaterial?.metalness.contents = UIImage(named: "Media.scnassets/scuffed-plastic-metal.png")
geometry.firstMaterial?.normal.contents = UIImage(named: "Media.scnassets/scuffed-plastic-normal.png")
geometry.firstMaterial?.ambientOcclusion.contents = UIImage(named: "Media.scnassets/scuffed-plastic-ao.png")

let horizontalLineNode = SCNNode(geometry: geometry)
horizontalLineNode.position = SCNVector3(lineOffset, height * 0.5, 0)
node.addChildNode(horizontalLineNode)

let verticalLineNode = SCNNode(geometry: vgeometry)

// using euler angles the object rotates around itself ;)
let verticalLineNode = SCNNode(geometry: geometry)
verticalLineNode.eulerAngles = SCNVector3(0, 90.0.degreesToRadians, 0)
verticalLineNode.position = SCNVector3(0, height * 0.5, lineOffset)
node.addChildNode(verticalLineNode)
Expand Down
18 changes: 14 additions & 4 deletions AR-TicTacToe/Figure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ class Figure {
class func xFigure() -> SCNNode {
let geometry = SCNCylinder(radius: Dimensions.FIGURE_RADIUS,
height: Dimensions.SQUARE_SIZE)
geometry.firstMaterial?.diffuse.contents = UIColor.brown
geometry.firstMaterial?.specular.contents = UIColor.white
geometry.firstMaterial?.lightingModel = .physicallyBased
geometry.firstMaterial?.diffuse.contents = UIImage(named: "Media.scnassets/scuffed-plastic6-alb.png")
geometry.firstMaterial?.roughness.contents = UIImage(named: "Media.scnassets/scuffed-plastic-rough.png")
geometry.firstMaterial?.metalness.contents = UIImage(named: "Media.scnassets/scuffed-plastic-metal.png")
geometry.firstMaterial?.normal.contents = UIImage(named: "Media.scnassets/scuffed-plastic-normal.png")
geometry.firstMaterial?.ambientOcclusion.contents = UIImage(named: "Media.scnassets/scuffed-plastic-ao.png")

let cylinderNode1 = SCNNode(geometry: geometry)
cylinderNode1.eulerAngles = SCNVector3(-90.0.degreesToRadians, 45.0.degreesToRadians, 0)
Expand All @@ -40,8 +44,14 @@ class Figure {
class func oFigure() -> SCNNode {
let geometry = SCNTorus(ringRadius: Dimensions.SQUARE_SIZE * 0.3,
pipeRadius: Dimensions.FIGURE_RADIUS)
geometry.firstMaterial?.diffuse.contents = UIColor.purple
geometry.firstMaterial?.specular.contents = UIColor.white
geometry.firstMaterial?.lightingModel = .physicallyBased
geometry.firstMaterial?.diffuse.contents = UIImage(named: "Media.scnassets/scuffed-plastic4-alb.png")
geometry.firstMaterial?.roughness.contents = UIImage(named: "Media.scnassets/scuffed-plastic-rough.png")
geometry.firstMaterial?.metalness.contents = UIImage(named: "Media.scnassets/scuffed-plastic-metal.png")
geometry.firstMaterial?.normal.contents = UIImage(named: "Media.scnassets/scuffed-plastic-normal.png")
geometry.firstMaterial?.ambientOcclusion.contents = UIImage(named: "Media.scnassets/scuffed-plastic-ao.png")

// applying PBR: https://medium.com/@avihay/amazing-physically-based-rendering-using-the-new-ios-10-scenekit-2489e43f7021

let torusNode = SCNNode(geometry: geometry)
torusNode.position = SCNVector3(0, Dimensions.FIGURE_RADIUS * 0.5, 0)
Expand Down
Binary file added AR-TicTacToe/Media.scnassets/environment.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AR-TicTacToe/Media.scnassets/environment_blur.exr
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions AR-TicTacToe/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ class ViewController: UIViewController, ARSCNViewDelegate {
// sceneView.antialiasingMode = .multisampling4X
//sceneView.preferredFramesPerSecond = 60
//sceneView.contentScaleFactor = 1.3
sceneView.antialiasingMode = .multisampling4X

sceneView.scene = SCNScene()
sceneView.automaticallyUpdatesLighting = true
//sceneView.autoenablesDefaultLighting = false
sceneView.automaticallyUpdatesLighting = false

let tap = UITapGestureRecognizer()
tap.addTarget(self, action: #selector(didTap))
Expand All @@ -96,6 +95,16 @@ class ViewController: UIViewController, ARSCNViewDelegate {
sceneView.addGestureRecognizer(pan)
}

// from APples app
func enableEnvironmentMapWithIntensity(_ intensity: CGFloat) {
if sceneView.scene.lightingEnvironment.contents == nil {
if let environmentMap = UIImage(named: "Media.scnassets/environment_blur.exr") {
sceneView.scene.lightingEnvironment.contents = environmentMap
}
}
sceneView.scene.lightingEnvironment.intensity = intensity
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

Expand Down Expand Up @@ -132,6 +141,7 @@ class ViewController: UIViewController, ARSCNViewDelegate {
board.node.position = position
sceneView.scene.rootNode.addChildNode(board.node)

/*
let spotLight = SCNLight()
spotLight.type = .spot
spotLight.castsShadow = true
Expand All @@ -144,6 +154,7 @@ class ViewController: UIViewController, ARSCNViewDelegate {
lightNode!.position = SCNVector3(position.x, position.y + 25, position.z)
lightNode!.constraints = [constraint]
sceneView.scene.rootNode.addChildNode(lightNode!)
*/

for (key, figure) in figures {
//TODO: how to get the coordinates for these?!?!?
Expand Down Expand Up @@ -300,6 +311,22 @@ class ViewController: UIViewController, ARSCNViewDelegate {

// MARK: - ARSCNViewDelegate

func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {

// from apples app
DispatchQueue.main.async {
// If light estimation is enabled, update the intensity of the model's lights and the environment map
if let lightEstimate = self.sceneView.session.currentFrame?.lightEstimate {

// Apple divived the ambientIntensity by 40, I find that, atleast with the materials used
// here that it's a big too bright, so I increased to to 50..
self.enableEnvironmentMapWithIntensity(lightEstimate.ambientIntensity / 50)
} else {
self.enableEnvironmentMapWithIntensity(25)
}
}
}

// did at plane(?)
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
print("didAdd")
Expand Down
8 changes: 8 additions & 0 deletions AR-TicTacToe/media_sources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


plastic (unreal engine variants):
https://freepbr.com/materials/worn-scuffed-plastic-pbr-material/

environment files:
Apple ARKIt Demo App

Binary file added tictactoe-pbr-closeup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tictactoe-pbr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bf6d19d

Please sign in to comment.