shadertoy入门画点,线,面

刚学没多久,记录一下


float circle(vec2 p,float r)
{
         
   	float c=(length(p/r)-1.0)*500.0;    
	float d=1.0-smoothstep(0.0,1.0,c*0.04);    
	return d;
}
float line(vec2 pos,vec2 point1,vec2 point2)
{
        
 	float k = (point1.y - point2.y)/(point1.x - point2.x);    
 	float b = point1.y - k * point1.x;    
 	float d = abs(k * pos.x - pos.y + b) / sqrt(k * k + 1.0);    
 	float t = 1.0-smoothstep(0.005/2.0, 0.005/2.0 + 0.001, d);    			  		
 	return t;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
         //
 	vec2 uv = fragCoord.xy / iResolution.xy;   
 	vec2 p = (fragCoord.xy - 0.5*iResolution.xy)/iResolution.y;    
 	vec3 layer0 = vec3(0.2235, 0.7725, 0.0863);    
 	float r=0.1;//半径    
 //画园   
  	float a=circle(p,r);    
  	vec3 color=vec3(0.2353, 0.0824, 0.4314);     
  	color+=layer0*a;     
  	vec2 point1=vec2(0.2,0.4);     
  	vec2 point2=vec2(-0.2,0.3);     
  //两点   
   	float c1=circle(p-point1,0.005);   
    	float c2=circle(p-point2,0.005);    
    	color+=c1*layer0;    
    	color+=c2*layer0;    
    //直线    
    	float c3=line(p,point1,point2);    
    	color+=c3*vec3(0.8784, 0.0667, 0.0667);    	   		
    	fragColor=vec4(color,1.0)
}

效果:shadertoy入门画点,线,面_第1张图片

你可能感兴趣的:(shadertoy,shader)