diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-02-15 19:51:19 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-02-15 19:53:22 +0300 |
commit | 48b26d9c2e0f4f4b6b5b7279c5bfc40c3ec77a6f (patch) | |
tree | 87ac7bfedae5d3e64c5fcac71a740bb02872ff94 /source/blender/draw/intern/draw_cache_impl_subdivision.cc | |
parent | 430ced76d559d828b6f47c5fbb22530dcc70c257 (diff) |
Fix T95697: GPU subdivision ignores custom normals
Similarly to the CPU subdivision, we interpolate custom loop normals
from the coarse mesh, and this for the final normals.
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_subdivision.cc')
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_subdivision.cc | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index ea05ae799b0..e4c53604370 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -1355,8 +1355,9 @@ void draw_subdiv_interp_custom_data(const DRWSubdivCache *cache, drw_subdiv_compute_dispatch(cache, shader, 0, dst_offset, cache->num_subdiv_quads); - /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. */ - GPU_memory_barrier(GPU_BARRIER_VERTEX_ATTRIB_ARRAY); + /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. Put + * a barrier on the shader storage as we may use the result in another compute shader. */ + GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE | GPU_BARRIER_VERTEX_ATTRIB_ARRAY); /* Cleanup. */ GPU_shader_unbind(); @@ -1437,6 +1438,28 @@ void draw_subdiv_finalize_normals(const DRWSubdivCache *cache, GPU_shader_unbind(); } +void draw_subdiv_finalize_custom_normals(const DRWSubdivCache *cache, + GPUVertBuf *src_custom_normals, + GPUVertBuf *pos_nor) +{ + GPUShader *shader = get_subdiv_shader(SHADER_BUFFER_NORMALS_FINALIZE, "#define CUSTOM_NORMALS"); + GPU_shader_bind(shader); + + GPU_vertbuf_bind_as_ssbo(src_custom_normals, 0); + /* outputPosNor is bound at index 2 in the base shader. */ + GPU_vertbuf_bind_as_ssbo(pos_nor, 2); + + drw_subdiv_compute_dispatch(cache, shader, 0, 0, cache->num_subdiv_quads); + + /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. + * We also need it for subsequent compute shaders, so a barrier on the shader storage is also + * needed. */ + GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE | GPU_BARRIER_VERTEX_ATTRIB_ARRAY); + + /* Cleanup. */ + GPU_shader_unbind(); +} + void draw_subdiv_build_tris_buffer(const DRWSubdivCache *cache, GPUIndexBuf *subdiv_tris, const int material_count) @@ -1828,6 +1851,11 @@ static bool draw_subdiv_create_requested_buffers(const Scene *scene, /* We can only evaluate limit normals if the patches are adaptive. */ draw_cache->do_limit_normals = settings.is_adaptive; + draw_cache->use_custom_loop_normals = (smd->flags & eSubsurfModifierFlag_UseCustomNormals) && + (mesh_eval->flag & ME_AUTOSMOOTH) && + CustomData_has_layer(&mesh_eval->ldata, + CD_CUSTOMLOOPNORMAL); + if (DRW_ibo_requested(mbc->buff.ibo.tris)) { draw_subdiv_cache_ensure_mat_offsets(draw_cache, mesh_eval, batch_cache->mat_len); } |