Skip to content

Instantly share code, notes, and snippets.

@delasign
Last active August 26, 2018 23:49
Show Gist options
  • Select an option

  • Save delasign/e38f4a5fd021212a4e296b4a9fe822aa to your computer and use it in GitHub Desktop.

Select an option

Save delasign/e38f4a5fd021212a4e296b4a9fe822aa to your computer and use it in GitHub Desktop.
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