Skip to content

Commit

Permalink
Fixes #244, Fixes #276. Fix blending artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Dec 16, 2023
1 parent 6d0f2c7 commit 4e4143c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/shaders/main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,18 @@ void get_material(vec2 uv, uint control, ivec3 iuv_center, vec3 normal, out Mate
vec3 n = unpack_normal(normal_rg);
normal_rg.xz = rotate(n.xz, rot.x, -rot.y);

// If any overlay texture from manual painting or auto shader
if (out_mat.blend > 0.f) {
float rand2 = r * _texture_uv_rotation_array[out_mat.over];
vec2 rot2 = vec2(cos(rand2), sin(rand2));
vec2 matUV2 = rotate(uv, rot2.x, rot2.y) * _texture_uv_scale_array[out_mat.over];
// Setup overlay texture to blend
float rand2 = r * _texture_uv_rotation_array[out_mat.over];
vec2 rot2 = vec2(cos(rand2), sin(rand2));
vec2 matUV2 = rotate(uv, rot2.x, rot2.y) * _texture_uv_scale_array[out_mat.over];

vec4 albedo_ht2 = texture(_texture_array_albedo, vec3(matUV2, float(out_mat.over)));
vec4 normal_rg2 = texture(_texture_array_normal, vec3(matUV2, float(out_mat.over)));
vec4 albedo_ht2 = texture(_texture_array_albedo, vec3(matUV2, float(out_mat.over)));
vec4 normal_rg2 = texture(_texture_array_normal, vec3(matUV2, float(out_mat.over)));

// Though it would seem having the above lookups in this block, or removing the branch would
// be more optimal, the first introduces artifacts #276, and the second is noticably slower.
// It seems the branching off dual scaling and the color array lookup is more optimal.
if (out_mat.blend > 0.f) {
//INSERT: DUAL_SCALING_OVERLAY
// Apply color to overlay
albedo_ht2.rgb *= _texture_color_array[out_mat.over].rgb;
Expand Down Expand Up @@ -277,7 +280,6 @@ void fragment() {
get_material(UV, control10, index10UV, w_normal, mat[2]);
get_material(UV, control11, index11UV, w_normal, mat[3]);


// Calculate weight for the pixel position between the vertices
// Bilinear interpolation of difference of UV and floor(UV)
vec2 weights1 = clamp(texel_pos - texel_pos_floor, 0, 1);
Expand Down

0 comments on commit 4e4143c

Please sign in to comment.