EEVEE: Fix GPUNodeLink memory leak for displacement nodes using SHD_SPACE_WORLD

When the displacement space is set to SHD_SPACE_WORLD, the GLSL method
"node_displacement_world" is used instead of the "node_displacement_object" method. The two GLSL methods:
```
void node_displacement_object(
    float height, float midlevel, float scale, vec3 N, mat4 obmat, out vec3 result)
{
  N = (vec4(N, 0.0) * obmat).xyz;
  result = (height - midlevel) * scale * normalize(N);
  result = (obmat * vec4(result, 0.0)).xyz;
}

void node_displacement_world(float height, float midlevel, float scale, vec3 N, out vec3 result)
{
  result = (height - midlevel) * scale * normalize(N);
}
```
In contrast to the "node_displacement_object" method, the "node_displacement_world"
does not require an "obmat" parameter. Attempting to still pass "GPU_builtin(GPU_OBJECT_MATRIX)"
as additional parameter will result in a memory leak. The "GPUNodeLink" allocated in
the "GPU_builtin" method will never get released.

Fixes T83941 Memory leak when using the Displacement shader node in Eevee with the displacement
space set to "World Space"
This commit is contained in:
Michael Möller 2021-01-29 17:07:27 +01:00 committed by Clément Foucault
parent b3fc885544
commit 5d215d5225
1 changed files with 1 additions and 2 deletions

View File

@ -65,8 +65,7 @@ static int gpu_shader_displacement(GPUMaterial *mat,
mat, node, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
}
return GPU_stack_link(
mat, node, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
return GPU_stack_link(mat, node, "node_displacement_world", in, out);
}
/* node type definition */