swift - Using a Metal shader in SceneKit -
i'd use metal
shader apply toon/cell shading materials used in scene. shader i'm trying implement apple's own aaplcelshader
found in metalshadershowcase. i'm little new implementing shaders in scenekit
doing wrong.
from understand in documentation metal
or gl shader can used modify scenekit
rendering of ios 9 , xcode 7. documentation suggests done in same way gl shaders.
my method try , path .metal
file , load string used in scnmaterial
shadermodifiers
property in form of [string: string] dictionary, gl shader (though i've yet working properly).
my code is:
var shaders = [string: string]() let path = nsbundle.mainbundle().pathforresource("aaplcelshader", oftype: "metal")! do{ let celshader = try string(contentsoffile: path, encoding: nsutf8stringencoding) shaders[scnshadermodifierentrypointlightingmodel] = celshader }catch let error nserror{ error.description } scene.rootnode.enumeratechildnodesusingblock({ (node, stop) -> void in node.geometry?.firstmaterial?.shadermodifiers = shaders })
this being run on test scene single box geometry in being loaded .scn
file. file loading works fine that's not issue.
the error comes second line try , find path, gives me "found nil while unwrapping optional value" expected force unwrapping, other fact file trying load in bundle , same code works fine other file types, not .metal
ones.
am going wrong way? can't understand why won't access file other issue me misusing metal file.
is there simpler or better way implement cell shading , bold outline on edges?
aaplcelshader.metal complete vertex/rastex/fragment implementation, not shadermodifiers are: source code injected already-complete shaders.
instead, can create scnprogram, using vertex , fragment functions in aaplcelshader.metal. what's nice metal, versus glsl, can use names of metal functions, instead of source code strings, easier work with, , results in having functions compiled before runtime, glsl doesn't support. (this still not should be, swift recognize metal functions correctly-typed, refactorable, namespaced closures.) of course, while glsl scnprograms converted metal, compatible hardware, metal scnprograms not translated obsolete devices.
as mapping scenekit rastex's (incorrectly-named colorinout) members:
float4 position [[position]]; float shine; float3 normal_cameraspace; float3 eye_direction_cameraspace; float3 light_direction_cameraspace;
…i unfortunately not have answer yet.
Comments
Post a Comment