├── README.md ├── ShaderSceneTransitionExample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── deon.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── ShaderSceneTransitionExample.xcscheme │ └── xcschememanagement.plist ├── ShaderSceneTransitionExample ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── GameScene.swift ├── GameScene2.swift ├── GameViewController.swift ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── dummy.imageset │ │ ├── Contents.json │ │ └── dummy@2x.png ├── Info.plist ├── SKScene+ShaderTransition.swift ├── retro_transition_fade_from_centre.fsh ├── retro_transition_fade_from_top.fsh ├── retro_transition_fade_from_top_left.fsh └── retro_transition_fade_to_centre.fsh └── ShaderSceneTransitionExampleTests ├── Info.plist └── ShaderSceneTransitionExampleTests.swift /README.md: -------------------------------------------------------------------------------- 1 | #SpriteKit game scene transitions with shaders example 2 | 3 | Example app to go with a blog post I wrote about transitioning between SpriteKit `SKScene`'s using shaders. The blog post can be found [here](http://www.dbotha.com/2015/07/18/spritekit-game-scene-transitions-with-shaders/) 4 | 5 | ![Demo](http://www.dbotha.com/images/transition.gif) 6 | 7 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3D38C1EF1B5449D7007B15D1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D38C1EE1B5449D7007B15D1 /* AppDelegate.swift */; }; 11 | 3D38C1F31B5449D7007B15D1 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D38C1F21B5449D7007B15D1 /* GameScene.swift */; }; 12 | 3D38C1F51B5449D7007B15D1 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D38C1F41B5449D7007B15D1 /* GameViewController.swift */; }; 13 | 3D38C1F81B5449D7007B15D1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3D38C1F61B5449D7007B15D1 /* Main.storyboard */; }; 14 | 3D38C1FA1B5449D7007B15D1 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D38C1F91B5449D7007B15D1 /* Images.xcassets */; }; 15 | 3D38C1FD1B5449D7007B15D1 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3D38C1FB1B5449D7007B15D1 /* LaunchScreen.xib */; }; 16 | 3D38C2091B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D38C2081B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.swift */; }; 17 | 3D38C2131B56B2F1007B15D1 /* GameScene2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D38C2121B56B2F1007B15D1 /* GameScene2.swift */; }; 18 | 3D38C2151B56B352007B15D1 /* SKScene+ShaderTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D38C2141B56B352007B15D1 /* SKScene+ShaderTransition.swift */; }; 19 | 3D38C21B1B56B969007B15D1 /* retro_transition_fade_from_centre.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 3D38C2171B56B969007B15D1 /* retro_transition_fade_from_centre.fsh */; }; 20 | 3D38C21C1B56B969007B15D1 /* retro_transition_fade_from_top_left.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 3D38C2181B56B969007B15D1 /* retro_transition_fade_from_top_left.fsh */; }; 21 | 3D38C21D1B56B969007B15D1 /* retro_transition_fade_from_top.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 3D38C2191B56B969007B15D1 /* retro_transition_fade_from_top.fsh */; }; 22 | 3D38C21E1B56B969007B15D1 /* retro_transition_fade_to_centre.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 3D38C21A1B56B969007B15D1 /* retro_transition_fade_to_centre.fsh */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXContainerItemProxy section */ 26 | 3D38C2031B5449D7007B15D1 /* PBXContainerItemProxy */ = { 27 | isa = PBXContainerItemProxy; 28 | containerPortal = 3D38C1E11B5449D7007B15D1 /* Project object */; 29 | proxyType = 1; 30 | remoteGlobalIDString = 3D38C1E81B5449D7007B15D1; 31 | remoteInfo = ShaderSceneTransitionExample; 32 | }; 33 | /* End PBXContainerItemProxy section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 3D38C1E91B5449D7007B15D1 /* ShaderSceneTransitionExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShaderSceneTransitionExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 3D38C1ED1B5449D7007B15D1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 3D38C1EE1B5449D7007B15D1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | 3D38C1F21B5449D7007B15D1 /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = ""; }; 40 | 3D38C1F41B5449D7007B15D1 /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; 41 | 3D38C1F71B5449D7007B15D1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | 3D38C1F91B5449D7007B15D1 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 43 | 3D38C1FC1B5449D7007B15D1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 44 | 3D38C2021B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ShaderSceneTransitionExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 3D38C2071B5449D7007B15D1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | 3D38C2081B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShaderSceneTransitionExampleTests.swift; sourceTree = ""; }; 47 | 3D38C2121B56B2F1007B15D1 /* GameScene2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameScene2.swift; sourceTree = ""; }; 48 | 3D38C2141B56B352007B15D1 /* SKScene+ShaderTransition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SKScene+ShaderTransition.swift"; sourceTree = ""; }; 49 | 3D38C2171B56B969007B15D1 /* retro_transition_fade_from_centre.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = retro_transition_fade_from_centre.fsh; sourceTree = ""; }; 50 | 3D38C2181B56B969007B15D1 /* retro_transition_fade_from_top_left.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = retro_transition_fade_from_top_left.fsh; sourceTree = ""; }; 51 | 3D38C2191B56B969007B15D1 /* retro_transition_fade_from_top.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = retro_transition_fade_from_top.fsh; sourceTree = ""; }; 52 | 3D38C21A1B56B969007B15D1 /* retro_transition_fade_to_centre.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = retro_transition_fade_to_centre.fsh; sourceTree = ""; }; 53 | /* End PBXFileReference section */ 54 | 55 | /* Begin PBXFrameworksBuildPhase section */ 56 | 3D38C1E61B5449D7007B15D1 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | 3D38C1FF1B5449D7007B15D1 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXFrameworksBuildPhase section */ 71 | 72 | /* Begin PBXGroup section */ 73 | 3D38C1E01B5449D7007B15D1 = { 74 | isa = PBXGroup; 75 | children = ( 76 | 3D38C1EB1B5449D7007B15D1 /* ShaderSceneTransitionExample */, 77 | 3D38C2051B5449D7007B15D1 /* ShaderSceneTransitionExampleTests */, 78 | 3D38C1EA1B5449D7007B15D1 /* Products */, 79 | ); 80 | sourceTree = ""; 81 | }; 82 | 3D38C1EA1B5449D7007B15D1 /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 3D38C1E91B5449D7007B15D1 /* ShaderSceneTransitionExample.app */, 86 | 3D38C2021B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.xctest */, 87 | ); 88 | name = Products; 89 | sourceTree = ""; 90 | }; 91 | 3D38C1EB1B5449D7007B15D1 /* ShaderSceneTransitionExample */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 3D38C2161B56B946007B15D1 /* shaders */, 95 | 3D38C1EE1B5449D7007B15D1 /* AppDelegate.swift */, 96 | 3D38C1F21B5449D7007B15D1 /* GameScene.swift */, 97 | 3D38C2121B56B2F1007B15D1 /* GameScene2.swift */, 98 | 3D38C2141B56B352007B15D1 /* SKScene+ShaderTransition.swift */, 99 | 3D38C1F41B5449D7007B15D1 /* GameViewController.swift */, 100 | 3D38C1F61B5449D7007B15D1 /* Main.storyboard */, 101 | 3D38C1F91B5449D7007B15D1 /* Images.xcassets */, 102 | 3D38C1FB1B5449D7007B15D1 /* LaunchScreen.xib */, 103 | 3D38C1EC1B5449D7007B15D1 /* Supporting Files */, 104 | ); 105 | path = ShaderSceneTransitionExample; 106 | sourceTree = ""; 107 | }; 108 | 3D38C1EC1B5449D7007B15D1 /* Supporting Files */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 3D38C1ED1B5449D7007B15D1 /* Info.plist */, 112 | ); 113 | name = "Supporting Files"; 114 | sourceTree = ""; 115 | }; 116 | 3D38C2051B5449D7007B15D1 /* ShaderSceneTransitionExampleTests */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 3D38C2081B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.swift */, 120 | 3D38C2061B5449D7007B15D1 /* Supporting Files */, 121 | ); 122 | path = ShaderSceneTransitionExampleTests; 123 | sourceTree = ""; 124 | }; 125 | 3D38C2061B5449D7007B15D1 /* Supporting Files */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 3D38C2071B5449D7007B15D1 /* Info.plist */, 129 | ); 130 | name = "Supporting Files"; 131 | sourceTree = ""; 132 | }; 133 | 3D38C2161B56B946007B15D1 /* shaders */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 3D38C2171B56B969007B15D1 /* retro_transition_fade_from_centre.fsh */, 137 | 3D38C2181B56B969007B15D1 /* retro_transition_fade_from_top_left.fsh */, 138 | 3D38C2191B56B969007B15D1 /* retro_transition_fade_from_top.fsh */, 139 | 3D38C21A1B56B969007B15D1 /* retro_transition_fade_to_centre.fsh */, 140 | ); 141 | name = shaders; 142 | sourceTree = ""; 143 | }; 144 | /* End PBXGroup section */ 145 | 146 | /* Begin PBXNativeTarget section */ 147 | 3D38C1E81B5449D7007B15D1 /* ShaderSceneTransitionExample */ = { 148 | isa = PBXNativeTarget; 149 | buildConfigurationList = 3D38C20C1B5449D7007B15D1 /* Build configuration list for PBXNativeTarget "ShaderSceneTransitionExample" */; 150 | buildPhases = ( 151 | 3D38C1E51B5449D7007B15D1 /* Sources */, 152 | 3D38C1E61B5449D7007B15D1 /* Frameworks */, 153 | 3D38C1E71B5449D7007B15D1 /* Resources */, 154 | ); 155 | buildRules = ( 156 | ); 157 | dependencies = ( 158 | ); 159 | name = ShaderSceneTransitionExample; 160 | productName = ShaderSceneTransitionExample; 161 | productReference = 3D38C1E91B5449D7007B15D1 /* ShaderSceneTransitionExample.app */; 162 | productType = "com.apple.product-type.application"; 163 | }; 164 | 3D38C2011B5449D7007B15D1 /* ShaderSceneTransitionExampleTests */ = { 165 | isa = PBXNativeTarget; 166 | buildConfigurationList = 3D38C20F1B5449D7007B15D1 /* Build configuration list for PBXNativeTarget "ShaderSceneTransitionExampleTests" */; 167 | buildPhases = ( 168 | 3D38C1FE1B5449D7007B15D1 /* Sources */, 169 | 3D38C1FF1B5449D7007B15D1 /* Frameworks */, 170 | 3D38C2001B5449D7007B15D1 /* Resources */, 171 | ); 172 | buildRules = ( 173 | ); 174 | dependencies = ( 175 | 3D38C2041B5449D7007B15D1 /* PBXTargetDependency */, 176 | ); 177 | name = ShaderSceneTransitionExampleTests; 178 | productName = ShaderSceneTransitionExampleTests; 179 | productReference = 3D38C2021B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.xctest */; 180 | productType = "com.apple.product-type.bundle.unit-test"; 181 | }; 182 | /* End PBXNativeTarget section */ 183 | 184 | /* Begin PBXProject section */ 185 | 3D38C1E11B5449D7007B15D1 /* Project object */ = { 186 | isa = PBXProject; 187 | attributes = { 188 | LastUpgradeCheck = 0640; 189 | ORGANIZATIONNAME = "Deon Botha"; 190 | TargetAttributes = { 191 | 3D38C1E81B5449D7007B15D1 = { 192 | CreatedOnToolsVersion = 6.4; 193 | }; 194 | 3D38C2011B5449D7007B15D1 = { 195 | CreatedOnToolsVersion = 6.4; 196 | TestTargetID = 3D38C1E81B5449D7007B15D1; 197 | }; 198 | }; 199 | }; 200 | buildConfigurationList = 3D38C1E41B5449D7007B15D1 /* Build configuration list for PBXProject "ShaderSceneTransitionExample" */; 201 | compatibilityVersion = "Xcode 3.2"; 202 | developmentRegion = English; 203 | hasScannedForEncodings = 0; 204 | knownRegions = ( 205 | en, 206 | Base, 207 | ); 208 | mainGroup = 3D38C1E01B5449D7007B15D1; 209 | productRefGroup = 3D38C1EA1B5449D7007B15D1 /* Products */; 210 | projectDirPath = ""; 211 | projectRoot = ""; 212 | targets = ( 213 | 3D38C1E81B5449D7007B15D1 /* ShaderSceneTransitionExample */, 214 | 3D38C2011B5449D7007B15D1 /* ShaderSceneTransitionExampleTests */, 215 | ); 216 | }; 217 | /* End PBXProject section */ 218 | 219 | /* Begin PBXResourcesBuildPhase section */ 220 | 3D38C1E71B5449D7007B15D1 /* Resources */ = { 221 | isa = PBXResourcesBuildPhase; 222 | buildActionMask = 2147483647; 223 | files = ( 224 | 3D38C21E1B56B969007B15D1 /* retro_transition_fade_to_centre.fsh in Resources */, 225 | 3D38C21C1B56B969007B15D1 /* retro_transition_fade_from_top_left.fsh in Resources */, 226 | 3D38C21B1B56B969007B15D1 /* retro_transition_fade_from_centre.fsh in Resources */, 227 | 3D38C1FD1B5449D7007B15D1 /* LaunchScreen.xib in Resources */, 228 | 3D38C1FA1B5449D7007B15D1 /* Images.xcassets in Resources */, 229 | 3D38C1F81B5449D7007B15D1 /* Main.storyboard in Resources */, 230 | 3D38C21D1B56B969007B15D1 /* retro_transition_fade_from_top.fsh in Resources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | 3D38C2001B5449D7007B15D1 /* Resources */ = { 235 | isa = PBXResourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | /* End PBXResourcesBuildPhase section */ 242 | 243 | /* Begin PBXSourcesBuildPhase section */ 244 | 3D38C1E51B5449D7007B15D1 /* Sources */ = { 245 | isa = PBXSourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 3D38C2151B56B352007B15D1 /* SKScene+ShaderTransition.swift in Sources */, 249 | 3D38C1F31B5449D7007B15D1 /* GameScene.swift in Sources */, 250 | 3D38C2131B56B2F1007B15D1 /* GameScene2.swift in Sources */, 251 | 3D38C1F51B5449D7007B15D1 /* GameViewController.swift in Sources */, 252 | 3D38C1EF1B5449D7007B15D1 /* AppDelegate.swift in Sources */, 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | 3D38C1FE1B5449D7007B15D1 /* Sources */ = { 257 | isa = PBXSourcesBuildPhase; 258 | buildActionMask = 2147483647; 259 | files = ( 260 | 3D38C2091B5449D7007B15D1 /* ShaderSceneTransitionExampleTests.swift in Sources */, 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | /* End PBXSourcesBuildPhase section */ 265 | 266 | /* Begin PBXTargetDependency section */ 267 | 3D38C2041B5449D7007B15D1 /* PBXTargetDependency */ = { 268 | isa = PBXTargetDependency; 269 | target = 3D38C1E81B5449D7007B15D1 /* ShaderSceneTransitionExample */; 270 | targetProxy = 3D38C2031B5449D7007B15D1 /* PBXContainerItemProxy */; 271 | }; 272 | /* End PBXTargetDependency section */ 273 | 274 | /* Begin PBXVariantGroup section */ 275 | 3D38C1F61B5449D7007B15D1 /* Main.storyboard */ = { 276 | isa = PBXVariantGroup; 277 | children = ( 278 | 3D38C1F71B5449D7007B15D1 /* Base */, 279 | ); 280 | name = Main.storyboard; 281 | sourceTree = ""; 282 | }; 283 | 3D38C1FB1B5449D7007B15D1 /* LaunchScreen.xib */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | 3D38C1FC1B5449D7007B15D1 /* Base */, 287 | ); 288 | name = LaunchScreen.xib; 289 | sourceTree = ""; 290 | }; 291 | /* End PBXVariantGroup section */ 292 | 293 | /* Begin XCBuildConfiguration section */ 294 | 3D38C20A1B5449D7007B15D1 /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ALWAYS_SEARCH_USER_PATHS = NO; 298 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 299 | CLANG_CXX_LIBRARY = "libc++"; 300 | CLANG_ENABLE_MODULES = YES; 301 | CLANG_ENABLE_OBJC_ARC = YES; 302 | CLANG_WARN_BOOL_CONVERSION = YES; 303 | CLANG_WARN_CONSTANT_CONVERSION = YES; 304 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 305 | CLANG_WARN_EMPTY_BODY = YES; 306 | CLANG_WARN_ENUM_CONVERSION = YES; 307 | CLANG_WARN_INT_CONVERSION = YES; 308 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 309 | CLANG_WARN_UNREACHABLE_CODE = YES; 310 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 311 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 312 | COPY_PHASE_STRIP = NO; 313 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 314 | ENABLE_STRICT_OBJC_MSGSEND = YES; 315 | GCC_C_LANGUAGE_STANDARD = gnu99; 316 | GCC_DYNAMIC_NO_PIC = NO; 317 | GCC_NO_COMMON_BLOCKS = YES; 318 | GCC_OPTIMIZATION_LEVEL = 0; 319 | GCC_PREPROCESSOR_DEFINITIONS = ( 320 | "DEBUG=1", 321 | "$(inherited)", 322 | ); 323 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 324 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 325 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 326 | GCC_WARN_UNDECLARED_SELECTOR = YES; 327 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 328 | GCC_WARN_UNUSED_FUNCTION = YES; 329 | GCC_WARN_UNUSED_VARIABLE = YES; 330 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 331 | MTL_ENABLE_DEBUG_INFO = YES; 332 | ONLY_ACTIVE_ARCH = YES; 333 | SDKROOT = iphoneos; 334 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 335 | TARGETED_DEVICE_FAMILY = "1,2"; 336 | }; 337 | name = Debug; 338 | }; 339 | 3D38C20B1B5449D7007B15D1 /* Release */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ALWAYS_SEARCH_USER_PATHS = NO; 343 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 344 | CLANG_CXX_LIBRARY = "libc++"; 345 | CLANG_ENABLE_MODULES = YES; 346 | CLANG_ENABLE_OBJC_ARC = YES; 347 | CLANG_WARN_BOOL_CONVERSION = YES; 348 | CLANG_WARN_CONSTANT_CONVERSION = YES; 349 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 350 | CLANG_WARN_EMPTY_BODY = YES; 351 | CLANG_WARN_ENUM_CONVERSION = YES; 352 | CLANG_WARN_INT_CONVERSION = YES; 353 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 354 | CLANG_WARN_UNREACHABLE_CODE = YES; 355 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 356 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 357 | COPY_PHASE_STRIP = NO; 358 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 359 | ENABLE_NS_ASSERTIONS = NO; 360 | ENABLE_STRICT_OBJC_MSGSEND = YES; 361 | GCC_C_LANGUAGE_STANDARD = gnu99; 362 | GCC_NO_COMMON_BLOCKS = YES; 363 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 364 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 365 | GCC_WARN_UNDECLARED_SELECTOR = YES; 366 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 367 | GCC_WARN_UNUSED_FUNCTION = YES; 368 | GCC_WARN_UNUSED_VARIABLE = YES; 369 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 370 | MTL_ENABLE_DEBUG_INFO = NO; 371 | SDKROOT = iphoneos; 372 | TARGETED_DEVICE_FAMILY = "1,2"; 373 | VALIDATE_PRODUCT = YES; 374 | }; 375 | name = Release; 376 | }; 377 | 3D38C20D1B5449D7007B15D1 /* Debug */ = { 378 | isa = XCBuildConfiguration; 379 | buildSettings = { 380 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 381 | INFOPLIST_FILE = ShaderSceneTransitionExample/Info.plist; 382 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 383 | PRODUCT_NAME = "$(TARGET_NAME)"; 384 | }; 385 | name = Debug; 386 | }; 387 | 3D38C20E1B5449D7007B15D1 /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 391 | INFOPLIST_FILE = ShaderSceneTransitionExample/Info.plist; 392 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 393 | PRODUCT_NAME = "$(TARGET_NAME)"; 394 | }; 395 | name = Release; 396 | }; 397 | 3D38C2101B5449D7007B15D1 /* Debug */ = { 398 | isa = XCBuildConfiguration; 399 | buildSettings = { 400 | BUNDLE_LOADER = "$(TEST_HOST)"; 401 | FRAMEWORK_SEARCH_PATHS = ( 402 | "$(SDKROOT)/Developer/Library/Frameworks", 403 | "$(inherited)", 404 | ); 405 | GCC_PREPROCESSOR_DEFINITIONS = ( 406 | "DEBUG=1", 407 | "$(inherited)", 408 | ); 409 | INFOPLIST_FILE = ShaderSceneTransitionExampleTests/Info.plist; 410 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 411 | PRODUCT_NAME = "$(TARGET_NAME)"; 412 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ShaderSceneTransitionExample.app/ShaderSceneTransitionExample"; 413 | }; 414 | name = Debug; 415 | }; 416 | 3D38C2111B5449D7007B15D1 /* Release */ = { 417 | isa = XCBuildConfiguration; 418 | buildSettings = { 419 | BUNDLE_LOADER = "$(TEST_HOST)"; 420 | FRAMEWORK_SEARCH_PATHS = ( 421 | "$(SDKROOT)/Developer/Library/Frameworks", 422 | "$(inherited)", 423 | ); 424 | INFOPLIST_FILE = ShaderSceneTransitionExampleTests/Info.plist; 425 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 426 | PRODUCT_NAME = "$(TARGET_NAME)"; 427 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ShaderSceneTransitionExample.app/ShaderSceneTransitionExample"; 428 | }; 429 | name = Release; 430 | }; 431 | /* End XCBuildConfiguration section */ 432 | 433 | /* Begin XCConfigurationList section */ 434 | 3D38C1E41B5449D7007B15D1 /* Build configuration list for PBXProject "ShaderSceneTransitionExample" */ = { 435 | isa = XCConfigurationList; 436 | buildConfigurations = ( 437 | 3D38C20A1B5449D7007B15D1 /* Debug */, 438 | 3D38C20B1B5449D7007B15D1 /* Release */, 439 | ); 440 | defaultConfigurationIsVisible = 0; 441 | defaultConfigurationName = Release; 442 | }; 443 | 3D38C20C1B5449D7007B15D1 /* Build configuration list for PBXNativeTarget "ShaderSceneTransitionExample" */ = { 444 | isa = XCConfigurationList; 445 | buildConfigurations = ( 446 | 3D38C20D1B5449D7007B15D1 /* Debug */, 447 | 3D38C20E1B5449D7007B15D1 /* Release */, 448 | ); 449 | defaultConfigurationIsVisible = 0; 450 | defaultConfigurationName = Release; 451 | }; 452 | 3D38C20F1B5449D7007B15D1 /* Build configuration list for PBXNativeTarget "ShaderSceneTransitionExampleTests" */ = { 453 | isa = XCConfigurationList; 454 | buildConfigurations = ( 455 | 3D38C2101B5449D7007B15D1 /* Debug */, 456 | 3D38C2111B5449D7007B15D1 /* Release */, 457 | ); 458 | defaultConfigurationIsVisible = 0; 459 | defaultConfigurationName = Release; 460 | }; 461 | /* End XCConfigurationList section */ 462 | }; 463 | rootObject = 3D38C1E11B5449D7007B15D1 /* Project object */; 464 | } 465 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample.xcodeproj/xcuserdata/deon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample.xcodeproj/xcuserdata/deon.xcuserdatad/xcschemes/ShaderSceneTransitionExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample.xcodeproj/xcuserdata/deon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ShaderSceneTransitionExample.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 3D38C1E81B5449D7007B15D1 16 | 17 | primary 18 | 19 | 20 | 3D38C2011B5449D7007B15D1 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ShaderSceneTransitionExample 4 | // 5 | // Created by Deon Botha on 13/07/2015. 6 | // Copyright (c) 2015 Deon Botha. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/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 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/GameScene.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GameScene.swift 3 | // ShaderSceneTransitionExample 4 | // 5 | // Created by Deon Botha on 13/07/2015. 6 | // Copyright (c) 2015 Deon Botha. All rights reserved. 7 | // 8 | 9 | import SpriteKit 10 | 11 | class GameScene: SKScene { 12 | 13 | override init(size: CGSize) { 14 | super.init(size: size) 15 | self.backgroundColor = SKColor.whiteColor() 16 | 17 | var label = SKLabelNode(text: "Scene 1") 18 | label.fontColor = SKColor.blackColor() 19 | label.fontSize = 32 20 | label.position = CGPointMake(size.width / 2, size.height / 2) 21 | self.addChild(label) 22 | 23 | label = SKLabelNode(text: "tap to transition") 24 | label.fontColor = SKColor.blackColor() 25 | label.fontSize = 24 26 | label.position = CGPointMake(size.width / 2, size.height / 2 - 50) 27 | self.addChild(label) 28 | } 29 | 30 | required init?(coder aDecoder: NSCoder) { 31 | fatalError("init(coder:) has not been implemented") 32 | } 33 | 34 | override func didMoveToView(view: SKView) { 35 | // fake some loading delay then finish the shader transition 36 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.3 * Double(NSEC_PER_SEC))) 37 | dispatch_after(delayTime, dispatch_get_main_queue(), { () -> Void in 38 | self.completeShaderTransition() 39 | }) 40 | } 41 | 42 | override func touchesBegan(touches: Set, withEvent event: UIEvent) { 43 | self.presentScene(GameScene2(size: self.size), shaderName: "retro_transition_fade_from_top.fsh", transitionDuration: 1.0) 44 | } 45 | 46 | override func update(currentTime: CFTimeInterval) { 47 | self.updateShaderTransition(currentTime) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/GameScene2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GameScene2.swift 3 | // ShaderSceneTransitionExample 4 | // 5 | // Created by Deon Botha on 15/07/2015. 6 | // Copyright (c) 2015 Deon Botha. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SpriteKit 11 | 12 | class GameScene2: SKScene { 13 | 14 | override init(size: CGSize) { 15 | super.init(size: size) 16 | self.backgroundColor = SKColor.whiteColor() 17 | 18 | var label = SKLabelNode(text: "Scene 2") 19 | label.fontColor = SKColor.blackColor() 20 | label.fontSize = 32 21 | label.position = CGPointMake(size.width / 2, size.height / 2) 22 | self.addChild(label) 23 | 24 | label = SKLabelNode(text: "tap to transition") 25 | label.fontColor = SKColor.blackColor() 26 | label.fontSize = 24 27 | label.position = CGPointMake(size.width / 2, size.height / 2 - 50) 28 | self.addChild(label) 29 | } 30 | 31 | required init?(coder aDecoder: NSCoder) { 32 | fatalError("init(coder:) has not been implemented") 33 | } 34 | 35 | override func didMoveToView(view: SKView) { 36 | // fake some loading delay then finish the shader transition 37 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.3 * Double(NSEC_PER_SEC))) 38 | dispatch_after(delayTime, dispatch_get_main_queue(), { () -> Void in 39 | self.completeShaderTransition() 40 | }) 41 | } 42 | 43 | override func touchesBegan(touches: Set, withEvent event: UIEvent) { 44 | self.presentScene(GameScene(size: self.size), shaderName: "retro_transition_fade_from_centre.fsh", transitionDuration: 1.0) 45 | } 46 | 47 | override func update(currentTime: CFTimeInterval) { 48 | self.updateShaderTransition(currentTime) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/GameViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GameViewController.swift 3 | // ShaderSceneTransitionExample 4 | // 5 | // Created by Deon Botha on 13/07/2015. 6 | // Copyright (c) 2015 Deon Botha. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SpriteKit 11 | 12 | class GameViewController: UIViewController { 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | 17 | // Configure the view. 18 | let skView = self.view as! SKView 19 | 20 | /* Sprite Kit applies additional optimizations to improve rendering performance */ 21 | skView.ignoresSiblingOrder = true 22 | 23 | /* Set the scale mode to scale to fit the window */ 24 | var scene = GameScene(size: skView.bounds.size) 25 | scene.scaleMode = .AspectFill 26 | skView.presentScene(scene) 27 | skView.backgroundColor = SKColor.whiteColor() 28 | } 29 | 30 | override func shouldAutorotate() -> Bool { 31 | return true 32 | } 33 | 34 | override func supportedInterfaceOrientations() -> Int { 35 | if UIDevice.currentDevice().userInterfaceIdiom == .Phone { 36 | return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue) 37 | } else { 38 | return Int(UIInterfaceOrientationMask.All.rawValue) 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/Images.xcassets/dummy.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "dummy@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/Images.xcassets/dummy.imageset/dummy@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dbotha/SpriteKitShaderTransitionExample/900988964aa425b487e5aa63a32126efb772d8c1/ShaderSceneTransitionExample/Images.xcassets/dummy.imageset/dummy@2x.png -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.dbotha.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarHidden 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/SKScene+ShaderTransition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SKScene+ShaderTransition.swift 3 | // ShaderSceneTransitionExample 4 | // 5 | // Created by Deon Botha on 15/07/2015. 6 | // Copyright (c) 2015 Deon Botha. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SpriteKit 11 | 12 | //private let totalAnimationDuration = 1.0 13 | private let kNodeNameTransitionShaderNode = "kNodeNameTransitionShaderNode" 14 | private let kNodeNameFadeColourOverlay = "kNodeNameFadeColourOverlay" 15 | private var presentationStartTime: CFTimeInterval = -1 16 | private var shaderChoice = -1 17 | 18 | extension SKScene { 19 | 20 | private var transitionShader: SKShader? { 21 | get { 22 | if let shaderContainerNode = self.childNodeWithName(kNodeNameTransitionShaderNode) as? SKSpriteNode { 23 | return shaderContainerNode.shader 24 | } 25 | 26 | return nil 27 | } 28 | } 29 | 30 | private func createShader(shaderName: String, transitionDuration: NSTimeInterval) -> SKShader { 31 | var shader = SKShader(fileNamed:shaderName) 32 | var u_size = SKUniform(name: "u_size", floatVector3: GLKVector3Make(Float(UIScreen.mainScreen().scale * size.width), Float(UIScreen.mainScreen().scale * size.height), Float(0))) 33 | var u_fill_colour = SKUniform(name: "u_fill_colour", floatVector4: GLKVector4Make(131.0 / 255.0, 149.0 / 255.0, 255.0 / 255.0, 1.0)) 34 | var u_border_colour = SKUniform(name: "u_border_colour", floatVector4: GLKVector4Make(104.0 / 255.0, 119.0 / 255.0, 204.0 / 255.0, 1.0)) 35 | var u_total_animation_duration = SKUniform(name: "u_total_animation_duration", float: Float(transitionDuration)) 36 | var u_elapsed_time = SKUniform(name: "u_elapsed_time", float: Float(0)) 37 | shader.uniforms = [u_size, u_fill_colour, u_border_colour, u_total_animation_duration, u_elapsed_time] 38 | return shader 39 | } 40 | 41 | func presentScene(scene: SKScene?, shaderName: String, transitionDuration: NSTimeInterval) { 42 | // Create shader and add it to the scene 43 | var shaderContainer = SKSpriteNode(imageNamed: "dummy") 44 | shaderContainer.name = kNodeNameTransitionShaderNode 45 | shaderContainer.zPosition = 9999 // something arbitrarily large to ensure it's in the foreground 46 | shaderContainer.position = CGPointMake(size.width / 2, size.height / 2) 47 | shaderContainer.size = CGSizeMake(size.width, size.height) 48 | shaderContainer.shader = createShader(shaderName, transitionDuration:transitionDuration) 49 | self.addChild(shaderContainer) 50 | 51 | // remove the shader from the scene after its animation has completed. 52 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(transitionDuration * Double(NSEC_PER_SEC))) 53 | dispatch_after(delayTime, dispatch_get_main_queue(), { () -> Void in 54 | var fadeOverlay = SKShapeNode(rect: CGRectMake(0, 0, self.size.width, self.size.height)) 55 | fadeOverlay.name = kNodeNameFadeColourOverlay 56 | fadeOverlay.fillColor = SKColor(red: 131.0 / 255.0, green: 149.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0) 57 | fadeOverlay.zPosition = shaderContainer.zPosition 58 | scene!.addChild(fadeOverlay) 59 | self.view!.presentScene(scene) 60 | }) 61 | 62 | // Reset the time presentScene was called so that the elapsed time from now can 63 | // be calculated in updateShaderTransitions(currentTime:) 64 | presentationStartTime = -1 65 | } 66 | 67 | func updateShaderTransition(currentTime: CFTimeInterval) { 68 | if let shader = self.transitionShader { 69 | let elapsedTime = shader.uniformNamed("u_elapsed_time")! 70 | if (presentationStartTime < 0) { 71 | presentationStartTime = currentTime 72 | } 73 | elapsedTime.floatValue = Float(currentTime - presentationStartTime) 74 | } 75 | } 76 | 77 | 78 | // this function is called by the scene being transitioned to when it's ready to have the view faded in to the scene i.e. loading is complete, etc. 79 | func completeShaderTransition() { 80 | if let fadeOverlay = self.childNodeWithName(kNodeNameFadeColourOverlay) { 81 | fadeOverlay.runAction(SKAction.sequence([SKAction.fadeAlphaTo(0, duration: 0.3), SKAction.removeFromParent()])) 82 | } 83 | } 84 | 85 | 86 | 87 | } -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/retro_transition_fade_from_centre.fsh: -------------------------------------------------------------------------------- 1 | int NUM_COLUMNS = 15; 2 | 3 | void main( void ) { 4 | float tileSize = u_size.x / float(NUM_COLUMNS); 5 | int NUM_ROWS = int(ceil(u_size.y / tileSize)); 6 | 7 | int column = int(floor(gl_FragCoord.x / tileSize)); 8 | int row = int(floor(gl_FragCoord.y / tileSize)); 9 | 10 | vec2 pos = mod(gl_FragCoord.xy, vec2(tileSize)) - vec2(tileSize / 2.0); 11 | float individualTileAnimationDuration = u_total_animation_duration / 3.0; 12 | 13 | float centreColumn = float(NUM_COLUMNS) / 2.0; 14 | float centreRow = float(NUM_ROWS) / 2.0; 15 | 16 | float dx = float(row) - centreRow; 17 | float dy = float(column) - centreColumn; 18 | float distFromCentre = dx * dx + dy * dy; 19 | 20 | float maxDx = float(NUM_ROWS) - centreRow; 21 | float maxDy = float(NUM_COLUMNS) - centreColumn; 22 | float maxDistFromCentre = maxDx * maxDx + maxDy * maxDy; 23 | 24 | float animStartOffset = (distFromCentre / maxDistFromCentre) * (u_total_animation_duration - individualTileAnimationDuration); 25 | float elapsedTileAnimTime = min(max(0.0, u_elapsed_time - animStartOffset), individualTileAnimationDuration); 26 | float tileRadius = (elapsedTileAnimTime / individualTileAnimationDuration) * (tileSize + 3.0); 27 | 28 | if (abs(pos.x) + abs(pos.y) < tileRadius - 3.0) { 29 | gl_FragColor = u_fill_colour; 30 | } else if (abs(pos.x) + abs(pos.y) < tileRadius) { 31 | gl_FragColor = u_border_colour; 32 | } else { 33 | gl_FragColor = SKDefaultShading(); 34 | } 35 | } -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/retro_transition_fade_from_top.fsh: -------------------------------------------------------------------------------- 1 | int NUM_COLUMNS = 15; 2 | 3 | void main( void ) { 4 | float tileSize = u_size.x / float(NUM_COLUMNS); 5 | int NUM_ROWS = int(ceil(u_size.y / tileSize)); 6 | 7 | int column = int(floor(gl_FragCoord.x / tileSize)); 8 | int row = int(floor(gl_FragCoord.y / tileSize)); 9 | 10 | vec2 pos = mod(gl_FragCoord.xy, vec2(tileSize)) - vec2(tileSize / 2.0); 11 | float individualTileAnimationDuration = u_total_animation_duration / 3.0; 12 | float animStartOffset = (float(NUM_ROWS - row) / float(NUM_ROWS)) * (u_total_animation_duration - individualTileAnimationDuration); 13 | float elapsedTileAnimTime = min(max(0.0, u_elapsed_time - animStartOffset), individualTileAnimationDuration); 14 | float tileRadius = (elapsedTileAnimTime / individualTileAnimationDuration) * (tileSize + 3.0); 15 | 16 | if (abs(pos.x) + abs(pos.y) < tileRadius - 3.0) { 17 | gl_FragColor = u_fill_colour; 18 | } else if (abs(pos.x) + abs(pos.y) < tileRadius) { 19 | gl_FragColor = u_border_colour; 20 | } else { 21 | gl_FragColor = SKDefaultShading(); 22 | } 23 | } 24 | 25 | // XXX: Becky is a triumphant elephant. Mr. Pudding is here too. -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/retro_transition_fade_from_top_left.fsh: -------------------------------------------------------------------------------- 1 | int NUM_COLUMNS = 15; 2 | 3 | void main( void ) { 4 | float tileSize = u_size.x / float(NUM_COLUMNS); 5 | int NUM_ROWS = int(ceil(u_size.y / tileSize)); 6 | 7 | int column = int(floor(gl_FragCoord.x / tileSize)); 8 | int row = int(floor(gl_FragCoord.y / tileSize)); 9 | 10 | vec2 pos = mod(gl_FragCoord.xy, vec2(tileSize)) - vec2(tileSize / 2.0); 11 | float individualTileAnimationDuration = u_total_animation_duration / 3.0; 12 | 13 | float centreColumn = 0.0; 14 | float centreRow = float(NUM_ROWS); 15 | 16 | float dx = float(row) - centreRow; 17 | float dy = float(column) - centreColumn; 18 | float distFromCentre = dx * dx + dy * dy; 19 | 20 | float maxDx = float(NUM_ROWS); 21 | float maxDy = float(NUM_COLUMNS); 22 | float maxDistFromCentre = maxDx * maxDx + maxDy * maxDy; 23 | 24 | float animStartOffset = (distFromCentre / maxDistFromCentre) * (u_total_animation_duration - individualTileAnimationDuration); 25 | float elapsedTileAnimTime = min(max(0.0, u_elapsed_time - animStartOffset), individualTileAnimationDuration); 26 | float tileRadius = (elapsedTileAnimTime / individualTileAnimationDuration) * (tileSize + 3.0); 27 | 28 | if (abs(pos.x) + abs(pos.y) < tileRadius - 3.0) { 29 | gl_FragColor = u_fill_colour; 30 | } else if (abs(pos.x) + abs(pos.y) < tileRadius) { 31 | gl_FragColor = u_border_colour; 32 | } else { 33 | gl_FragColor = SKDefaultShading(); 34 | } 35 | } -------------------------------------------------------------------------------- /ShaderSceneTransitionExample/retro_transition_fade_to_centre.fsh: -------------------------------------------------------------------------------- 1 | int NUM_COLUMNS = 15; 2 | 3 | void main( void ) { 4 | float tileSize = u_size.x / float(NUM_COLUMNS); 5 | int NUM_ROWS = int(ceil(u_size.y / tileSize)); 6 | 7 | int column = int(floor(gl_FragCoord.x / tileSize)); 8 | int row = int(floor(gl_FragCoord.y / tileSize)); 9 | 10 | vec2 pos = mod(gl_FragCoord.xy, vec2(tileSize)) - vec2(tileSize / 2.0); 11 | float individualTileAnimationDuration = u_total_animation_duration / 3.0; 12 | 13 | float centreColumn = float(NUM_COLUMNS) / 2.0; 14 | float centreRow = float(NUM_ROWS) / 2.0; 15 | 16 | float dx = float(row) - centreRow; 17 | float dy = float(column) - centreColumn; 18 | float distFromCentre = dx * dx + dy * dy; 19 | 20 | float maxDx = float(NUM_ROWS) - centreRow; 21 | float maxDy = float(NUM_COLUMNS) - centreColumn; 22 | float maxDistFromCentre = maxDx * maxDx + maxDy * maxDy; 23 | 24 | float animStartOffset = (u_total_animation_duration - individualTileAnimationDuration) - (distFromCentre / maxDistFromCentre) * (u_total_animation_duration - individualTileAnimationDuration); 25 | float elapsedTileAnimTime = min(max(0.0, u_elapsed_time - animStartOffset), individualTileAnimationDuration); 26 | float tileRadius = (elapsedTileAnimTime / individualTileAnimationDuration) * (tileSize + 3.0); 27 | 28 | if (abs(pos.x) + abs(pos.y) < tileRadius - 3.0) { 29 | gl_FragColor = u_fill_colour; 30 | } else if (abs(pos.x) + abs(pos.y) < tileRadius) { 31 | gl_FragColor = u_border_colour; 32 | } else { 33 | gl_FragColor = SKDefaultShading(); 34 | } 35 | } -------------------------------------------------------------------------------- /ShaderSceneTransitionExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.dbotha.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ShaderSceneTransitionExampleTests/ShaderSceneTransitionExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ShaderSceneTransitionExampleTests.swift 3 | // ShaderSceneTransitionExampleTests 4 | // 5 | // Created by Deon Botha on 13/07/2015. 6 | // Copyright (c) 2015 Deon Botha. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class ShaderSceneTransitionExampleTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------