GLSL Checkerboard Pattern

前端 未结 5 1051
情书的邮戳
情书的邮戳 2021-02-10 03:03

i want to shade the quad with checkers:

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

My quad is:

glBegin(GL_QUADS);    
  glVerte         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 03:37

    May I suggest the following:

    float result = mod(dot(vec2(1.0), step(vec2(0.5), fract(v_uv * u_repeat))), 2.0);
    
    • v_uv is a vec2 of UV values,
    • u_repeat is a vec2 of how many times the pattern should be repeated for each axis.
    • result is 0 or 1, you can use it in mix function to provide colors, for example:
    gl_FragColor = mix(vec4(1.0, 1.0, 1.0, 1.0), vec4(0.0, 0.0, 0.0, 1.0) result);
    

提交回复
热议问题