Use kanzi's shader shader: finish digging a circle in the picture

Writing materials in kanzi is a way for us to achieve cool effects. Basically, most of the simple effects in opengl can be realized in kanzi. The following is a picture that only shows the effect of a part of the picture, which is quite Yu dug a hole in the picture

Vertex shader :

attribute vec3 kzPosition;
attribute vec2 kzTextureCoordinate0;
uniform highp mat4 kzProjectionCameraWorldMatrix;
varying mediump vec2 vTexCoord;
void main()
{
    
    
    precision mediump float;
    vTexCoord = kzTextureCoordinate0;
    gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);
}

 
 
  
  

    Fragment shader:

    uniform sampler2D Texture;
    varying mediump vec2 vTexCoord;
    uniform lowp float BlendIntensity;
    uniform lowp float Radius;
    uniform lowp float RadiusWidth;
    
    void main()
    {
        
        
        precision mediump float;
        vec4  color = vec4(0.0); 
        vec4  outcolor = vec4(0.0); 
        vec4  colorTT = texture2D(Texture, vTexCoord);
        
        vec2 pos = vTexCoord *2.0-1.0;  //圆心
        float dis = length(pos);  //半径
        if(dis < Radius)
        {
        
        
    //小于Radius-0.1返回0,大于Radiu返回1,Radius-0.1到Radius取平滑算法差值
            float offset  = smoothstep(Radius-0.1,Radius,dis);
    //offset=0取colorTT,offset=1取color
    //colorTT*(1-offset) + color*offset
            outcolor = mix(colorTT,color,offset);  
        }
        else
        {
        
        
            outcolor = vec4(0.0);   
        }       
        gl_FragColor.rgba = outcolor.rgba * BlendIntensity;
    }
    
     
     
      
      

      insert image description here

      Writing materials in kanzi is a way for us to achieve cool effects. Basically, most of the simple effects in opengl can be realized in kanzi. The following is a picture that only shows the effect of a part of the picture, which is quite Yu dug a hole in the picture

      Vertex shader :

      Guess you like

      Origin blog.csdn.net/moneyxjj/article/details/125301439