Last active
August 26, 2018 23:49
-
-
Save delasign/e38f4a5fd021212a4e296b4a9fe822aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addTextureShaderToChild(child:SCNNode) { | |
| let program = SCNProgram() | |
| program.fragmentFunctionName = "TextureSurfaceFragment" | |
| program.vertexFunctionName = "TextureVertexShader" | |
| program.isOpaque = false; | |
| // CREATE A MATERIAL, ADD THE PROGRAM, AND ADD IT TO THE CHILD. | |
| let shaderMaterial = SCNMaterial() | |
| shaderMaterial.program = program; | |
| shaderMaterial.transparencyMode = .rgbZero; | |
| shaderMaterial.blendMode = .alpha; | |
| shaderMaterial.writesToDepthBuffer = false | |
| shaderMaterial.readsFromDepthBuffer = false | |
| shaderMaterial.cullMode = .back | |
| let image = UIImage(named: "YOUR_TEXTURE")! | |
| let imageProperty = SCNMaterialProperty(contents: image) | |
| // The name you supply here should match the texture parameter name in the fragment shader | |
| shaderMaterial.setValue(imageProperty, forKey: "diffuseTexture") | |
| child.geometry?.materials.removeAll(); | |
| child.geometry?.materials = [shaderMaterial]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment