首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >金属/机具-取样器上的重复织构

问金属/机具-取样器上的重复织构
EN

Stack Overflow用户
提问于 2021-12-02 13:05:19
回答 1查看 53关注 0票数 0

不知道为什么,但我不能重复纹理时,使用客户片段着色

这是我的碎片

代码语言:javascript
复制
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);

}

下面是我如何传递纹理的方法:

代码语言:javascript
复制
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")

图像不重复,只是夹紧在物体上,无论纹理大小。

如果在没有客户着色器的情况下使用相同的设置:

代码语言:javascript
复制
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

纹理正确重复

问题:

  • ,为了在定制片段着色器中使用采样器时,我必须改变什么才能有效地实现contentsTransform值?
  • ,如果这是不可能的,那么实现这一目标的最简单方法是什么?(缩放,repeating.redrawing纹理不是选项)

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-02 13:23:48

当使用SCNProgram时,SCNMaterialProperty的contentsTransform属性没有任何影响(因为支持是在SceneKit的内置顶点和片段着色器中实现的)。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70200030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档