不知道为什么,但我不能重复纹理时,使用客户片段着色
这是我的碎片
fragment float4 bFragment( VertexOut vertexOut [[stage_in]],
texture2d<float, access::sample> textureInput [[texture(0)]],)
{
constexpr sampler sampler2d(coord::normalized, address::repeat, filter::linear, address::repeat);
float4 outputColor;
outputColor = textureInput.sample(sampler2d, vertexOut.texCoord);
return float4(outputColor.x , outputColor.y , outputColor.z , 1.0);
}下面是我如何传递纹理的方法:
let imageProperty = SCNMaterialProperty(contents: texture)
imageProperty.wrapS = .repeat
imageProperty.wrapT = .repeat
imageProperty.contentsTransform = SCNMatrix4MakeScale(screenRatio * numberOfRepetitionsOnX, numberOfRepetitionsOnX , 1)
node.geometry!.firstMaterial!.setValue(imageProperty, forKey: "textureInput")图像不重复,只是夹紧在物体上,无论纹理大小。
如果在没有客户着色器的情况下使用相同的设置:
let myMaterial = SCNMaterial()
myMaterial.lightingModel = .constant
myMaterial.diffuse.contents = texture
myMaterial.diffuse.wrapS = .repeat
myMaterial.diffuse.wrapT = .repeat
myMaterial.diffuse.contentsTransform = SCNMatrix4MakeScale(screenRatio * numberOfRepetitionsOnX, numberOfRepetitionsOnX , 1)
node.geometry!.firstMaterial! = myMaterial纹理正确重复
问题:
谢谢。
发布于 2021-12-02 13:23:48
当使用SCNProgram时,SCNMaterialProperty的contentsTransform属性没有任何影响(因为支持是在SceneKit的内置顶点和片段着色器中实现的)。
您将需要将2D矩阵传递给自定义的SCNProgram着色器,并手动转换那里的纹理坐标。
https://stackoverflow.com/questions/70200030
复制相似问题