Toon.shader找不到_light var

时间:2015-02-27 21:03:03

标签: ios objective-c opengl-es glsl scenekit

所以我在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'

1 个答案:

答案 0 :(得分:1)

_light结构仅在SCNShaderModifierEntryPointLightingModel入口点可用。

您可以查看标题文件,它比SCNShadable protocol documentation更详细。