Permalink
Browse files

added PBR materials, and updated screenshots

  • Loading branch information...
Bjarne Lundgren Bjarne Lundgren
Bjarne Lundgren authored and Bjarne Lundgren committed Jun 24, 2017
1 parent 554b8ac commit bf6d19de1e720bdb47fdf79069f8ee43a3133afe
View
BIN +0 Bytes (100%) .DS_Store
Binary file not shown.
@@ -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 */
@@ -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 */
@@ -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>";
@@ -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 */,
View
Binary file not shown.
View
@@ -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)
View
@@ -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)
@@ -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)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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))
@@ -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)
@@ -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
@@ -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?!?!?
@@ -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")
@@ -0,0 +1,8 @@
plastic (unreal engine variants):
https://freepbr.com/materials/worn-scuffed-plastic-pbr-material/
environment files:
Apple ARKIt Demo App
View
Binary file not shown.
View
BIN +180 KB tictactoe-pbr.jpg
Binary file not shown.

0 comments on commit bf6d19d

Please sign in to comment.