2013年8月6日 星期二

[GLSL] 入門-1 矩陣圓球


[example 1] ↓

//沒有光暈的球
uniform vec2 resolution;
uniform float time;
vec2 uv;

vec2 circle(float i){ 
 return vec2(uv+vec2(fract(i/10.0)*2.0-0.9 ,
  fract(floor(i/10.0)/10.0)*2.0-0.9 ));
}


void main(void){
 uv = (gl_FragCoord.xy / resolution.xy)*2.0-1.0;
 float col;
 float k;

 for(float i=0.0;i<100 .0="" 1.0:0.0="" col="" gl_fragcolor="vec4(col,col,col,1.0);" i="" k="" pre="">

[example 2]

//有光暈的球
uniform vec2 resolution;
uniform float time;
vec2 uv;

vec2 circle(float i){ 
 return uv-vec2(fract(i/10.0)*2.0-0.9 ,fract(floor(i/10.0)/10.0)*2.0-0.9 );
}


void main(void){
 uv = (gl_FragCoord.xy / resolution.xy)*2.0-1.0;
 float col;
 float back=abs(time-0.5);

 for(float i=0.0;i<100 .0="" back="" circle="" col="" gl_fragcolor="vec4(col,col,col,1.0);" i="" length="" pow="" pre="">
example download