Advertisement
mivebe

Ex: 3 - Rectangle

Nov 21st, 2023
1,464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 300 es
  2. #ifdef GL_ES
  3. precision mediump float;
  4. #endif
  5.  
  6. uniform vec2 u_resolution;
  7. out vec4 outColor;
  8.  
  9. float rectShape(vec2 position, vec2 scale) {
  10.   scale = vec2(0.5) - scale * 0.5;
  11.   vec2 shaper = vec2(step(scale.x, position.x), step(scale.y, position.y));
  12.   shaper *= vec2(step(scale.x, 1.0 - position.x), step(scale.y, 1.0 - position.y));
  13.  
  14.   return shaper.x * shaper.y;
  15. }
  16.  
  17. void main() {
  18.  
  19.   vec2 position = gl_FragCoord.xy / u_resolution.x;
  20.   vec3 color = vec3(0.0);
  21.   float rectangle = rectShape(position, vec2(0.3, 0.3));
  22.   color = vec3(rectangle);
  23.   outColor = vec4(color, 1.0);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement