This is the human shader from https://humanshader.com/ implemented in GLSL using Kivy.
Last active
July 21, 2023 20:48
-
-
Save Cheaterman/7feca3ffa55d182a7d67cde9d12207cb to your computer and use it in GitHub Desktop.
Human shader in GLSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.config import Config | |
from kivy.uix.effectwidget import EffectBase, EffectWidget | |
Config.set('graphics', 'width', 845) | |
Config.set('graphics', 'height', 475) | |
class Shader(EffectBase): | |
glsl = ''' | |
int remove_digits(int number, int digits) { | |
return int(float(number) / pow(10., float(digits)) + .5); | |
} | |
vec4 effect(vec4 color, sampler2D texture, vec2 tex_coords, vec2 coords) { | |
// Inputs | |
int x = int(coords.x / resolution.x * 70.); | |
int y = int((1. - coords.y / resolution.y) * 40.); | |
// Outputs | |
int R = 0; | |
int G = 0; | |
int B = 0; | |
// A2 | |
int u = x - 36; | |
// A3 | |
int v = 18 - y; | |
// A4 | |
int h = int(pow(float(u), 2.) + pow(float(v), 2.)); | |
// A5 | |
if(h < 200) { | |
// Section B | |
// B1 | |
R = 420; | |
// B2 | |
B = 520; | |
// B3 | |
int t = 5000 + 8 * h; | |
// B4 | |
int p = remove_digits(t * u, 2); | |
// B5 | |
int q = remove_digits(t * v, 2); | |
// B6 | |
int s = 2 * q; | |
// B7 | |
int w = remove_digits(1000 + p - s, 2) + 8; | |
// B8 | |
if(w > 0) { | |
R += int(pow(float(w), 2.)); | |
} | |
// B9 | |
int o = s + 2200; | |
// B10 | |
R = remove_digits(R * o, 4); | |
// B11 | |
B = remove_digits(B * o, 4); | |
// B12 | |
if(p > -q) { | |
// B13 | |
w = remove_digits(p + q, 1); | |
// B14 | |
R += w; | |
// B15 | |
B += w; | |
// B16 | |
} | |
} | |
else if(v < 0) { | |
// Section C | |
// C1 | |
R = 150 + 2 * v; | |
// C2 | |
B = 50; | |
// C3 | |
int p = h + 8 * int(pow(float(v), 2.)); | |
// C4 | |
int c = 240 * -v - p; | |
// C5 | |
if(c > 1200) { | |
// C6 | |
int o = remove_digits(6 * c, 1); | |
// C7 | |
o = c * (1500 - o); | |
// C8 | |
o = remove_digits(o, 2) - 8360; | |
// C9 | |
R = remove_digits(R * o, 3); | |
// C10 | |
B = remove_digits(B * o, 3); | |
} | |
// C11 | |
int r = c + u * v; | |
// C12 | |
int d = 3200 - h - 2 * r; | |
// C13 | |
if(d > 0) { | |
R += d; | |
} | |
// C14 | |
} | |
else { | |
// Section D | |
// D1 | |
int c = x + 4 * y; | |
// D2 | |
R = 132 + c; | |
// D3 | |
B = 192 + c; | |
// D4 | |
} | |
// Section E | |
// E1 | |
if(R > 255) { | |
R = 255; | |
} | |
// E2 | |
if(B > 255) { | |
B = 255; | |
} | |
// E3 | |
G = remove_digits(7 * R + 3 * B, 1); | |
// E4 | |
return vec4(float(R) / 255., float(G) / 255., float(B) / 255., 1.0); | |
} | |
''' | |
class ShaderApp(App): | |
def build(self): | |
return EffectWidget(effects=[Shader()]) | |
ShaderApp().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.animation import Animation | |
from kivy.app import App | |
from kivy.config import Config | |
from kivy.properties import DictProperty, NumericProperty | |
from kivy.uix.effectwidget import AdvancedEffectBase, EffectWidget | |
Config.set('graphics', 'width', 845) | |
Config.set('graphics', 'height', 475) | |
class Shader(AdvancedEffectBase): | |
uniforms = DictProperty({'density': 1.0}) | |
density = NumericProperty(1.0) | |
def on_density(self, _, density): | |
self.uniforms['density'] = density | |
glsl = ''' | |
uniform float density; | |
float remove_digits(float number, int digits) { | |
return number / pow(10., float(digits)); | |
} | |
vec4 effect(vec4 color, sampler2D texture, vec2 tex_coords, vec2 coords) { | |
// Inputs | |
float x = float(int(coords.x / resolution.x * 70. * density)) / density; | |
float y = float(int((1. - coords.y / resolution.y) * 40. * density)) / density; | |
// Outputs | |
float R = 0.; | |
float G = 0.; | |
float B = 0.; | |
// A2 | |
float u = x - 36.; | |
// A3 | |
float v = 18. - y; | |
// A4 | |
float h = pow(float(u), 2.) + pow(float(v), 2.); | |
// A5 | |
if(h < 200.) { | |
// Section B | |
// B1 | |
R = 420.; | |
// B2 | |
B = 520.; | |
// B3 | |
float t = 5000. + 8. * h; | |
// B4 | |
float p = remove_digits(t * u, 2); | |
// B5 | |
float q = remove_digits(t * v, 2); | |
// B6 | |
float s = 2. * q; | |
// B7 | |
float w = remove_digits(1000. + p - s, 2) + 8.; | |
// B8 | |
if(w > 0.) { | |
R += pow(float(w), 2.); | |
} | |
// B9 | |
float o = s + 2200.; | |
// B10 | |
R = remove_digits(R * o, 4); | |
// B11 | |
B = remove_digits(B * o, 4); | |
// B12 | |
if(p > -q) { | |
// B13 | |
w = remove_digits(p + q, 1); | |
// B14 | |
R += w; | |
// B15 | |
B += w; | |
// B16 | |
} | |
} | |
else if(v < 0.) { | |
// Section C | |
// C1 | |
R = 150. + 2. * v; | |
// C2 | |
B = 50.; | |
// C3 | |
float p = h + 8. * pow(float(v), 2.); | |
// C4 | |
float c = 240. * -v - p; | |
// C5 | |
if(c > 1200.) { | |
// C6 | |
float o = remove_digits(6. * c, 1); | |
// C7 | |
o = c * (1500. - o); | |
// C8 | |
o = remove_digits(o, 2) - 8360.; | |
// C9 | |
R = remove_digits(R * o, 3); | |
// C10 | |
B = remove_digits(B * o, 3); | |
} | |
// C11 | |
float r = c + u * v; | |
// C12 | |
float d = 3200. - h - 2. * r; | |
// C13 | |
if(d > 0.) { | |
R += d; | |
} | |
// C14 | |
} | |
else { | |
// Section D | |
// D1 | |
float c = x + 4. * y; | |
// D2 | |
R = 132. + c; | |
// D3 | |
B = 192. + c; | |
// D4 | |
} | |
// Section E | |
// E1 | |
if(R > 255.) { | |
R = 255.; | |
} | |
// E2 | |
if(B > 255.) { | |
B = 255.; | |
} | |
// E3 | |
G = remove_digits(7. * R + 3. * B, 1); | |
// E4 | |
return vec4(R / 255., G / 255., B / 255., 1.0); | |
} | |
''' | |
class ShaderApp(App): | |
def build(self): | |
shader = Shader() | |
shader.density = .1 | |
animation = ( | |
Animation(density=10, d=5, t='in_expo') | |
+ Animation(density=.1, d=5, t='out_expo') | |
) | |
animation.repeat = True | |
animation.start(shader) | |
return EffectWidget(effects=[shader]) | |
ShaderApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment