출처 : http://wannemag.blogspot.kr/2014/03/glsl-function-mix.html

 

 

mix 에 대한 간단한 기능 구현

 

vec4 my_mix(vec4 x, vec4 y, float a) {
vec4 x_contribution = x * (1.0 - a);
vec4 y_contribution = y * a;

return x_contribution + y_contribution;
}

void main(void) {

vec4 white_layer = vec4(1.0, 1.0, 1.0, 1.0);
vec4 black_layer = vec4(0.0, 0.0, 0.0, 1.0);

float amount_of_second_layer = 0.5;

//gl_FragColor = mix(white_layer, black_layer, amount_of_second_layer);
gl_FragColor = my_mix(white_layer, black_layer, amount_of_second_layer);

}

 

clamp 에 대한 간단한 기능 구현

 

 

vec4 my_clamp(vec4 x, vec4 minVal, vec4 maxVal) {
float x_comp = x.x < minVal.x ? minVal.x : x.x > maxVal.x ? maxVal.x : x.x;
float y_comp = x.y < minVal.y ? minVal.y : x.y > maxVal.y ? maxVal.y : x.y;
float z_comp = x.z < minVal.z ? minVal.z : x.z > maxVal.z ? maxVal.z : x.z;
float w_comp = x.w < minVal.w ? minVal.w : x.w > maxVal.w ? maxVal.w : x.w;

return vec4(x_comp, y_comp, z_comp, w_comp);
}

'Programmer의 텅빈 공간 > OpenGL/GLSL' 카테고리의 다른 글

Emboss shader  (0) 2014.05.21
Mosaic Shader  (0) 2014.05.20
Hertzman Painterly Rendering  (0) 2014.05.16
embossing & sharpening  (0) 2014.05.12
Gaussian Filter  (0) 2014.05.09

+ Recent posts