ios 使用自定义表面修改器时 Scenekit 阴影不同
ios Scenekit shadow differs when use custom surface modifier
我有一个有两个平面的简单场景。第一个带有花纹理和阴影的平面被投射到背景平面(墙纹理)上。
我尝试使用表面修改器 SCNShaderModifierEntryPointSurface 并且阴影变得完全不同。现在它不再是花,而是投射了它自己所在平面的影子。
请看附图。
1。
2。
我的代码
花飞机
SCNPlane *planeGeometry = [SCNPlane planeWithWidth:16.0 height:8.0];
SCNNode *planeNode = [SCNNode nodeWithGeometry:planeGeometry];
第一张图片的代码可以
planeGeometry.firstMaterial.diffuse.contents = [UIImage imageNamed:@"flowerTexture"];
第二张图片的代码不正确
NSString * surfModifier = ...;
planeGeometry.firstMaterial.shaderModifiers = @{SCNShaderModifierEntryPointSurface : surfModifier};
SCNMaterialProperty* diffuseTexture = [SCNMaterialProperty materialPropertyWithContents:[UIImage imageNamed:@"flowerTexture"]];
[planeGeometry.firstMaterial setValue:diffuseTexture forKey:@"mixTexture"];
和 surfModifier 着色器
uniform sampler2D mixTexture;
#pragma transparent
#pragma body
vec4 originalTexture = texture2D(mixTexture, _surface.diffuseTexcoord);
_surface.diffuse = originalTexture;
请帮助我使第二个工作正常
谢谢
您的着色器修改器专门在渲染该花平面节点时应用。您实际上是在 post 处理花平面节点,此后不会影响对象上的阴影。
一个解决方案是基本上预处理花平面纹理,然后像示例 1 中那样将其分配给平面。因此,例如,使用 Metal 将花图像渲染为纹理,您仍然可以用shader代码修改,然后在Scenekit中作为花平面的贴图。
我有一个有两个平面的简单场景。第一个带有花纹理和阴影的平面被投射到背景平面(墙纹理)上。
我尝试使用表面修改器 SCNShaderModifierEntryPointSurface 并且阴影变得完全不同。现在它不再是花,而是投射了它自己所在平面的影子。
请看附图。
1。
2。
我的代码 花飞机
SCNPlane *planeGeometry = [SCNPlane planeWithWidth:16.0 height:8.0];
SCNNode *planeNode = [SCNNode nodeWithGeometry:planeGeometry];
第一张图片的代码可以
planeGeometry.firstMaterial.diffuse.contents = [UIImage imageNamed:@"flowerTexture"];
第二张图片的代码不正确
NSString * surfModifier = ...;
planeGeometry.firstMaterial.shaderModifiers = @{SCNShaderModifierEntryPointSurface : surfModifier};
SCNMaterialProperty* diffuseTexture = [SCNMaterialProperty materialPropertyWithContents:[UIImage imageNamed:@"flowerTexture"]];
[planeGeometry.firstMaterial setValue:diffuseTexture forKey:@"mixTexture"];
和 surfModifier 着色器
uniform sampler2D mixTexture;
#pragma transparent
#pragma body
vec4 originalTexture = texture2D(mixTexture, _surface.diffuseTexcoord);
_surface.diffuse = originalTexture;
请帮助我使第二个工作正常
谢谢
您的着色器修改器专门在渲染该花平面节点时应用。您实际上是在 post 处理花平面节点,此后不会影响对象上的阴影。
一个解决方案是基本上预处理花平面纹理,然后像示例 1 中那样将其分配给平面。因此,例如,使用 Metal 将花图像渲染为纹理,您仍然可以用shader代码修改,然后在Scenekit中作为花平面的贴图。