ShaderToy SDF Beginner Template



float circle(vec2 uv,float radius){
    return length(uv)-radius;
}
float sdBox( in vec2 p, in vec2 b )
{
    vec2 d = abs(p)-b;
    return length(max(d,0.0)) + min(max(d.x,d.y),0.0);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord.xy / iResolution.xy; //convert pixels from screen resolution[1920x1080] to 0-1 space
    uv -= 0.5;  //center
    uv.x *= iResolution.x / iResolution.y; // make a proper square instead of a rectangle    
    float d = sdBox( uv,vec2(0.3) ); //set square side
    //float d= circle(uv,0.3);//set circle radius
    vec4 color = vec4(0.0); //set background-color
    if(d<0.0)   color = vec4(1.0);//set inside color    
    fragColor = vec4(color);//color the canvas
}


Comments

Popular posts from this blog

How to get started with Vue in under a minute?

aigiri nandini - Brodha V you rock