본문 바로가기

Shader/TheBookofShaders12

Pattern Pattern #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; void main(){ vec2 coord = gl_FragCoord.xy/u_resolution; coord.x *= u_resolution.x/u_resolution.y; coord *= 3.; coord = fract(coord); vec3 col = vec3(step(.3, distance(coord, vec2(.5)))); // vec3 col = vec3(coord, vec2(1.)); gl_FragColor = vec4(col, 1.); } #ifdef GL_ES preci.. 2021. 8. 19.
rotate & scale rotate & scale Dot = 내적연산 Cross = 외적연산 실제로 사용하고 있음므로 crucis = cross의 라틴어로 대체 #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; float rect(vec2 loc, vec2 size, vec2 coord){ vec2 sw = loc - size/2.; vec2 ne = loc + size/2.; float pad = 0.01; vec2 rect = smoothstep(sw-pad, sw, coord); rect -= smoothstep(ne, ne+pad, coord); return(rec.. 2021. 8. 19.
Matrix Matrix https://thndl.com/square-shaped-shaders.html 도형의 위치를 바꾸는 방법 #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 sw = loc - size/2.; vec2 ne = loc + size/2.; vec2 rect = step(sw, coord) - step(ne, coord); return rect.x*rect.y; } float cross(vec2 loc, vec2 size, vec2 coord){ floa.. 2021. 8. 19.
Circle Circle distance는 input 변수가 2개 length는 input 변수가 1개라서 length가 더 빠르고 알려졌기때문에 length를 쓰는것이 좋다. 단 distance는 두개의 좌표의 거리를 구하지만 length는 하나의 값과 원점과의 거리를 나타내기때문에 구별해서는 써야 한다. step smoothstep //화면 비율에 구애 받지 않고 유지 시켜주는 코드 st.x *= u_resolution.x/u_resolution.y; d의 값이 최대 0.1이기 때문에 어둡게 나옴 #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; void m.. 2021. 8. 19.