t3du - Add Brick Texture

This commit is contained in:
Onek8 2025-05-28 21:25:25 +00:00
parent 32ff286691
commit f379685fdd

View File

@ -298,6 +298,125 @@ float tex_brick_f(vec3 p) {
}
"""
#https://github.com/blender/blender/blob/main/source/blender/gpu/shaders/material/gpu_shader_material_tex_brick.glsl
str_tex_brick_blender = """
float integer_noise(int n)
{
/* Integer bit-shifts for these calculations can cause precision problems on macOS.
* Using uint resolves these issues. */
uint nn;
nn = (uint(n) + 1013u) & 0x7fffffffu;
nn = (nn >> 13u) ^ nn;
nn = (uint(nn * (nn * nn * 60493u + 19990303u)) + 1376312589u) & 0x7fffffffu;
return 0.5f * (float(nn) / 1073741824.0f);
}
vec2 calc_brick_texture(vec3 p,
float mortar_size,
float mortar_smooth,
float bias,
float brick_width,
float row_height,
float offset_amount,
int offset_frequency,
float squash_amount,
int squash_frequency)
{
int bricknum, rownum;
float offset = 0.0f;
float x, y;
rownum = int(floor(p.y / row_height));
if (offset_frequency != 0 && squash_frequency != 0) {
brick_width *= (rownum % squash_frequency != 0) ? 1.0f : squash_amount; /* squash */
offset = (rownum % offset_frequency != 0) ? 0.0f : (brick_width * offset_amount); /* offset */
}
bricknum = int(floor((p.x + offset) / brick_width));
x = (p.x + offset) - brick_width * bricknum;
y = p.y - row_height * rownum;
float tint = clamp((integer_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0f, 1.0f);
float min_dist = min(min(x, y), min(brick_width - x, row_height - y));
if (min_dist >= mortar_size) {
return vec2(tint, 0.0f);
}
else if (mortar_smooth == 0.0f) {
return vec2(tint, 1.0f);
}
else {
min_dist = 1.0f - min_dist / mortar_size;
return vec2(tint, smoothstep(0.0f, mortar_smooth, min_dist));
}
}
vec3 tex_brick_blender(vec3 co,
vec3 color1,
vec3 color2,
vec3 mortar,
float scale,
float mortar_size,
float mortar_smooth,
float bias,
float brick_width,
float row_height,
float offset_amount,
float offset_frequency,
float squash_amount,
float squash_frequency)
{
vec2 f2 = calc_brick_texture(co * scale,
mortar_size,
mortar_smooth,
bias,
brick_width,
row_height,
offset_amount,
int(offset_frequency),
squash_amount,
int(squash_frequency));
float tint = f2.x;
float f = f2.y;
if (f != 1.0f) {
float facm = 1.0f - tint;
color1 = facm * color1 + tint * color2;
}
return mix(color1, mortar, f);
}
float tex_brick_blender_f(vec3 co,
vec3 color1,
vec3 color2,
vec3 mortar,
float scale,
float mortar_size,
float mortar_smooth,
float bias,
float brick_width,
float row_height,
float offset_amount,
float offset_frequency,
float squash_amount,
float squash_frequency)
{
vec2 f2 = calc_brick_texture(co * scale,
mortar_size,
mortar_smooth,
bias,
brick_width,
row_height,
offset_amount,
int(offset_frequency),
squash_amount,
int(squash_frequency));
float tint = f2.x;
float f = f2.y;
if (f != 1.0f) {
float facm = 1.0f - tint;
color1 = facm * color1 + tint * color2;
}
return f;
}
"""
str_tex_wave = """
float tex_wave_f(const vec3 p, const int type, const int profile, const float dist, const float detail, const float detail_scale) {
float n;