Advertisement
mivebe

Ex: 2 - Polygon

Nov 21st, 2023
913
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. const float PI = 3.1415926535;
  7. uniform vec2 u_resolution;
  8. out vec4 outColor;
  9.  
  10. float polyShape(vec2 position, float radius, float sides) {
  11.   position = position * 2.0 - 1.0;
  12.   float angle = atan(position.x, position.y);
  13.   float slice = PI * 2.0 / sides;
  14.  
  15.   return step(radius, cos(floor(0.5 + angle / slice) * slice - angle) * length(position));
  16. }
  17.  
  18. void main() {
  19.   vec2 position = gl_FragCoord.xy / u_resolution.x;
  20.  
  21.   float polygon = polyShape(position, 0.6, 6.0);
  22.  
  23.   vec3 color = vec3(polygon);
  24.  
  25.   outColor = vec4(color, 1.0);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement