diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 1e3bd947c73..51738d6b9e3 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -377,6 +377,7 @@ set(GLSL_SRC engines/eevee/shaders/eevee_geom_curves_vert.glsl engines/eevee/shaders/eevee_geom_mesh_vert.glsl engines/eevee/shaders/eevee_geom_pointcloud_vert.glsl + engines/eevee/shaders/eevee_geom_types_lib.glsl engines/eevee/shaders/eevee_geom_volume_vert.glsl engines/eevee/shaders/eevee_geom_world_vert.glsl engines/eevee/shaders/eevee_hiz_debug_frag.glsl diff --git a/source/blender/draw/engines/eevee/eevee_shader.cc b/source/blender/draw/engines/eevee/eevee_shader.cc index 6bcb1a4e2b0..50639ab2d26 100644 --- a/source/blender/draw/engines/eevee/eevee_shader.cc +++ b/source/blender/draw/engines/eevee/eevee_shader.cc @@ -653,11 +653,14 @@ void ShaderModule::material_create_info_amend(GPUMaterial *gpumat, GPUCodegenOut } } + bool use_ao_node = false; + if (GPU_material_flag_get(gpumat, GPU_MATFLAG_AO) && ELEM(pipeline_type, MAT_PIPE_FORWARD, MAT_PIPE_DEFERRED) && geometry_type_has_surface(geometry_type)) { info.define("MAT_AMBIENT_OCCLUSION"); + use_ao_node = true; } if (GPU_material_flag_get(gpumat, GPU_MATFLAG_TRANSPARENT)) { @@ -947,6 +950,7 @@ void ShaderModule::material_create_info_amend(GPUMaterial *gpumat, GPUCodegenOut Vector dependencies = {}; if (use_vertex_displacement) { + dependencies.append("eevee_geom_types_lib.glsl"); dependencies.append("eevee_nodetree_lib.glsl"); dependencies.extend(codegen.displacement.dependencies); } @@ -955,7 +959,12 @@ void ShaderModule::material_create_info_amend(GPUMaterial *gpumat, GPUCodegenOut } if (pipeline_type != MAT_PIPE_VOLUME_OCCUPANCY) { - Vector dependencies = {"eevee_nodetree_lib.glsl"}; + Vector dependencies; + if (use_ao_node) { + dependencies.append("eevee_ambient_occlusion_lib.glsl"); + } + dependencies.append("eevee_geom_types_lib.glsl"); + dependencies.append("eevee_nodetree_lib.glsl"); for (const auto &graph : codegen.material_functions) { frag_gen << graph.serialized; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_attributes_curves_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_attributes_curves_lib.glsl index c40d3f90a73..462666ec765 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_attributes_curves_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_attributes_curves_lib.glsl @@ -17,7 +17,7 @@ SHADER_LIBRARY_CREATE_INFO(draw_curves) #include "draw_curves_lib.glsl" #include "draw_model_lib.glsl" #include "draw_object_infos_lib.glsl" -#include "eevee_nodetree_lib.glsl" +#include "eevee_geom_types_lib.glsl" #include "gpu_shader_codegen_lib.glsl" #include "gpu_shader_math_vector_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_attributes_mesh_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_attributes_mesh_lib.glsl index 381f4f3381b..31fbeebd7fd 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_attributes_mesh_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_attributes_mesh_lib.glsl @@ -12,7 +12,7 @@ SHADER_LIBRARY_CREATE_INFO(draw_modelmat) #include "draw_model_lib.glsl" #include "draw_object_infos_lib.glsl" -#include "eevee_nodetree_lib.glsl" +#include "eevee_geom_types_lib.glsl" #include "gpu_shader_codegen_lib.glsl" #include "gpu_shader_math_vector_safe_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_attributes_pointcloud_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_attributes_pointcloud_lib.glsl index 163d37a5bf1..cdf713f077c 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_attributes_pointcloud_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_attributes_pointcloud_lib.glsl @@ -17,7 +17,7 @@ SHADER_LIBRARY_CREATE_INFO(draw_pointcloud) #include "draw_model_lib.glsl" #include "draw_object_infos_lib.glsl" #include "draw_pointcloud_lib.glsl" -#include "eevee_nodetree_lib.glsl" +#include "eevee_geom_types_lib.glsl" #include "gpu_shader_codegen_lib.glsl" #include "gpu_shader_math_matrix_transform_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_attributes_volume_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_attributes_volume_lib.glsl index 10c875dfaf5..046ff33fb51 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_attributes_volume_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_attributes_volume_lib.glsl @@ -12,7 +12,7 @@ SHADER_LIBRARY_CREATE_INFO(draw_modelmat) #include "draw_model_lib.glsl" #include "draw_object_infos_lib.glsl" -#include "eevee_nodetree_lib.glsl" +#include "eevee_geom_types_lib.glsl" #include "gpu_shader_codegen_lib.glsl" #include "gpu_shader_math_vector_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_attributes_world_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_attributes_world_lib.glsl index c69310f6c03..18a3f22c47b 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_attributes_world_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_attributes_world_lib.glsl @@ -4,11 +4,9 @@ #pragma once -#include "eevee_nodetree_lib.glsl" +#include "eevee_geom_types_lib.glsl" #include "gpu_shader_codegen_lib.glsl" -#include "gpu_shader_math_vector_lib.glsl" - /* -------------------------------------------------------------------- */ /** \name World * diff --git a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_diffuse_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_diffuse_lib.glsl index 46439177e83..9ce40a490c4 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_diffuse_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_diffuse_lib.glsl @@ -8,6 +8,7 @@ #include "gpu_shader_codegen_lib.glsl" #include "gpu_shader_math_base_lib.glsl" #include "gpu_shader_math_safe_lib.glsl" +#include "gpu_shader_ray_lib.glsl" #include "gpu_shader_utildefines_lib.glsl" /* -------------------------------------------------------------------- */ diff --git a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_lib.glsl index 82ec8aa8d24..2b602fcd3c3 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_lib.glsl @@ -62,13 +62,6 @@ struct LightProbeRay { float perceptual_roughness; }; -/* General purpose 3D ray. */ -struct Ray { - packed_float3 direction; - float max_time; - packed_float3 origin; -}; - /* -------------------------------------------------------------------- */ /** \name Utils * \{ */ diff --git a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl index 60d5f2ff361..d5d29a27e4d 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl @@ -16,6 +16,7 @@ SHADER_LIBRARY_CREATE_INFO(eevee_utility_texture) #include "gpu_shader_math_fast_lib.glsl" #include "gpu_shader_math_vector_lib.glsl" #include "gpu_shader_math_vector_safe_lib.glsl" +#include "gpu_shader_ray_lib.glsl" #include "gpu_shader_utildefines_lib.glsl" /* -------------------------------------------------------------------- */ diff --git a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl index cf973f1dd84..4fe1a8a471c 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl @@ -5,6 +5,7 @@ #pragma once #include "eevee_bxdf_lib.glsl" +#include "gpu_shader_ray_lib.glsl" /* -------------------------------------------------------------------- */ /** \name Oren Nayar BSDF diff --git a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_sampling_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_sampling_lib.glsl index 68294e4ac7d..76ecb77f609 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_sampling_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_sampling_lib.glsl @@ -8,6 +8,6 @@ * Sampling of Normal Distribution Function for various BxDF. */ -#include "eevee_bxdf_diffuse_lib.glsl" -#include "eevee_bxdf_lib.glsl" -#include "eevee_bxdf_microfacet_lib.glsl" +#include "eevee_bxdf_diffuse_lib.glsl" // IWYU pragma: export +#include "eevee_bxdf_lib.glsl" // IWYU pragma: export +#include "eevee_bxdf_microfacet_lib.glsl" // IWYU pragma: export diff --git a/source/blender/draw/engines/eevee/shaders/eevee_geom_types_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_geom_types_lib.glsl new file mode 100644 index 00000000000..eaab57d4b7e --- /dev/null +++ b/source/blender/draw/engines/eevee/shaders/eevee_geom_types_lib.glsl @@ -0,0 +1,40 @@ +/* SPDX-FileCopyrightText: 2022-2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +#include "gpu_shader_compat.hh" + +struct MeshVertex { + int _pad; /* TODO(fclem): Add explicit attribute loading for mesh. */ + METAL_CONSTRUCTOR_1(MeshVertex, int, _pad) +}; + +struct PointCloudPoint { + int _pad; /* TODO(fclem): Add explicit attribute loading for mesh. */ + METAL_CONSTRUCTOR_1(PointCloudPoint, int, _pad) +}; + +struct CurvesPoint { + int curve_id; + int point_id; + int curve_segment; + + METAL_CONSTRUCTOR_3(CurvesPoint, int, curve_id, int, point_id, int, curve_segment) +}; + +struct WorldPoint { + int _pad; + METAL_CONSTRUCTOR_1(WorldPoint, int, _pad) +}; + +struct VolumePoint { + int _pad; /* TODO(fclem): Add explicit attribute loading for volumes. */ + METAL_CONSTRUCTOR_1(VolumePoint, int, _pad) +}; + +struct GPencilPoint { + int _pad; + METAL_CONSTRUCTOR_1(GPencilPoint, int, _pad) +}; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_geom_world_vert.glsl b/source/blender/draw/engines/eevee/shaders/eevee_geom_world_vert.glsl index 01540c4c222..0bb4e01604f 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_geom_world_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_geom_world_vert.glsl @@ -11,9 +11,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_geom_world) #include "draw_view_lib.glsl" -#include "eevee_nodetree_lib.glsl" #include "eevee_reverse_z_lib.glsl" -#include "eevee_surf_lib.glsl" void main() { diff --git a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl index b2869f29c8c..90ff3d82c99 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl @@ -21,7 +21,6 @@ SHADER_LIBRARY_CREATE_INFO(eevee_horizon_scan) #include "draw_shape_lib.glsl" #include "draw_view_lib.glsl" -#include "eevee_bxdf_lib.glsl" #include "eevee_horizon_scan_lib.glsl" #include "eevee_ray_types_lib.glsl" #include "eevee_sampling_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_frag_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_frag_lib.glsl index a0f6370e4ef..93f4b8088f7 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_frag_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_frag_lib.glsl @@ -6,6 +6,7 @@ /* This file must replaced at runtime. The following content is only a possible implementation. */ #pragma runtime_generated +#include "eevee_geom_types_lib.glsl" #include "eevee_nodetree_lib.glsl" /* Loading of the attributes into GlobalData. */ diff --git a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl index 8d1ebfdbaa7..c521a5f71bf 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl @@ -4,7 +4,6 @@ #pragma once -#include "gpu_shader_math_vector_reduce_lib.glsl" #include "infos/eevee_common_info.hh" SHADER_LIBRARY_CREATE_INFO(eevee_global_ubo) @@ -18,41 +17,9 @@ SHADER_LIBRARY_CREATE_INFO(eevee_utility_texture) #include "gpu_shader_codegen_lib.glsl" #include "gpu_shader_math_base_lib.glsl" #include "gpu_shader_math_safe_lib.glsl" +#include "gpu_shader_math_vector_reduce_lib.glsl" #include "gpu_shader_utildefines_lib.glsl" -struct MeshVertex { - int _pad; /* TODO(fclem): Add explicit attribute loading for mesh. */ - METAL_CONSTRUCTOR_1(MeshVertex, int, _pad) -}; - -struct PointCloudPoint { - int _pad; /* TODO(fclem): Add explicit attribute loading for mesh. */ - METAL_CONSTRUCTOR_1(PointCloudPoint, int, _pad) -}; - -struct CurvesPoint { - int curve_id; - int point_id; - int curve_segment; - - METAL_CONSTRUCTOR_3(CurvesPoint, int, curve_id, int, point_id, int, curve_segment) -}; - -struct WorldPoint { - int _pad; - METAL_CONSTRUCTOR_1(WorldPoint, int, _pad) -}; - -struct VolumePoint { - int _pad; /* TODO(fclem): Add explicit attribute loading for volumes. */ - METAL_CONSTRUCTOR_1(VolumePoint, int, _pad) -}; - -struct GPencilPoint { - int _pad; - METAL_CONSTRUCTOR_1(GPencilPoint, int, _pad) -}; - packed_float3 g_emission; packed_float3 g_transmittance; float g_holdout; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_vert_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_vert_lib.glsl index 18d0669654f..65453c68f89 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_vert_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_vert_lib.glsl @@ -6,6 +6,7 @@ /* This file must replaced at runtime. The following content is only a possible implementation. */ #pragma runtime_generated +#include "eevee_geom_types_lib.glsl" #include "eevee_nodetree_lib.glsl" /* Loading of the attributes into GlobalData. */ diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl index c60b130bacb..afcfafc6afb 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl @@ -6,9 +6,9 @@ #include "draw_math_geom_lib.glsl" #include "draw_view_lib.glsl" -#include "eevee_bxdf_lib.glsl" /* Needed for Ray. */ #include "gpu_shader_math_matrix_transform_lib.glsl" #include "gpu_shader_math_safe_lib.glsl" +#include "gpu_shader_ray_lib.glsl" /* Screen-space ray ([0..1] "uv" range) where direction is normalize to be as small as one * full-resolution pixel. The ray is also clipped to all frustum sides. @@ -22,6 +22,7 @@ struct ScreenSpaceRay { }; void raytrace_screenspace_ray_finalize(inout ScreenSpaceRay ray, float2 pixel_size) + { /* Constant bias (due to depth buffer precision). Helps with self intersection. */ /* Magic numbers for 24bits of precision. diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl index c3d94f31873..bf8d5de8119 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl @@ -19,7 +19,6 @@ FRAGMENT_SHADER_CREATE_INFO(eevee_cryptomatte_out) #include "draw_curves_lib.glsl" #include "draw_view_lib.glsl" -#include "eevee_ambient_occlusion_lib.glsl" #include "eevee_gbuffer_write_lib.glsl" #include "eevee_nodetree_frag_lib.glsl" #include "eevee_sampling_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_forward_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_forward_frag.glsl index b3621930c86..e645f57ad34 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_forward_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_forward_frag.glsl @@ -15,7 +15,6 @@ FRAGMENT_SHADER_CREATE_INFO(eevee_surf_forward) #include "draw_curves_lib.glsl" #include "draw_view_lib.glsl" -#include "eevee_ambient_occlusion_lib.glsl" #include "eevee_forward_lib.glsl" #include "eevee_nodetree_frag_lib.glsl" #include "eevee_reverse_z_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl index e29129c2732..7a1004f9bd5 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl @@ -19,7 +19,6 @@ FRAGMENT_SHADER_CREATE_INFO(eevee_cryptomatte_out) #include "draw_curves_lib.glsl" #include "draw_view_lib.glsl" -#include "eevee_ambient_occlusion_lib.glsl" #include "eevee_forward_lib.glsl" #include "eevee_gbuffer_write_lib.glsl" #include "eevee_nodetree_frag_lib.glsl" diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_lib.glsl index e99220ed6fe..a53dad01402 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_lib.glsl @@ -7,13 +7,11 @@ #include "infos/eevee_material_info.hh" SHADER_LIBRARY_CREATE_INFO(eevee_geom_mesh) +SHADER_LIBRARY_CREATE_INFO(eevee_global_ubo) -#include "draw_model_lib.glsl" -#include "eevee_nodetree_lib.glsl" -#include "eevee_sampling_lib.glsl" +#include "draw_view_lib.glsl" #include "gpu_shader_codegen_lib.glsl" #include "gpu_shader_math_base_lib.glsl" -#include "gpu_shader_math_vector_lib.glsl" #include "gpu_shader_math_vector_safe_lib.glsl" #if defined(USE_BARYCENTRICS) && defined(GPU_FRAGMENT_SHADER) && defined(MAT_GEOM_MESH) @@ -86,8 +84,8 @@ void init_globals() g_data.barycentric_dists = float3(0.0f); #ifdef GPU_FRAGMENT_SHADER - g_data.N = (FrontFacing) ? g_data.N : -g_data.N; - g_data.Ni = (FrontFacing) ? g_data.Ni : -g_data.Ni; + 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 diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_occupancy_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_occupancy_frag.glsl index f02410f5ac1..852cbf95824 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_occupancy_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_occupancy_frag.glsl @@ -35,16 +35,10 @@ FRAGMENT_SHADER_CREATE_INFO(eevee_geom_mesh) FRAGMENT_SHADER_CREATE_INFO(eevee_surf_occupancy) -#include "eevee_nodetree_lib.glsl" #include "eevee_occupancy_lib.glsl" #include "eevee_sampling_lib.glsl" #include "eevee_volume_lib.glsl" -float4 closure_to_rgba(Closure cl) -{ - return float4(0.0f); -} - void main() { int2 texel = int2(gl_FragCoord.xy); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl index 0ee65050b40..d1f79131180 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl @@ -20,7 +20,6 @@ FRAGMENT_SHADER_CREATE_INFO(eevee_surf_shadow_atomic) # define MAT_SHADOW #endif -#include "draw_view_lib.glsl" #include "eevee_nodetree_frag_lib.glsl" #include "eevee_sampling_lib.glsl" #include "eevee_shadow_tilemap_lib.glsl" @@ -48,7 +47,7 @@ void main() #endif /* Clip to light shape. */ - if (length_squared(shadow_clip.vector) < 1.0f) { + if (dot(shadow_clip.vector, shadow_clip.vector) < 1.0f) { discard_result; } diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 15e77d5fd73..25288fce427 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -554,6 +554,7 @@ set(GLSL_SRC shaders/common/gpu_shader_offset_indices_lib.glsl shaders/common/gpu_shader_print_lib.glsl shaders/common/gpu_shader_ray_utils_lib.glsl + shaders/common/gpu_shader_ray_lib.glsl shaders/common/gpu_shader_sequencer_lib.glsl shaders/common/gpu_shader_shared_exponent_lib.glsl shaders/common/gpu_shader_smaa_lib.glsl diff --git a/source/blender/gpu/intern/gpu_shader_dependency.cc b/source/blender/gpu/intern/gpu_shader_dependency.cc index 12de7e94825..13a7fdcca2b 100644 --- a/source/blender/gpu/intern/gpu_shader_dependency.cc +++ b/source/blender/gpu/intern/gpu_shader_dependency.cc @@ -15,10 +15,11 @@ #include #include -#include "BLI_ghash.h" #include "BLI_map.hh" #include "BLI_string_ref.hh" +#include "CLG_log.h" + #include "gpu_capabilities_private.hh" #include "gpu_material_library.hh" #include "gpu_shader_create_info.hh" @@ -44,6 +45,8 @@ extern "C" { #undef SHADER_SOURCE } +static CLG_LogRef LOG = {"gpu.shader_dependencies"}; + namespace blender::gpu { using GPUPrintFormatMap = Map; @@ -330,10 +333,6 @@ struct GPUSource { if (result != 0) { return 1; } - - for (auto *dep : dependency_source->dependencies) { - dependencies.append_non_duplicates(dep); - } dependencies.append_non_duplicates(dependency_source); } dependencies_names.clear(); @@ -342,19 +341,41 @@ struct GPUSource { void source_get(Vector &result, const shader::GeneratedSourceList &generated_sources, - const GPUSourceDictionary &dict) const + const GPUSourceDictionary &dict, + const GPUSource &from) const { +#define CLOG_FILE_INCLUDE(_from, _include) \ + if ((from).filename.c_str() != (_include).filename.c_str()) { \ + const char *from_filename = (_from).filename.c_str(); \ + const char *include_filename = (_include).filename.c_str(); \ + const int from_size = int((_from).source.size()); \ + const int include_size = int((_include).source.size()); \ + CLOG_INFO(&LOG, "%s_%d --> %s_%d", from_filename, from_size, include_filename, include_size); \ + CLOG_INFO(&LOG, \ + "style %s_%d fill:#%x%x0", \ + include_filename, \ + include_size, \ + min_uu(15, include_size / 1000), \ + 15 - min_uu(15, include_size / 1000)); \ + } + /* Check if this file was already included. */ for (const StringRefNull &source_content : result) { /* Yes, compare pointer instead of string for speed. * Each source is guaranteed to be unique and non-moving during the building process. */ if (source_content.c_str() == this->source.c_str()) { /* Already included. */ + CLOG_FILE_INCLUDE(from, *this); return; } } if (!bool(this->builtins & shader::BuiltinBits::RUNTIME_GENERATED)) { + for (const auto &dependency : this->dependencies) { + /* WATCH: Recursive. */ + dependency->source_get(result, generated_sources, dict, *this); + } + CLOG_FILE_INCLUDE(from, *this); result.append(this->source); return; } @@ -364,7 +385,7 @@ struct GPUSource { for (const shader::GeneratedSource &generated_src : generated_sources) { if (generated_src.filename == this->filename) { /* Include dependencies before the generated file. */ - for (auto dependency_name : generated_src.dependencies) { + for (const auto &dependency_name : generated_src.dependencies) { BLI_assert_msg(dependency_name != this->filename, "Recursive include"); GPUSource *dependency_source = dict.lookup_default(dependency_name, nullptr); @@ -373,9 +394,10 @@ struct GPUSource { std::cerr << "Generated dependency not found : " + dependency_name << std::endl; return; } - dependency_source->build(result, generated_sources, dict); + /* WATCH: Recursive. */ + dependency_source->source_get(result, generated_sources, dict, *this); } - + CLOG_FILE_INCLUDE(from, *this); result.append(generated_src.content); return; } @@ -383,6 +405,13 @@ struct GPUSource { std::cerr << "warn: Generated source not provided. Using fallback for : " << this->filename << std::endl; + /* Dependencies for generated sources are not folded on startup. + * This allows for different set of dependencies at runtime. */ + for (const auto &dependency : this->dependencies) { + /* WATCH: Recursive. */ + dependency->source_get(result, generated_sources, dict, *this); + } + CLOG_FILE_INCLUDE(from, *this); result.append(this->source); } @@ -391,17 +420,14 @@ struct GPUSource { const shader::GeneratedSourceList &generated_sources, const GPUSourceDictionary &dict) const { - for (auto *dep : dependencies) { - dep->source_get(result, generated_sources, dict); - } - source_get(result, generated_sources, dict); + source_get(result, generated_sources, dict, *this); } shader::BuiltinBits builtins_get() const { shader::BuiltinBits out_builtins = builtins; for (auto *dep : dependencies) { - out_builtins |= dep->builtins; + out_builtins |= dep->builtins_get(); } return out_builtins; } @@ -567,7 +593,10 @@ Vector gpu_shader_dependency_get_resolved_source( if (src == nullptr) { std::cerr << "Error source not found : " << shader_source_name << std::endl; } + CLOG_INFO(&LOG, "Resolved Source Tree (Mermaid flowchart)"); + CLOG_INFO(&LOG, "flowchart LR"); src->build(result, generated_sources, *g_sources); + CLOG_INFO(&LOG, " "); return result; } diff --git a/source/blender/gpu/shaders/common/gpu_shader_ray_lib.glsl b/source/blender/gpu/shaders/common/gpu_shader_ray_lib.glsl new file mode 100644 index 00000000000..7ab953c0a42 --- /dev/null +++ b/source/blender/gpu/shaders/common/gpu_shader_ray_lib.glsl @@ -0,0 +1,14 @@ +/* SPDX-FileCopyrightText: 2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +#include "gpu_shader_compat.hh" + +/* General purpose 3D ray. */ +struct Ray { + packed_float3 direction; + float max_time; + packed_float3 origin; +}; diff --git a/source/blender/gpu/shaders/gpu_shader_compat.hh b/source/blender/gpu/shaders/gpu_shader_compat.hh index 88c02af5ba4..aef1b0b4c41 100644 --- a/source/blender/gpu/shaders/gpu_shader_compat.hh +++ b/source/blender/gpu/shaders/gpu_shader_compat.hh @@ -12,7 +12,7 @@ /* This file must replaced at runtime. The following content is only a possible implementation. */ #pragma runtime_generated -#include "gpu_shader_compat_cxx.hh" +#include "gpu_shader_compat_cxx.hh" // IWYU pragma: export /* Other possible implementation. */ // #include "gpu_shader_compat_glsl.hh" // #include "gpu_shader_compat_msl.hh" diff --git a/source/blender/gpu/shaders/gpu_shader_compat_cxx.hh b/source/blender/gpu/shaders/gpu_shader_compat_cxx.hh index 41487eec86c..703d8bced7d 100644 --- a/source/blender/gpu/shaders/gpu_shader_compat_cxx.hh +++ b/source/blender/gpu/shaders/gpu_shader_compat_cxx.hh @@ -26,12 +26,12 @@ #pragma once -#include "gpu_shader_cxx_builtin.hh" -#include "gpu_shader_cxx_global.hh" -#include "gpu_shader_cxx_image.hh" -#include "gpu_shader_cxx_matrix.hh" -#include "gpu_shader_cxx_sampler.hh" -#include "gpu_shader_cxx_vector.hh" +#include "gpu_shader_cxx_builtin.hh" // IWYU pragma: export +#include "gpu_shader_cxx_global.hh" // IWYU pragma: export +#include "gpu_shader_cxx_image.hh" // IWYU pragma: export +#include "gpu_shader_cxx_matrix.hh" // IWYU pragma: export +#include "gpu_shader_cxx_sampler.hh" // IWYU pragma: export +#include "gpu_shader_cxx_vector.hh" // IWYU pragma: export #define assert(assertion) #define printf(...)