init
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
shader_type canvas_item;
|
||||
uniform int radius = 5;
|
||||
uniform vec3 offset=vec3(0.0);
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture;
|
||||
|
||||
void fragment()
|
||||
{
|
||||
vec2 src_size = vec2 ( SCREEN_PIXEL_SIZE.x, SCREEN_PIXEL_SIZE.y);
|
||||
vec2 uv = SCREEN_UV.xy;
|
||||
float n = float((radius + 1) * (radius + 1));
|
||||
vec3 m0 = offset; vec3 m1 = offset; vec3 m2 = offset; vec3 m3 = offset;
|
||||
vec3 s0 = offset; vec3 s1 = offset; vec3 s2 = offset; vec3 s3 = offset;
|
||||
vec3 c;
|
||||
|
||||
for (int j = -radius; j <= 0; ++j) {
|
||||
for (int i = -radius; i <= 0; ++i) {
|
||||
c = texture(SCREEN_TEXTURE, uv + vec2(float(i),float(j)) * src_size).rgb;
|
||||
m0 += c;
|
||||
s0 += c * c;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = -radius; j <= 0; ++j) {
|
||||
for (int i = 0; i <= radius; ++i) {
|
||||
c = texture(SCREEN_TEXTURE, uv + vec2(float(i),float(j)) * src_size).rgb;
|
||||
m1 += c;
|
||||
s1 += c * c;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j <= radius; ++j) {
|
||||
for (int i = 0; i <= radius; ++i) {
|
||||
c = texture(SCREEN_TEXTURE, uv + vec2(float(i),float(j)) * src_size).rgb;
|
||||
m2 += c;
|
||||
s2 += c * c;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j <= radius; ++j) {
|
||||
for (int i = -radius; i <= 0; ++i) {
|
||||
c = texture(SCREEN_TEXTURE, uv + vec2(float(i),float(j)) * src_size).rgb;
|
||||
m3 += c;
|
||||
s3 += c * c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float min_sigma2 = 1e+2;
|
||||
m0 /= n;
|
||||
s0 = abs(s0 / n - m0 * m0);
|
||||
|
||||
float sigma2 = s0.r + s0.g + s0.b;
|
||||
if (sigma2 < min_sigma2) {
|
||||
min_sigma2 = sigma2;
|
||||
COLOR = vec4(m0, 1.0);
|
||||
}
|
||||
|
||||
m1 /= n;
|
||||
s1 = abs(s1 / n - m1 * m1);
|
||||
|
||||
sigma2 = s1.r + s1.g + s1.b;
|
||||
if (sigma2 < min_sigma2) {
|
||||
min_sigma2 = sigma2;
|
||||
COLOR = vec4(m1, 1.0);
|
||||
}
|
||||
|
||||
m2 /= n;
|
||||
s2 = abs(s2 / n - m2 * m2);
|
||||
|
||||
sigma2 = s2.r + s2.g + s2.b;
|
||||
if (sigma2 < min_sigma2) {
|
||||
min_sigma2 = sigma2;
|
||||
COLOR = vec4(m2, 1.0);
|
||||
}
|
||||
|
||||
m3 /= n;
|
||||
s3 = abs(s3 / n - m3 * m3);
|
||||
|
||||
sigma2 = s3.r + s3.g + s3.b;
|
||||
if (sigma2 < min_sigma2) {
|
||||
min_sigma2 = sigma2;
|
||||
COLOR = vec4(m3, 1.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://drolsk0gyboao
|
||||
@@ -0,0 +1,72 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
// Récupère l'image rendue par la caméra 3D (Godot 4)
|
||||
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
|
||||
|
||||
// Taille du "pinceau" (plus c'est grand, plus l'effet peinture est fort)
|
||||
uniform int radius : hint_range(1, 10) = 4;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv = SCREEN_UV;
|
||||
vec2 tex_size = vec2(textureSize(screen_texture, 0));
|
||||
vec2 texel = 1.0 / tex_size;
|
||||
|
||||
// Nombre de pixels analysés par quadrant
|
||||
float n = float((radius + 1) * (radius + 1));
|
||||
|
||||
// Moyennes (m) et Variances (s) pour les 4 quadrants
|
||||
vec3 m0 = vec3(0.0), m1 = vec3(0.0), m2 = vec3(0.0), m3 = vec3(0.0);
|
||||
vec3 s0 = vec3(0.0), s1 = vec3(0.0), s2 = vec3(0.0), s3 = vec3(0.0);
|
||||
vec3 c;
|
||||
|
||||
// Quadrant 0 (Haut Gauche)
|
||||
for (int j = -radius; j <= 0; ++j) {
|
||||
for (int i = -radius; i <= 0; ++i) {
|
||||
c = texture(screen_texture, uv + vec2(float(i), float(j)) * texel).rgb;
|
||||
m0 += c; s0 += c * c;
|
||||
}
|
||||
}
|
||||
// Quadrant 1 (Haut Droite)
|
||||
for (int j = -radius; j <= 0; ++j) {
|
||||
for (int i = 0; i <= radius; ++i) {
|
||||
c = texture(screen_texture, uv + vec2(float(i), float(j)) * texel).rgb;
|
||||
m1 += c; s1 += c * c;
|
||||
}
|
||||
}
|
||||
// Quadrant 2 (Bas Droite)
|
||||
for (int j = 0; j <= radius; ++j) {
|
||||
for (int i = 0; i <= radius; ++i) {
|
||||
c = texture(screen_texture, uv + vec2(float(i), float(j)) * texel).rgb;
|
||||
m2 += c; s2 += c * c;
|
||||
}
|
||||
}
|
||||
// Quadrant 3 (Bas Gauche)
|
||||
for (int j = 0; j <= radius; ++j) {
|
||||
for (int i = -radius; i <= 0; ++i) {
|
||||
c = texture(screen_texture, uv + vec2(float(i), float(j)) * texel).rgb;
|
||||
m3 += c; s3 += c * c;
|
||||
}
|
||||
}
|
||||
|
||||
float min_var = 1e+6; // Valeur de base très haute
|
||||
vec3 final_color = vec3(0.0);
|
||||
float var;
|
||||
|
||||
// Calcul pour le Q0
|
||||
m0 /= n; s0 = abs(s0 / n - m0 * m0); var = s0.r + s0.g + s0.b;
|
||||
if (var < min_var) { min_var = var; final_color = m0; }
|
||||
|
||||
// Calcul pour le Q1
|
||||
m1 /= n; s1 = abs(s1 / n - m1 * m1); var = s1.r + s1.g + s1.b;
|
||||
if (var < min_var) { min_var = var; final_color = m1; }
|
||||
|
||||
// Calcul pour le Q2
|
||||
m2 /= n; s2 = abs(s2 / n - m2 * m2); var = s2.r + s2.g + s2.b;
|
||||
if (var < min_var) { min_var = var; final_color = m2; }
|
||||
|
||||
// Calcul pour le Q3
|
||||
m3 /= n; s3 = abs(s3 / n - m3 * m3); var = s3.r + s3.g + s3.b;
|
||||
if (var < min_var) { min_var = var; final_color = m3; }
|
||||
|
||||
COLOR = vec4(final_color, 1.0);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b1y2oarbiem6l
|
||||
@@ -0,0 +1,103 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap, repeat_disable;
|
||||
|
||||
// --- Kuwahara (painterly smoothing) ---
|
||||
uniform int kuwahara_radius : hint_range(1, 10) = 4;
|
||||
|
||||
// --- Edge / line art ---
|
||||
uniform float edge_strength : hint_range(0.0, 4.0) = 1.2;
|
||||
uniform float edge_threshold : hint_range(0.0, 1.0) = 0.12;
|
||||
uniform vec3 edge_color : source_color = vec3(0.05, 0.04, 0.03);
|
||||
|
||||
// --- Brush / canvas texture overlay ---
|
||||
uniform sampler2D brush_tex : filter_linear_mipmap, repeat_enable;
|
||||
uniform vec2 brush_scale = vec2(18.0, 18.0);
|
||||
uniform float brush_strength : hint_range(0.0, 1.0) = 0.35;
|
||||
|
||||
// --- Final color tweaks ---
|
||||
uniform float saturation : hint_range(0.0, 2.0) = 1.1;
|
||||
|
||||
float luminance(vec3 c) {
|
||||
return dot(c, vec3(0.299, 0.587, 0.114));
|
||||
}
|
||||
|
||||
// Classic 4-quadrant Kuwahara filter
|
||||
vec3 kuwahara(sampler2D tex, vec2 uv, vec2 px, int r) {
|
||||
vec3 mean[4];
|
||||
float variance[4];
|
||||
|
||||
vec2 signs[4];
|
||||
signs[0] = vec2(-1.0, -1.0);
|
||||
signs[1] = vec2(1.0, -1.0);
|
||||
signs[2] = vec2(-1.0, 1.0);
|
||||
signs[3] = vec2(1.0, 1.0);
|
||||
|
||||
for (int q = 0; q < 4; q++) {
|
||||
vec3 sum = vec3(0.0);
|
||||
vec3 sum_sq = vec3(0.0);
|
||||
float count = 0.0;
|
||||
for (int j = 0; j <= r; j++) {
|
||||
for (int i = 0; i <= r; i++) {
|
||||
vec2 offset = vec2(float(i), float(j)) * signs[q] * px;
|
||||
vec3 c = texture(tex, uv + offset).rgb;
|
||||
sum += c;
|
||||
sum_sq += c * c;
|
||||
count += 1.0;
|
||||
}
|
||||
}
|
||||
vec3 m = sum / count;
|
||||
vec3 v = sum_sq / count - m * m;
|
||||
mean[q] = m;
|
||||
variance[q] = v.r + v.g + v.b;
|
||||
}
|
||||
|
||||
float min_var = variance[0];
|
||||
vec3 result = mean[0];
|
||||
for (int q = 1; q < 4; q++) {
|
||||
if (variance[q] < min_var) {
|
||||
min_var = variance[q];
|
||||
result = mean[q];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Sobel edge detection on luminance
|
||||
float sobel_edge(sampler2D tex, vec2 uv, vec2 px) {
|
||||
float tl = luminance(texture(tex, uv + vec2(-px.x, -px.y)).rgb);
|
||||
float t = luminance(texture(tex, uv + vec2(0.0, -px.y)).rgb);
|
||||
float tr = luminance(texture(tex, uv + vec2(px.x, -px.y)).rgb);
|
||||
float l = luminance(texture(tex, uv + vec2(-px.x, 0.0)).rgb);
|
||||
float r = luminance(texture(tex, uv + vec2(px.x, 0.0)).rgb);
|
||||
float bl = luminance(texture(tex, uv + vec2(-px.x, px.y)).rgb);
|
||||
float b = luminance(texture(tex, uv + vec2(0.0, px.y)).rgb);
|
||||
float br = luminance(texture(tex, uv + vec2(px.x, px.y)).rgb);
|
||||
|
||||
float gx = -tl - 2.0 * l - bl + tr + 2.0 * r + br;
|
||||
float gy = -tl - 2.0 * t - tr + bl + 2.0 * b + br;
|
||||
return sqrt(gx * gx + gy * gy);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 uv = SCREEN_UV;
|
||||
vec2 px = SCREEN_PIXEL_SIZE;
|
||||
|
||||
// STEP 1: painterly color smoothing
|
||||
vec3 painted = kuwahara(SCREEN_TEXTURE, uv, px, kuwahara_radius);
|
||||
|
||||
// STEP 2: line art from the smoothed image (cleaner lines than raw noise)
|
||||
float edge = sobel_edge(SCREEN_TEXTURE, uv, px);
|
||||
edge = smoothstep(edge_threshold, edge_threshold + 0.3, edge) * edge_strength;
|
||||
vec3 with_edges = mix(painted, edge_color, clamp(edge, 0.0, 1.0));
|
||||
|
||||
// STEP 3: brush / canvas texture overlay (fake stroke + paper grain)
|
||||
vec3 brush = texture(brush_tex, uv * brush_scale).rgb;
|
||||
vec3 with_brush = with_edges * mix(vec3(1.0), brush, brush_strength);
|
||||
|
||||
// STEP 4: slight saturation boost, like paint pigment richness
|
||||
float l = luminance(with_brush);
|
||||
vec3 final_color = mix(vec3(l), with_brush, saturation);
|
||||
|
||||
COLOR = vec4(final_color, 1.0);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cy200il0ufw86
|
||||
@@ -0,0 +1,9 @@
|
||||
shader_type canvas_item;
|
||||
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear_mipmap;
|
||||
|
||||
uniform float lod: hint_range(0.0, 5) = 0.0;
|
||||
|
||||
void fragment(){
|
||||
vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV, lod);
|
||||
COLOR = color;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://1we0jycvvn8u
|
||||
@@ -0,0 +1,28 @@
|
||||
shader_type spatial;
|
||||
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
|
||||
|
||||
uniform sampler2D main_texture : source_color;
|
||||
// On passe en vec2 pour ajuster X et Y indépendamment
|
||||
uniform vec2 main_uv_scale = vec2(1.0, 1.0);
|
||||
|
||||
uniform sampler2D secondary_texture : source_color;
|
||||
uniform vec2 secondary_uv_scale = vec2(1.0, 1.0);
|
||||
|
||||
uniform sampler2D blend_noise : source_color;
|
||||
|
||||
void fragment() {
|
||||
// Multiplie l'UV par le vector 2D (ex: scale.x sur UV.x, scale.y sur UV.y)
|
||||
vec2 main_uv = UV * main_uv_scale;
|
||||
vec4 main_albedo = texture(main_texture, main_uv);
|
||||
|
||||
vec2 secondary_uv = UV * secondary_uv_scale;
|
||||
vec4 secondary_albedo = texture(secondary_texture, secondary_uv);
|
||||
|
||||
vec4 blend_noise_texture = texture(blend_noise, UV);
|
||||
|
||||
vec3 final_albedo = mix(main_albedo.rgb, secondary_albedo.rgb, blend_noise_texture.rgb);
|
||||
|
||||
// Note : Votre conversion RGB -> HSV -> RGB était neutre (faisait un aller-retour sans modificateur).
|
||||
// On peut assigner directement pour simplifier et optimiser les performances :
|
||||
ALBEDO = final_albedo;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cfu7cwiw7vrgq
|
||||
Reference in New Issue
Block a user