【发布时间】:2019-05-08 14:08:27
【问题描述】:
我想改进我最近的question 并在SceneKit 中使用金属(片段)着色器实现卡通效果like this。
这是我的片段着色器,实现了简单的 phong 光照和卡通效果:
fragment float4 lightingFragment(VertexOut in [[stage_in]]) {
float3 normal = normalize(in.normal);
// For edges set color to yellow
float3 V = normalize(in.eye - in.position.xyz);
float edgeDetection = (abs(dot(V, normal)) > 0.1) ? 1 : 0;
if ( edgeDetection != 1 ) {
return float4(1, 1, 0, 1);
}
// Compute simple phong
float3 lightDirection = normalize(light.position - in.position.xyz);
float diffuseIntensity = saturate(dot(normal, lightDirection));
float3 diffuseTerm = light.diffuseColor * material.diffuseColor * diffuseIntensity;
// Ambient color
float3 ambientTerm = light.ambientColor * material.ambientColor;
return float4(ambientTerm + diffuseTerm, 1.0);
}
正如我所说,我受到this article 的启发,但我得到了非常不同的结果......
有什么想法吗?这是whole project
【问题讨论】:
-
我根据 Warren 的建议更新了 GitHub 项目:github.com/martinpilch/toon-shading-example
标签: shader scenekit metal fragment-shader