본문 바로가기
College Study/GLSL

[GLSL] Translate

by 2den 2022. 1. 6.
728x90

 


 
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

float bar (vec2 loc, vec2 size, vec2 coord){
    vec2 lb = loc - size/2.;
    vec2 rt = loc + size/2.;
    
    vec2 st = step(lb, coord) - step(rt, coord);
    
    return st.x * st.y;
}
float cross(vec2 loc, vec2 size, vec2 coord){
    float b1 = bar(loc, size, coord);
    float b2 = bar(loc, vec2(size.y, size.x), coord);
    
    return max(b1, b2);
}
void main(){
	vec2 coord = gl_FragCoord.xy/u_resolution;
    coord.x *= u_resolution.x/u_resolution.y;
    coord = coord * 2. - 1.;

    vec2 loc = vec2(0.) + vec2(sin(u_time), cos(u_time))*.5;
    vec2 size = vec2(0.750,0.250);
    
    vec3 col = vec3(cross(loc, size, coord));
    
	gl_FragColor = vec4(col, 1.0);
}

 

728x90

'College Study > GLSL' 카테고리의 다른 글

[GLSL] Patterns  (0) 2022.01.06
[GLSL] Rotate and Scale  (0) 2022.01.06
[GLSL] Polar Shapes  (0) 2022.01.06
[GLSL] Circle Shapes  (0) 2022.01.06
[GLSL] Circle  (0) 2022.01.06

댓글