• 11 Votes - 4.64 Average
• 1
• 2
• 3
• 4
• 5
12-22-2015, 05:22 PM
Post: #232
 eddiefur Junior Member Posts: 14 Joined: Dec 2015 Reputation: 0
RE: GLSL Documentation / Tutorial - Cel Shading Wind Waker
I think I've got some great results so far... there is the code :

attribute vec4 a_position;
attribute vec2 a_texcoord0;

varying vec4 v_texcoord0;

void main()
{
gl_Position = a_position;
v_texcoord0=a_texcoord0.xyxy;
}

uniform sampler2D sampler0;

varying vec4 v_texcoord0;

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()
{
vec3 ct = texture2D(sampler0, v_texcoord0.zw).xyz;
vec3 hsv = rgb2hsv(ct);

if (hsv.z >= 0 && hsv.z < 0.05) hsv.z = 0.025;
else if (hsv.z >= 0.05 && hsv.z < 0.2) hsv.z = 0.125;
else if (hsv.z >= 0.2 && hsv.z < 0.25) hsv.z = 0.225;
else if (hsv.z >= 0.25 && hsv.z < 0.30) hsv.z = 0.275;
else if (hsv.z >= 0.30 && hsv.z < 0.45) hsv.z = 0.375;
else if (hsv.z >= 0.45 && hsv.z < 0.50) hsv.z = 0.475;
else if (hsv.z >= 0.5 && hsv.z < 0.55) hsv.z = 0.525;
else if (hsv.z >= 0.55 && hsv.z < 0.70) hsv.z = 0.625;
else if (hsv.z >= 0.70 && hsv.z < 0.75) hsv.z = 0.725;
else if (hsv.z >= 0.75 && hsv.z < 0.8) hsv.z = 0.775;
else if (hsv.z >= 0.8 && hsv.z < 0.95) hsv.z = 0.875;
else if (hsv.z >= 0.95 && hsv.z <= 1) hsv.z = 0.975;

ct = hsv2rgb(hsv);

gl_FragColor.xyz = ct;
gl_FragColor.a = 1.0;
}
 « Next Oldest | Next Newest »