WebGL 矩形

2022/6/22 23:21:32

本文主要是介绍WebGL 矩形,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

shadertoy

vec3 Rect(vec2 st, float left, float bottom, float right, float top, float blur ){
  vec3 col = vec3(0.);
  
  float l = smoothstep(left,left+blur,st.x);
  float b = smoothstep(bottom,bottom+blur,st.y);
  float t = smoothstep(top,top+blur,1.-st.y);
  float r = smoothstep(right,right+blur,1.-st.x);
  col = vec3(t*b*l*r);
  return col;
}

vec3 Rect2(vec2 st, float left, float bottom, float right, float top, float blur ){
  vec3 col = vec3(0.);
  // left-bottom
  vec2  lb = step(vec2(left,bottom), 1.-st);
  float pct = lb.x * lb.y;
    
  // top-right
  vec2 tr = step(vec2(right, top),st);
  pct *= tr.x * tr.y;
  col = vec3(pct);
  return col;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 st = fragCoord.xy/iResolution.xy;
    //st.x *= iResolution.x/iResolution.y;
    vec3 col = vec3(1.);
    
    
    col = Rect2(st, .1,.1,.1,.1,.01);
    // Output to screen
    fragColor = vec4(col,1.0);
}



这篇关于WebGL 矩形的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程