GPU: GLSL compilation as C++ for workbench static shaders

This commit is contained in:
Clément Foucault
2024-11-08 00:15:10 +01:00
parent 39da29cedd
commit c0c816f846
49 changed files with 660 additions and 33 deletions

View File

@@ -147,6 +147,7 @@ add_subdirectory(blenlib)
add_subdirectory(bmesh)
add_subdirectory(draw)
add_subdirectory(draw/intern/shaders)
add_subdirectory(draw/engines/workbench/shaders)
add_subdirectory(render)
add_subdirectory(blenfont)
add_subdirectory(blentranslation)

View File

@@ -597,7 +597,9 @@ set(GLSL_SRC
intern/shaders/draw_intersect_lib.glsl
intern/shaders/draw_math_geom_lib.glsl
intern/shaders/draw_model_lib.glsl
intern/shaders/draw_pointcloud_lib.glsl
intern/shaders/draw_resource_finalize_comp.glsl
intern/shaders/draw_view_clipping_lib.glsl
intern/shaders/draw_view_finalize_comp.glsl
intern/shaders/draw_view_lib.glsl
intern/shaders/draw_view_reconstruction_lib.glsl

View File

@@ -0,0 +1,100 @@
# SPDX-FileCopyrightText: 2024 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
# avoid noisy warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_c_flag(
"-Wno-unused-result"
)
remove_cc_flag(
"-Wmissing-declarations"
)
endif()
set(INC_GLSL
.
..
# For variadic macros
../../../../blenlib
../../../intern
../../../intern/shaders
../../../../gpu
../../../../gpu/intern
../../../../gpu/shaders
../../../../gpu/shaders/infos
../../../../gpu/shaders/common
)
set(SRC_GLSL_VERT
workbench_effect_smaa_vert.glsl
workbench_prepass_hair_vert.glsl
workbench_prepass_pointcloud_vert.glsl
workbench_prepass_vert.glsl
workbench_shadow_caps_vert.glsl
workbench_shadow_vert.glsl
workbench_volume_vert.glsl
)
set(SRC_GLSL_FRAG
workbench_composite_frag.glsl
workbench_effect_dof_frag.glsl
workbench_effect_outline_frag.glsl
workbench_effect_smaa_frag.glsl
workbench_effect_taa_frag.glsl
workbench_extract_stencil.glsl
workbench_merge_depth_frag.glsl
workbench_overlay_depth_frag.glsl
workbench_prepass_frag.glsl
workbench_shadow_debug_frag.glsl
workbench_transparent_accum_frag.glsl
workbench_transparent_resolve_frag.glsl
workbench_volume_frag.glsl
)
set(SRC_GLSL_COMP
workbench_shadow_visibility_comp.glsl
)
set(SRC_GLSL_LIB
workbench_cavity_lib.glsl
workbench_common_lib.glsl
workbench_curvature_lib.glsl
workbench_image_lib.glsl
workbench_matcap_lib.glsl
workbench_material_lib.glsl
workbench_shadow_lib.glsl
workbench_world_light_lib.glsl
)
add_definitions(-DGPU_SHADER)
# TODO Remove
add_definitions(-DUSE_GPU_SHADER_CREATE_INFO)
function(compile_sources_as_cpp
executable
sources
define
)
foreach(glsl_file ${sources})
set_source_files_properties(${glsl_file} PROPERTIES LANGUAGE CXX)
endforeach()
add_library(${executable} OBJECT ${sources})
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()
# Compile shaders with shader code.
if (WITH_GPU_SHADER_CPP_COMPILATION)
compile_sources_as_cpp(workbench_cpp_shaders_vert "${SRC_GLSL_VERT}" "GPU_VERTEX_SHADER")
compile_sources_as_cpp(workbench_cpp_shaders_frag "${SRC_GLSL_FRAG}" "GPU_FRAGMENT_SHADER")
compile_sources_as_cpp(workbench_cpp_shaders_comp "${SRC_GLSL_COMP}" "GPU_COMPUTE_SHADER")
compile_sources_as_cpp(workbench_cpp_shaders_lib "${SRC_GLSL_LIB}" "GPU_LIBRARY_SHADER")
endif()

View File

@@ -2,6 +2,25 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "BLI_utildefines_variadic.h"
# include "gpu_glsl_cpp_stubs.hh"
# include "workbench_shader_shared.h"
# include "draw_fullscreen_info.hh"
# include "draw_view_info.hh"
# define WORKBENCH_LIGHTING_STUDIO
# define WORKBENCH_LIGHTING_MATCAP
# define WORKBENCH_LIGHTING_FLAT
# define WORKBENCH_CURVATURE
# define WORKBENCH_CAVITY
# define WORKBENCH_SHADOW
#endif
#include "gpu_shader_create_info.hh"
#include "workbench_defines.hh"

View File

@@ -2,6 +2,13 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "gpu_glsl_cpp_stubs.hh"
# include "draw_fullscreen_info.hh"
#endif
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(workbench_merge_depth)

View File

@@ -2,6 +2,20 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "gpu_glsl_cpp_stubs.hh"
# include "draw_fullscreen_info.hh"
# define SMAA_GLSL_3
# define SMAA_STAGE 1
# define SMAA_PRESET_HIGH
# define SMAA_NO_DISCARD
# define SMAA_RT_METRICS viewportMetrics
# define SMAA_LUMA_WEIGHT float4(1.0, 1.0, 1.0, 1.0)
#endif
#include "gpu_shader_create_info.hh"
/* -------------------------------------------------------------------- */

View File

@@ -2,6 +2,23 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "gpu_glsl_cpp_stubs.hh"
# include "workbench_shader_shared.h"
# include "draw_fullscreen_info.hh"
# include "draw_view_info.hh"
# define PREPARE
# define DOWNSAMPLE
# define BLUR1
# define BLUR2
# define RESOLVE
# define NUM_SAMPLES 49
#endif
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(workbench_effect_dof)

View File

@@ -2,6 +2,15 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "gpu_glsl_cpp_stubs.hh"
# include "draw_fullscreen_info.hh"
# include "workbench_shader_shared.h"
#endif
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(workbench_effect_outline)

View File

@@ -2,6 +2,31 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "BLI_utildefines_variadic.h"
# include "gpu_glsl_cpp_stubs.hh"
# include "draw_object_infos_info.hh"
# include "draw_view_info.hh"
# include "workbench_shader_shared.h"
# define WORKBENCH_COLOR_MATERIAL
# define WORKBENCH_COLOR_TEXTURE
# define WORKBENCH_TEXTURE_IMAGE_ARRAY
# define WORKBENCH_COLOR_MATERIAL
# define WORKBENCH_COLOR_VERTEX
# define WORKBENCH_LIGHTING_MATCAP
# define HAIR_SHADER
# define DRW_HAIR_INFO
# define POINTCLOUD_SHADER
# define DRW_POINTCLOUD_INFO
#endif
#include "gpu_shader_create_info.hh"
#include "workbench_defines.hh"
@@ -92,7 +117,6 @@ DEFINE("WORKBENCH_COLOR_VERTEX")
GPU_SHADER_CREATE_END()
GPU_SHADER_CREATE_INFO(workbench_prepass)
DEFINE("WORKBENCH_NEXT")
UNIFORM_BUF(WB_WORLD_SLOT, WorldData, world_data)
VERTEX_OUT(workbench_material_iface)
ADDITIONAL_INFO(draw_view)

View File

@@ -2,6 +2,24 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "BLI_utildefines_variadic.h"
# include "gpu_glsl_cpp_stubs.hh"
# include "draw_object_infos_info.hh"
# include "draw_view_info.hh"
# include "gpu_index_load_info.hh"
# include "workbench_shader_shared.h"
# define DYNAMIC_PASS_SELECTION
# define SHADOW_PASS
# define SHADOW_FAIL
# define DOUBLE_MANIFOLD
#endif
#include "draw_defines.hh"
#include "gpu_shader_create_info.hh"

View File

@@ -2,6 +2,13 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "gpu_glsl_cpp_stubs.hh"
# include "draw_fullscreen_info.hh"
#endif
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(workbench_transparent_resolve)

View File

@@ -2,6 +2,24 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef GPU_SHADER
# pragma once
# include "BLI_utildefines_variadic.h"
# include "gpu_glsl_cpp_stubs.hh"
# include "draw_object_infos_info.hh"
# include "workbench_shader_shared.h"
# define VOLUME_SMOKE
# define VOLUME_OBJECT
# define USE_COBA
# define USE_TRILINEAR
# define USE_TRICUBIC
# define USE_CLOSEST
# define VOLUME_SLICE
#endif
#include "gpu_shader_create_info.hh"
/* -------------------------------------------------------------------- */
@@ -23,7 +41,6 @@ FRAGMENT_SOURCE("workbench_volume_frag.glsl")
GPU_SHADER_CREATE_END()
GPU_SHADER_CREATE_INFO(workbench_volume)
DEFINE("WORKBENCH_NEXT")
SAMPLER(6, UINT_2D, stencil_tx)
ADDITIONAL_INFO(workbench_volume_common)
ADDITIONAL_INFO(draw_object_infos_new)

View File

@@ -3,10 +3,15 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "infos/workbench_composite_info.hh"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
SHADER_LIBRARY_CREATE_INFO(draw_view)
SHADER_LIBRARY_CREATE_INFO(workbench_composite)
SHADER_LIBRARY_CREATE_INFO(workbench_resolve_cavity)
/* From The Alchemy screen-space ambient obscurance algorithm
* http://graphics.cs.williams.edu/papers/AlchemyHPG11/VV11AlchemyAO.pdf */

View File

@@ -4,6 +4,8 @@
#pragma once
#include "gpu_glsl_cpp_stubs.hh"
#define EPSILON 0.00001
#define CAVITY_BUFFER_RANGE 4.0

View File

@@ -2,6 +2,13 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_composite_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_composite)
FRAGMENT_SHADER_CREATE_INFO(workbench_resolve_opaque_matcap)
FRAGMENT_SHADER_CREATE_INFO(workbench_resolve_curvature)
FRAGMENT_SHADER_CREATE_INFO(workbench_resolve_shadow)
#include "draw_view_lib.glsl"
#include "workbench_cavity_lib.glsl"
#include "workbench_common_lib.glsl"
@@ -11,7 +18,7 @@
void main()
{
vec2 uv = uvcoordsvar.st;
vec2 uv = uvcoordsvar.xy;
float depth = texture(depth_tx, uv).r;
if (depth == 1.0) {

View File

@@ -8,10 +8,14 @@
* Converted and adapted from HLSL to GLSL by Clément Foucault
*/
#include "infos/workbench_effect_dof_info.hh"
#include "draw_view_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"
#include "gpu_shader_utildefines_lib.glsl"
FRAGMENT_SHADER_CREATE_INFO(workbench_effect_dof)
#define dof_aperturesize dofParams.x
#define dof_distance dofParams.y
#define dof_invsensorsize dofParams.z
@@ -45,7 +49,9 @@ float decode_signed_coc(vec2 cocs)
*/
#ifdef PREPARE
void main()
FRAGMENT_SHADER_CREATE_INFO(workbench_effect_dof_prepare)
void main_prepare()
{
ivec4 texel = ivec4(gl_FragCoord.xyxy) * 2 + ivec4(0, 0, 1, 1);
@@ -88,7 +94,9 @@ void main()
*/
#ifdef DOWNSAMPLE
void main()
FRAGMENT_SHADER_CREATE_INFO(workbench_effect_dof_downsample)
void main_downsample()
{
vec4 texel = vec4(gl_FragCoord.xyxy) * 2.0 + vec4(0.0, 0.0, 1.0, 1.0);
texel = (texel - 0.5) / vec4(textureSize(sceneColorTex, 0).xyxy);
@@ -203,6 +211,8 @@ void main()
*/
#ifdef BLUR1
FRAGMENT_SHADER_CREATE_INFO(workbench_effect_dof_blur1)
vec2 get_random_vector(float offset)
{
/* Interleaved gradient noise by Jorge Jimenez
@@ -215,7 +225,7 @@ vec2 get_random_vector(float offset)
// return noise.rg * sqrt(ign);
}
void main()
void main_blur1()
{
vec2 uv = gl_FragCoord.xy * invertedViewportSize * 2.0;
@@ -264,7 +274,9 @@ void main()
*/
#ifdef BLUR2
void main()
FRAGMENT_SHADER_CREATE_INFO(workbench_effect_dof_blur2)
void main_blur2()
{
/* Half Res pass */
vec2 pixel_size = 1.0 / vec2(textureSize(blurTex, 0).xy);
@@ -339,7 +351,9 @@ void main()
*/
#ifdef RESOLVE
void main()
FRAGMENT_SHADER_CREATE_INFO(workbench_effect_dof_resolve)
void main_resolve()
{
/* Full-screen pass. */
vec2 pixel_size = 0.5 / vec2(textureSize(halfResColorTex, 0).xy);
@@ -355,3 +369,26 @@ void main()
finalColorMul = vec4(1.0 - blend);
}
#endif
void main()
{
#ifdef PREPARE
main_prepare();
#endif
#ifdef DOWNSAMPLE
main_downsample();
#endif
#ifdef BLUR1
main_blur1();
#endif
#ifdef BLUR2
main_blur2();
#endif
#ifdef RESOLVE
main_resolve();
#endif
}

View File

@@ -2,10 +2,14 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_effect_outline_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_effect_outline)
void main()
{
vec3 offset = vec3(world_data.viewport_size_inv, 0.0) * world_data.ui_scale;
vec2 uv = uvcoordsvar.st;
vec2 uv = uvcoordsvar.xy;
uint center_id = texture(objectIdBuffer, uv).r;
uvec4 adjacent_ids = uvec4(texture(objectIdBuffer, uv + offset.zy).r,

View File

@@ -2,6 +2,11 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_effect_antialiasing_info.hh"
/* Adjust according to SMAA_STAGE for C++ compilation. */
FRAGMENT_SHADER_CREATE_INFO(workbench_smaa_stage_1)
#include "gpu_shader_smaa_lib.glsl"
void main()

View File

@@ -2,6 +2,10 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_effect_antialiasing_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_smaa)
#include "gpu_shader_smaa_lib.glsl"
void main()

View File

@@ -2,6 +2,10 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_effect_antialiasing_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_taa)
void main()
{
vec2 texel_size = 1.0 / vec2(textureSize(colorBuffer, 0));

View File

@@ -2,6 +2,10 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_depth_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_extract_stencil)
void main()
{
out_stencil_value = 0xFF;

View File

@@ -4,6 +4,10 @@
#pragma once
#include "infos/workbench_prepass_info.hh"
SHADER_LIBRARY_CREATE_INFO(workbench_color_texture)
/* TODO(fclem): deduplicate code. */
bool node_tex_tile_lookup(inout vec3 co, sampler2DArray ima, sampler1DArray map)
{

View File

@@ -4,6 +4,12 @@
#pragma once
#include "infos/workbench_prepass_info.hh"
#ifdef GPU_LIBRARY_SHADER
SHADER_LIBRARY_CREATE_INFO(workbench_prepass)
#endif
vec2 matcap_uv_compute(vec3 I, vec3 N, bool flipped)
{
/* Quick creation of an orthonormal basis */

View File

@@ -4,6 +4,11 @@
#pragma once
#include "infos/workbench_prepass_info.hh"
// SHADER_LIBRARY_CREATE_INFO(workbench_color_material)
SHADER_LIBRARY_CREATE_INFO(workbench_color_texture)
void workbench_material_data_get(int handle,
vec3 vertex_color,
out vec3 color,

View File

@@ -2,6 +2,10 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_depth_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_merge_depth)
void main()
{
gl_FragDepth = texture(depth_tx, uvcoordsvar.xy).r;

View File

@@ -4,6 +4,10 @@
/* Prepare the Depth Buffer for the Overlay Engine. */
#include "infos/workbench_depth_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_overlay_depth)
void main()
{
/* Set the depth to 0 for "In Front" objects,

View File

@@ -2,6 +2,12 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_prepass_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_prepass)
FRAGMENT_SHADER_CREATE_INFO(workbench_opaque)
FRAGMENT_SHADER_CREATE_INFO(workbench_lighting_matcap)
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"

View File

@@ -2,8 +2,16 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_prepass_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_prepass)
VERTEX_SHADER_CREATE_INFO(workbench_lighting_flat)
VERTEX_SHADER_CREATE_INFO(workbench_transparent_accum)
VERTEX_SHADER_CREATE_INFO(workbench_curves)
#include "common_hair_lib.glsl"
#include "common_view_clipping_lib.glsl"
#include "draw_model_lib.glsl"
#include "draw_view_clipping_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"
@@ -51,7 +59,7 @@ void main()
float time, thick_time, thickness;
vec3 world_pos, tan, binor;
hair_get_pos_tan_binor_time(is_persp,
ModelMatrixInverse,
drw_modelinv(),
drw_view.viewinv[3].xyz,
drw_view.viewinv[2].xyz,
world_pos,
@@ -70,7 +78,7 @@ void main()
uv_interp = hair_get_customdata_vec2(au);
normal_interp = normalize(normal_world_to_view(nor));
normal_interp = normalize(drw_normal_world_to_view(nor));
workbench_material_data_get(int(drw_CustomID),
hair_get_customdata_vec3(ac),

View File

@@ -2,10 +2,17 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_prepass_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_prepass)
VERTEX_SHADER_CREATE_INFO(workbench_lighting_flat)
VERTEX_SHADER_CREATE_INFO(workbench_transparent_accum)
VERTEX_SHADER_CREATE_INFO(workbench_pointcloud)
#include "draw_view_lib.glsl"
#include "common_pointcloud_lib.glsl"
#include "common_view_clipping_lib.glsl"
#include "draw_pointcloud_lib.glsl"
#include "draw_view_clipping_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"
@@ -16,7 +23,7 @@ void main()
vec3 world_pos;
pointcloud_get_pos_and_nor(world_pos, normal_interp);
normal_interp = normalize(normal_world_to_view(normal_interp));
normal_interp = normalize(drw_normal_world_to_view(normal_interp));
gl_Position = drw_point_world_to_homogenous(world_pos);

View File

@@ -2,8 +2,15 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "common_view_clipping_lib.glsl"
#include "infos/workbench_prepass_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_prepass)
VERTEX_SHADER_CREATE_INFO(workbench_lighting_flat)
VERTEX_SHADER_CREATE_INFO(workbench_transparent_accum)
VERTEX_SHADER_CREATE_INFO(workbench_mesh)
#include "draw_model_lib.glsl"
#include "draw_view_clipping_lib.glsl"
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"
@@ -18,7 +25,7 @@ void main()
uv_interp = au;
normal_interp = normalize(normal_object_to_view(nor));
normal_interp = normalize(drw_normal_object_to_view(nor));
object_id = int(uint(resource_id) & 0xFFFFu) + 1;

View File

@@ -16,9 +16,11 @@
* execute the vertex shader code on each of the input primitive's vertices.
*/
#include "workbench_shadow_lib.glsl"
#include "infos/workbench_shadow_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_shadow_fail_manifold_caps)
VERTEX_SHADER_CREATE_INFO(workbench_shadow_common)
#include "workbench_shadow_lib.glsl"
void emit_cap(bool front,
bool invert,

View File

@@ -2,6 +2,10 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_shadow_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_shadow_debug)
void main()
{
const float a = 0.1;

View File

@@ -4,6 +4,10 @@
#pragma once
#include "infos/workbench_shadow_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_shadow_common)
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"
#include "gpu_shader_attribute_load_lib.glsl"
@@ -11,8 +15,6 @@
#include "gpu_shader_math_vector_lib.glsl"
#include "gpu_shader_utildefines_lib.glsl"
SHADER_LIBRARY_CREATE_INFO(workbench_shadow_common)
struct VertIn {
/* Local position. */
vec3 lP;

View File

@@ -17,6 +17,10 @@
* execute the vertex shader code on each of the input primitive's vertices.
*/
#include "infos/workbench_shadow_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_shadow_common)
#include "workbench_shadow_lib.glsl"
void extrude_edge(

View File

@@ -2,6 +2,10 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_shadow_info.hh"
COMPUTE_SHADER_CREATE_INFO(workbench_shadow_visibility_compute_dynamic_pass_type)
#include "common_intersect_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"

View File

@@ -2,6 +2,12 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_prepass_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_prepass)
FRAGMENT_SHADER_CREATE_INFO(workbench_transparent_accum)
FRAGMENT_SHADER_CREATE_INFO(workbench_lighting_matcap)
#include "draw_view_lib.glsl"
#include "workbench_common_lib.glsl"
#include "workbench_image_lib.glsl"

View File

@@ -7,6 +7,10 @@
* Computer Graphics Techniques (JCGT), vol. 2, no. 2, 122141, 2013
*/
#include "infos/workbench_transparent_resolve_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_transparent_resolve)
void main()
{
/* Revealage is actually stored in transparentAccum alpha channel.

View File

@@ -2,6 +2,14 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_volume_info.hh"
FRAGMENT_SHADER_CREATE_INFO(workbench_volume)
FRAGMENT_SHADER_CREATE_INFO(workbench_volume_slice)
FRAGMENT_SHADER_CREATE_INFO(workbench_volume_coba)
FRAGMENT_SHADER_CREATE_INFO(workbench_volume_cubic)
FRAGMENT_SHADER_CREATE_INFO(workbench_volume_smoke)
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"

View File

@@ -2,6 +2,14 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "infos/workbench_volume_info.hh"
VERTEX_SHADER_CREATE_INFO(workbench_volume)
VERTEX_SHADER_CREATE_INFO(workbench_volume_slice)
VERTEX_SHADER_CREATE_INFO(workbench_volume_coba)
VERTEX_SHADER_CREATE_INFO(workbench_volume_cubic)
VERTEX_SHADER_CREATE_INFO(workbench_volume_smoke)
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"

View File

@@ -4,6 +4,12 @@
#pragma once
#include "infos/workbench_prepass_info.hh"
#ifdef GPU_LIBRARY_SHADER
SHADER_LIBRARY_CREATE_INFO(workbench_prepass)
#endif
/* [Drobot2014a] Low Level Optimizations for GCN */
vec4 fast_rcp(vec4 v)
{

View File

@@ -2,6 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#ifndef GPU_SHADER
# include "GPU_shader_shared_utils.hh"
#endif

View File

@@ -151,6 +151,7 @@ void hair_get_interp_attrs(
*/
# if !defined(HAIR_PHASE_SUBDIV) && defined(GPU_VERTEX_SHADER)
VERTEX_SHADER_CREATE_INFO(draw_hair_new)
int hair_get_strand_id()
{

View File

@@ -8,8 +8,6 @@
#include "draw_view_lib.glsl"
SHADER_LIBRARY_CREATE_INFO(draw_modelmat_new)
#if !defined(DRAW_MODELMAT_CREATE_INFO) && !defined(GLSL_CPP_STUBS)
# error Missing draw_modelmat additional create info on shader create info
#endif
@@ -34,6 +32,9 @@ VERTEX_SHADER_CREATE_INFO(draw_resource_id_varying)
#elif defined(GPU_FRAGMENT_SHADER)
FRAGMENT_SHADER_CREATE_INFO(draw_resource_id_varying)
# define resource_id drw_ResourceID_iface.resource_index
#elif defined(GPU_LIBRARY_SHADER)
SHADER_LIBRARY_CREATE_INFO(draw_resource_id_varying)
# define resource_id drw_ResourceID_iface.resource_index
#endif
mat4x4 drw_modelmat()

View File

@@ -9,6 +9,15 @@
# include "draw_shader_shared.hh"
# include "draw_view_info.hh"
# define HAIR_SHADER
# define OrcoTexCoFactors (drw_infos[resource_id].orco_mul_bias)
# define ObjectInfo (drw_infos[resource_id].infos)
# define ObjectColor (drw_infos[resource_id].ob_color)
# define ObjectAttributeStart (drw_infos[resource_id].orco_mul_bias[0].w)
# define ObjectAttributeLen (drw_infos[resource_id].orco_mul_bias[1].w)
#endif
#include "draw_defines.hh"

View File

@@ -0,0 +1,133 @@
/* SPDX-FileCopyrightText: 2020-2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "draw_model_lib.glsl"
#include "draw_view_lib.glsl"
/* NOTE: To be used with UNIFORM_RESOURCE_ID and INSTANCED_ATTR as define. */
#ifdef POINTCLOUD_SHADER
# define COMMON_POINTCLOUD_LIB
# ifndef DRW_POINTCLOUD_INFO
# error Ensure createInfo includes draw_pointcloud.
# endif
int pointcloud_get_point_id()
{
# ifdef GPU_VERTEX_SHADER
/* Remove shape indices. */
return gl_VertexID >> 3;
# endif
return 0;
}
mat3 pointcloud_get_facing_matrix(vec3 p)
{
mat3 facing_mat;
facing_mat[2] = drw_world_incident_vector(p);
facing_mat[1] = normalize(cross(drw_view.viewinv[0].xyz, facing_mat[2]));
facing_mat[0] = cross(facing_mat[1], facing_mat[2]);
return facing_mat;
}
/* Returns world center position and radius. */
void pointcloud_get_pos_and_radius(out vec3 outpos, out float outradius)
{
int id = pointcloud_get_point_id();
vec4 pos_rad = texelFetch(ptcloud_pos_rad_tx, id);
outpos = drw_point_object_to_world(pos_rad.xyz);
outradius = dot(abs(to_float3x3(ModelMatrix) * pos_rad.www), vec3(1.0 / 3.0));
}
/* Return world position and normal. */
void pointcloud_get_pos_nor_radius(out vec3 outpos, out vec3 outnor, out float outradius)
{
vec3 p;
float radius;
pointcloud_get_pos_and_radius(p, radius);
mat3 facing_mat = pointcloud_get_facing_matrix(p);
uint vert_id = 0u;
# ifdef GPU_VERTEX_SHADER
/* Mask point indices. */
vert_id = uint(gl_VertexID) & ~(0xFFFFFFFFu << 3u);
# endif
vec3 pos_inst = vec3(0.0);
switch (vert_id) {
case 0:
pos_inst.z = 1.0;
break;
case 1:
pos_inst.x = 1.0;
break;
case 2:
pos_inst.y = 1.0;
break;
case 3:
pos_inst.x = -1.0;
break;
case 4:
pos_inst.y = -1.0;
break;
}
/* TODO(fclem): remove multiplication here. Here only for keeping the size correct for now. */
radius *= 0.01;
outnor = facing_mat * pos_inst;
outpos = p + outnor * radius;
outradius = radius;
}
/* Return world position and normal. */
void pointcloud_get_pos_and_nor(out vec3 outpos, out vec3 outnor)
{
vec3 nor, pos;
float radius;
pointcloud_get_pos_nor_radius(pos, nor, radius);
outpos = pos;
outnor = nor;
}
vec3 pointcloud_get_pos()
{
vec3 outpos, outnor;
pointcloud_get_pos_and_nor(outpos, outnor);
return outpos;
}
float pointcloud_get_customdata_float(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).r;
}
vec2 pointcloud_get_customdata_vec2(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).rg;
}
vec3 pointcloud_get_customdata_vec3(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).rgb;
}
vec4 pointcloud_get_customdata_vec4(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).rgba;
}
vec2 pointcloud_get_barycentric()
{
/* TODO: To be implemented. */
return vec2(0.0);
}
#endif

View File

@@ -0,0 +1,61 @@
/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "draw_view_info.hh"
#if defined(GPU_VERTEX_SHADER) || defined(GPU_GEOMETRY_SHADER)
VERTEX_SHADER_CREATE_INFO(drw_clipped)
void view_clipping_distances(vec3 wpos)
{
# ifdef USE_WORLD_CLIP_PLANES
vec4 pos_4d = vec4(wpos, 1.0);
# ifdef OVERLAY_NEXT
gl_ClipDistance[0] = dot(globalsBlock.clip_planes[0], pos_4d);
gl_ClipDistance[1] = dot(globalsBlock.clip_planes[1], pos_4d);
gl_ClipDistance[2] = dot(globalsBlock.clip_planes[2], pos_4d);
gl_ClipDistance[3] = dot(globalsBlock.clip_planes[3], pos_4d);
gl_ClipDistance[4] = dot(globalsBlock.clip_planes[4], pos_4d);
gl_ClipDistance[5] = dot(globalsBlock.clip_planes[5], pos_4d);
# else
gl_ClipDistance[0] = dot(drw_clipping_[0], pos_4d);
gl_ClipDistance[1] = dot(drw_clipping_[1], pos_4d);
gl_ClipDistance[2] = dot(drw_clipping_[2], pos_4d);
gl_ClipDistance[3] = dot(drw_clipping_[3], pos_4d);
gl_ClipDistance[4] = dot(drw_clipping_[4], pos_4d);
gl_ClipDistance[5] = dot(drw_clipping_[5], pos_4d);
# endif
# endif
}
void view_clipping_distances_bypass()
{
# ifdef USE_WORLD_CLIP_PLANES
gl_ClipDistance[0] = 1.0;
gl_ClipDistance[1] = 1.0;
gl_ClipDistance[2] = 1.0;
gl_ClipDistance[3] = 1.0;
gl_ClipDistance[4] = 1.0;
gl_ClipDistance[5] = 1.0;
# endif
}
/* Kept as define for compiler compatibility. */
# ifdef USE_WORLD_CLIP_PLANES
# define view_clipping_distances_set(c) \
gl_ClipDistance[0] = (c).gl_ClipDistance[0]; \
gl_ClipDistance[1] = (c).gl_ClipDistance[1]; \
gl_ClipDistance[2] = (c).gl_ClipDistance[2]; \
gl_ClipDistance[3] = (c).gl_ClipDistance[3]; \
gl_ClipDistance[4] = (c).gl_ClipDistance[4]; \
gl_ClipDistance[5] = (c).gl_ClipDistance[5];
# else
# define view_clipping_distances_set(c)
# endif
#endif

View File

@@ -17,6 +17,7 @@
# define DRAW_VIEW_CREATE_INFO
# define DRW_VIEW_CULLING_INFO
# define DRW_LEGACY_MODEL_MATRIX
# define USE_WORLD_CLIP_PLANES
# define drw_ModelMatrix drw_matrix_buf[resource_id].model
# define drw_ModelMatrixInverse drw_matrix_buf[resource_id].model_inverse
@@ -26,7 +27,6 @@
# define gpThicknessIsScreenSpace (gpThicknessWorldScale < 0.0)
# define ModelMatrix drw_ModelMatrix
# define ModelMatrixInverse drw_ModelMatrixInverse
# define resource_handle drw_ResourceID
#endif
#include "gpu_shader_create_info.hh"
@@ -270,3 +270,11 @@ COMPUTE_SOURCE("draw_command_generate_comp.glsl")
GPU_SHADER_CREATE_END()
/** \} */
/* Stub needs to be after all definitions to avoid conflict with legacy definitions. */
#ifdef GPU_SHADER
/* Make it work for both draw_resource_id_new and draw_resource_with_custom_id_new. */
# define drw_ResourceID vec2(resource_id_buf[gpu_BaseInstance + gl_InstanceID]).x
# define drw_CustomID drw_ResourceID
# define resource_handle drw_ResourceID
#endif

View File

@@ -1363,18 +1363,18 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord,
float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.xz, int2(0, 1)).g;
// Get the area for this direction:
weights.ba = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.x);
weights.zw = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.x);
// Fix corners:
coords.x = texcoord.x;
# ifdef GPU_METAL
/* Partial vector references are unsupported in MSL. */
vec2 _weights = weights.ba;
vec2 _weights = weights.zw;
SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), _weights, coords.xyxz, d);
weights.ba = _weights;
weights.zw = _weights;
# else
SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, d);
SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.zw, coords.xyxz, d);
# endif
}

View File

@@ -265,6 +265,8 @@ template<> struct VecBase<bool, 2> : VecSwizzle2<bool> {
VecBase() = default;
explicit VecBase(bool) {}
explicit VecBase(bool, bool) {}
/* Should be forbidden, but is used by SMAA. */
explicit VecBase(VecBase<double, 2>) {}
};
template<> struct VecBase<bool, 3> : VecSwizzle3<bool> {
@@ -492,6 +494,7 @@ TEX_TEMPLATE DataVec texture(T, FltCoord, double /*bias*/ = 0.0) RET;
TEX_TEMPLATE DataVec textureGather(T, FltCoord) RET;
TEX_TEMPLATE DataVec textureGrad(T, FltCoord, DerivVec, DerivVec) RET;
TEX_TEMPLATE DataVec textureLod(T, FltCoord, double) RET;
TEX_TEMPLATE DataVec textureLodOffset(T, FltCoord, double, IntCoord) RET;
#undef TEX_TEMPLATE
@@ -675,7 +678,8 @@ template<typename T, typename U> T pow(T, U) RET;
template<typename T> T round(T) RET;
template<typename T> T smoothstep(T, T, T) RET;
template<typename T> T sqrt(T) RET;
template<typename T> T step(T, T) RET;
template<int D> VecBase<double, D> step(VecBase<double, D>, VecBase<double, D>) RET;
template<int D> VecBase<double, D> step(double, VecBase<double, D>) RET;
template<typename T> T trunc(T) RET;
template<typename T, typename U> T ldexp(T, U) RET;
double smoothstep(double, double, double) RET;
@@ -729,9 +733,10 @@ template<typename T> T fwidth(T) RET;
} // namespace gl_FragmentShader
/* Geometric functions. */
template<typename T, int D> float faceforward(VecBase<T, D>, VecBase<T, D>, VecBase<T, D>) RET;
template<typename T, int D> float reflect(VecBase<T, D>, VecBase<T, D>) RET;
template<typename T, int D> float refract(VecBase<T, D>, VecBase<T, D>, double) RET;
template<typename T, int D>
VecBase<T, D> faceforward(VecBase<T, D>, VecBase<T, D>, VecBase<T, D>) RET;
template<typename T, int D> VecBase<T, D> reflect(VecBase<T, D>, VecBase<T, D>) RET;
template<typename T, int D> VecBase<T, D> refract(VecBase<T, D>, VecBase<T, D>, double) RET;
/* Atomic operations. */
int atomicAdd(int &, int) RET;
@@ -786,7 +791,8 @@ namespace gl_VertexShader {
const int gl_VertexID = 0;
const int gl_InstanceID = 0;
const int gl_BaseVertex = 0;
const int gl_BaseInstance = 0;
const int gpu_BaseInstance = 0;
const int gpu_InstanceIndex = 0;
float4 gl_Position = float4(0);
double gl_PointSize = 0;
float gl_ClipDistance[6] = {0};