Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions project/addons/terrain_3d/extras/shaders/lightweight.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ void fragment() {
// Recover UVs
vec2 uv = UV;
vec2 uv2 = UV2;
vec2 uv_control = uv;
vec2 uv_tex = uv * _vertex_spacing;

// Lookup offsets, ID and blend weight
vec3 region_uv = get_index_uv(uv2);
const vec3 offsets = vec3(0, 1, 2);
vec2 index_id = floor(uv);
vec2 weight = fract(uv);
vec2 index_id = floor(uv_control);
vec2 weight = fract(uv_control);
vec2 invert = 1.0 - weight;
vec4 weights = vec4(
invert.x * weight.y, // 0
Expand Down Expand Up @@ -373,8 +375,6 @@ void fragment() {
uint id_read = 0u; // 1 bit per possible ID
// world normal adjustment requires acess to previous id during next iteration
vec4 nrm = vec4(0.0, 1.0, 0.0, 1.0);
// adjust uv scale to account for vertex spacing
uv *= _vertex_spacing;
for (int i = 0; i < 4; i++) {
for (int t = 0; t < 2; t++) {
int id = texture_ids[i][t];
Expand All @@ -384,7 +384,7 @@ void fragment() {
id_read |= mask;
float id_w = t_weights[i][t];
float id_scale = _texture_uv_scale_array[id] * 0.5;
vec2 id_uv = fma(uv, vec2(id_scale), vec2(0.5));
vec2 id_uv = fma(uv_tex, vec2(id_scale), vec2(0.5));
vec4 i_dd = base_dd * id_scale;
vec4 alb = textureGrad(_texture_array_albedo, vec3(id_uv, float(id)), i_dd.xy, i_dd.zw);
float world_normal = clamp(fma(TBN[0], vec3(nrm.x), fma(TBN[1], vec3(nrm.z), v_normal * vec3(nrm.y))).y, 0., 1.);
Expand Down