所以我在Apple的SceneKit中加载自定义着色器。
- (NSDictionary *)celShading {
NSMutableDictionary *shaders = [NSMutableDictionary new];
shaders[SCNShaderModifierEntryPointFragment] =
[NSString stringWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"toon" withExtension:@"shader"]
encoding:NSUTF8StringEncoding
error:NULL];
return shaders;
}
我的自定义着色器是toon.shader
vec3 lDir = normalize(vec3(0.1,1.0,1.0));
float dotProduct = dot(_surface.normal,lDir);
_lightingContribution.diffuse += (dotProduct * dotProduct * _light.intensity.rgb);
_lightingContribution.diffuse = floor(_lightingContribution.diffuse * 4.0) / 3.0;
vec3 halfVector = normalize(lDir + _surface.view);
dotProduct = max(0.0, pow(max(0.0, dot(_surface.normal, halfVector)), _surface.shininess));
dotProduct = floor(dotProduct * 3.0) / 3.0;
//_lightingContribution.specular += (dotProduct * _light.intensity.rgb);
_lightingContribution.specular = vec3(0,0,0);
这就是我得到的错误。
2015-02-27 12:52:48.164 ShadeTest[4729:499612] SceneKit: error, failed to link program: ERROR: 0:64: Use of undeclared identifier '_light'
答案 0 :(得分:1)
_light
结构仅在SCNShaderModifierEntryPointLightingModel
入口点可用。
您可以查看标题文件,它比SCNShadable protocol documentation更详细。