출처 : http://littlecheesecake.me/blog/13804700/opengles-shader
이미지 정보를 바탕으로 볼륨감을 주는 Emboss effect
해당 효과를 적용하기 위한 shader code 정리
Emboss vertex shader
precision highp float; attribute vec3 aVertex; attribute vec2 aTexCoord; varying vec2 vTexCoord; void main(void) { vTexCoord = vec2(aTexCoord); gl_Position = vec4(aVertex, 1); } |
Emboss fragment shader
uniform sampler2D uTexID0; varying vec2 vTexCoord; uniform vec2 uTexel; //texel size void main() { vec3 irgb = texture2D(uTexID0, vTexCoord).rgb; vec3 texrgb = texture2D(uTexID0, vTexCoord + uTexel).rgb;
vec3 diffs = irgb - texrgb; float max = diffs.r; if(abs(diffs.g)>abs(max)) max = diffs.g; if(abs(diffs.b)>abs(max)) max = diffs.b;
float grayDIFFS = clamp(max + .5, 0., 1.); vec3 color = vec3(grayDIFFS, grayDIFFS, grayDIFFS);
gl_FragColor = vec4(color.r-0.5+irgb.r, color.g-0.5+irgb.g, color.b-0.5+irgb.b, 1.); |
'Programmer의 텅빈 공간 > OpenGL/GLSL' 카테고리의 다른 글
LoG : Laplacian of Gaussian edge detection (0) | 2014.05.29 |
---|---|
unsharp mask 를 이용한 sharpen filter (0) | 2014.05.27 |
Mosaic Shader (0) | 2014.05.20 |
Hertzman Painterly Rendering (0) | 2014.05.16 |
embossing & sharpening (0) | 2014.05.12 |