ios - Toon.shader 找不到 _light 变量

标签 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'

最佳答案

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

可以看一下头文件,比SCNShadable protocol documentation详细一点.

关于ios - Toon.shader 找不到 _light 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28774207/

相关文章:

ios - iOS 上的实际风景 OpenGL View

ios - XCode iPhone 如何处理 UI 元素的垂直对齐

ios - 在旋转时调整 UIViewController 内的全屏 View 大小?

IOS7验证iap收据,in_app filed是什么意思?

ios - 对于键 setDefaultLabelText,此类不符合键值编码。

ios - Object1.position.y = Object2.position.y?

iphone - iOS 中的内存泄漏

objective-c - 以编程方式计算 APR(年度百分比率)

c++ - 如何在 Windows 中创建全屏 OpenGL-ES 渲染 View ?

c++ - 在 Windows 上使用 ANGLE 和 GLFW 设置 C++ 项目