/* SPDX-License-Identifier: GPL-2.0-or-later */ /** * Shared structures, enums & defines between C++ and GLSL. * Can also include some math functions but they need to be simple enough to be valid in both * language. */ #ifndef USE_GPU_SHADER_CREATE_INFO # pragma once # include "BLI_memory_utils.hh" # include "DRW_gpu_wrapper.hh" // # include "eevee_defines.hh" # include "GPU_shader_shared.h" namespace blender::eevee { using draw::Framebuffer; using draw::SwapChain; using draw::Texture; using draw::TextureFromPool; #endif #define UBO_MIN_MAX_SUPPORTED_SIZE 1 << 14 /* -------------------------------------------------------------------- */ /** \name Camera * \{ */ enum eCameraType : uint32_t { CAMERA_PERSP = 0u, CAMERA_ORTHO = 1u, CAMERA_PANO_EQUIRECT = 2u, CAMERA_PANO_EQUISOLID = 3u, CAMERA_PANO_EQUIDISTANT = 4u, CAMERA_PANO_MIRROR = 5u }; static inline bool is_panoramic(eCameraType type) { return type > CAMERA_ORTHO; } struct CameraData { /* View Matrices of the camera, not from any view! */ float4x4 persmat; float4x4 persinv; float4x4 viewmat; float4x4 viewinv; float4x4 winmat; float4x4 wininv; /** Camera UV scale and bias. Also known as `viewcamtexcofac`. */ float2 uv_scale; float2 uv_bias; /** Panorama parameters. */ float2 equirect_scale; float2 equirect_scale_inv; float2 equirect_bias; float fisheye_fov; float fisheye_lens; /** Clipping distances. */ float clip_near; float clip_far; /** Film pixel filter radius. */ float filter_size; eCameraType type; }; BLI_STATIC_ASSERT_ALIGN(CameraData, 16) /** \} */ /* -------------------------------------------------------------------- */ /** \name VelocityModule * \{ */ #define VELOCITY_INVALID 512.0 enum eVelocityStep : uint32_t { STEP_PREVIOUS = 0, STEP_NEXT = 1, STEP_CURRENT = 2, }; struct VelocityObjectIndex { /** Offset inside #VelocityObjectBuf for each timestep. Indexed using eVelocityStep. */ int3 ofs; /** Temporary index to copy this to the #VelocityIndexBuf. */ uint resource_id; #ifdef __cplusplus VelocityObjectIndex() : ofs(-1, -1, -1), resource_id(-1){}; #endif }; BLI_STATIC_ASSERT_ALIGN(VelocityObjectIndex, 16) struct VelocityGeometryIndex { /** Offset inside #VelocityGeometryBuf for each timestep. Indexed using eVelocityStep. */ int3 ofs; /** If true, compute deformation motion blur. */ bool1 do_deform; /** Length of data inside #VelocityGeometryBuf for each timestep. Indexed using eVelocityStep. */ int3 len; int _pad0; #ifdef __cplusplus VelocityGeometryIndex() : ofs(-1, -1, -1), do_deform(false), len(-1, -1, -1), _pad0(1){}; #endif }; BLI_STATIC_ASSERT_ALIGN(VelocityGeometryIndex, 16) struct VelocityIndex { VelocityObjectIndex obj; VelocityGeometryIndex geo; }; BLI_STATIC_ASSERT_ALIGN(VelocityGeometryIndex, 16) /** \} */ /* -------------------------------------------------------------------- */ /** \name Ray-Tracing * \{ */ enum eClosureBits : uint32_t { /** NOTE: These are used as stencil bits. So we are limited to 8bits. */ CLOSURE_DIFFUSE = (1u << 0u), CLOSURE_SSS = (1u << 1u), CLOSURE_REFLECTION = (1u << 2u), CLOSURE_REFRACTION = (1u << 3u), /* Non-stencil bits. */ CLOSURE_TRANSPARENCY = (1u << 8u), CLOSURE_EMISSION = (1u << 9u), CLOSURE_HOLDOUT = (1u << 10u), CLOSURE_VOLUME = (1u << 11u), CLOSURE_AMBIENT_OCCLUSION = (1u << 12u), }; /** \} */ /* -------------------------------------------------------------------- */ /** \name Utility Texture * \{ */ #define UTIL_TEX_SIZE 64 #define UTIL_BTDF_LAYER_COUNT 16 /* Scale and bias to avoid interpolation of the border pixel. * Remap UVs to the border pixels centers. */ #define UTIL_TEX_UV_SCALE ((UTIL_TEX_SIZE - 1.0f) / UTIL_TEX_SIZE) #define UTIL_TEX_UV_BIAS (0.5f / UTIL_TEX_SIZE) #define UTIL_BLUE_NOISE_LAYER 0 #define UTIL_LTC_MAT_LAYER 1 #define UTIL_LTC_MAG_LAYER 2 #define UTIL_BSDF_LAYER 2 #define UTIL_BTDF_LAYER 3 #define UTIL_DISK_INTEGRAL_LAYER 3 #define UTIL_DISK_INTEGRAL_COMP 2 #ifndef __cplusplus /* Fetch texel. Wrapping if above range. */ float4 utility_tx_fetch(sampler2DArray util_tx, float2 texel, float layer) { return texelFetch(util_tx, int3(int2(texel) % UTIL_TEX_SIZE, layer), 0); } /* Sample at uv position. Filtered & Wrapping enabled. */ float4 utility_tx_sample(sampler2DArray util_tx, float2 uv, float layer) { return textureLod(util_tx, float3(uv, layer), 0.0); } #endif /** \} */ #ifdef __cplusplus using CameraDataBuf = draw::UniformBuffer; using VelocityIndexBuf = draw::StorageArrayBuffer; using VelocityObjectBuf = draw::StorageArrayBuffer; using VelocityGeometryBuf = draw::StorageArrayBuffer; } // namespace blender::eevee #endif