some fine tune shaders

This commit is contained in:
langolierz
2019-12-03 20:42:03 +00:00
parent 2e133df8c3
commit 0d32e5aa1a
7 changed files with 201 additions and 49 deletions

View File

@@ -0,0 +1,59 @@
//1-input
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texcoord;
uniform sampler2D u_tex0;
uniform sampler2D u_tex1;
uniform vec2 u_resolution;
uniform float u_time;
uniform float u_x0;
uniform float u_x1;
uniform float u_x2;
uniform float u_x3;
vec3 rgb2grayscale(vec3 c)
{
return(vec3(dot(c, vec3(0.299, 0.587, 0.114))));
}
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main(){
vec2 pos = v_texcoord;
vec4 color = texture2D(u_tex0, pos);
vec3 hsv = rgb2hsv(color.rgb);
hsv.x += 0.1*u_x0 - 0.05;
hsv.y += 0.1*u_x1 - 0.05;
hsv.z += 0.1*u_x2 - 0.05;
//hsv.x += -0.2;
vec3 rgb = hsv2rgb(hsv.xyz);
gl_FragColor = vec4(rgb, color.a);
}

View File

@@ -0,0 +1,54 @@
//1-input
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texcoord;
uniform sampler2D u_tex0;
uniform sampler2D u_tex1;
uniform vec2 u_resolution;
uniform float u_time;
uniform float u_x0;
uniform float u_x1;
uniform float u_x2;
uniform float u_x3;
vec4 rotate(sampler2D tex, vec2 pos){
vec4 texColourRotate;
vec2 center;
//center = vec2(u_x3 / u_resolution.x, u_x4 / u_resolution.y);
center = vec2(0.45 + 0.1*u_x1,0.45 + 0.1*u_x2);
pos.x = (pos.x - center.x)*(0.5 / (0.45 + 0.1*u_x3)) + center.x;
pos.y = (pos.y - center.y)*(0.5 / (0.45 + 0.1*u_x3)) + center.y;
float r = distance(center, pos);
float a = atan(pos.x - center.x, pos.y - center.y);
pos.x = r * cos(a + 2.0 * 3.141592 * (0.2 + 0.1*u_x0)) + 0.5;
pos.y = r * sin(a + 2.0 * 3.141592 * (0.2 + 0.1*u_x0)) + 0.5;
pos.x = 1.0 - pos.x;
if((pos.x < 0.0)||(pos.y < 0.0)||(pos.x > 1.0)||(pos.y > 1.0)){
texColourRotate = vec4(0.0);
}
else{
texColourRotate = texture2D(tex, pos);
}
return texColourRotate;
}
void main(){
vec2 pos = v_texcoord;
vec4 texColour0;
texColour0 = rotate(u_tex0, v_texcoord);
gl_FragColor = texColour0;
}