简体   繁体   English

在着色器上实现 GL_REPEAT

[英]Implementing GL_REPEAT on shader

I'm trying to implement GL_REPEAT on glsl.我正在尝试在 glsl 上实现 GL_REPEAT。 I wrote something using the mod function but there's a problem where the two textures combine.我使用 mod 函数写了一些东西,但是两个纹理结合起来存在问题 Could you explain why it doesn't work right?你能解释为什么它不起作用吗?

in main: 在主要:
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
my shader code looks like this: 我的着色器代码如下所示:
 in vec2 TextureCoord; float yCoord = mod(TextureCoord.y + 0.5, 1.0); emission = texture(material.emission,vec2(TextureCoord.x, yCoord)).rgb; //result vec3 result = emission; FragColor = vec4(result, 1.0f);

The wrap mode is honored during texture filtering .纹理过滤期间使用环绕模式。 You set the GL_LINEAR filter mode, hence it will always use a 2x2 texel footprint.您设置了GL_LINEAR过滤器模式,因此它将始终使用2x2纹素足迹。 If that footprint happens to be at the border, the selected wrap mode will apply to selecting each individual texel .如果该足迹恰好在边界处,则所选的环绕模式将应用于选择每个单独的 texel In your case, if you get near the border, you told it to filter into the textrue border color, which a filter with GL_REPEAT wrap mode never would have done, it would have used the texel data from the opposing border instead.在你的情况下,如果你靠近边界,你告诉它过滤到 textrue 边界颜色,这是一个带有GL_REPEAT环绕模式的过滤器永远不会做的,它会使用来自相反边界的 texel 数据。

So if you want to re-implement that manually in the shader, you must also implement the texel selection and the filtering itself .因此,如果您想在着色器中手动重新实现它,您还必须实现 texel 选择和过滤本身 Since you also use mipmapping, doing so will be quite complex, and slow.由于您还使用 mipmapping,因此这样做会非常复杂且缓慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM