Files
test2/source/blender/draw/engines/eevee/shaders/eevee_surf_lib.glsl

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

155 lines
4.6 KiB
Plaintext
Raw Normal View History

/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "infos/eevee_material_infos.hh"
SHADER_LIBRARY_CREATE_INFO(eevee_geom_mesh)
EEVEE: Reduce necessary includes This saves a few milisecond of compile time per shader. This removes the need for occlusion lib when not using occlusion node. To improve detection of uneeded includes, we add a new logging system which output can be fed to mermaid to inspect dependencies. The new dependencies can be inspected using `--log "gpu.shader_dependencies"` Example pasted here: ```mermaid flowchart LR draw_curves_lib.glsl_7298 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_euler_lib.glsl_461 style gpu_shader_math_euler_lib.glsl_461 fill:#0f0 gpu_shader_math_matrix_compare_lib.glsl_2964 --> gpu_shader_math_vector_compare_lib.glsl_2489 style gpu_shader_math_vector_compare_lib.glsl_2489 fill:#2d0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_matrix_compare_lib.glsl_2964 style gpu_shader_math_matrix_compare_lib.glsl_2964 fill:#2d0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_quaternion_lib.glsl_395 style gpu_shader_math_quaternion_lib.glsl_395 fill:#0f0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_conversion_lib.glsl_1032 style gpu_shader_math_matrix_conversion_lib.glsl_1032 fill:#1e0 draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_transform_lib.glsl_706 style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> draw_curves_lib.glsl_7298 style draw_curves_lib.glsl_7298 fill:#780 eevee_surf_deferred_frag.glsl_4531 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_lib.glsl_5038 style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_gbuffer_write_lib.glsl_7324 --> eevee_gbuffer_lib.glsl_14598 style eevee_gbuffer_lib.glsl_14598 fill:#e10 eevee_surf_deferred_frag.glsl_4531 --> eevee_gbuffer_write_lib.glsl_7324 style eevee_gbuffer_write_lib.glsl_7324 fill:#780 eevee_ambient_occlusion_lib.glsl_10738 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_lib.glsl_5038 style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0 draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_ray_types_lib.glsl_2390 --> draw_math_geom_lib.glsl_5172 style draw_math_geom_lib.glsl_5172 fill:#5a0 eevee_ray_types_lib.glsl_2390 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_matrix_transform_lib.glsl_706 style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0 gpu_shader_math_safe_lib.glsl_1235 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_ray_lib.glsl_137 style gpu_shader_ray_lib.glsl_137 fill:#0f0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_ray_types_lib.glsl_2390 style eevee_ray_types_lib.glsl_2390 fill:#2d0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_sampling_lib.glsl_4291 style eevee_sampling_lib.glsl_4291 fill:#4b0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_utility_tx_lib.glsl_1225 style eevee_utility_tx_lib.glsl_1225 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 gpu_shader_math_fast_lib.glsl_921 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_fast_lib.glsl_921 style gpu_shader_math_fast_lib.glsl_921 fill:#0f0 gpu_shader_math_vector_safe_lib.glsl_5847 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_nodetree_frag_lib.glsl_395 --> eevee_ambient_occlusion_lib.glsl_10738 style eevee_ambient_occlusion_lib.glsl_10738 fill:#a50 eevee_nodetree_frag_lib.glsl_395 --> eevee_geom_types_lib.glsl_682 style eevee_geom_types_lib.glsl_682 fill:#0f0 draw_model_lib.glsl_2563 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_nodetree_lib.glsl_16051 --> draw_model_lib.glsl_2563 style draw_model_lib.glsl_2563 fill:#2d0 draw_object_infos_lib.glsl_1114 --> draw_model_lib.glsl_2563 style draw_model_lib.glsl_2563 fill:#2d0 eevee_nodetree_lib.glsl_16051 --> draw_object_infos_lib.glsl_1114 style draw_object_infos_lib.glsl_1114 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_nodetree_lib.glsl_16051 --> eevee_renderpass_lib.glsl_1793 style eevee_renderpass_lib.glsl_1793 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> eevee_utility_tx_lib.glsl_1225 style eevee_utility_tx_lib.glsl_1225 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_nodetree_frag_lib.glsl_395 --> eevee_nodetree_lib.glsl_16051 style eevee_nodetree_lib.glsl_16051 fill:#f00 gpu_shader_material_ambient_occlusion.glsl_558 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_ambient_occlusion.glsl_558 style gpu_shader_material_ambient_occlusion.glsl_558 fill:#0f0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_emission.glsl_380 style gpu_shader_material_emission.glsl_380 fill:#0f0 gpu_shader_material_output_material.glsl_850 --> gpu_shader_material_transform_utils.glsl_2136 style gpu_shader_material_transform_utils.glsl_2136 fill:#2d0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_output_material.glsl_850 style gpu_shader_material_output_material.glsl_850 fill:#0f0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_world_normals.glsl_128 style gpu_shader_material_world_normals.glsl_128 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> eevee_nodetree_frag_lib.glsl_395 style eevee_nodetree_frag_lib.glsl_395 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> eevee_sampling_lib.glsl_4291 style eevee_sampling_lib.glsl_4291 fill:#4b0 eevee_surf_lib.glsl_3650 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_surf_lib.glsl_3650 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_surf_lib.glsl_3650 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_surf_lib.glsl_3650 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_surf_deferred_frag.glsl_4531 --> eevee_surf_lib.glsl_3650 style eevee_surf_lib.glsl_3650 fill:#3c0 ``` Pull Request: https://projects.blender.org/blender/blender/pulls/146580
2025-09-23 17:21:56 +02:00
SHADER_LIBRARY_CREATE_INFO(eevee_global_ubo)
EEVEE: Reduce necessary includes This saves a few milisecond of compile time per shader. This removes the need for occlusion lib when not using occlusion node. To improve detection of uneeded includes, we add a new logging system which output can be fed to mermaid to inspect dependencies. The new dependencies can be inspected using `--log "gpu.shader_dependencies"` Example pasted here: ```mermaid flowchart LR draw_curves_lib.glsl_7298 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_euler_lib.glsl_461 style gpu_shader_math_euler_lib.glsl_461 fill:#0f0 gpu_shader_math_matrix_compare_lib.glsl_2964 --> gpu_shader_math_vector_compare_lib.glsl_2489 style gpu_shader_math_vector_compare_lib.glsl_2489 fill:#2d0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_matrix_compare_lib.glsl_2964 style gpu_shader_math_matrix_compare_lib.glsl_2964 fill:#2d0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_quaternion_lib.glsl_395 style gpu_shader_math_quaternion_lib.glsl_395 fill:#0f0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_conversion_lib.glsl_1032 style gpu_shader_math_matrix_conversion_lib.glsl_1032 fill:#1e0 draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_transform_lib.glsl_706 style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> draw_curves_lib.glsl_7298 style draw_curves_lib.glsl_7298 fill:#780 eevee_surf_deferred_frag.glsl_4531 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_lib.glsl_5038 style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_gbuffer_write_lib.glsl_7324 --> eevee_gbuffer_lib.glsl_14598 style eevee_gbuffer_lib.glsl_14598 fill:#e10 eevee_surf_deferred_frag.glsl_4531 --> eevee_gbuffer_write_lib.glsl_7324 style eevee_gbuffer_write_lib.glsl_7324 fill:#780 eevee_ambient_occlusion_lib.glsl_10738 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_lib.glsl_5038 style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0 draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_ray_types_lib.glsl_2390 --> draw_math_geom_lib.glsl_5172 style draw_math_geom_lib.glsl_5172 fill:#5a0 eevee_ray_types_lib.glsl_2390 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_matrix_transform_lib.glsl_706 style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0 gpu_shader_math_safe_lib.glsl_1235 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_ray_lib.glsl_137 style gpu_shader_ray_lib.glsl_137 fill:#0f0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_ray_types_lib.glsl_2390 style eevee_ray_types_lib.glsl_2390 fill:#2d0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_sampling_lib.glsl_4291 style eevee_sampling_lib.glsl_4291 fill:#4b0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_utility_tx_lib.glsl_1225 style eevee_utility_tx_lib.glsl_1225 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 gpu_shader_math_fast_lib.glsl_921 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_fast_lib.glsl_921 style gpu_shader_math_fast_lib.glsl_921 fill:#0f0 gpu_shader_math_vector_safe_lib.glsl_5847 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_nodetree_frag_lib.glsl_395 --> eevee_ambient_occlusion_lib.glsl_10738 style eevee_ambient_occlusion_lib.glsl_10738 fill:#a50 eevee_nodetree_frag_lib.glsl_395 --> eevee_geom_types_lib.glsl_682 style eevee_geom_types_lib.glsl_682 fill:#0f0 draw_model_lib.glsl_2563 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_nodetree_lib.glsl_16051 --> draw_model_lib.glsl_2563 style draw_model_lib.glsl_2563 fill:#2d0 draw_object_infos_lib.glsl_1114 --> draw_model_lib.glsl_2563 style draw_model_lib.glsl_2563 fill:#2d0 eevee_nodetree_lib.glsl_16051 --> draw_object_infos_lib.glsl_1114 style draw_object_infos_lib.glsl_1114 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_nodetree_lib.glsl_16051 --> eevee_renderpass_lib.glsl_1793 style eevee_renderpass_lib.glsl_1793 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> eevee_utility_tx_lib.glsl_1225 style eevee_utility_tx_lib.glsl_1225 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_nodetree_frag_lib.glsl_395 --> eevee_nodetree_lib.glsl_16051 style eevee_nodetree_lib.glsl_16051 fill:#f00 gpu_shader_material_ambient_occlusion.glsl_558 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_ambient_occlusion.glsl_558 style gpu_shader_material_ambient_occlusion.glsl_558 fill:#0f0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_emission.glsl_380 style gpu_shader_material_emission.glsl_380 fill:#0f0 gpu_shader_material_output_material.glsl_850 --> gpu_shader_material_transform_utils.glsl_2136 style gpu_shader_material_transform_utils.glsl_2136 fill:#2d0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_output_material.glsl_850 style gpu_shader_material_output_material.glsl_850 fill:#0f0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_world_normals.glsl_128 style gpu_shader_material_world_normals.glsl_128 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> eevee_nodetree_frag_lib.glsl_395 style eevee_nodetree_frag_lib.glsl_395 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> eevee_sampling_lib.glsl_4291 style eevee_sampling_lib.glsl_4291 fill:#4b0 eevee_surf_lib.glsl_3650 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_surf_lib.glsl_3650 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_surf_lib.glsl_3650 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_surf_lib.glsl_3650 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_surf_deferred_frag.glsl_4531 --> eevee_surf_lib.glsl_3650 style eevee_surf_lib.glsl_3650 fill:#3c0 ``` Pull Request: https://projects.blender.org/blender/blender/pulls/146580
2025-09-23 17:21:56 +02:00
#include "draw_view_lib.glsl"
#include "gpu_shader_codegen_lib.glsl"
#include "gpu_shader_math_base_lib.glsl"
#include "gpu_shader_math_vector_safe_lib.glsl"
#if defined(USE_BARYCENTRICS) && defined(GPU_FRAGMENT_SHADER) && defined(MAT_GEOM_MESH)
float3 barycentric_distances_get()
{
float wp_delta = length(gpu_dfdx(interp.P)) + length(gpu_dfdy(interp.P));
float bc_delta = length(gpu_dfdx(gpu_BaryCoord)) + length(gpu_dfdy(gpu_BaryCoord));
float rate_of_change = wp_delta / bc_delta;
return rate_of_change * (1.0f - gpu_BaryCoord);
}
#endif
void init_globals_mesh()
{
#if defined(USE_BARYCENTRICS) && defined(GPU_FRAGMENT_SHADER) && defined(MAT_GEOM_MESH)
g_data.barycentric_coords = gpu_BaryCoord.xy;
g_data.barycentric_dists = barycentric_distances_get();
#endif
}
void init_globals_curves()
{
#if defined(MAT_GEOM_CURVES)
/* Shade as a cylinder. */
DRW: New Curve Drawing Implementation of the design task #142969. This adds the following: - Exact GPU interpolation of curves of all types. - Radius attribute support. - Cyclic curve support. - Resolution attribute support. - New Cylinder hair shape type. ![image.png](/attachments/a8e7aea0-b0e5-4694-b660-89fb3df1ddcd) What changed: - EEVEE doesn't compute random normals for strand hairs anymore. These are considered legacy now. - EEVEE now have an internal shadow bias to avoid self shadowing on hair. - Workbench Curves Strip display option is no longer flat and has better shading. - Legacy Hair particle system evaluates radius at control points before applying additional subdivision. This now matches Cycles. - Color Attribute Node without a name do not fetch the active color attribute anymore. This now matches Cycles. Notes: - This is not 100% matching the CPU implementation for interpolation (see the epsilons in the tests). - Legacy Hair Particle points is now stored in local space after interpolation. The new cylinder shape allows for more correct hair shading in workbench and better intersection in EEVEE. | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand.png](/attachments/67d3b792-962c-4272-a92c-1c0c7c6cf8de) | ![main_strip.png](/attachments/f2aa3575-368e-4fbb-b888-74df845918f1) | N/A | | PR | ![pr_strand.png](/attachments/cc012483-25f0-491f-a06e-ad3029981d47) | ![pr_strip.png](/attachments/73fa2f5c-5252-4b30-a334-e935ed0fb938) | ![pr_cylinder.png](/attachments/3133b2d4-a6f2-41ee-8e2d-f6fd00db0c8d) | | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand_closeup.png](/attachments/730bd79c-6762-446d-819b-3ea47961ff9f) |![main_strip_closeup.png](/attachments/d9ace578-cfeb-4895-9896-3625b6ad7a02) | N/A | | PR | ![pr_strand_closeup.png](/attachments/ac8f3b0c-6ef6-4d54-b714-6322f9865036)|![pr_strip_closeup.png](/attachments/8504711a-955b-4ab2-aa3d-c2d114baf9d4)| ![pr_cylinder_closeup.png](/attachments/1e2899a8-0a5c-431f-ac6c-5184d87e9598) | Cyclic Curve, Mixed curve type, and proper radius support: ![image.png](/attachments/7f0bf05e-62ee-4ae9-aef9-a5599249b8d7) Test file for attribute lookup: [test_attribute_lookup.blend](/attachments/1d54dd06-379b-4480-a1c5-96adc1953f77) Follow Up Tasks: - Correct full tube segments orientation based on tangent and normal attributes - Correct V resolution property per object - More attribute type support (currently only color) TODO: - [x] Attribute Loading Changes - [x] Generic Attributes - [x] Length Attribute - [x] Intercept Attribute - [x] Original Coordinate Attribute - [x] Cyclic Curves - [x] Legacy Hair Particle conversion - [x] Attribute Loading - [x] Additional Subdivision - [x] Move some function to generic headers (VertBuf, OffsetIndices) - [x] Fix default UV/Color attribute assignment Pull Request: https://projects.blender.org/blender/blender/pulls/143180
2025-08-27 09:49:43 +02:00
float cos_theta = curve_interp.time_width / curve_interp.radius;
float sin_theta = sin_from_cos(cos_theta);
g_data.N = g_data.Ni = normalize(interp.N * sin_theta + curve_interp.binormal * cos_theta);
/* Costly, but follows cycles per pixel tangent space (not following curve shape). */
float3 V = drw_world_incident_vector(g_data.P);
g_data.curve_T = -curve_interp.tangent;
g_data.curve_B = cross(V, g_data.curve_T);
g_data.curve_N = safe_normalize(cross(g_data.curve_T, g_data.curve_B));
g_data.is_strand = true;
DRW: New Curve Drawing Implementation of the design task #142969. This adds the following: - Exact GPU interpolation of curves of all types. - Radius attribute support. - Cyclic curve support. - Resolution attribute support. - New Cylinder hair shape type. ![image.png](/attachments/a8e7aea0-b0e5-4694-b660-89fb3df1ddcd) What changed: - EEVEE doesn't compute random normals for strand hairs anymore. These are considered legacy now. - EEVEE now have an internal shadow bias to avoid self shadowing on hair. - Workbench Curves Strip display option is no longer flat and has better shading. - Legacy Hair particle system evaluates radius at control points before applying additional subdivision. This now matches Cycles. - Color Attribute Node without a name do not fetch the active color attribute anymore. This now matches Cycles. Notes: - This is not 100% matching the CPU implementation for interpolation (see the epsilons in the tests). - Legacy Hair Particle points is now stored in local space after interpolation. The new cylinder shape allows for more correct hair shading in workbench and better intersection in EEVEE. | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand.png](/attachments/67d3b792-962c-4272-a92c-1c0c7c6cf8de) | ![main_strip.png](/attachments/f2aa3575-368e-4fbb-b888-74df845918f1) | N/A | | PR | ![pr_strand.png](/attachments/cc012483-25f0-491f-a06e-ad3029981d47) | ![pr_strip.png](/attachments/73fa2f5c-5252-4b30-a334-e935ed0fb938) | ![pr_cylinder.png](/attachments/3133b2d4-a6f2-41ee-8e2d-f6fd00db0c8d) | | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand_closeup.png](/attachments/730bd79c-6762-446d-819b-3ea47961ff9f) |![main_strip_closeup.png](/attachments/d9ace578-cfeb-4895-9896-3625b6ad7a02) | N/A | | PR | ![pr_strand_closeup.png](/attachments/ac8f3b0c-6ef6-4d54-b714-6322f9865036)|![pr_strip_closeup.png](/attachments/8504711a-955b-4ab2-aa3d-c2d114baf9d4)| ![pr_cylinder_closeup.png](/attachments/1e2899a8-0a5c-431f-ac6c-5184d87e9598) | Cyclic Curve, Mixed curve type, and proper radius support: ![image.png](/attachments/7f0bf05e-62ee-4ae9-aef9-a5599249b8d7) Test file for attribute lookup: [test_attribute_lookup.blend](/attachments/1d54dd06-379b-4480-a1c5-96adc1953f77) Follow Up Tasks: - Correct full tube segments orientation based on tangent and normal attributes - Correct V resolution property per object - More attribute type support (currently only color) TODO: - [x] Attribute Loading Changes - [x] Generic Attributes - [x] Length Attribute - [x] Intercept Attribute - [x] Original Coordinate Attribute - [x] Cyclic Curves - [x] Legacy Hair Particle conversion - [x] Attribute Loading - [x] Additional Subdivision - [x] Move some function to generic headers (VertBuf, OffsetIndices) - [x] Fix default UV/Color attribute assignment Pull Request: https://projects.blender.org/blender/blender/pulls/143180
2025-08-27 09:49:43 +02:00
g_data.hair_diameter = curve_interp.radius * 2.0;
g_data.hair_strand_id = curve_interp_flat.strand_id;
# if defined(USE_BARYCENTRICS) && defined(GPU_FRAGMENT_SHADER)
DRW: New Curve Drawing Implementation of the design task #142969. This adds the following: - Exact GPU interpolation of curves of all types. - Radius attribute support. - Cyclic curve support. - Resolution attribute support. - New Cylinder hair shape type. ![image.png](/attachments/a8e7aea0-b0e5-4694-b660-89fb3df1ddcd) What changed: - EEVEE doesn't compute random normals for strand hairs anymore. These are considered legacy now. - EEVEE now have an internal shadow bias to avoid self shadowing on hair. - Workbench Curves Strip display option is no longer flat and has better shading. - Legacy Hair particle system evaluates radius at control points before applying additional subdivision. This now matches Cycles. - Color Attribute Node without a name do not fetch the active color attribute anymore. This now matches Cycles. Notes: - This is not 100% matching the CPU implementation for interpolation (see the epsilons in the tests). - Legacy Hair Particle points is now stored in local space after interpolation. The new cylinder shape allows for more correct hair shading in workbench and better intersection in EEVEE. | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand.png](/attachments/67d3b792-962c-4272-a92c-1c0c7c6cf8de) | ![main_strip.png](/attachments/f2aa3575-368e-4fbb-b888-74df845918f1) | N/A | | PR | ![pr_strand.png](/attachments/cc012483-25f0-491f-a06e-ad3029981d47) | ![pr_strip.png](/attachments/73fa2f5c-5252-4b30-a334-e935ed0fb938) | ![pr_cylinder.png](/attachments/3133b2d4-a6f2-41ee-8e2d-f6fd00db0c8d) | | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand_closeup.png](/attachments/730bd79c-6762-446d-819b-3ea47961ff9f) |![main_strip_closeup.png](/attachments/d9ace578-cfeb-4895-9896-3625b6ad7a02) | N/A | | PR | ![pr_strand_closeup.png](/attachments/ac8f3b0c-6ef6-4d54-b714-6322f9865036)|![pr_strip_closeup.png](/attachments/8504711a-955b-4ab2-aa3d-c2d114baf9d4)| ![pr_cylinder_closeup.png](/attachments/1e2899a8-0a5c-431f-ac6c-5184d87e9598) | Cyclic Curve, Mixed curve type, and proper radius support: ![image.png](/attachments/7f0bf05e-62ee-4ae9-aef9-a5599249b8d7) Test file for attribute lookup: [test_attribute_lookup.blend](/attachments/1d54dd06-379b-4480-a1c5-96adc1953f77) Follow Up Tasks: - Correct full tube segments orientation based on tangent and normal attributes - Correct V resolution property per object - More attribute type support (currently only color) TODO: - [x] Attribute Loading Changes - [x] Generic Attributes - [x] Length Attribute - [x] Intercept Attribute - [x] Original Coordinate Attribute - [x] Cyclic Curves - [x] Legacy Hair Particle conversion - [x] Attribute Loading - [x] Additional Subdivision - [x] Move some function to generic headers (VertBuf, OffsetIndices) - [x] Fix default UV/Color attribute assignment Pull Request: https://projects.blender.org/blender/blender/pulls/143180
2025-08-27 09:49:43 +02:00
g_data.barycentric_coords.y = fract(curve_interp.point_id);
g_data.barycentric_coords.x = 1.0 - g_data.barycentric_coords.y;
# endif
#endif
}
void init_globals()
{
/* Default values. */
g_data.P = interp.P;
g_data.Ni = interp.N;
g_data.N = safe_normalize(interp.N);
g_data.Ng = g_data.N;
g_data.is_strand = false;
DRW: New Curve Drawing Implementation of the design task #142969. This adds the following: - Exact GPU interpolation of curves of all types. - Radius attribute support. - Cyclic curve support. - Resolution attribute support. - New Cylinder hair shape type. ![image.png](/attachments/a8e7aea0-b0e5-4694-b660-89fb3df1ddcd) What changed: - EEVEE doesn't compute random normals for strand hairs anymore. These are considered legacy now. - EEVEE now have an internal shadow bias to avoid self shadowing on hair. - Workbench Curves Strip display option is no longer flat and has better shading. - Legacy Hair particle system evaluates radius at control points before applying additional subdivision. This now matches Cycles. - Color Attribute Node without a name do not fetch the active color attribute anymore. This now matches Cycles. Notes: - This is not 100% matching the CPU implementation for interpolation (see the epsilons in the tests). - Legacy Hair Particle points is now stored in local space after interpolation. The new cylinder shape allows for more correct hair shading in workbench and better intersection in EEVEE. | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand.png](/attachments/67d3b792-962c-4272-a92c-1c0c7c6cf8de) | ![main_strip.png](/attachments/f2aa3575-368e-4fbb-b888-74df845918f1) | N/A | | PR | ![pr_strand.png](/attachments/cc012483-25f0-491f-a06e-ad3029981d47) | ![pr_strip.png](/attachments/73fa2f5c-5252-4b30-a334-e935ed0fb938) | ![pr_cylinder.png](/attachments/3133b2d4-a6f2-41ee-8e2d-f6fd00db0c8d) | | | Strand | Strip | Cylinder | | ---- | --- | --- | --- | | Main | ![main_strand_closeup.png](/attachments/730bd79c-6762-446d-819b-3ea47961ff9f) |![main_strip_closeup.png](/attachments/d9ace578-cfeb-4895-9896-3625b6ad7a02) | N/A | | PR | ![pr_strand_closeup.png](/attachments/ac8f3b0c-6ef6-4d54-b714-6322f9865036)|![pr_strip_closeup.png](/attachments/8504711a-955b-4ab2-aa3d-c2d114baf9d4)| ![pr_cylinder_closeup.png](/attachments/1e2899a8-0a5c-431f-ac6c-5184d87e9598) | Cyclic Curve, Mixed curve type, and proper radius support: ![image.png](/attachments/7f0bf05e-62ee-4ae9-aef9-a5599249b8d7) Test file for attribute lookup: [test_attribute_lookup.blend](/attachments/1d54dd06-379b-4480-a1c5-96adc1953f77) Follow Up Tasks: - Correct full tube segments orientation based on tangent and normal attributes - Correct V resolution property per object - More attribute type support (currently only color) TODO: - [x] Attribute Loading Changes - [x] Generic Attributes - [x] Length Attribute - [x] Intercept Attribute - [x] Original Coordinate Attribute - [x] Cyclic Curves - [x] Legacy Hair Particle conversion - [x] Attribute Loading - [x] Additional Subdivision - [x] Move some function to generic headers (VertBuf, OffsetIndices) - [x] Fix default UV/Color attribute assignment Pull Request: https://projects.blender.org/blender/blender/pulls/143180
2025-08-27 09:49:43 +02:00
g_data.hair_diameter = 0.0f;
g_data.hair_strand_id = 0;
#if defined(MAT_SHADOW)
g_data.ray_type = RAY_TYPE_SHADOW;
#elif defined(MAT_CAPTURE)
g_data.ray_type = RAY_TYPE_DIFFUSE;
#else
if (uniform_buf.pipeline.is_sphere_probe) {
g_data.ray_type = RAY_TYPE_GLOSSY;
}
else {
g_data.ray_type = RAY_TYPE_CAMERA;
}
#endif
g_data.ray_depth = 0.0f;
g_data.ray_length = distance(g_data.P, drw_view_position());
g_data.barycentric_coords = float2(0.0f);
g_data.barycentric_dists = float3(0.0f);
#ifdef GPU_FRAGMENT_SHADER
EEVEE: Reduce necessary includes This saves a few milisecond of compile time per shader. This removes the need for occlusion lib when not using occlusion node. To improve detection of uneeded includes, we add a new logging system which output can be fed to mermaid to inspect dependencies. The new dependencies can be inspected using `--log "gpu.shader_dependencies"` Example pasted here: ```mermaid flowchart LR draw_curves_lib.glsl_7298 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_euler_lib.glsl_461 style gpu_shader_math_euler_lib.glsl_461 fill:#0f0 gpu_shader_math_matrix_compare_lib.glsl_2964 --> gpu_shader_math_vector_compare_lib.glsl_2489 style gpu_shader_math_vector_compare_lib.glsl_2489 fill:#2d0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_matrix_compare_lib.glsl_2964 style gpu_shader_math_matrix_compare_lib.glsl_2964 fill:#2d0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_quaternion_lib.glsl_395 style gpu_shader_math_quaternion_lib.glsl_395 fill:#0f0 gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_conversion_lib.glsl_1032 style gpu_shader_math_matrix_conversion_lib.glsl_1032 fill:#1e0 draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_transform_lib.glsl_706 style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> draw_curves_lib.glsl_7298 style draw_curves_lib.glsl_7298 fill:#780 eevee_surf_deferred_frag.glsl_4531 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_lib.glsl_5038 style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0 eevee_gbuffer_lib.glsl_14598 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_gbuffer_write_lib.glsl_7324 --> eevee_gbuffer_lib.glsl_14598 style eevee_gbuffer_lib.glsl_14598 fill:#e10 eevee_surf_deferred_frag.glsl_4531 --> eevee_gbuffer_write_lib.glsl_7324 style eevee_gbuffer_write_lib.glsl_7324 fill:#780 eevee_ambient_occlusion_lib.glsl_10738 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_lib.glsl_5038 style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0 draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_ray_types_lib.glsl_2390 --> draw_math_geom_lib.glsl_5172 style draw_math_geom_lib.glsl_5172 fill:#5a0 eevee_ray_types_lib.glsl_2390 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_matrix_transform_lib.glsl_706 style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0 gpu_shader_math_safe_lib.glsl_1235 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ray_types_lib.glsl_2390 --> gpu_shader_ray_lib.glsl_137 style gpu_shader_ray_lib.glsl_137 fill:#0f0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_ray_types_lib.glsl_2390 style eevee_ray_types_lib.glsl_2390 fill:#2d0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_sampling_lib.glsl_4291 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_sampling_lib.glsl_4291 style eevee_sampling_lib.glsl_4291 fill:#4b0 eevee_ambient_occlusion_lib.glsl_10738 --> eevee_utility_tx_lib.glsl_1225 style eevee_utility_tx_lib.glsl_1225 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 gpu_shader_math_fast_lib.glsl_921 --> gpu_shader_math_constants_lib.glsl_600 style gpu_shader_math_constants_lib.glsl_600 fill:#0f0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_fast_lib.glsl_921 style gpu_shader_math_fast_lib.glsl_921 fill:#0f0 gpu_shader_math_vector_safe_lib.glsl_5847 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_nodetree_frag_lib.glsl_395 --> eevee_ambient_occlusion_lib.glsl_10738 style eevee_ambient_occlusion_lib.glsl_10738 fill:#a50 eevee_nodetree_frag_lib.glsl_395 --> eevee_geom_types_lib.glsl_682 style eevee_geom_types_lib.glsl_682 fill:#0f0 draw_model_lib.glsl_2563 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_nodetree_lib.glsl_16051 --> draw_model_lib.glsl_2563 style draw_model_lib.glsl_2563 fill:#2d0 draw_object_infos_lib.glsl_1114 --> draw_model_lib.glsl_2563 style draw_model_lib.glsl_2563 fill:#2d0 eevee_nodetree_lib.glsl_16051 --> draw_object_infos_lib.glsl_1114 style draw_object_infos_lib.glsl_1114 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_nodetree_lib.glsl_16051 --> eevee_renderpass_lib.glsl_1793 style eevee_renderpass_lib.glsl_1793 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> eevee_utility_tx_lib.glsl_1225 style eevee_utility_tx_lib.glsl_1225 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_safe_lib.glsl_1235 style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_vector_reduce_lib.glsl_1383 style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0 eevee_nodetree_lib.glsl_16051 --> gpu_shader_utildefines_lib.glsl_3112 style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0 eevee_nodetree_frag_lib.glsl_395 --> eevee_nodetree_lib.glsl_16051 style eevee_nodetree_lib.glsl_16051 fill:#f00 gpu_shader_material_ambient_occlusion.glsl_558 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_ambient_occlusion.glsl_558 style gpu_shader_material_ambient_occlusion.glsl_558 fill:#0f0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_emission.glsl_380 style gpu_shader_material_emission.glsl_380 fill:#0f0 gpu_shader_material_output_material.glsl_850 --> gpu_shader_material_transform_utils.glsl_2136 style gpu_shader_material_transform_utils.glsl_2136 fill:#2d0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_output_material.glsl_850 style gpu_shader_material_output_material.glsl_850 fill:#0f0 eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_world_normals.glsl_128 style gpu_shader_material_world_normals.glsl_128 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> eevee_nodetree_frag_lib.glsl_395 style eevee_nodetree_frag_lib.glsl_395 fill:#0f0 eevee_surf_deferred_frag.glsl_4531 --> eevee_sampling_lib.glsl_4291 style eevee_sampling_lib.glsl_4291 fill:#4b0 eevee_surf_lib.glsl_3650 --> draw_view_lib.glsl_3551 style draw_view_lib.glsl_3551 fill:#3c0 eevee_surf_lib.glsl_3650 --> gpu_shader_codegen_lib.glsl_6143 style gpu_shader_codegen_lib.glsl_6143 fill:#690 eevee_surf_lib.glsl_3650 --> gpu_shader_math_base_lib.glsl_1406 style gpu_shader_math_base_lib.glsl_1406 fill:#1e0 eevee_surf_lib.glsl_3650 --> gpu_shader_math_vector_safe_lib.glsl_5847 style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0 eevee_surf_deferred_frag.glsl_4531 --> eevee_surf_lib.glsl_3650 style eevee_surf_lib.glsl_3650 fill:#3c0 ``` Pull Request: https://projects.blender.org/blender/blender/pulls/146580
2025-09-23 17:21:56 +02:00
g_data.N = (gl_FrontFacing) ? g_data.N : -g_data.N;
g_data.Ni = (gl_FrontFacing) ? g_data.Ni : -g_data.Ni;
g_data.Ng = safe_normalize(cross(gpu_dfdx(g_data.P), gpu_dfdy(g_data.P)));
#endif
#if defined(MAT_GEOM_MESH)
init_globals_mesh();
#elif defined(MAT_GEOM_CURVES)
init_globals_curves();
#endif
}
/* Avoid some compiler issue with non set interface parameters. */
void init_interface()
{
#ifdef GPU_VERTEX_SHADER
interp.P = float3(0.0f);
interp.N = float3(0.0f);
drw_ResourceID_iface.resource_index = drw_resource_id_raw();
#endif
}
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
#if defined(GPU_VERTEX_SHADER) && defined(MAT_SHADOW)
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
void shadow_viewport_layer_set(int view_id, int lod)
{
# ifdef SHADOW_UPDATE_ATOMIC_RASTER
shadow_iface.shadow_view_id = view_id;
# else
/* We still render to a layered frame-buffer in the case of Metal + Tile Based Renderer.
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
* Since it needs correct depth buffering, each view needs to not overlap each others.
* It doesn't matter much for other platform, so we use that as a way to pass the view id. */
gpu_Layer = view_id;
# endif
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
gpu_ViewportIndex = lod;
}
float3 shadow_position_vector_get(float3 view_position, ShadowRenderView view)
{
2024-05-08 20:57:05 +10:00
if (view.is_directional) {
return float3(0.0f, 0.0f, -view_position.z - view.clip_near);
}
return view_position;
}
/* In order to support physical clipping, we pass a vector to the fragment shader that then clips
* each fragment using a unit sphere test. This allows to support both point light and area light
* clipping at the same time. */
float3 shadow_clip_vector_get(float3 view_position, float clip_distance_inv)
{
if (clip_distance_inv == 0.0f) {
/* No clipping. */
return float3(2.0f);
}
/* Punctual shadow case. */
return view_position * clip_distance_inv;
}
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
#endif
#if defined(GPU_FRAGMENT_SHADER) && defined(MAT_SHADOW)
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
int shadow_view_id_get()
{
# ifdef SHADOW_UPDATE_ATOMIC_RASTER
return shadow_iface.shadow_view_id;
# else
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
return gpu_Layer;
# endif
EEVEE-Next: Shadow Rendering Refactor Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. Pull Request: https://projects.blender.org/blender/blender/pulls/110979
2023-08-17 17:35:19 +02:00
}
#endif