├── .gitignore ├── LICENSE ├── README.md ├── TechniqueTest.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── TechniqueTest ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── Main.storyboard ├── GameViewController.swift ├── Info.plist ├── TechniqueTest.entitlements ├── art.scnassets ├── ship.scn └── texture.png ├── displacement ├── displacement.fsh ├── displacement.json ├── displacement.metal ├── displacement.plist └── displacement.vsh ├── draw_normals ├── draw_normals.json └── draw_normals.metal └── noise.png /.gitignore: -------------------------------------------------------------------------------- 1 | TechniqueTest.xcodeproj/project.xcworkspace/xcuserdata 2 | TechniqueTest.xcodeproj/xcuserdata 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Volodymyr Boichentsov 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 | # SCNTechniqueTest 2 | 3 | This code sample demonstrates how to utilize SCNTechnique with metal. 4 | 5 | Two examples: 6 | - render normals of presented objects on scene into texture. 7 | - displacement (which was part of apple's how to for OpenGL) 8 | 9 | -------------------------------------------------------------------------------- /TechniqueTest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D2180CAD208495AD005353CF /* displacement.metal in Sources */ = {isa = PBXBuildFile; fileRef = D2180CAC208495AD005353CF /* displacement.metal */; }; 11 | D24C16A820813C7E00C03622 /* displacement.json in Resources */ = {isa = PBXBuildFile; fileRef = D24C16A720813C7E00C03622 /* displacement.json */; }; 12 | D24C16AA208289D900C03622 /* draw_normals.json in Resources */ = {isa = PBXBuildFile; fileRef = D24C16A9208289D900C03622 /* draw_normals.json */; }; 13 | D29C5E09207A15B70073C00D /* draw_normals.metal in Sources */ = {isa = PBXBuildFile; fileRef = D29C5E08207A15B70073C00D /* draw_normals.metal */; }; 14 | D29C5E0B207A15EC0073C00D /* displacement.plist in Resources */ = {isa = PBXBuildFile; fileRef = D29C5E0A207A15EC0073C00D /* displacement.plist */; }; 15 | D2DCC69F20798BBC00477BFD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DCC69E20798BBC00477BFD /* AppDelegate.swift */; }; 16 | D2DCC6A120798BBC00477BFD /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DCC6A020798BBC00477BFD /* GameViewController.swift */; }; 17 | D2DCC6A320798BBC00477BFD /* art.scnassets in Resources */ = {isa = PBXBuildFile; fileRef = D2DCC6A220798BBC00477BFD /* art.scnassets */; }; 18 | D2DCC6A520798BBD00477BFD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D2DCC6A420798BBD00477BFD /* Assets.xcassets */; }; 19 | D2DCC6A820798BBD00477BFD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2DCC6A620798BBD00477BFD /* Main.storyboard */; }; 20 | D2DCC6B120798CE800477BFD /* displacement.vsh in Resources */ = {isa = PBXBuildFile; fileRef = D2DCC6B020798CE800477BFD /* displacement.vsh */; }; 21 | D2DCC6B320798D0D00477BFD /* displacement.fsh in Resources */ = {isa = PBXBuildFile; fileRef = D2DCC6B220798D0D00477BFD /* displacement.fsh */; }; 22 | D2DCC6B520798D4000477BFD /* noise.png in Resources */ = {isa = PBXBuildFile; fileRef = D2DCC6B420798D4000477BFD /* noise.png */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | D2180CAC208495AD005353CF /* displacement.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = displacement.metal; sourceTree = ""; }; 27 | D24C16A720813C7E00C03622 /* displacement.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = displacement.json; sourceTree = ""; }; 28 | D24C16A9208289D900C03622 /* draw_normals.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = draw_normals.json; sourceTree = ""; }; 29 | D29C5E08207A15B70073C00D /* draw_normals.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = draw_normals.metal; sourceTree = ""; }; 30 | D29C5E0A207A15EC0073C00D /* displacement.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = displacement.plist; sourceTree = ""; }; 31 | D2DCC69B20798BBC00477BFD /* TechniqueTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TechniqueTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | D2DCC69E20798BBC00477BFD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | D2DCC6A020798BBC00477BFD /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; 34 | D2DCC6A220798BBC00477BFD /* art.scnassets */ = {isa = PBXFileReference; lastKnownFileType = wrapper.scnassets; path = art.scnassets; sourceTree = ""; }; 35 | D2DCC6A420798BBD00477BFD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 36 | D2DCC6A720798BBD00477BFD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 37 | D2DCC6A920798BBD00477BFD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | D2DCC6AA20798BBD00477BFD /* TechniqueTest.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TechniqueTest.entitlements; sourceTree = ""; }; 39 | D2DCC6B020798CE800477BFD /* displacement.vsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; path = displacement.vsh; sourceTree = ""; }; 40 | D2DCC6B220798D0D00477BFD /* displacement.fsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; path = displacement.fsh; sourceTree = ""; }; 41 | D2DCC6B420798D4000477BFD /* noise.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = noise.png; sourceTree = ""; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | D2DCC69820798BBC00477BFD /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | D2180CAE20849683005353CF /* displacement */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | D29C5E0A207A15EC0073C00D /* displacement.plist */, 59 | D24C16A720813C7E00C03622 /* displacement.json */, 60 | D2180CAC208495AD005353CF /* displacement.metal */, 61 | D2DCC6B020798CE800477BFD /* displacement.vsh */, 62 | D2DCC6B220798D0D00477BFD /* displacement.fsh */, 63 | ); 64 | path = displacement; 65 | sourceTree = ""; 66 | }; 67 | D2180CAF20849695005353CF /* draw_normals */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | D24C16A9208289D900C03622 /* draw_normals.json */, 71 | D29C5E08207A15B70073C00D /* draw_normals.metal */, 72 | ); 73 | path = draw_normals; 74 | sourceTree = ""; 75 | }; 76 | D2DCC69220798BBC00477BFD = { 77 | isa = PBXGroup; 78 | children = ( 79 | D2DCC69D20798BBC00477BFD /* TechniqueTest */, 80 | D2DCC69C20798BBC00477BFD /* Products */, 81 | ); 82 | sourceTree = ""; 83 | }; 84 | D2DCC69C20798BBC00477BFD /* Products */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | D2DCC69B20798BBC00477BFD /* TechniqueTest.app */, 88 | ); 89 | name = Products; 90 | sourceTree = ""; 91 | }; 92 | D2DCC69D20798BBC00477BFD /* TechniqueTest */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | D2DCC69E20798BBC00477BFD /* AppDelegate.swift */, 96 | D2DCC6A020798BBC00477BFD /* GameViewController.swift */, 97 | D2180CAF20849695005353CF /* draw_normals */, 98 | D2180CAE20849683005353CF /* displacement */, 99 | D2DCC6B420798D4000477BFD /* noise.png */, 100 | D2DCC6A220798BBC00477BFD /* art.scnassets */, 101 | D2DCC6A420798BBD00477BFD /* Assets.xcassets */, 102 | D2DCC6A620798BBD00477BFD /* Main.storyboard */, 103 | D2DCC6A920798BBD00477BFD /* Info.plist */, 104 | D2DCC6AA20798BBD00477BFD /* TechniqueTest.entitlements */, 105 | ); 106 | path = TechniqueTest; 107 | sourceTree = ""; 108 | }; 109 | /* End PBXGroup section */ 110 | 111 | /* Begin PBXNativeTarget section */ 112 | D2DCC69A20798BBC00477BFD /* TechniqueTest */ = { 113 | isa = PBXNativeTarget; 114 | buildConfigurationList = D2DCC6AD20798BBD00477BFD /* Build configuration list for PBXNativeTarget "TechniqueTest" */; 115 | buildPhases = ( 116 | D2DCC69720798BBC00477BFD /* Sources */, 117 | D2DCC69820798BBC00477BFD /* Frameworks */, 118 | D2DCC69920798BBC00477BFD /* Resources */, 119 | ); 120 | buildRules = ( 121 | ); 122 | dependencies = ( 123 | ); 124 | name = TechniqueTest; 125 | productName = TechniqueTest; 126 | productReference = D2DCC69B20798BBC00477BFD /* TechniqueTest.app */; 127 | productType = "com.apple.product-type.application"; 128 | }; 129 | /* End PBXNativeTarget section */ 130 | 131 | /* Begin PBXProject section */ 132 | D2DCC69320798BBC00477BFD /* Project object */ = { 133 | isa = PBXProject; 134 | attributes = { 135 | LastSwiftUpdateCheck = 0930; 136 | LastUpgradeCheck = 0930; 137 | ORGANIZATIONNAME = "3D4Medical LLC"; 138 | TargetAttributes = { 139 | D2DCC69A20798BBC00477BFD = { 140 | CreatedOnToolsVersion = 9.3; 141 | }; 142 | }; 143 | }; 144 | buildConfigurationList = D2DCC69620798BBC00477BFD /* Build configuration list for PBXProject "TechniqueTest" */; 145 | compatibilityVersion = "Xcode 9.3"; 146 | developmentRegion = en; 147 | hasScannedForEncodings = 0; 148 | knownRegions = ( 149 | en, 150 | Base, 151 | ); 152 | mainGroup = D2DCC69220798BBC00477BFD; 153 | productRefGroup = D2DCC69C20798BBC00477BFD /* Products */; 154 | projectDirPath = ""; 155 | projectRoot = ""; 156 | targets = ( 157 | D2DCC69A20798BBC00477BFD /* TechniqueTest */, 158 | ); 159 | }; 160 | /* End PBXProject section */ 161 | 162 | /* Begin PBXResourcesBuildPhase section */ 163 | D2DCC69920798BBC00477BFD /* Resources */ = { 164 | isa = PBXResourcesBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | D2DCC6B520798D4000477BFD /* noise.png in Resources */, 168 | D2DCC6B120798CE800477BFD /* displacement.vsh in Resources */, 169 | D24C16A820813C7E00C03622 /* displacement.json in Resources */, 170 | D24C16AA208289D900C03622 /* draw_normals.json in Resources */, 171 | D2DCC6A820798BBD00477BFD /* Main.storyboard in Resources */, 172 | D2DCC6A520798BBD00477BFD /* Assets.xcassets in Resources */, 173 | D29C5E0B207A15EC0073C00D /* displacement.plist in Resources */, 174 | D2DCC6A320798BBC00477BFD /* art.scnassets in Resources */, 175 | D2DCC6B320798D0D00477BFD /* displacement.fsh in Resources */, 176 | ); 177 | runOnlyForDeploymentPostprocessing = 0; 178 | }; 179 | /* End PBXResourcesBuildPhase section */ 180 | 181 | /* Begin PBXSourcesBuildPhase section */ 182 | D2DCC69720798BBC00477BFD /* Sources */ = { 183 | isa = PBXSourcesBuildPhase; 184 | buildActionMask = 2147483647; 185 | files = ( 186 | D2180CAD208495AD005353CF /* displacement.metal in Sources */, 187 | D29C5E09207A15B70073C00D /* draw_normals.metal in Sources */, 188 | D2DCC6A120798BBC00477BFD /* GameViewController.swift in Sources */, 189 | D2DCC69F20798BBC00477BFD /* AppDelegate.swift in Sources */, 190 | ); 191 | runOnlyForDeploymentPostprocessing = 0; 192 | }; 193 | /* End PBXSourcesBuildPhase section */ 194 | 195 | /* Begin PBXVariantGroup section */ 196 | D2DCC6A620798BBD00477BFD /* Main.storyboard */ = { 197 | isa = PBXVariantGroup; 198 | children = ( 199 | D2DCC6A720798BBD00477BFD /* Base */, 200 | ); 201 | name = Main.storyboard; 202 | sourceTree = ""; 203 | }; 204 | /* End PBXVariantGroup section */ 205 | 206 | /* Begin XCBuildConfiguration section */ 207 | D2DCC6AB20798BBD00477BFD /* Debug */ = { 208 | isa = XCBuildConfiguration; 209 | buildSettings = { 210 | ALWAYS_SEARCH_USER_PATHS = NO; 211 | CLANG_ANALYZER_NONNULL = YES; 212 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 213 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 214 | CLANG_CXX_LIBRARY = "libc++"; 215 | CLANG_ENABLE_MODULES = YES; 216 | CLANG_ENABLE_OBJC_ARC = YES; 217 | CLANG_ENABLE_OBJC_WEAK = YES; 218 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 219 | CLANG_WARN_BOOL_CONVERSION = YES; 220 | CLANG_WARN_COMMA = YES; 221 | CLANG_WARN_CONSTANT_CONVERSION = YES; 222 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 223 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 224 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 225 | CLANG_WARN_EMPTY_BODY = YES; 226 | CLANG_WARN_ENUM_CONVERSION = YES; 227 | CLANG_WARN_INFINITE_RECURSION = YES; 228 | CLANG_WARN_INT_CONVERSION = YES; 229 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 230 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 231 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 232 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 233 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 234 | CLANG_WARN_STRICT_PROTOTYPES = YES; 235 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 236 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 237 | CLANG_WARN_UNREACHABLE_CODE = YES; 238 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 239 | CODE_SIGN_IDENTITY = "Mac Developer"; 240 | COPY_PHASE_STRIP = NO; 241 | DEBUG_INFORMATION_FORMAT = dwarf; 242 | ENABLE_STRICT_OBJC_MSGSEND = YES; 243 | ENABLE_TESTABILITY = YES; 244 | GCC_C_LANGUAGE_STANDARD = gnu11; 245 | GCC_DYNAMIC_NO_PIC = NO; 246 | GCC_NO_COMMON_BLOCKS = YES; 247 | GCC_OPTIMIZATION_LEVEL = 0; 248 | GCC_PREPROCESSOR_DEFINITIONS = ( 249 | "DEBUG=1", 250 | "$(inherited)", 251 | ); 252 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 253 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 254 | GCC_WARN_UNDECLARED_SELECTOR = YES; 255 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 256 | GCC_WARN_UNUSED_FUNCTION = YES; 257 | GCC_WARN_UNUSED_VARIABLE = YES; 258 | MACOSX_DEPLOYMENT_TARGET = 10.13; 259 | MTL_ENABLE_DEBUG_INFO = YES; 260 | ONLY_ACTIVE_ARCH = YES; 261 | SDKROOT = macosx; 262 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 263 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 264 | }; 265 | name = Debug; 266 | }; 267 | D2DCC6AC20798BBD00477BFD /* Release */ = { 268 | isa = XCBuildConfiguration; 269 | buildSettings = { 270 | ALWAYS_SEARCH_USER_PATHS = NO; 271 | CLANG_ANALYZER_NONNULL = YES; 272 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 273 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 274 | CLANG_CXX_LIBRARY = "libc++"; 275 | CLANG_ENABLE_MODULES = YES; 276 | CLANG_ENABLE_OBJC_ARC = YES; 277 | CLANG_ENABLE_OBJC_WEAK = YES; 278 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 279 | CLANG_WARN_BOOL_CONVERSION = YES; 280 | CLANG_WARN_COMMA = YES; 281 | CLANG_WARN_CONSTANT_CONVERSION = YES; 282 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 283 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 284 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 285 | CLANG_WARN_EMPTY_BODY = YES; 286 | CLANG_WARN_ENUM_CONVERSION = YES; 287 | CLANG_WARN_INFINITE_RECURSION = YES; 288 | CLANG_WARN_INT_CONVERSION = YES; 289 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 290 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 291 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 292 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 293 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 294 | CLANG_WARN_STRICT_PROTOTYPES = YES; 295 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 296 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 297 | CLANG_WARN_UNREACHABLE_CODE = YES; 298 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 299 | CODE_SIGN_IDENTITY = "Mac Developer"; 300 | COPY_PHASE_STRIP = NO; 301 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 302 | ENABLE_NS_ASSERTIONS = NO; 303 | ENABLE_STRICT_OBJC_MSGSEND = YES; 304 | GCC_C_LANGUAGE_STANDARD = gnu11; 305 | GCC_NO_COMMON_BLOCKS = YES; 306 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 307 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 308 | GCC_WARN_UNDECLARED_SELECTOR = YES; 309 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 310 | GCC_WARN_UNUSED_FUNCTION = YES; 311 | GCC_WARN_UNUSED_VARIABLE = YES; 312 | MACOSX_DEPLOYMENT_TARGET = 10.13; 313 | MTL_ENABLE_DEBUG_INFO = NO; 314 | SDKROOT = macosx; 315 | SWIFT_COMPILATION_MODE = wholemodule; 316 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 317 | }; 318 | name = Release; 319 | }; 320 | D2DCC6AE20798BBD00477BFD /* Debug */ = { 321 | isa = XCBuildConfiguration; 322 | buildSettings = { 323 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 324 | CODE_SIGN_ENTITLEMENTS = TechniqueTest/TechniqueTest.entitlements; 325 | CODE_SIGN_STYLE = Automatic; 326 | COMBINE_HIDPI_IMAGES = YES; 327 | DEVELOPMENT_TEAM = 4EWJ52878E; 328 | INFOPLIST_FILE = TechniqueTest/Info.plist; 329 | LD_RUNPATH_SEARCH_PATHS = ( 330 | "$(inherited)", 331 | "@executable_path/../Frameworks", 332 | ); 333 | PRODUCT_BUNDLE_IDENTIFIER = com.3d4medical.TechniqueTest; 334 | PRODUCT_NAME = "$(TARGET_NAME)"; 335 | SWIFT_VERSION = 4.0; 336 | }; 337 | name = Debug; 338 | }; 339 | D2DCC6AF20798BBD00477BFD /* Release */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 343 | CODE_SIGN_ENTITLEMENTS = TechniqueTest/TechniqueTest.entitlements; 344 | CODE_SIGN_STYLE = Automatic; 345 | COMBINE_HIDPI_IMAGES = YES; 346 | DEVELOPMENT_TEAM = 4EWJ52878E; 347 | INFOPLIST_FILE = TechniqueTest/Info.plist; 348 | LD_RUNPATH_SEARCH_PATHS = ( 349 | "$(inherited)", 350 | "@executable_path/../Frameworks", 351 | ); 352 | PRODUCT_BUNDLE_IDENTIFIER = com.3d4medical.TechniqueTest; 353 | PRODUCT_NAME = "$(TARGET_NAME)"; 354 | SWIFT_VERSION = 4.0; 355 | }; 356 | name = Release; 357 | }; 358 | /* End XCBuildConfiguration section */ 359 | 360 | /* Begin XCConfigurationList section */ 361 | D2DCC69620798BBC00477BFD /* Build configuration list for PBXProject "TechniqueTest" */ = { 362 | isa = XCConfigurationList; 363 | buildConfigurations = ( 364 | D2DCC6AB20798BBD00477BFD /* Debug */, 365 | D2DCC6AC20798BBD00477BFD /* Release */, 366 | ); 367 | defaultConfigurationIsVisible = 0; 368 | defaultConfigurationName = Release; 369 | }; 370 | D2DCC6AD20798BBD00477BFD /* Build configuration list for PBXNativeTarget "TechniqueTest" */ = { 371 | isa = XCConfigurationList; 372 | buildConfigurations = ( 373 | D2DCC6AE20798BBD00477BFD /* Debug */, 374 | D2DCC6AF20798BBD00477BFD /* Release */, 375 | ); 376 | defaultConfigurationIsVisible = 0; 377 | defaultConfigurationName = Release; 378 | }; 379 | /* End XCConfigurationList section */ 380 | }; 381 | rootObject = D2DCC69320798BBC00477BFD /* Project object */; 382 | } 383 | -------------------------------------------------------------------------------- /TechniqueTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TechniqueTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TechniqueTest/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TechniqueTest 4 | // 5 | // Created by Volodymyr Boichentsov on 08/04/2018. 6 | // Copyright © 2018 3D4Medical LLC. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | func applicationDidFinishLaunching(_ aNotification: Notification) { 15 | // Insert code here to initialize your application 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /TechniqueTest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /TechniqueTest/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TechniqueTest/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 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | Default 531 | 532 | 533 | 534 | 535 | 536 | 537 | Left to Right 538 | 539 | 540 | 541 | 542 | 543 | 544 | Right to Left 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | Default 556 | 557 | 558 | 559 | 560 | 561 | 562 | Left to Right 563 | 564 | 565 | 566 | 567 | 568 | 569 | Right to Left 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | -------------------------------------------------------------------------------- /TechniqueTest/GameViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GameViewController.swift 3 | // TechniqueTest 4 | // 5 | // Created by Volodymyr Boichentsov on 08/04/2018. 6 | // Copyright © 2018 3D4Medical LLC. All rights reserved. 7 | // 8 | 9 | import SceneKit 10 | import QuartzCore 11 | 12 | class GameViewController: NSViewController { 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | 17 | // create a new scene 18 | let scene = SCNScene(named: "art.scnassets/ship.scn")! 19 | 20 | // create and add a camera to the scene 21 | let cameraNode = SCNNode() 22 | cameraNode.camera = SCNCamera() 23 | scene.rootNode.addChildNode(cameraNode) 24 | 25 | // place the camera 26 | cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) 27 | 28 | // create and add a light to the scene 29 | let lightNode = SCNNode() 30 | lightNode.light = SCNLight() 31 | lightNode.light!.type = .omni 32 | lightNode.position = SCNVector3(x: 0, y: 10, z: 10) 33 | scene.rootNode.addChildNode(lightNode) 34 | 35 | // create and add an ambient light to the scene 36 | let ambientLightNode = SCNNode() 37 | ambientLightNode.light = SCNLight() 38 | ambientLightNode.light!.type = .ambient 39 | ambientLightNode.light!.color = NSColor.darkGray 40 | scene.rootNode.addChildNode(ambientLightNode) 41 | 42 | // retrieve the ship node 43 | let ship = scene.rootNode.childNode(withName: "ship", recursively: true)! 44 | 45 | // animate the 3d object 46 | ship.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1))) 47 | 48 | // retrieve the SCNView 49 | let scnView = self.view as! SCNView 50 | 51 | // set the scene to the view 52 | scnView.scene = scene 53 | 54 | // allows the user to manipulate the camera 55 | scnView.allowsCameraControl = true 56 | 57 | // show statistics such as fps and timing information 58 | scnView.showsStatistics = true 59 | 60 | // configure the view 61 | scnView.backgroundColor = NSColor.darkGray 62 | 63 | 64 | // if let path = Bundle.main.path(forResource: "displacement", ofType: "plist") { 65 | // if let dico1 = NSDictionary(contentsOfFile: path) { 66 | // let dico = dico1 as! [String : AnyObject] 67 | // 68 | // let technique = SCNTechnique(dictionary:dico) 69 | // (self.view as! SCNView).technique = technique 70 | // } 71 | // } 72 | 73 | // set SCNTechnique 74 | if let path = Bundle.main.url(forResource: "draw_normals", withExtension: "json") { 75 | let data = try? Data.init(contentsOf: path) 76 | let techDict = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions(rawValue: 0)) 77 | let tec = SCNTechnique.init(dictionary: techDict! as! [String : Any]) 78 | (self.view as! SCNView).technique = tec 79 | } 80 | 81 | 82 | 83 | } 84 | 85 | @objc 86 | func handleClick(_ gestureRecognizer: NSGestureRecognizer) { 87 | // retrieve the SCNView 88 | let scnView = self.view as! SCNView 89 | 90 | // check what nodes are clicked 91 | let p = gestureRecognizer.location(in: scnView) 92 | let hitResults = scnView.hitTest(p, options: [:]) 93 | // check that we clicked on at least one object 94 | if hitResults.count > 0 { 95 | // retrieved the first clicked object 96 | let result = hitResults[0] 97 | 98 | // get its material 99 | let material = result.node.geometry!.firstMaterial! 100 | 101 | // highlight it 102 | SCNTransaction.begin() 103 | SCNTransaction.animationDuration = 0.5 104 | 105 | // on completion - unhighlight 106 | SCNTransaction.completionBlock = { 107 | SCNTransaction.begin() 108 | SCNTransaction.animationDuration = 0.5 109 | 110 | material.emission.contents = NSColor.black 111 | 112 | SCNTransaction.commit() 113 | } 114 | 115 | material.emission.contents = NSColor.red 116 | 117 | SCNTransaction.commit() 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /TechniqueTest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | Copyright © 2018 3D4Medical LLC. All rights reserved. 27 | NSMainStoryboardFile 28 | Main 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /TechniqueTest/TechniqueTest.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TechniqueTest/art.scnassets/ship.scn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sakrist/SCNTechniqueTest/5470d0808ce097794229dffd0adc230486d50d1f/TechniqueTest/art.scnassets/ship.scn -------------------------------------------------------------------------------- /TechniqueTest/art.scnassets/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sakrist/SCNTechniqueTest/5470d0808ce097794229dffd0adc230486d50d1f/TechniqueTest/art.scnassets/texture.png -------------------------------------------------------------------------------- /TechniqueTest/displacement/displacement.fsh: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D colorSampler; 3 | uniform sampler2D noiseSampler; 4 | 5 | varying vec2 uv; 6 | 7 | void main() { 8 | vec2 displacement = texture2D(noiseSampler, uv).rg - vec2(0.5, 0.5); 9 | gl_FragColor = texture2D(colorSampler, uv + displacement * vec2(0.1,0.1)); 10 | } 11 | -------------------------------------------------------------------------------- /TechniqueTest/displacement/displacement.json: -------------------------------------------------------------------------------- 1 | { 2 | "passes" : { 3 | "displacement" : { 4 | 5 | "outputs" : { 6 | "color" : "COLOR" 7 | }, 8 | 9 | "inputs" : { 10 | "colorSampler" : "COLOR", 11 | "noiseSampler" : "noiseSymbol", 12 | "a_position" : "a_position-symbol" 13 | }, 14 | 15 | "program" : "displacement", 16 | "metalVertexShader" : "displacementVertex", 17 | "metalFragmentShader" : "displacementFragment", 18 | "draw" : "DRAW_QUAD" 19 | } 20 | }, 21 | 22 | "sequence" : [ "displacement"], 23 | 24 | "symbols" : { 25 | "a_position-symbol" : { 26 | "semantic" : "vertex" 27 | }, 28 | 29 | "noiseSymbol" : { 30 | "image" : "noise.png", 31 | "type" : "sampler2D" 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /TechniqueTest/displacement/displacement.metal: -------------------------------------------------------------------------------- 1 | // 2 | // displacement.metal 3 | // TechniqueTest 4 | // 5 | // Created by Volodymyr Boichentsov on 16/04/2018. 6 | // Copyright © 2018 3D4Medical LLC. All rights reserved. 7 | // 8 | 9 | #include 10 | using namespace metal; 11 | #include 12 | 13 | struct custom_vertex_t 14 | { 15 | float4 a_position [[attribute(SCNVertexSemanticPosition)]]; 16 | }; 17 | 18 | constexpr sampler s = sampler(coord::normalized, 19 | address::repeat, 20 | filter::linear); 21 | 22 | struct out_vertex_t 23 | { 24 | float4 position [[position]]; 25 | float2 uv; 26 | }; 27 | 28 | vertex out_vertex_t displacementVertex(custom_vertex_t in [[stage_in]], 29 | constant SCNSceneBuffer& scn_frame [[buffer(0)]]) 30 | { 31 | out_vertex_t out; 32 | out.position = in.a_position; 33 | out.uv = float2((in.a_position.x + 1.0) * 0.5 , (in.a_position.y + 1.0) * -0.5); 34 | return out; 35 | }; 36 | 37 | 38 | fragment half4 displacementFragment(out_vertex_t vert [[stage_in]], 39 | texture2d colorSampler [[texture(0)]], 40 | texture2d noiseSampler [[texture(1)]]) 41 | { 42 | 43 | float2 displacement = noiseSampler.sample( s, vert.uv).rg - float2(0.5, 0.5); 44 | float4 FragmentColor = colorSampler.sample(s, vert.uv + displacement * float2(0.1, 0.1)); 45 | 46 | // float4 FragmentColor = colorSampler.sample( s, vert.uv) * weight[0]; 47 | // for (int i=1; i<5; i++) { 48 | // FragmentColor += colorSampler.sample( s, ( vert.uv + float2(offset[i], 0.0)/324.0 ) ) * weight[i]; 49 | // FragmentColor += colorSampler.sample( s, ( vert.uv - float2(offset[i], 0.0)/324.0 ) ) * weight[i]; 50 | // } 51 | // vec2 displacement = texture2D(noiseSampler, uv).rg - vec2(0.5, 0.5); 52 | // gl_FragColor = texture2D(colorSampler, uv + displacement * vec2(0.1,0.1)); 53 | 54 | return half4(FragmentColor); 55 | } 56 | -------------------------------------------------------------------------------- /TechniqueTest/displacement/displacement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | symbols 6 | 7 | noiseSymbol 8 | 9 | type 10 | sampler2D 11 | image 12 | noise.png 13 | 14 | a_position-symbol 15 | 16 | semantic 17 | vertex 18 | 19 | 20 | sequence 21 | 22 | displacement 23 | 24 | passes 25 | 26 | displacement 27 | 28 | metalFragmentShader 29 | displacementFragment 30 | metalVertexShader 31 | displacementVertex 32 | program 33 | displacement 34 | draw 35 | DRAW_QUAD 36 | inputs 37 | 38 | a_position 39 | a_position-symbol 40 | noiseSampler 41 | noiseSymbol 42 | colorSampler 43 | COLOR 44 | 45 | outputs 46 | 47 | color 48 | COLOR 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /TechniqueTest/displacement/displacement.vsh: -------------------------------------------------------------------------------- 1 | 2 | attribute vec4 a_position; 3 | varying vec2 uv; 4 | 5 | void main() { 6 | gl_Position = a_position; 7 | uv = (a_position.xy + 1.0) * 0.5; 8 | } 9 | -------------------------------------------------------------------------------- /TechniqueTest/draw_normals/draw_normals.json: -------------------------------------------------------------------------------- 1 | { 2 | "passes" : { 3 | "draw_normals" : { 4 | 5 | "outputs" : { 6 | "color" : "normal_map" 7 | }, 8 | 9 | "inputs" : { 10 | "a_position" : "a_position-symbol" 11 | }, 12 | 13 | "metalVertexShader" : "normalsVertex", 14 | "metalFragmentShader" : "normalsFragment", 15 | 16 | "draw" : "DRAW_SCENE", 17 | 18 | "colorStates" : { 19 | "clear" : 1 20 | }, 21 | 22 | "depthStates" : { 23 | "clear" : 1 24 | } 25 | }, 26 | "draw_result" : { 27 | "metalVertexShader" : "resultVertex", 28 | "metalFragmentShader" : "resultFragment", 29 | "draw" : "DRAW_QUAD", 30 | "inputs" : { 31 | "a_position" : "a_position-symbol", 32 | "normalSampler" : "normal_map" 33 | }, 34 | "outputs" : { 35 | "color" : "COLOR" 36 | }, 37 | "colorStates" : { 38 | "clear" : 1, 39 | 40 | } 41 | } 42 | }, 43 | 44 | "sequence" : [ "draw_normals", "draw_result"], 45 | 46 | "targets" : { 47 | "normal_map" : {"type" : "color"} 48 | }, 49 | 50 | "symbols" : { 51 | "a_position-symbol" : { 52 | "semantic" : "vertex" 53 | }, 54 | 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /TechniqueTest/draw_normals/draw_normals.metal: -------------------------------------------------------------------------------- 1 | // 2 | // common.metal 3 | // TechniqueTest 4 | // 5 | // Created by Volodymyr Boichentsov on 08/04/2018. 6 | // Copyright © 2018 3D4Medical LLC. All rights reserved. 7 | // 8 | 9 | #include 10 | using namespace metal; 11 | #include 12 | 13 | constexpr sampler samp = sampler(coord::normalized, 14 | filter::linear); 15 | 16 | 17 | // ----------------------- normals ------------------------ 18 | 19 | 20 | struct VertexIn_t 21 | { 22 | float4 position [[ attribute(SCNVertexSemanticPosition) ]]; 23 | float4 normal [[ attribute(SCNVertexSemanticNormal) ]]; 24 | float4 color [[ attribute(SCNVertexSemanticColor) ]]; 25 | }; 26 | 27 | struct VertexOut_t 28 | { 29 | float4 position [[position]]; 30 | float4 normal; 31 | float2 uv; 32 | }; 33 | 34 | 35 | struct SceneNode { 36 | float4x4 modelViewProjectionTransform; 37 | float4x4 normalTransform; 38 | }; 39 | 40 | vertex VertexOut_t normalsVertex(VertexIn_t in [[stage_in]], 41 | constant SceneNode& scn_node [[buffer(0)]]) 42 | { 43 | VertexOut_t out; 44 | out.position = scn_node.modelViewProjectionTransform * in.position; 45 | out.normal = scn_node.normalTransform * in.normal; 46 | return out; 47 | } 48 | 49 | 50 | fragment half4 normalsFragment(VertexOut_t vert [[stage_in]]) 51 | { 52 | half3 normal = normalize(half3(vert.normal.xyz)); 53 | // return half4(1.0,0.,0.,1.0); 54 | return half4(normal, 1.0); 55 | } 56 | 57 | 58 | // ---- result pass 59 | 60 | vertex VertexOut_t resultVertex(VertexIn_t in [[stage_in]], 61 | constant SCNSceneBuffer& scn_frame [[buffer(0)]], 62 | constant SceneNode& scn_node [[buffer(1)]]) 63 | { 64 | VertexOut_t out; 65 | out.position = in.position; 66 | out.uv = in.position.xy*float2(.5,-.5) + .5; 67 | return out; 68 | }; 69 | 70 | 71 | fragment half4 resultFragment(VertexOut_t vert [[stage_in]], 72 | texture2d normalSampler [[texture(0)]]) 73 | { 74 | 75 | float4 FragmentColor = normalSampler.sample(samp, vert.uv); 76 | // return half4(1.0,0.0,0.0,1.0); 77 | return half4(FragmentColor); 78 | } 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /TechniqueTest/noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sakrist/SCNTechniqueTest/5470d0808ce097794229dffd0adc230486d50d1f/TechniqueTest/noise.png --------------------------------------------------------------------------------