WebGL glsl gl_FragCoord与UV

336 阅读1分钟
precision mediump float ;
  
uniform vec2 screenSize;  // step  1

void main()
{
     vec2 uv = vec2(gl_FragCoord.xy/screenSize.xy);  // step 2

    //Calculate polar coordinates
     float r = length(uv);
     float c = 0.0;

    if(uv.x>0.98 &&uv.x<1.0 )                       // step 3
    {
       c = 1.0;
    }

     if(uv.y>0.98 &&uv.y<1.0 )                     // step 4
     {
       c = 1.0;
     }

     //Calculate the final color mixing lines and backgrounds.
     vec3 bg = mix(vec3(0.93 , 0.71 ,  0.62 ),  vec3(0.9 , 0.44 , 0.44),   r);  // step 5
     bg = mix(bg, vec3 (0.9 , 0.91 , 0.62 ), c);                                //  step 6

     gl_FragColor = vec4(bg, 1.0);
}

image.png