【问题标题】:Metal / Scenekit - Repeating texture on samplerMetal / Scenekit - 在采样器上重复纹理
【发布时间】: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 值有效?
  • 如果不可能,最简单的方法是什么? (缩放、重复。重绘纹理不是一种选择)

谢谢。

【问题讨论】:

    标签: scenekit metal metalkit


    【解决方案1】:

    使用SCNProgram 时,SCNMaterialPropertycontentsTransform 属性无效(因为在 SceneKit 的内置顶点和片段着色器中实现了支持)。

    您需要将 2D 矩阵传递给自定义 SCNProgram 着色器,并在那里手动转换纹理坐标。

    【讨论】:

    • 谢谢,在线或这里有相同的文档或示例吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多