【发布时间】:2022-01-08 23:29:21
【问题描述】:
不知道为什么,但在使用客户片段着色器时我无法重复纹理
这是我的片段
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
纹理正确重复
问题:
- 在自定义片段着色器中使用采样器时,我还必须更改哪些内容才能使 contentTransform 值有效?
- 如果不可能,最简单的方法是什么? (缩放、重复。重绘纹理不是一种选择)
谢谢。
【问题讨论】: