Last active
August 4, 2026 08:42
-
-
Save HungryProton/2a53aea50893bc14840bdeb45444e6c0 to your computer and use it in GitHub Desktop.
half_tone_shader
This file contains hidden or 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
| shader_type spatial; | |
| uniform float pattern_scale = 20; | |
| uniform sampler2D pattern_texture : source_color; | |
| uniform float cutoff: hint_range(0.0, 1.0) = 0.5; | |
| uniform float band_width: hint_range(0.0, 2.0) = 1.0; | |
| // Optionel, pour le screen_uv local | |
| varying flat vec4 NODE_POSITION_CLIP; | |
| void vertex() { | |
| NODE_POSITION_CLIP = (PROJECTION_MATRIX * vec4(NODE_POSITION_VIEW, 1.0)); | |
| } | |
| void fragment() { | |
| ALBEDO = vec3(0.9); | |
| } | |
| void light() { | |
| // Optionel: Permet d'ancrer le pattern sur l'objet en fonction de sa position à l'écran. | |
| // Donne l'impression que les points bougent avec l'objet | |
| // | |
| // Alternative: utiliser `SCREEN_UV * pattern_scale` pour ancrer l'effet sur l'écran | |
| vec2 local_screen_uv = (SCREEN_UV * 2.0 - 1.0) - (NODE_POSITION_CLIP.xy / NODE_POSITION_CLIP.w); | |
| local_screen_uv.x *= VIEWPORT_SIZE.x / VIEWPORT_SIZE.y; | |
| local_screen_uv *= -1.0 / PROJECTION_MATRIX[1][1]; | |
| local_screen_uv *= pattern_scale; | |
| // Définit la zone dans l'ombre | |
| float shadow = dot(NORMAL, LIGHT) * 0.5 + 0.5; // [0, 1] range | |
| // Optionel: | |
| shadow = pow(shadow, 2.0); // Make it softer | |
| shadow += (cutoff * 2.0 - 1.0) * 0.5; // Controle la taille de la zone couverte par l'ombre | |
| // Ajoute les ombres projetées | |
| shadow = clamp(shadow, 0.0, 1.0) * ATTENUATION; | |
| // ------ HALF TONE EFFECT ------- | |
| float pattern = 1.0 - texture(pattern_texture, local_screen_uv).r; | |
| pattern = mix(0.5, pattern, band_width); // Optionel: largeur de la transition | |
| // Make the hard edges + antialiasing | |
| float epsilon = fwidth(pattern); | |
| float shadow_final = smoothstep(pattern - epsilon, pattern + epsilon, shadow); | |
| DIFFUSE_LIGHT += shadow_final * LIGHT_COLOR / PI ; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment