antoinefortin
1/6/2020 - 5:56 AM

For Shadertoy

For Shadertoy


float plane(vec3 pos)
{
	return pos.y;
}


float sphere(vec3  pos, float radius)
{
	return length(pos) - radius;
}

float map(vec3 pos)
{
	return min(plane(pos), sphere(pos, 2.0));
    
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = (fragCoord -.5 * iResolution.xy) / iResolution.y;
	
    // Camera position
    vec3 pos = vec3(0.0, 5.0, -15.0);
    
    // Rayon que l'on envoie dans l'espace pour chacuns des pixels
    vec3 dir = normalize(vec3(uv.x, uv.y, 1));    
    vec3 col = vec3(0.);
    
    for(int i = 0; i < 64; i++)
    {
       	float d/*istance*/ = map(pos); 
       	//  Point is near enough
        if(d < 0.01)
        {	
            col = fract(pos * 0.5);
        	break;
        }
        pos += d * dir;
        

    }
    
    
    // Output to screen
    fragColor = vec4(col, 1.0);
}