출처 : http://gmc.yoyogames.com/index.php?showtopic=608626
Mosaic Shader Vertex
precision highp float; attribute vec3 aVertex; attribute vec2 aTexCoord; varying vec2 vTexCoord; void main(void) { vTexCoord = vec2(aTexCoord); gl_Position = vec4(aVertex, 1); } |
보시는 것 처럼 vertex 부분은 손댈 곳이 없습니다.
그냥 shader에 들어온 vertex와 texCoord를 그대로 사용해서 넘겨주시면 됩니다.
Mosaic Shader Frag
uniform sampler2D uTexID0; varying vec2 vTexCoord; uniform vec2 uTexel; //texel size uniform float uScale; //tile size void main() { float dx = uScale*uTexel.x; float dy = uScale*uTexel.y; vec2 coord = vec2(floor(vTexCoord.x/dx)*dx+(dx/2.0), floor(vTexCoord.y/dy)*dy+(dy/2.0)); gl_FragColor = texture2D(uTexID0, coord); } |
frag Shader에 경우 Scale값과 Texel 값으로 모자이크의 범위를 정하고
해당 좌표의 모자이크 범위를 구해 범위의 중점 색상으로 타일 전체를 칠해줍니다.
'Programmer의 텅빈 공간 > OpenGL/GLSL' 카테고리의 다른 글
unsharp mask 를 이용한 sharpen filter (0) | 2014.05.27 |
---|---|
Emboss shader (0) | 2014.05.21 |
Hertzman Painterly Rendering (0) | 2014.05.16 |
embossing & sharpening (0) | 2014.05.12 |
Gaussian Filter (0) | 2014.05.09 |