gpt4 book ai didi

GLSL 棋盘格图案

转载 作者:行者123 更新时间:2023-12-04 16:22:30 24 4
gpt4 key购买 nike

我想用跳棋来遮蔽四边形:

f(P)=[floor(Px)+floor(Py)]mod2.



我的四边形是:
glBegin(GL_QUADS);    
glVertex3f(0,0,0.0);
glVertex3f(4,0,0.0);
glVertex3f(4,4,0.0);
glVertex3f(0,4, 0.0);
glEnd();

顶点着色器文件:
varying float factor;
float x,y;
void main(){
x=floor(gl_Position.x);
y=floor(gl_Position.y);
factor = mod((x+y),2.0);
}

片段着色器文件是:
varying float factor;
void main(){
gl_FragColor = vec4(factor,factor,factor,1.0);
}

但我得到了这个:

alt text

似乎 mod 功能不起作用或者其他东西......
有什么帮助吗?

最佳答案

最好在片段着色器中计算这种效果,如下所示:

顶点程序 =>

varying vec2 texCoord;

void main(void)
{
gl_Position = vec4( gl_Vertex.xy, 0.0, 1.0 );
gl_Position = sign( gl_Position );

texCoord = (vec2( gl_Position.x, gl_Position.y )
+ vec2( 1.0 ) ) / vec2( 2.0 );
}

片段程序 =>
#extension GL_EXT_gpu_shader4 : enable
uniform sampler2D Texture0;
varying vec2 texCoord;

void main(void)
{
ivec2 size = textureSize2D(Texture0,0);
float total = floor(texCoord.x*float(size.x)) +
floor(texCoord.y*float(size.y));
bool isEven = mod(total,2.0)==0.0;
vec4 col1 = vec4(0.0,0.0,0.0,1.0);
vec4 col2 = vec4(1.0,1.0,1.0,1.0);
gl_FragColor = (isEven)? col1:col2;
}

输出 =>

alt text

祝你好运!

关于GLSL 棋盘格图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4694608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com