├── .gitignore ├── LICENSE ├── README.md ├── SCNShaderModifier-Examples.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── SCNShaderModifier-Examples ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ShaderGeometries.swift ├── Shaders │ ├── cube_circular.shader │ ├── sphere_ripple.shader │ ├── sun_geometry.shader │ └── sun_surface.shader └── ViewController.swift └── media ├── cube-example.gif └── sun-example.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Maxx Cobb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ARKit + SceneKit Shaders Intro 2 | 3 | [Check out the Medium post that goes with this repo](https://medium.com/@maxxfrazer/arkit-scenekit-shaders-intro-99df65137006) 4 | 5 | 6 | Tutorial examples: 7 | 8 | ![Sun example](media/sun-example.gif) 9 | ![Cube example](media/cube-example.gif) 10 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 00649F6921A7CFD100163BEB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00649F6821A7CFD100163BEB /* AppDelegate.swift */; }; 11 | 00649F6D21A7CFD100163BEB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00649F6C21A7CFD100163BEB /* ViewController.swift */; }; 12 | 00649F7021A7CFD100163BEB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00649F6E21A7CFD100163BEB /* Main.storyboard */; }; 13 | 00649F7221A7CFD100163BEB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 00649F7121A7CFD100163BEB /* Assets.xcassets */; }; 14 | 00649F7521A7CFD100163BEB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00649F7321A7CFD100163BEB /* LaunchScreen.storyboard */; }; 15 | 00649F7D21A7D00E00163BEB /* ShaderGeometries.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00649F7C21A7D00E00163BEB /* ShaderGeometries.swift */; }; 16 | 00649F8021A7D04400163BEB /* sun_geometry.shader in Resources */ = {isa = PBXBuildFile; fileRef = 00649F7F21A7D04400163BEB /* sun_geometry.shader */; }; 17 | 00649F8221A7D05400163BEB /* sun_surface.shader in Resources */ = {isa = PBXBuildFile; fileRef = 00649F8121A7D05400163BEB /* sun_surface.shader */; }; 18 | 00649F8421A7D05D00163BEB /* cube_circular.shader in Resources */ = {isa = PBXBuildFile; fileRef = 00649F8321A7D05D00163BEB /* cube_circular.shader */; }; 19 | 00649F8621A7D06500163BEB /* sphere_ripple.shader in Resources */ = {isa = PBXBuildFile; fileRef = 00649F8521A7D06500163BEB /* sphere_ripple.shader */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 00649F6521A7CFD100163BEB /* SCNShaderModifier-Examples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SCNShaderModifier-Examples.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 00649F6821A7CFD100163BEB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 25 | 00649F6C21A7CFD100163BEB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 26 | 00649F6F21A7CFD100163BEB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | 00649F7121A7CFD100163BEB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 00649F7421A7CFD100163BEB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 00649F7621A7CFD100163BEB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 00649F7C21A7D00E00163BEB /* ShaderGeometries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShaderGeometries.swift; sourceTree = ""; }; 31 | 00649F7F21A7D04400163BEB /* sun_geometry.shader */ = {isa = PBXFileReference; lastKnownFileType = text; path = sun_geometry.shader; sourceTree = ""; }; 32 | 00649F8121A7D05400163BEB /* sun_surface.shader */ = {isa = PBXFileReference; lastKnownFileType = text; path = sun_surface.shader; sourceTree = ""; }; 33 | 00649F8321A7D05D00163BEB /* cube_circular.shader */ = {isa = PBXFileReference; lastKnownFileType = text; path = cube_circular.shader; sourceTree = ""; }; 34 | 00649F8521A7D06500163BEB /* sphere_ripple.shader */ = {isa = PBXFileReference; lastKnownFileType = text; path = sphere_ripple.shader; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 00649F6221A7CFD100163BEB /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 00649F5C21A7CFD100163BEB = { 49 | isa = PBXGroup; 50 | children = ( 51 | 00649F6721A7CFD100163BEB /* SCNShaderModifier-Examples */, 52 | 00649F6621A7CFD100163BEB /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 00649F6621A7CFD100163BEB /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 00649F6521A7CFD100163BEB /* SCNShaderModifier-Examples.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 00649F6721A7CFD100163BEB /* SCNShaderModifier-Examples */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 00649F6821A7CFD100163BEB /* AppDelegate.swift */, 68 | 00649F6C21A7CFD100163BEB /* ViewController.swift */, 69 | 00649F7C21A7D00E00163BEB /* ShaderGeometries.swift */, 70 | 00649F7E21A7D03000163BEB /* Shaders */, 71 | 00649F6E21A7CFD100163BEB /* Main.storyboard */, 72 | 00649F7121A7CFD100163BEB /* Assets.xcassets */, 73 | 00649F7321A7CFD100163BEB /* LaunchScreen.storyboard */, 74 | 00649F7621A7CFD100163BEB /* Info.plist */, 75 | ); 76 | path = "SCNShaderModifier-Examples"; 77 | sourceTree = ""; 78 | }; 79 | 00649F7E21A7D03000163BEB /* Shaders */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 00649F7F21A7D04400163BEB /* sun_geometry.shader */, 83 | 00649F8121A7D05400163BEB /* sun_surface.shader */, 84 | 00649F8321A7D05D00163BEB /* cube_circular.shader */, 85 | 00649F8521A7D06500163BEB /* sphere_ripple.shader */, 86 | ); 87 | path = Shaders; 88 | sourceTree = ""; 89 | }; 90 | /* End PBXGroup section */ 91 | 92 | /* Begin PBXNativeTarget section */ 93 | 00649F6421A7CFD100163BEB /* SCNShaderModifier-Examples */ = { 94 | isa = PBXNativeTarget; 95 | buildConfigurationList = 00649F7921A7CFD100163BEB /* Build configuration list for PBXNativeTarget "SCNShaderModifier-Examples" */; 96 | buildPhases = ( 97 | 00649F6121A7CFD100163BEB /* Sources */, 98 | 00649F6221A7CFD100163BEB /* Frameworks */, 99 | 00649F6321A7CFD100163BEB /* Resources */, 100 | 00649F8721A7D0E300163BEB /* SwiftLint */, 101 | ); 102 | buildRules = ( 103 | ); 104 | dependencies = ( 105 | ); 106 | name = "SCNShaderModifier-Examples"; 107 | productName = "SCNShaderModifier-Examples"; 108 | productReference = 00649F6521A7CFD100163BEB /* SCNShaderModifier-Examples.app */; 109 | productType = "com.apple.product-type.application"; 110 | }; 111 | /* End PBXNativeTarget section */ 112 | 113 | /* Begin PBXProject section */ 114 | 00649F5D21A7CFD100163BEB /* Project object */ = { 115 | isa = PBXProject; 116 | attributes = { 117 | LastSwiftUpdateCheck = 1010; 118 | LastUpgradeCheck = 1010; 119 | ORGANIZATIONNAME = "Max Cobb"; 120 | TargetAttributes = { 121 | 00649F6421A7CFD100163BEB = { 122 | CreatedOnToolsVersion = 10.1; 123 | }; 124 | }; 125 | }; 126 | buildConfigurationList = 00649F6021A7CFD100163BEB /* Build configuration list for PBXProject "SCNShaderModifier-Examples" */; 127 | compatibilityVersion = "Xcode 9.3"; 128 | developmentRegion = en; 129 | hasScannedForEncodings = 0; 130 | knownRegions = ( 131 | en, 132 | Base, 133 | ); 134 | mainGroup = 00649F5C21A7CFD100163BEB; 135 | productRefGroup = 00649F6621A7CFD100163BEB /* Products */; 136 | projectDirPath = ""; 137 | projectRoot = ""; 138 | targets = ( 139 | 00649F6421A7CFD100163BEB /* SCNShaderModifier-Examples */, 140 | ); 141 | }; 142 | /* End PBXProject section */ 143 | 144 | /* Begin PBXResourcesBuildPhase section */ 145 | 00649F6321A7CFD100163BEB /* Resources */ = { 146 | isa = PBXResourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | 00649F8221A7D05400163BEB /* sun_surface.shader in Resources */, 150 | 00649F7521A7CFD100163BEB /* LaunchScreen.storyboard in Resources */, 151 | 00649F8021A7D04400163BEB /* sun_geometry.shader in Resources */, 152 | 00649F7221A7CFD100163BEB /* Assets.xcassets in Resources */, 153 | 00649F8621A7D06500163BEB /* sphere_ripple.shader in Resources */, 154 | 00649F7021A7CFD100163BEB /* Main.storyboard in Resources */, 155 | 00649F8421A7D05D00163BEB /* cube_circular.shader in Resources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXResourcesBuildPhase section */ 160 | 161 | /* Begin PBXShellScriptBuildPhase section */ 162 | 00649F8721A7D0E300163BEB /* SwiftLint */ = { 163 | isa = PBXShellScriptBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | ); 167 | inputFileListPaths = ( 168 | ); 169 | inputPaths = ( 170 | ); 171 | name = SwiftLint; 172 | outputFileListPaths = ( 173 | ); 174 | outputPaths = ( 175 | ); 176 | runOnlyForDeploymentPostprocessing = 0; 177 | shellPath = /bin/sh; 178 | shellScript = "#!/bin/sh\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, install with `brew install swiftlint`\"\nfi\n"; 179 | }; 180 | /* End PBXShellScriptBuildPhase section */ 181 | 182 | /* Begin PBXSourcesBuildPhase section */ 183 | 00649F6121A7CFD100163BEB /* Sources */ = { 184 | isa = PBXSourcesBuildPhase; 185 | buildActionMask = 2147483647; 186 | files = ( 187 | 00649F7D21A7D00E00163BEB /* ShaderGeometries.swift in Sources */, 188 | 00649F6D21A7CFD100163BEB /* ViewController.swift in Sources */, 189 | 00649F6921A7CFD100163BEB /* AppDelegate.swift in Sources */, 190 | ); 191 | runOnlyForDeploymentPostprocessing = 0; 192 | }; 193 | /* End PBXSourcesBuildPhase section */ 194 | 195 | /* Begin PBXVariantGroup section */ 196 | 00649F6E21A7CFD100163BEB /* Main.storyboard */ = { 197 | isa = PBXVariantGroup; 198 | children = ( 199 | 00649F6F21A7CFD100163BEB /* Base */, 200 | ); 201 | name = Main.storyboard; 202 | sourceTree = ""; 203 | }; 204 | 00649F7321A7CFD100163BEB /* LaunchScreen.storyboard */ = { 205 | isa = PBXVariantGroup; 206 | children = ( 207 | 00649F7421A7CFD100163BEB /* Base */, 208 | ); 209 | name = LaunchScreen.storyboard; 210 | sourceTree = ""; 211 | }; 212 | /* End PBXVariantGroup section */ 213 | 214 | /* Begin XCBuildConfiguration section */ 215 | 00649F7721A7CFD100163BEB /* Debug */ = { 216 | isa = XCBuildConfiguration; 217 | buildSettings = { 218 | ALWAYS_SEARCH_USER_PATHS = NO; 219 | CLANG_ANALYZER_NONNULL = YES; 220 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 221 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 222 | CLANG_CXX_LIBRARY = "libc++"; 223 | CLANG_ENABLE_MODULES = YES; 224 | CLANG_ENABLE_OBJC_ARC = YES; 225 | CLANG_ENABLE_OBJC_WEAK = YES; 226 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 227 | CLANG_WARN_BOOL_CONVERSION = YES; 228 | CLANG_WARN_COMMA = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INFINITE_RECURSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 239 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 241 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 242 | CLANG_WARN_STRICT_PROTOTYPES = YES; 243 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 244 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 245 | CLANG_WARN_UNREACHABLE_CODE = YES; 246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 247 | CODE_SIGN_IDENTITY = "iPhone Developer"; 248 | COPY_PHASE_STRIP = NO; 249 | DEBUG_INFORMATION_FORMAT = dwarf; 250 | ENABLE_STRICT_OBJC_MSGSEND = YES; 251 | ENABLE_TESTABILITY = YES; 252 | GCC_C_LANGUAGE_STANDARD = gnu11; 253 | GCC_DYNAMIC_NO_PIC = NO; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_OPTIMIZATION_LEVEL = 0; 256 | GCC_PREPROCESSOR_DEFINITIONS = ( 257 | "DEBUG=1", 258 | "$(inherited)", 259 | ); 260 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 261 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 262 | GCC_WARN_UNDECLARED_SELECTOR = YES; 263 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 264 | GCC_WARN_UNUSED_FUNCTION = YES; 265 | GCC_WARN_UNUSED_VARIABLE = YES; 266 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 267 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 268 | MTL_FAST_MATH = YES; 269 | ONLY_ACTIVE_ARCH = YES; 270 | SDKROOT = iphoneos; 271 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 272 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 273 | }; 274 | name = Debug; 275 | }; 276 | 00649F7821A7CFD100163BEB /* Release */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ALWAYS_SEARCH_USER_PATHS = NO; 280 | CLANG_ANALYZER_NONNULL = YES; 281 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 282 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 283 | CLANG_CXX_LIBRARY = "libc++"; 284 | CLANG_ENABLE_MODULES = YES; 285 | CLANG_ENABLE_OBJC_ARC = YES; 286 | CLANG_ENABLE_OBJC_WEAK = YES; 287 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_COMMA = YES; 290 | CLANG_WARN_CONSTANT_CONVERSION = YES; 291 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 292 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 293 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 294 | CLANG_WARN_EMPTY_BODY = YES; 295 | CLANG_WARN_ENUM_CONVERSION = YES; 296 | CLANG_WARN_INFINITE_RECURSION = YES; 297 | CLANG_WARN_INT_CONVERSION = YES; 298 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 299 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 300 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 301 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 302 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 303 | CLANG_WARN_STRICT_PROTOTYPES = YES; 304 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 305 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 306 | CLANG_WARN_UNREACHABLE_CODE = YES; 307 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 308 | CODE_SIGN_IDENTITY = "iPhone Developer"; 309 | COPY_PHASE_STRIP = NO; 310 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 311 | ENABLE_NS_ASSERTIONS = NO; 312 | ENABLE_STRICT_OBJC_MSGSEND = YES; 313 | GCC_C_LANGUAGE_STANDARD = gnu11; 314 | GCC_NO_COMMON_BLOCKS = YES; 315 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 316 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 317 | GCC_WARN_UNDECLARED_SELECTOR = YES; 318 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 319 | GCC_WARN_UNUSED_FUNCTION = YES; 320 | GCC_WARN_UNUSED_VARIABLE = YES; 321 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 322 | MTL_ENABLE_DEBUG_INFO = NO; 323 | MTL_FAST_MATH = YES; 324 | SDKROOT = iphoneos; 325 | SWIFT_COMPILATION_MODE = wholemodule; 326 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 327 | VALIDATE_PRODUCT = YES; 328 | }; 329 | name = Release; 330 | }; 331 | 00649F7A21A7CFD100163BEB /* Debug */ = { 332 | isa = XCBuildConfiguration; 333 | buildSettings = { 334 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 335 | CODE_SIGN_STYLE = Automatic; 336 | DEVELOPMENT_TEAM = N2RTJDRM64; 337 | INFOPLIST_FILE = "SCNShaderModifier-Examples/Info.plist"; 338 | LD_RUNPATH_SEARCH_PATHS = ( 339 | "$(inherited)", 340 | "@executable_path/Frameworks", 341 | ); 342 | PRODUCT_BUNDLE_IDENTIFIER = "com.maxxfrazer.SCNShaderModifier-Examples"; 343 | PRODUCT_NAME = "$(TARGET_NAME)"; 344 | SWIFT_VERSION = 4.2; 345 | TARGETED_DEVICE_FAMILY = "1,2"; 346 | }; 347 | name = Debug; 348 | }; 349 | 00649F7B21A7CFD100163BEB /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | buildSettings = { 352 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 353 | CODE_SIGN_STYLE = Automatic; 354 | DEVELOPMENT_TEAM = N2RTJDRM64; 355 | INFOPLIST_FILE = "SCNShaderModifier-Examples/Info.plist"; 356 | LD_RUNPATH_SEARCH_PATHS = ( 357 | "$(inherited)", 358 | "@executable_path/Frameworks", 359 | ); 360 | PRODUCT_BUNDLE_IDENTIFIER = "com.maxxfrazer.SCNShaderModifier-Examples"; 361 | PRODUCT_NAME = "$(TARGET_NAME)"; 362 | SWIFT_VERSION = 4.2; 363 | TARGETED_DEVICE_FAMILY = "1,2"; 364 | }; 365 | name = Release; 366 | }; 367 | /* End XCBuildConfiguration section */ 368 | 369 | /* Begin XCConfigurationList section */ 370 | 00649F6021A7CFD100163BEB /* Build configuration list for PBXProject "SCNShaderModifier-Examples" */ = { 371 | isa = XCConfigurationList; 372 | buildConfigurations = ( 373 | 00649F7721A7CFD100163BEB /* Debug */, 374 | 00649F7821A7CFD100163BEB /* Release */, 375 | ); 376 | defaultConfigurationIsVisible = 0; 377 | defaultConfigurationName = Release; 378 | }; 379 | 00649F7921A7CFD100163BEB /* Build configuration list for PBXNativeTarget "SCNShaderModifier-Examples" */ = { 380 | isa = XCConfigurationList; 381 | buildConfigurations = ( 382 | 00649F7A21A7CFD100163BEB /* Debug */, 383 | 00649F7B21A7CFD100163BEB /* Release */, 384 | ); 385 | defaultConfigurationIsVisible = 0; 386 | defaultConfigurationName = Release; 387 | }; 388 | /* End XCConfigurationList section */ 389 | }; 390 | rootObject = 00649F5D21A7CFD100163BEB /* Project object */; 391 | } 392 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SCNShaderModifier-Examples 4 | // 5 | // Created by Max Cobb on 11/22/18. 6 | // Copyright © 2018 Max Cobb. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application( 17 | _ application: UIApplication, 18 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 19 | ) -> Bool { 20 | // Override point for customization after application launch. 21 | return true 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSCameraUsageDescription 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | arkit 33 | 34 | UIStatusBarHidden 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/ShaderGeometries.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ShaderGeometries.swift 3 | // SCNShaderModifier-Examples 4 | // 5 | // Created by Max Cobb on 11/22/18. 6 | // Copyright © 2018 Max Cobb. All rights reserved. 7 | // 8 | 9 | import SceneKit 10 | 11 | private func getShader(from filename: String) -> String { 12 | do { 13 | if let dirs = Bundle.main.url(forResource: filename, withExtension: "shader") { 14 | return try String(contentsOf: dirs, encoding: .utf8) 15 | } 16 | } catch { 17 | print(error) 18 | } 19 | print("shader \(filename) not found") 20 | return "" 21 | } 22 | 23 | func cubeRotateSkew() -> SCNNode { 24 | let cubeGeometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0) 25 | cubeGeometry.firstMaterial?.diffuse.contents = UIColor.red 26 | cubeGeometry.shaderModifiers = [ 27 | .geometry: getShader(from: "cube_circular") 28 | ] 29 | let node = SCNNode(geometry: cubeGeometry) 30 | node.scale = SCNVector3(0.5, 0.5, 0.5) 31 | return node 32 | } 33 | 34 | func sphereRipple() -> SCNNode { 35 | let sphereGeometry = SCNSphere(radius: 1) 36 | sphereGeometry.segmentCount = 100 37 | sphereGeometry.firstMaterial?.diffuse.contents = UIColor.red 38 | sphereGeometry.shaderModifiers = [ 39 | .geometry: getShader(from: "sphere_ripple") 40 | ] 41 | let node = SCNNode(geometry: sphereGeometry) 42 | node.scale = SCNVector3(0.5, 0.5, 0.5) 43 | return node 44 | } 45 | 46 | func sphereSun() -> SCNNode { 47 | let sunGeometry = SCNSphere(radius: 1) 48 | sunGeometry.shaderModifiers = [ 49 | .surface: getShader(from: "sun_surface"), 50 | .geometry: getShader(from: "sun_geometry") 51 | ] 52 | let node = SCNNode(geometry: sunGeometry) 53 | node.scale = SCNVector3(0.5, 0.5, 0.5) 54 | 55 | let ambientLight = SCNLight() 56 | ambientLight.type = .ambient 57 | node.light = ambientLight 58 | 59 | return node 60 | } 61 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Shaders/cube_circular.shader: -------------------------------------------------------------------------------- 1 | 2 | if (_geometry.position.y > 0.0) { 3 | _geometry.position.xz += vec2( 4 | 0.5 * sin(3.0 * u_time), 5 | 0.5 * cos(3.0 * u_time) 6 | ) * (u_time < 3.0 ? u_time / 3.0 : 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Shaders/sphere_ripple.shader: -------------------------------------------------------------------------------- 1 | 2 | _geometry.position.xz += _geometry.position.xz 3 | * sin(30.0 * _geometry.position.y - 3.0 * u_time) * 0.1 4 | * (u_time < 3.0 ? u_time / 3.0 : 1.0); 5 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Shaders/sun_geometry.shader: -------------------------------------------------------------------------------- 1 | 2 | float theta1 = atan2(_geometry.position.x, _geometry.position.y); 3 | float theta2 = atan2(_geometry.position.x, _geometry.position.z); 4 | float pi = 3.14159; 5 | 6 | _geometry.position.xyz += _geometry.position.xyz * 0.2 7 | * sin(theta1 * pi - u_time * 2) * sin(6.0 * theta1) 8 | * cos(7.0 * theta2); 9 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/Shaders/sun_surface.shader: -------------------------------------------------------------------------------- 1 | 2 | #pragma transparent 3 | #pragma body 4 | 5 | float dotProductEdge = 0.5; 6 | 7 | float dotProduct = dot(_surface.view, _surface.normal); 8 | dotProduct = dotProduct < 0.0 ? 0.0 : dotProduct; 9 | 10 | _surface.diffuse.rgb = vec3(1.0, 1.0, 0.0); 11 | 12 | if (dotProduct <= dotProductEdge) { 13 | float a = dotProduct / dotProductEdge; 14 | _surface.diffuse = vec4(_surface.diffuse.rgb * a, a); 15 | } 16 | -------------------------------------------------------------------------------- /SCNShaderModifier-Examples/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SCNShaderModifier-Examples 4 | // 5 | // Created by Max Cobb on 11/22/18. 6 | // Copyright © 2018 Max Cobb. All rights reserved. 7 | // 8 | 9 | import ARKit 10 | 11 | class ViewController: UIViewController, ARSCNViewDelegate { 12 | 13 | @IBOutlet var sceneView: ARSCNView! 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | sceneView.delegate = self 19 | let scene = SCNScene() 20 | sceneView.scene = scene 21 | 22 | self.addLight() 23 | 24 | var geometryNode: SCNNode! 25 | switch Int.random(in: 0...2) { 26 | case 0: 27 | geometryNode = cubeRotateSkew() 28 | case 1: 29 | geometryNode = sphereRipple() 30 | default: 31 | geometryNode = sphereSun() 32 | } 33 | 34 | geometryNode.position.z = -1.5 35 | scene.rootNode.addChildNode(geometryNode) 36 | } 37 | 38 | override func viewWillAppear(_ animated: Bool) { 39 | super.viewWillAppear(animated) 40 | sceneView.session.run(ARWorldTrackingConfiguration()) 41 | } 42 | 43 | override func viewWillDisappear(_ animated: Bool) { 44 | super.viewWillDisappear(animated) 45 | sceneView.session.pause() 46 | } 47 | 48 | func addLight() { 49 | let light = SCNLight() 50 | light.type = .omni 51 | sceneView.pointOfView?.light = light 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /media/cube-example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxxfrazer/SCNShaderModifier-Examples/7d765eed16027b8447bf641cf6297d532ca03b8d/media/cube-example.gif -------------------------------------------------------------------------------- /media/sun-example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxxfrazer/SCNShaderModifier-Examples/7d765eed16027b8447bf641cf6297d532ca03b8d/media/sun-example.gif --------------------------------------------------------------------------------