diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-01-27 21:33:09 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-01-27 21:33:09 +0300 |
commit | ea577c499ffc4e7c98b6a8d964a6a2f13c404280 (patch) | |
tree | ca3bd70af24819bd77c2838010e10e9bbba7c8cf /source | |
parent | 0ea5f3fb5d26fed20e42f84aa4f3e7e3e0ab5ec6 (diff) |
EEVEE: Make use of float4x4 instead of float[4][4] and rename vectors
This follows the type defined in `gpu_shader_shared_utils.h`.
Diffstat (limited to 'source')
30 files changed, 295 insertions, 345 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_build.cc b/source/blender/draw/engines/eevee/eevee_build.cc index 59be843fcbb..94e0a0a08b9 100644 --- a/source/blender/draw/engines/eevee/eevee_build.cc +++ b/source/blender/draw/engines/eevee/eevee_build.cc @@ -36,7 +36,7 @@ using namespace std; typedef unsigned char uchar; -typedef float vec3[3]; +typedef float float3[3]; const int samples_per_pool = 32; @@ -53,11 +53,11 @@ static void raytrace_sample_reuse_table(string &output_name, bool debug) }; array<vector<sample>, 4> pools; - array<vec3, 4> pools_color = {1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0}; - vector<vec3> debug_image(64 * 64); + array<float3, 4> pools_color = {1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0}; + vector<float3> debug_image(64 * 64); ofstream ppm; - auto ppm_file_out = [&](const char *name, vector<vec3> &debug_image) { + auto ppm_file_out = [&](const char *name, vector<float3> &debug_image) { ppm.open(name); ppm << "P3\n64 64\n255\n"; for (auto &vec : debug_image) { @@ -123,11 +123,11 @@ static void raytrace_sample_reuse_table(string &output_name, bool debug) table_out << "\n/* Sample table generated at build time. */\n"; table_out << "const int resolve_sample_max = " << samples_per_pool << ";\n"; - table_out << "const vec2 resolve_sample_offsets[" << total << "] = vec2[" << total << "](\n"; + table_out << "const float2 resolve_sample_offsets[" << total << "] = float2[" << total << "](\n"; for (int pool_id = 0; pool_id < 4; pool_id++) { auto &pool = pools[poolmap[pool_id]]; for (int i = 0; i < samples_per_pool; i++) { - table_out << " vec2(" << pool[i].x << ", " << pool[i].y << ")"; + table_out << " float2(" << pool[i].x << ", " << pool[i].y << ")"; if (i < samples_per_pool - 1) { table_out << ",\n"; } diff --git a/source/blender/draw/engines/eevee/eevee_camera.cc b/source/blender/draw/engines/eevee/eevee_camera.cc index 3af221e8689..b7555fb7cb0 100644 --- a/source/blender/draw/engines/eevee/eevee_camera.cc +++ b/source/blender/draw/engines/eevee/eevee_camera.cc @@ -99,33 +99,33 @@ void Camera::sync(void) data.filter_size = inst_.scene->r.gauss; if (inst_.drw_view) { - DRW_view_viewmat_get(inst_.drw_view, data.viewmat, false); - DRW_view_viewmat_get(inst_.drw_view, data.viewinv, true); - DRW_view_winmat_get(inst_.drw_view, data.winmat, false); - DRW_view_winmat_get(inst_.drw_view, data.wininv, true); - DRW_view_persmat_get(inst_.drw_view, data.persmat, false); - DRW_view_persmat_get(inst_.drw_view, data.persinv, true); + DRW_view_viewmat_get(inst_.drw_view, data.viewmat.ptr(), false); + DRW_view_viewmat_get(inst_.drw_view, data.viewinv.ptr(), true); + DRW_view_winmat_get(inst_.drw_view, data.winmat.ptr(), false); + DRW_view_winmat_get(inst_.drw_view, data.wininv.ptr(), true); + DRW_view_persmat_get(inst_.drw_view, data.persmat.ptr(), false); + DRW_view_persmat_get(inst_.drw_view, data.persinv.ptr(), true); DRW_view_camtexco_get(inst_.drw_view, data.uv_scale); } else if (inst_.render) { /* TODO(fclem) Overscan */ // RE_GetCameraWindowWithOverscan(inst_.render->re, g_data->overscan, data.winmat); - RE_GetCameraWindow(inst_.render->re, camera_eval, data.winmat); - RE_GetCameraModelMatrix(inst_.render->re, camera_eval, data.viewinv); - invert_m4_m4(data.viewmat, data.viewinv); - invert_m4_m4(data.wininv, data.winmat); - mul_m4_m4m4(data.persmat, data.winmat, data.viewmat); - invert_m4_m4(data.persinv, data.persmat); - data.uv_scale = vec2(1.0f); - data.uv_bias = vec2(0.0f); + RE_GetCameraWindow(inst_.render->re, camera_eval, data.winmat.ptr()); + RE_GetCameraModelMatrix(inst_.render->re, camera_eval, data.viewinv.ptr()); + invert_m4_m4(data.viewmat.ptr(), data.viewinv.ptr()); + invert_m4_m4(data.wininv.ptr(), data.winmat.ptr()); + mul_m4_m4m4(data.persmat.ptr(), data.winmat.ptr(), data.viewmat.ptr()); + invert_m4_m4(data.persinv.ptr(), data.persmat.ptr()); + data.uv_scale = float2(1.0f); + data.uv_bias = float2(0.0f); } else { - unit_m4(data.viewmat); - unit_m4(data.viewinv); - perspective_m4(data.winmat, -0.1f, 0.1f, -0.1f, 0.1f, 0.1f, 1.0f); - invert_m4_m4(data.wininv, data.winmat); - mul_m4_m4m4(data.persmat, data.winmat, data.viewmat); - invert_m4_m4(data.persinv, data.persmat); + data.viewmat.identity(); + data.viewinv.identity(); + perspective_m4(data.winmat.ptr(), -0.1f, 0.1f, -0.1f, 0.1f, 0.1f, 1.0f); + data.wininv = data.winmat.inverted(); + data.persmat = data.winmat * data.viewmat; + data.persinv = data.persmat.inverted(); } if (camera_eval) { @@ -148,8 +148,8 @@ void Camera::sync(void) data.clip_near = DRW_view_near_distance_get(inst_.drw_view); data.clip_far = DRW_view_far_distance_get(inst_.drw_view); data.fisheye_fov = data.fisheye_lens = -1.0f; - data.equirect_bias = vec2(0.0f); - data.equirect_scale = vec2(0.0f); + data.equirect_bias = float2(0.0f); + data.equirect_scale = float2(0.0f); } data_[data_id_].push_update(); diff --git a/source/blender/draw/engines/eevee/eevee_camera.hh b/source/blender/draw/engines/eevee/eevee_camera.hh index f2aadf6391e..f4cb06e9e4e 100644 --- a/source/blender/draw/engines/eevee/eevee_camera.hh +++ b/source/blender/draw/engines/eevee/eevee_camera.hh @@ -67,10 +67,10 @@ static const float cubeface_mat[6][4][4] = { {0.0f, 0.0f, 0.0f, 1.0f}}, }; -inline void cubeface_winmat_get(mat4 &winmat, float near, float far) +inline void cubeface_winmat_get(float4x4 &winmat, float near, float far) { /* Simple 90° FOV projection. */ - perspective_m4(winmat, -near, near, -near, near, near, far); + perspective_m4(winmat.ptr(), -near, near, -near, near, near, far); } /* -------------------------------------------------------------------- */ @@ -79,7 +79,7 @@ inline void cubeface_winmat_get(mat4 &winmat, float near, float far) inline bool operator==(const CameraData &a, const CameraData &b) { - return compare_m4m4(a.persmat, b.persmat, FLT_MIN) && (a.uv_scale == b.uv_scale) && + return compare_m4m4(a.persmat.ptr(), b.persmat.ptr(), FLT_MIN) && (a.uv_scale == b.uv_scale) && (a.uv_bias == b.uv_bias) && (a.equirect_scale == b.equirect_scale) && (a.equirect_bias == b.equirect_bias) && (a.fisheye_fov == b.fisheye_fov) && (a.fisheye_lens == b.fisheye_lens) && (a.filter_size == b.filter_size) && @@ -138,9 +138,9 @@ class Camera { { return data_[data_id_].type == CAMERA_ORTHO; } - vec3 position(void) const + float3 position(void) const { - return vec3(data_[data_id_].viewinv[3]); + return float3(data_[data_id_].viewinv[3]); } }; diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.cc b/source/blender/draw/engines/eevee/eevee_depth_of_field.cc index 959bf0df259..27912977a06 100644 --- a/source/blender/draw/engines/eevee/eevee_depth_of_field.cc +++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.cc @@ -69,7 +69,7 @@ void DepthOfField::init(void) jitter_radius_ = 0.0f; } -void DepthOfField::sync(const mat4 winmat, ivec2 input_extent) +void DepthOfField::sync(const float4x4 winmat, int2 input_extent) { const Object *camera_object_eval = inst_.camera_eval_object; const ::Camera *cam = (camera_object_eval) ? @@ -136,8 +136,8 @@ void DepthOfField::sync(const mat4 winmat, ivec2 input_extent) /* OPTI(fclem) Could be optimized. */ float jitter[3] = {fx_radius_, 0.0f, -focus_distance_}; float center[3] = {0.0f, 0.0f, -focus_distance_}; - mul_project_m4_v3(winmat, jitter); - mul_project_m4_v3(winmat, center); + mul_project_m4_v3(winmat.ptr(), jitter); + mul_project_m4_v3(winmat.ptr(), center); /* Simplify CoC calculation to a simple MADD. */ if (data_.camera_type != CAMERA_ORTHO) { data_.coc_bias = -(center[0] - jitter[0]) * 0.5f * extent_[0]; @@ -169,7 +169,7 @@ void DepthOfField::sync(const mat4 winmat, ivec2 input_extent) } } -void DepthOfField::jitter_apply(mat4 winmat, mat4 viewmat) +void DepthOfField::jitter_apply(float4x4 winmat, float4x4 viewmat) { if (jitter_radius_ == 0.0f) { return; @@ -185,13 +185,13 @@ void DepthOfField::jitter_apply(mat4 winmat, mat4 viewmat) theta += data_.bokeh_rotation; /* Sample in View Space. */ - vec2 sample = vec2(radius * cosf(theta), radius * sinf(theta)); + float2 sample = float2(radius * cosf(theta), radius * sinf(theta)); sample *= data_.bokeh_anisotropic_scale; /* Convert to NDC Space. */ - vec3 jitter = vec3(UNPACK2(sample), -focus_distance_); - vec3 center = vec3(0.0f, 0.0f, -focus_distance_); - mul_project_m4_v3(winmat, jitter); - mul_project_m4_v3(winmat, center); + float3 jitter = float3(UNPACK2(sample), -focus_distance_); + float3 center = float3(0.0f, 0.0f, -focus_distance_); + mul_project_m4_v3(winmat.ptr(), jitter); + mul_project_m4_v3(winmat.ptr(), center); const bool is_ortho = (winmat[2][3] != -1.0f); if (is_ortho) { @@ -236,7 +236,7 @@ void DepthOfField::render(GPUTexture *depth_tx, GPUTexture **input_tx, GPUTextur **/ void DepthOfField::bokeh_lut_pass_sync(void) { - const bool has_anisotropy = data_.bokeh_anisotropic_scale != vec2(1.0f); + const bool has_anisotropy = data_.bokeh_anisotropic_scale != float2(1.0f); if (has_anisotropy && (data_.bokeh_blades == 0.0)) { bokeh_gather_lut_tx_ = nullptr; bokeh_scatter_lut_tx_ = nullptr; diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.hh b/source/blender/draw/engines/eevee/eevee_depth_of_field.hh index c0fe3abf970..afcbec981b4 100644 --- a/source/blender/draw/engines/eevee/eevee_depth_of_field.hh +++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.hh @@ -122,7 +122,7 @@ class DepthOfField { /** Focus distance in view space. */ float focus_distance_; /** Extent of the input buffer. */ - ivec2 extent_; + int2 extent_; /** Tile dilation uniforms. */ int tiles_dilate_slight_focus_; @@ -141,10 +141,10 @@ class DepthOfField { void init(); - void sync(const mat4 winmat, ivec2 input_extent); + void sync(const float4x4 winmat, int2 input_extent); /** Apply Depth Of Field jittering to the view and projection matrices.. */ - void jitter_apply(mat4 winmat, mat4 viewmat); + void jitter_apply(float4x4 winmat, float4x4 viewmat); /** Will swap input and output texture if rendering happens. The actual output of this function * is in intput_tx. */ diff --git a/source/blender/draw/engines/eevee/eevee_film.cc b/source/blender/draw/engines/eevee/eevee_film.cc index e77aba39928..ee2d872e0c2 100644 --- a/source/blender/draw/engines/eevee/eevee_film.cc +++ b/source/blender/draw/engines/eevee/eevee_film.cc @@ -78,11 +78,11 @@ inline bool operator!=(const FilmData &a, const FilmData &b) /** \name Film * \{ */ -void Film::init(const ivec2 &full_extent, const rcti *output_rect) +void Film::init(const int2 &full_extent, const rcti *output_rect) { FilmData data = data_; - data.extent = ivec2(BLI_rcti_size_x(output_rect), BLI_rcti_size_y(output_rect)); - data.offset = ivec2(output_rect->xmin, output_rect->ymin); + data.extent = int2(BLI_rcti_size_x(output_rect), BLI_rcti_size_y(output_rect)); + data.offset = int2(output_rect->xmin, output_rect->ymin); has_changed_ = data_ != data; @@ -92,9 +92,9 @@ void Film::init(const ivec2 &full_extent, const rcti *output_rect) } data_.opacity = 1.0f; - data_.uv_scale_inv = vec2(full_extent); + data_.uv_scale_inv = float2(full_extent); data_.uv_scale = 1.0f / data_.uv_scale_inv; - data_.uv_bias = vec2(data_.offset) * data_.uv_scale; + data_.uv_bias = float2(data_.offset) * data_.uv_scale; } void Film::sync(void) diff --git a/source/blender/draw/engines/eevee/eevee_film.hh b/source/blender/draw/engines/eevee/eevee_film.hh index 16c156ac181..ae1c25c6ea5 100644 --- a/source/blender/draw/engines/eevee/eevee_film.hh +++ b/source/blender/draw/engines/eevee/eevee_film.hh @@ -89,7 +89,7 @@ class Film { ~Film(){}; - void init(const ivec2 &full_extent, const rcti *output_rect); + void init(const int2 &full_extent, const rcti *output_rect); void sync(void); void end_sync(void); diff --git a/source/blender/draw/engines/eevee/eevee_gbuffer.hh b/source/blender/draw/engines/eevee/eevee_gbuffer.hh index 271094e27d4..e659a30c79c 100644 --- a/source/blender/draw/engines/eevee/eevee_gbuffer.hh +++ b/source/blender/draw/engines/eevee/eevee_gbuffer.hh @@ -116,7 +116,7 @@ struct GBuffer { void prepare(eClosureBits closures_used) { - ivec2 extent = {GPU_texture_width(depth_tx), GPU_texture_height(depth_tx)}; + int2 extent = {GPU_texture_width(depth_tx), GPU_texture_height(depth_tx)}; /* TODO Reuse for different config. */ if (closures_used & (CLOSURE_DIFFUSE | CLOSURE_SSS | CLOSURE_REFRACTION)) { diff --git a/source/blender/draw/engines/eevee/eevee_hizbuffer.cc b/source/blender/draw/engines/eevee/eevee_hizbuffer.cc index ab9c6e89a26..9658b7e0c83 100644 --- a/source/blender/draw/engines/eevee/eevee_hizbuffer.cc +++ b/source/blender/draw/engines/eevee/eevee_hizbuffer.cc @@ -57,8 +57,8 @@ void HiZBufferModule::sync(void) void HiZBuffer::prepare(GPUTexture *depth_src_tx) { int div = 1 << mip_count_; - vec2 extent_src(GPU_texture_width(depth_src_tx), GPU_texture_height(depth_src_tx)); - ivec2 extent_hiz(divide_ceil_u(extent_src.x, div) * div, divide_ceil_u(extent_src.y, div) * div); + float2 extent_src(GPU_texture_width(depth_src_tx), GPU_texture_height(depth_src_tx)); + int2 extent_hiz(divide_ceil_u(extent_src.x, div) * div, divide_ceil_u(extent_src.y, div) * div); inst_.hiz.data_.pixel_to_ndc = 2.0f / extent_src; inst_.hiz.texel_size_ = 1.0f / float2(extent_hiz); @@ -85,7 +85,7 @@ void HiZBuffer::update(GPUTexture *depth_src_tx) { DRW_stats_group_start("Hiz"); - inst_.hiz.texel_size_ = 1.0f / vec2(GPU_texture_width(hiz_tx_), GPU_texture_height(hiz_tx_)); + inst_.hiz.texel_size_ = 1.0f / float2(GPU_texture_width(hiz_tx_), GPU_texture_height(hiz_tx_)); inst_.hiz.input_depth_tx_ = depth_src_tx; GPU_framebuffer_bind(hiz_fb_); diff --git a/source/blender/draw/engines/eevee/eevee_hizbuffer.hh b/source/blender/draw/engines/eevee/eevee_hizbuffer.hh index d724af0306c..6b98f6a5c9a 100644 --- a/source/blender/draw/engines/eevee/eevee_hizbuffer.hh +++ b/source/blender/draw/engines/eevee/eevee_hizbuffer.hh @@ -85,7 +85,7 @@ class HiZBufferModule { /** References only. */ GPUTexture *input_depth_tx_ = nullptr; /** Pixel size of the render target during hiz downsampling. */ - vec2 texel_size_; + float2 texel_size_; public: HiZBufferModule(Instance &inst) : inst_(inst){}; diff --git a/source/blender/draw/engines/eevee/eevee_instance.cc b/source/blender/draw/engines/eevee/eevee_instance.cc index f614d4b4a97..a7de66e787b 100644 --- a/source/blender/draw/engines/eevee/eevee_instance.cc +++ b/source/blender/draw/engines/eevee/eevee_instance.cc @@ -44,7 +44,7 @@ namespace blender::eevee { * Any attempt to do so will likely produce use after free situations. * \{ */ -void Instance::init(const ivec2 &output_res, +void Instance::init(const int2 &output_res, const rcti *output_rect, RenderEngine *render_, Depsgraph *depsgraph_, diff --git a/source/blender/draw/engines/eevee/eevee_instance.hh b/source/blender/draw/engines/eevee/eevee_instance.hh index 3079f931231..3b4d9941051 100644 --- a/source/blender/draw/engines/eevee/eevee_instance.hh +++ b/source/blender/draw/engines/eevee/eevee_instance.hh @@ -125,7 +125,7 @@ class Instance { lookdev(*this){}; ~Instance(){}; - void init(const ivec2 &output_res, + void init(const int2 &output_res, const rcti *output_rect, RenderEngine *render, Depsgraph *depsgraph, diff --git a/source/blender/draw/engines/eevee/eevee_light.cc b/source/blender/draw/engines/eevee/eevee_light.cc index bcc68d773f5..d260d936fc2 100644 --- a/source/blender/draw/engines/eevee/eevee_light.cc +++ b/source/blender/draw/engines/eevee/eevee_light.cc @@ -73,10 +73,10 @@ void Light::sync(ShadowModule &shadows, const Object *ob, float threshold) (1.0f / square_f(influence_radius_volume)) : 0.0f; - this->color = vec3(&la->r) * la->energy; - normalize_m4_m4_ex(this->object_mat, ob->obmat, scale); + this->color = float3(&la->r) * la->energy; + normalize_m4_m4_ex(this->object_mat.ptr(), ob->obmat, scale); /* Make sure we have consistent handedness (in case of negatively scaled Z axis). */ - vec3 cross = math::cross(float3(this->_right), float3(this->_up)); + float3 cross = math::cross(float3(this->_right), float3(this->_up)); if (math::dot(cross, float3(this->_back)) < 0.0f) { negate_v3(this->_up); } @@ -411,7 +411,7 @@ void LightModule::debug_end_sync(void) } /* Compute acceleration structure for the given view. If extent is 0, bind no lights. */ -void LightModule::set_view(const DRWView *view, const ivec2 extent, bool enable_specular) +void LightModule::set_view(const DRWView *view, const int2 extent, bool enable_specular) { const bool no_lights = (extent.x == 0); diff --git a/source/blender/draw/engines/eevee/eevee_light.hh b/source/blender/draw/engines/eevee/eevee_light.hh index 254d9231eef..98d7fa1656f 100644 --- a/source/blender/draw/engines/eevee/eevee_light.hh +++ b/source/blender/draw/engines/eevee/eevee_light.hh @@ -127,7 +127,7 @@ class LightModule { void sync_light(const Object *ob, ObjectHandle &handle); void end_sync(void); - void set_view(const DRWView *view, const ivec2 extent, bool enable_specular = true); + void set_view(const DRWView *view, const int2 extent, bool enable_specular = true); void shgroup_resources(DRWShadingGroup *grp); diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.cc b/source/blender/draw/engines/eevee/eevee_lightcache.cc index 8c6625e4515..0f919e96b92 100644 --- a/source/blender/draw/engines/eevee/eevee_lightcache.cc +++ b/source/blender/draw/engines/eevee/eevee_lightcache.cc @@ -177,7 +177,7 @@ bool LightCache::validate(const int cube_len, return false; } /* See if we need the same amount of texture space. */ - if ((ivec3(irr_size) == ivec3(grid_tx.tex_size)) && (grid_len == this->grid_len)) { + if ((int3(irr_size) == int3(grid_tx.tex_size)) && (grid_len == this->grid_len)) { int mip_len = log2_floor_u(cube_res) - min_cube_lod_level; if ((cube_res == cube_tx.tex_size[0]) && (cube_len == cube_tx.tex_size[2] / 6) && (cube_len == this->cube_len) && (mip_len == this->mips_len)) { @@ -502,9 +502,10 @@ class LightBake { bake.inst_->lightprobes.swap_irradiance_cache(); } - ivec3 cell_co = grid_cell_index_to_coordinate(sample_index, grid->resolution); - vec3 position = vec3(grid->corner) + vec3(grid->increment_x) * cell_co.x + - vec3(grid->increment_y) * cell_co.y + vec3(grid->increment_z) * cell_co.z; + int3 cell_co = grid_cell_index_to_coordinate(sample_index, grid->resolution); + float3 position = float3(grid->corner) + float3(grid->increment_x) * cell_co.x + + float3(grid->increment_y) * cell_co.y + + float3(grid->increment_z) * cell_co.z; bake.inst_->lightprobes.bake(bake.depsgraph_, LIGHTPROBE_TYPE_GRID, @@ -751,8 +752,8 @@ class LightBake { grid.attenuation_bias = fac; /* Update transforms */ - vec3 half_cell_dim = vec3(1.0f) / vec3(UNPACK3(grid.resolution)); - vec3 cell_dim = half_cell_dim * 2.0f; + float3 half_cell_dim = float3(1.0f) / float3(UNPACK3(grid.resolution)); + float3 cell_dim = half_cell_dim * 2.0f; /* Matrix converting world space to cell ranges. */ invert_m4_m4(grid.mat, ob->obmat); @@ -760,15 +761,15 @@ class LightBake { float4x4 obmat(ob->obmat); /* First cell. */ - vec3 corner = obmat * (half_cell_dim - vec3(1.0f)); + float3 corner = obmat * (half_cell_dim - float3(1.0f)); copy_v3_v3(grid.corner, corner); /* Opposite neighbor cell. */ - vec3 increment_x = (obmat * vec3(cell_dim.x, 0.0f, 0.0f)) - vec3(obmat.values[3]); + float3 increment_x = (obmat * float3(cell_dim.x, 0.0f, 0.0f)) - float3(obmat.values[3]); copy_v3_v3(grid.increment_x, increment_x); - vec3 increment_y = (obmat * vec3(0.0f, cell_dim.y, 0.0f)) - vec3(obmat.values[3]); + float3 increment_y = (obmat * float3(0.0f, cell_dim.y, 0.0f)) - float3(obmat.values[3]); copy_v3_v3(grid.increment_y, increment_y); - vec3 increment_z = (obmat * vec3(0.0f, 0.0f, cell_dim.z)) - vec3(obmat.values[3]); + float3 increment_z = (obmat * float3(0.0f, 0.0f, cell_dim.z)) - float3(obmat.values[3]); copy_v3_v3(grid.increment_z, increment_z); grid.probe_index = probe_index; @@ -886,7 +887,7 @@ class LightBake { grid_len_ = grids_data.size(); cube_len_ = cubes_data.size(); - ivec3 irradiance_tx_size; + int3 irradiance_tx_size; LightCache::irradiance_cache_size_get( sce_eevee.gi_visibility_resolution, irradiance_samples_count, irradiance_tx_size); diff --git a/source/blender/draw/engines/eevee/eevee_lightprobe.cc b/source/blender/draw/engines/eevee/eevee_lightprobe.cc index 0701f5e198c..9fe06ed10f4 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobe.cc +++ b/source/blender/draw/engines/eevee/eevee_lightprobe.cc @@ -51,7 +51,7 @@ void LightProbeModule::init() int grid_len = 1; int irr_samples_len = 1; - ivec3 irr_size; + int3 irr_size; LightCache::irradiance_cache_size_get( sce_eevee.gi_visibility_resolution, irr_samples_len, irr_size); @@ -186,18 +186,21 @@ void LightProbeModule::begin_sync() void LightProbeModule::end_sync() { if (lightcache_->flag & LIGHTCACHE_UPDATE_WORLD) { - cubemap_prepare(vec3(0.0f), 0.01f, 1.0f, true); + cubemap_prepare(float3(0.0f), 0.01f, 1.0f, true); } } -void LightProbeModule::cubemap_prepare(vec3 position, float near, float far, bool background_only) +void LightProbeModule::cubemap_prepare(float3 position, + float near, + float far, + bool background_only) { SceneEEVEE &sce_eevee = inst_.scene->eevee; int cube_res = sce_eevee.gi_cubemap_resolution; int cube_mip_count = (int)log2_ceil_u(cube_res); - mat4 viewmat; - unit_m4(viewmat); + float4x4 viewmat; + viewmat.identity(); negate_v3_v3(viewmat[3], position); /* TODO(fclem) We might want to have theses as temporary textures. */ @@ -211,7 +214,7 @@ void LightProbeModule::cubemap_prepare(vec3 position, float near, float far, boo filter_cube_fb_.ensure(GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(lightcache_->cube_tx.tex)); filter_grid_fb_.ensure(GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(lightcache_->grid_tx.tex)); - mat4 winmat; + float4x4 winmat; cubeface_winmat_get(winmat, near, far); for (auto i : IndexRange(ARRAY_SIZE(probe_views_))) { @@ -300,8 +303,8 @@ void LightProbeModule::filter_diffuse(int sample_index, float intensity) filter_data_.push_update(); - ivec2 extent = ivec2(3, 2); - ivec2 offset = extent; + int2 extent = int2(3, 2); + int2 offset = extent; offset.x *= sample_index % info_data_.grids.irradiance_cells_per_row; offset.y *= sample_index / info_data_.grids.irradiance_cells_per_row; @@ -315,8 +318,8 @@ void LightProbeModule::filter_visibility(int sample_index, float visibility_blur, float visibility_range) { - ivec2 extent = ivec2(info_data_.grids.visibility_size); - ivec2 offset = extent; + int2 extent = int2(info_data_.grids.visibility_size); + int2 offset = extent; offset.x *= sample_index % info_data_.grids.visibility_cells_per_row; offset.y *= (sample_index / info_data_.grids.visibility_cells_per_row) % info_data_.grids.visibility_cells_per_layer; @@ -409,7 +412,7 @@ void LightProbeModule::bake(Depsgraph *depsgraph, SceneEEVEE &sce_eevee = DEG_get_evaluated_scene(depsgraph)->eevee; sce_eevee.flag &= ~(SCE_EEVEE_GTAO_ENABLED | SCE_EEVEE_RAYTRACING_ENABLED); - inst_.init(ivec2(1), &rect, nullptr, depsgraph, probe); + inst_.init(int2(1), &rect, nullptr, depsgraph, probe); inst_.sampling.reset(); inst_.render_sync(); inst_.sampling.step(); @@ -462,12 +465,11 @@ void LightProbeModule::sync_world(const DRWView *view) CubemapData &cube = cube_data_[0]; GridData &grid = grid_data_[0]; - scale_m4_fl(grid.local_mat, view_bounds.radius); + scale_m4_fl(grid.local_mat.ptr(), view_bounds.radius); negate_v3_v3(grid.local_mat[3], view_bounds.center); - copy_m4_m4(cube.influence_mat, grid.local_mat); - copy_m4_m4(cube.parallax_mat, cube.influence_mat); + cube.parallax_mat = cube.influence_mat = grid.local_mat; - grid.resolution = ivec3(1); + grid.resolution = int3(1); grid.offset = 0; grid.level_skip = 1; grid.attenuation_bias = 0.001f; @@ -475,10 +477,10 @@ void LightProbeModule::sync_world(const DRWView *view) grid.visibility_range = 1.0f; grid.visibility_bleed = 0.001f; grid.visibility_bias = 0.0f; - grid.increment_x = vec3(0.0f); - grid.increment_y = vec3(0.0f); - grid.increment_z = vec3(0.0f); - grid.corner = vec3(0.0f); + grid.increment_x = float3(0.0f); + grid.increment_y = float3(0.0f); + grid.increment_z = float3(0.0f); + grid.corner = float3(0.0f); cube._parallax_type = CUBEMAP_SHAPE_SPHERE; cube._layer = 0.0; @@ -493,8 +495,8 @@ void LightProbeModule::sync_grid(const DRWView *UNUSED(view), return; } GridData &grid = grid_data_[info_data_.grids.grid_count]; - copy_m4_m4(grid.local_mat, grid_cache.mat); - grid.resolution = ivec3(grid_cache.resolution); + copy_m4_m4(grid.local_mat.ptr(), grid_cache.mat); + grid.resolution = int3(grid_cache.resolution); grid.offset = grid_cache.offset; grid.level_skip = grid_cache.level_bias; grid.attenuation_bias = grid_cache.attenuation_bias; @@ -502,10 +504,10 @@ void LightProbeModule::sync_grid(const DRWView *UNUSED(view), grid.visibility_range = grid_cache.visibility_range; grid.visibility_bleed = grid_cache.visibility_bleed; grid.visibility_bias = grid_cache.visibility_bias; - grid.increment_x = vec3(grid_cache.increment_x); - grid.increment_y = vec3(grid_cache.increment_y); - grid.increment_z = vec3(grid_cache.increment_z); - grid.corner = vec3(grid_cache.corner); + grid.increment_x = float3(grid_cache.increment_x); + grid.increment_y = float3(grid_cache.increment_y); + grid.increment_z = float3(grid_cache.increment_z); + grid.corner = float3(grid_cache.corner); info_data_.grids.grid_count++; } @@ -519,8 +521,8 @@ void LightProbeModule::sync_cubemap(const DRWView *UNUSED(view), return; } CubemapData &cube = cube_data_[info_data_.cubes.cube_count]; - copy_m4_m4(cube.parallax_mat, cube_cache.parallaxmat); - copy_m4_m4(cube.influence_mat, cube_cache.attenuationmat); + copy_m4_m4(cube.parallax_mat.ptr(), cube_cache.parallaxmat); + copy_m4_m4(cube.influence_mat.ptr(), cube_cache.attenuationmat); cube._attenuation_factor = cube_cache.attenuation_fac; cube._attenuation_type = cube_cache.attenuation_type; cube._parallax_type = cube_cache.parallax_type; @@ -533,7 +535,7 @@ void LightProbeModule::sync_cubemap(const DRWView *UNUSED(view), } /* Only enables world light probe if extent is invalid (no culling possible). */ -void LightProbeModule::set_view(const DRWView *view, const ivec2 extent) +void LightProbeModule::set_view(const DRWView *view, const int2 extent) { if (lightcache_->flag & LIGHTCACHE_UPDATE_WORLD) { /* Set before update to avoid infinite recursion. */ diff --git a/source/blender/draw/engines/eevee/eevee_lightprobe.hh b/source/blender/draw/engines/eevee/eevee_lightprobe.hh index 865339039fa..1eb5b8d0ea6 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobe.hh +++ b/source/blender/draw/engines/eevee/eevee_lightprobe.hh @@ -98,7 +98,7 @@ class LightProbeModule { void begin_sync(); void end_sync(); - void set_view(const DRWView *view, const ivec2 extent); + void set_view(const DRWView *view, const int2 extent); void set_world_dirty(void) { @@ -152,7 +152,7 @@ class LightProbeModule { LightCache *baking_cache_get(void); - void cubemap_prepare(vec3 position, float near, float far, bool background_only); + void cubemap_prepare(float3 position, float near, float far, bool background_only); void filter_glossy(int cube_index, float intensity); void filter_diffuse(int sample_index, float intensity); diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.cc b/source/blender/draw/engines/eevee/eevee_lookdev.cc index 881ab90343f..d49f3e3ffd6 100644 --- a/source/blender/draw/engines/eevee/eevee_lookdev.cc +++ b/source/blender/draw/engines/eevee/eevee_lookdev.cc @@ -86,7 +86,7 @@ bNodeTree *LookDevWorldNodeTree::nodetree_get(float strength) * use custom shader to draw the background. * \{ */ -void LookDev::init(const ivec2 &output_res, const rcti *render_border) +void LookDev::init(const int2 &output_res, const rcti *render_border) { StudioLight *studiolight = nullptr; if (inst_.v3d) { @@ -142,7 +142,7 @@ void LookDev::init(const ivec2 &output_res, const rcti *render_border) * Scale between 1000px and 2000px. */ float viewport_scale = clamp_f(BLI_rcti_size_x(&rect) / (2000.0f * U.dpi_fac), 0.5f, 1.0f); int sphere_size = U.lookdev_sphere_size * U.dpi_fac * viewport_scale; - ivec2 anchor = ivec2(rect.xmax, rect.ymin); + int2 anchor = int2(rect.xmax, rect.ymin); if (sphere_size != sphere_size_ || anchor != anchor_) { /* Make sphere resolution adaptive to viewport_scale, dpi and lookdev_sphere_size */ @@ -167,7 +167,7 @@ void LookDev::init(const ivec2 &output_res, const rcti *render_border) } } -bool LookDev::do_overlay(const ivec2 &output_res, const rcti *render_border) +bool LookDev::do_overlay(const int2 &output_res, const rcti *render_border) { const View3D *v3d = inst_.v3d; /* Only show the HDRI Preview in Shading Preview in the Viewport. */ @@ -187,7 +187,7 @@ bool LookDev::do_overlay(const ivec2 &output_res, const rcti *render_border) if (inst_.camera.is_panoramic()) { return false; } - if (output_res != ivec2(BLI_rcti_size_x(render_border), BLI_rcti_size_y(render_border))) { + if (output_res != int2(BLI_rcti_size_x(render_border), BLI_rcti_size_y(render_border))) { /* TODO(fclem) support this case. */ return false; } @@ -214,21 +214,20 @@ bool LookDev::sync_world(void) return true; } -void LookDev::rotation_get(mat4 r_mat) +void LookDev::rotation_get(float4x4 r_mat) { if (studiolight_ == nullptr) { - unit_m4(r_mat); + r_mat.identity(); } else { - axis_angle_to_mat4_single(r_mat, 'Z', rotation_); + axis_angle_to_mat4_single(r_mat.ptr(), 'Z', rotation_); } if (view_rotation_) { - float x_rot_matrix[4][4]; + float4x4 x_rot_matrix; const CameraData &cam = inst_.camera.data_get(); - axis_angle_to_mat4_single(x_rot_matrix, 'X', M_PI / 2.0f); - mul_m4_m4m4(x_rot_matrix, x_rot_matrix, cam.viewmat); - mul_m4_m4m4(r_mat, r_mat, x_rot_matrix); + axis_angle_to_mat4_single(x_rot_matrix.ptr(), 'X', M_PI / 2.0f); + r_mat = r_mat * (x_rot_matrix * cam.viewmat); } } @@ -285,16 +284,15 @@ void LookDev::sync_overlay(void) LightProbeModule &lightprobes = inst_.lightprobes; /* Jitter for AA. */ - vec2 jitter = -0.5f + vec2(inst_.sampling.rng_get(SAMPLING_FILTER_U), - inst_.sampling.rng_get(SAMPLING_FILTER_V)); + float2 jitter = -0.5f + float2(inst_.sampling.rng_get(SAMPLING_FILTER_U), + inst_.sampling.rng_get(SAMPLING_FILTER_V)); /* Matrix used to position the spheres in viewport space. */ - mat4 sphere_mat; - copy_m4_m4(sphere_mat, cam.viewmat); + float4x4 sphere_mat = cam.viewmat; const float *viewport_size = DRW_viewport_size_get(); const int sphere_margin = sphere_size_ / 6; - vec2 offset = vec2(0, sphere_margin); + float2 offset = float2(0, sphere_margin); std::array<::Material *, 2> materials = {inst_.materials.diffuse_mat_, inst_.materials.glossy_mat_}; @@ -313,10 +311,11 @@ void LookDev::sync_overlay(void) offset.x -= sphere_size_ + sphere_margin; /* Pass 2D scale and bias factor in the last column. */ - vec2 scale = sphere_size_ / vec2(viewport_size); - vec2 bias = -1.0f + scale + 2.0f * (vec2(anchor_) + offset + jitter) / vec2(viewport_size); + float2 scale = sphere_size_ / float2(viewport_size); + float2 bias = -1.0f + scale + + 2.0f * (float2(anchor_) + offset + jitter) / float2(viewport_size); copy_v4_fl4(sphere_mat[3], UNPACK2(scale), UNPACK2(bias)); - DRW_shgroup_call_obmat(grp, sphere, sphere_mat); + DRW_shgroup_call_obmat(grp, sphere, sphere_mat.ptr()); offset.x -= sphere_margin; } @@ -333,18 +332,18 @@ void LookDev::render_overlay(GPUFrameBuffer *fb) const DRWView *active_view = DRW_view_get_active(); - inst_.lightprobes.set_view(active_view, ivec2(0)); - inst_.lights.set_view(active_view, ivec2(0)); + inst_.lightprobes.set_view(active_view, int2(0)); + inst_.lights.set_view(active_view, int2(0)); /* Create subview for correct shading. Sub because we don not care about culling. */ const CameraData &cam = inst_.camera.data_get(); - mat4 winmat; - orthographic_m4(winmat, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); + float4x4 winmat; + orthographic_m4(winmat.ptr(), -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); if (view_) { - DRW_view_update_sub(view_, cam.viewmat, winmat); + DRW_view_update_sub(view_, cam.viewmat.ptr(), winmat.ptr()); } else { - view_ = DRW_view_create_sub(active_view, cam.viewmat, winmat); + view_ = DRW_view_create_sub(active_view, cam.viewmat.ptr(), winmat.ptr()); } DRW_view_set_active(view_); diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.hh b/source/blender/draw/engines/eevee/eevee_lookdev.hh index 092c33ed98c..ff97e646585 100644 --- a/source/blender/draw/engines/eevee/eevee_lookdev.hh +++ b/source/blender/draw/engines/eevee/eevee_lookdev.hh @@ -83,7 +83,7 @@ class LookDev { /** Screen space radius in pixels. */ int sphere_size_ = 0; /** Lower right corner of the area where we can start drawing. */ - ivec2 anchor_; + int2 anchor_; public: LookDev(Instance &inst) : inst_(inst){}; @@ -92,7 +92,7 @@ class LookDev { GPU_material_free(&material); }; - void init(const ivec2 &output_res, const rcti *render_border); + void init(const int2 &output_res, const rcti *render_border); void sync_background(void); bool sync_world(void); @@ -101,10 +101,10 @@ class LookDev { bool render_background(void); void render_overlay(GPUFrameBuffer *view_fb); - void rotation_get(mat4 r_mat); + void rotation_get(float4x4 r_mat); private: - bool do_overlay(const ivec2 &output_res, const rcti *render_border); + bool do_overlay(const int2 &output_res, const rcti *render_border); }; /** \} */ diff --git a/source/blender/draw/engines/eevee/eevee_raytracing.cc b/source/blender/draw/engines/eevee/eevee_raytracing.cc index 960e66d69e9..48be86f1ff0 100644 --- a/source/blender/draw/engines/eevee/eevee_raytracing.cc +++ b/source/blender/draw/engines/eevee/eevee_raytracing.cc @@ -73,7 +73,7 @@ void RaytracingModule::sync(void) * * \{ */ -void RaytraceBuffer::sync(ivec2 extent) +void RaytraceBuffer::sync(int2 extent) { extent_ = extent; dispatch_size_.x = divide_ceil_u(extent.x, 8); diff --git a/source/blender/draw/engines/eevee/eevee_raytracing.hh b/source/blender/draw/engines/eevee/eevee_raytracing.hh index ddd6348997d..f90acc8b68c 100644 --- a/source/blender/draw/engines/eevee/eevee_raytracing.hh +++ b/source/blender/draw/engines/eevee/eevee_raytracing.hh @@ -120,14 +120,14 @@ struct RaytraceBuffer { RaytraceBufferDataBuf data_; - ivec2 extent_ = ivec2(0); - ivec3 dispatch_size_ = ivec3(1); + int2 extent_ = int2(0); + int3 dispatch_size_ = int3(1); public: RaytraceBuffer(Instance &inst) : inst_(inst){}; ~RaytraceBuffer(){}; - void sync(ivec2 extent); + void sync(int2 extent); void trace(eClosureBits closure_type, GBuffer &gbuffer, HiZBuffer &hiz, HiZBuffer &hiz_front); void denoise(eClosureBits closure_type); @@ -200,7 +200,7 @@ struct RaytraceBuffer { void render_end(const DRWView *view) { using draw::Texture; - DRW_view_persmat_get(view, data_.history_persmat, false); + DRW_view_persmat_get(view, data_.history_persmat.ptr(), false); Texture::swap(diffuse_radiance_tx_, diffuse_radiance_history_tx_); Texture::swap(diffuse_variance_tx_, diffuse_variance_history_tx_); Texture::swap(reflection_radiance_tx_, reflection_radiance_history_tx_); diff --git a/source/blender/draw/engines/eevee/eevee_sampling.hh b/source/blender/draw/engines/eevee/eevee_sampling.hh index 6ac63e34cbb..6f79ecfb202 100644 --- a/source/blender/draw/engines/eevee/eevee_sampling.hh +++ b/source/blender/draw/engines/eevee/eevee_sampling.hh @@ -333,9 +333,9 @@ class Sampling { * projected into any plane, the resulting distribution is (close to) * a uniform disc distribution. */ - vec3 sample_ball(const float rand[3]) + float3 sample_ball(const float rand[3]) { - vec3 sample; + float3 sample; sample.z = rand[0] * 2.0f - 1.0f; /* cos theta */ float r = sqrtf(fmaxf(0.0f, 1.0f - square_f(sample.z))); /* sin theta */ @@ -348,10 +348,10 @@ class Sampling { return sample; } - vec2 sample_disk(const float rand[2]) + float2 sample_disk(const float rand[2]) { float omega = rand[1] * 2.0f * M_PI; - return sqrtf(rand[0]) * vec2(cosf(omega), sinf(omega)); + return sqrtf(rand[0]) * float2(cosf(omega), sinf(omega)); } }; diff --git a/source/blender/draw/engines/eevee/eevee_shader.cc b/source/blender/draw/engines/eevee/eevee_shader.cc index ff3a668d474..c2e2489b2b4 100644 --- a/source/blender/draw/engines/eevee/eevee_shader.cc +++ b/source/blender/draw/engines/eevee/eevee_shader.cc @@ -557,7 +557,7 @@ char *ShaderModule::material_shader_code_vert_get(const GPUCodegenOutput *codege switch (geometry_type) { case MAT_GEOM_MESH: /* Example print: - * in vec2 u015684; */ + * in float2 u015684; */ output += "in "; output += sub.substr(0, pos + delimiter.length()); break; @@ -570,7 +570,7 @@ char *ShaderModule::material_shader_code_vert_get(const GPUCodegenOutput *codege break; case MAT_GEOM_GPENCIL: /* Example print: - * vec2 u015684; + * float2 u015684; * These are not used and just here to make the attribs_load functions call valids. * Only one uv and one color attribute layer is supported by gpencil objects. */ output += sub.substr(0, pos + delimiter.length()); @@ -611,13 +611,13 @@ char *ShaderModule::material_shader_code_vert_get(const GPUCodegenOutput *codege output += "\n"; } - output += "vec3 nodetree_displacement(void)\n"; + output += "float3 nodetree_displacement(void)\n"; output += "{\n"; if (codegen->displacement) { output += codegen->displacement; } else { - output += "return vec3(0);\n"; + output += "return float3(0);\n"; } output += "}\n\n"; } @@ -722,7 +722,7 @@ char *ShaderModule::material_shader_code_frag_get(const GPUCodegenOutput *codege size_t pos = 0; while ((pos = sub.find(delimiter)) != std::string::npos) { /* Example print: - * vec2 u015684; + * float2 u015684; * These are not used and just here to make the attribs_load functions call valids. * Only orco layer is supported by world. */ output += sub.substr(0, pos + delimiter.length()); diff --git a/source/blender/draw/engines/eevee/eevee_shader_shared.hh b/source/blender/draw/engines/eevee/eevee_shader_shared.hh index a50d5042365..2fabd5e40c6 100644 --- a/source/blender/draw/engines/eevee/eevee_shader_shared.hh +++ b/source/blender/draw/engines/eevee/eevee_shader_shared.hh @@ -5,63 +5,13 @@ * language. */ -/** - * NOTE: Enum support is not part of GLSL. It is handled by our own pre-processor pass in - * EEVEE's shader module. - * - * IMPORTANT: - * - Don't add trailing comma at the end of the enum. Our custom pre-processor will noy trim it - * for GLSL. - * - Always use `u` suffix for values. GLSL do not support implicit cast. - * - Define all values. This is in order to simplify custom pre-processor code. - * - Always use uint32_t as underlying type. - * - Use float suffix by default for float literals to avoid double promotion in C++. - * - Pack one float or int after a vec3/ivec3 to fullfil alligment rules. - * - * NOTE: Due to alignment restriction and buggy drivers, do not try to use mat3 inside structs. - * Do not use arrays of float. They are padded to arrays of vec4 and are not worth it. - * - * IMPORTANT: Don't forget to align mat4 and vec4 to 16 bytes. - **/ - -#ifndef __cplusplus /* GLSL */ -# pragma BLENDER_REQUIRE(common_math_lib.glsl) -# define BLI_STATIC_ASSERT_ALIGN(type_, align_) -# define BLI_STATIC_ASSERT_SIZE(type_, size_) -# define static -# define inline -# define cosf cos -# define sinf sin -# define tanf tan -# define acosf acos -# define asinf asin -# define atanf atan -# define floorf floor -# define ceilf ceil -# define sqrtf sqrt - -#else /* C++ */ +#ifndef USE_GPU_SHADER_CREATE_INFO # pragma once -# include "BLI_float4x4.hh" - -typedef float mat4[4][4]; -using vec4 = blender::float4; -using vec3 = blender::float3; -using vec2 = blender::float2; -typedef int ivec4[4]; -using ivec3 = blender::int3; -using ivec2 = blender::int2; -typedef uint uvec4[4]; -typedef uint uvec3[3]; -typedef uint uvec2[2]; -typedef int bvec4[4]; -typedef int bvec2[2]; -/* Ugly but it does the job! */ -# define bool int - # include "eevee_wrapper.hh" +# include "GPU_shader_shared.h" + namespace blender::eevee { #endif @@ -99,9 +49,9 @@ enum eSamplingDimension : uint32_t { struct SamplingData { /** Array containing random values from Low Discrepency Sequence in [0..1) range. */ - /** HACK: float arrays are padded to vec4 in GLSL. Using vec4 for now to get the same alignment - * but this is wasteful. */ - vec4 dimensions[SAMPLING_DIMENSION_COUNT]; + /** HACK: float arrays are padded to float4 in GLSL. Using float4 for now to get the same + * alignment but this is wasteful. */ + float4 dimensions[SAMPLING_DIMENSION_COUNT]; }; BLI_STATIC_ASSERT_ALIGN(SamplingData, 16) @@ -143,19 +93,19 @@ static inline bool is_panoramic(eCameraType type) struct CameraData { /* View Matrices of the camera, not from any view! */ - mat4 persmat; - mat4 persinv; - mat4 viewmat; - mat4 viewinv; - mat4 winmat; - mat4 wininv; + float4x4 persmat; + float4x4 persinv; + float4x4 viewmat; + float4x4 viewinv; + float4x4 winmat; + float4x4 wininv; /** Camera UV scale and bias. Also known as viewcamtexcofac. */ - vec2 uv_scale; - vec2 uv_bias; + float2 uv_scale; + float2 uv_bias; /** Panorama parameters. */ - vec2 equirect_scale; - vec2 equirect_scale_inv; - vec2 equirect_bias; + float2 equirect_scale; + float2 equirect_scale_inv; + float2 equirect_bias; float fisheye_fov; float fisheye_lens; /** Clipping distances. */ @@ -236,20 +186,20 @@ enum eFilmDataType : uint32_t { struct FilmData { /** Size of the render target in pixels. */ - ivec2 extent; + int2 extent; /** Offset of the render target in the full-res frame, in pixels. */ - ivec2 offset; + int2 offset; /** Scale and bias to filter only a region of the render (aka. render_border). */ - vec2 uv_bias; - vec2 uv_scale; - vec2 uv_scale_inv; + float2 uv_bias; + float2 uv_scale; + float2 uv_scale_inv; /** Data type stored by this film. */ eFilmDataType data_type; /** Is true if history is valid and can be sampled. Bypassing history to resets accumulation. */ - bool use_history; + bool1 use_history; /** Used for fade-in effect. */ float opacity; - /** Padding to sizeof(vec4). */ + /** Padding to sizeof(float4). */ int _pad0, _pad1, _pad2; }; BLI_STATIC_ASSERT_ALIGN(FilmData, 16) @@ -269,14 +219,14 @@ BLI_STATIC_ASSERT_ALIGN(FilmData, 16) struct DepthOfFieldData { /** Size of the render targets for gather & scatter passes. */ - ivec2 extent; + int2 extent; /** Size of a pixel in uv space (1.0 / extent). */ - vec2 texel_size; + float2 texel_size; /** Bokeh Scale factor. */ - vec2 bokeh_anisotropic_scale; - vec2 bokeh_anisotropic_scale_inv; + float2 bokeh_anisotropic_scale; + float2 bokeh_anisotropic_scale_inv; /* Correction factor to align main target pixels with the filtered mipmap chain texture. */ - vec2 gather_uv_fac; + float2 gather_uv_fac; /** Scatter parameters. */ float scatter_coc_threshold; float scatter_color_threshold; @@ -350,8 +300,8 @@ static inline float circle_to_polygon_angle(float sides_count, float theta) * \{ */ struct VelocityObjectData { - mat4 next_object_mat; - mat4 prev_object_mat; + float4x4 next_object_mat; + float4x4 prev_object_mat; }; BLI_STATIC_ASSERT_ALIGN(VelocityObjectData, 16) @@ -369,9 +319,9 @@ struct MotionBlurData { /** Depth scaling factor. Avoid bluring background behind moving objects. */ float depth_scale; /** As the name suggests. Used to avoid a division in the sampling. */ - vec2 target_size_inv; + float2 target_size_inv; /** Viewport motion blur only blurs using previous frame vectors. */ - bool is_viewport; + bool1 is_viewport; int _pad0, _pad1, _pad2; }; BLI_STATIC_ASSERT_ALIGN(MotionBlurData, 16) @@ -397,7 +347,7 @@ BLI_STATIC_ASSERT_ALIGN(MotionBlurData, 16) struct CullingData { /** Scale applied to tile pixel coordinates to get target UV coordinate. */ - vec2 tile_to_uv_fac; + float2 tile_to_uv_fac; /** Scale and bias applied to linear Z to get zbin. */ float zbin_scale; float zbin_bias; @@ -408,7 +358,7 @@ struct CullingData { /** Number of items that passes the first culling test. */ uint visible_count; /** Will disable specular during light data copy.. */ - bool enable_specular; + bool1 enable_specular; /** Extent of one square tile in pixels. */ uint tile_size; /** Number of tiles on the X/Y axis. */ @@ -453,11 +403,11 @@ struct ShadowData { * So after transformation, you are in the tilemap space [0..SHADOW_TILEMAP_RES] * of the largest clipmap. */ - mat4 mat; - /** NOTE: It is ok to use vec3 here. A float is declared right after it. - * vec3 is also aligned to 16 bytes. */ + float4x4 mat; + /** NOTE: It is ok to use float3 here. A float is declared right after it. + * float3 is also aligned to 16 bytes. */ /** Shadow offset caused by jittering projection origin (for soft shadows). */ - vec3 offset; + float3 offset; /** Shadow bias in world space. */ float bias; /** Near and far clipping distance to convert shadowmap to world space distances. */ @@ -470,7 +420,7 @@ struct ShadowData { /** Directional : Clipmap lod range to avoid sampling outside of valid range. */ int clipmap_lod_min, clipmap_lod_max; /** Directional : Offset of the lod min in base units. */ - ivec2 base_offset; + int2 base_offset; }; BLI_STATIC_ASSERT_ALIGN(ShadowData, 16) @@ -504,9 +454,9 @@ BLI_STATIC_ASSERT_ALIGN(ShadowData, 16) #endif /* Given an input tile coordinate [0..SHADOW_TILEMAP_RES] returns the coordinate in NDC [-1..1]. */ -static inline vec2 shadow_tile_coord_to_ndc(ivec2 tile) +static inline float2 shadow_tile_coord_to_ndc(int2 tile) { - vec2 co = vec2(tile.x, tile.y) / float(SHADOW_TILEMAP_RES); + float2 co = float2(tile.x, tile.y) / float(SHADOW_TILEMAP_RES); return co * 2.0f - 1.0f; } @@ -515,21 +465,21 @@ static inline vec2 shadow_tile_coord_to_ndc(ivec2 tile) */ struct ShadowTileMapData { /** View Projection matrix used to tag tiles (World > UV Tile [0..SHADOW_TILEMAP_RES]). */ - mat4 tilemat; + float4x4 tilemat; /** Corners of the frustum. */ - vec4 corners[4]; + float4 corners[4]; /** NDC depths to clip usage bbox. */ #define _max_usage_depth corners[0].w #define _min_usage_depth corners[1].w #define _punctual_distance corners[2].w /** Shift to apply to the tile grid in the setup phase. */ - ivec2 grid_shift; + int2 grid_shift; /** True for punctual lights. */ - bool is_cubeface; + bool1 is_cubeface; /** Index inside the tilemap allocator. */ int index; /** Cone direction for punctual shadows. */ - vec3 cone_direction; + float3 cone_direction; /** Cosine of the max angle. Offset to take into acount the max tile angle. */ float cone_angle_cos; }; @@ -569,7 +519,7 @@ static inline bool is_area_light(eLightType type) struct LightData { /** Normalized obmat. Last column contains data accessible using the following macros. */ - mat4 object_mat; + float4x4 object_mat; /** Packed data in the last column of the object_mat. */ #define _area_size_x object_mat[0][3] #define _area_size_y object_mat[1][3] @@ -595,9 +545,9 @@ struct LightData { float influence_radius_max; /** Index of the shadow struct on CPU. -1 means no shadow. */ int shadow_id; - /** NOTE: It is ok to use vec3 here. A float is declared right after it. - * vec3 is also aligned to 16 bytes. */ - vec3 color; + /** NOTE: It is ok to use float3 here. A float is declared right after it. + * float3 is also aligned to 16 bytes. */ + float3 color; /** Power depending on shader type. */ float diffuse_power; float specular_power; @@ -607,10 +557,10 @@ struct LightData { float radius_squared; /** Light Type. */ eLightType type; - /** Padding to sizeof(vec2). */ + /** Padding to sizeof(float2). */ float _pad1; - /** Spot size. Aligned to size of vec2. */ - vec2 spot_size_inv; + /** Spot size. Aligned to size of float2. */ + float2 spot_size_inv; /** Associated shadow data. Only valid if shadow_id is not LIGHT_NO_SHADOW. */ ShadowData shadow_data; }; @@ -622,7 +572,7 @@ BLI_STATIC_ASSERT_ALIGN(LightData, 16) struct ShadowDebugData { LightData light; ShadowData shadow; - vec3 camera_position; + float3 camera_position; eDebugMode type; int tilemap_data_index; int _pad1; @@ -666,7 +616,7 @@ BLI_STATIC_ASSERT_ALIGN(LightProbeFilterData, 16) * Common data to all irradiance grid. */ struct GridInfoData { - mat4 lookdev_rotation; + float4x4 lookdev_rotation; /** Total of visibility cells per row and layer. */ int visibility_cells_per_row; int visibility_cells_per_layer; @@ -689,25 +639,25 @@ BLI_STATIC_ASSERT_ALIGN(GridInfoData, 16) */ struct GridData { /** Object matrix inverse (World -> Local). */ - mat4 local_mat; + float4x4 local_mat; /** Resolution of the light grid. */ - ivec3 resolution; + int3 resolution; /** Offset of the first cell of this grid in the grid texture. */ int offset; /** World space vector between 2 adjacent cells. */ - vec3 increment_x; + float3 increment_x; /** Attenuation Bias. */ float attenuation_bias; /** World space vector between 2 adjacent cells. */ - vec3 increment_y; + float3 increment_y; /** Attenuation scaling. */ float attenuation_scale; /** World space vector between 2 adjacent cells. */ - vec3 increment_z; + float3 increment_z; /** Number of grid levels not ready for display during baking. */ int level_skip; /** World space corner position. */ - vec3 corner; + float3 corner; /** Visibility test parameters. */ float visibility_range; float visibility_bleed; @@ -717,9 +667,9 @@ struct GridData { }; BLI_STATIC_ASSERT_ALIGN(GridData, 16) -static inline ivec3 grid_cell_index_to_coordinate(int cell_id, ivec3 resolution) +static inline int3 grid_cell_index_to_coordinate(int cell_id, int3 resolution) { - ivec3 cell_coord; + int3 cell_coord; cell_coord.z = cell_id % resolution.z; cell_coord.y = (cell_id / resolution.z) % resolution.y; cell_coord.x = cell_id / (resolution.z * resolution.y); @@ -730,7 +680,7 @@ static inline ivec3 grid_cell_index_to_coordinate(int cell_id, ivec3 resolution) * Common data to all cubemaps. */ struct CubemapInfoData { - mat4 lookdev_rotation; + float4x4 lookdev_rotation; /** LOD containing data for roughness of 1. */ float roughness_max_lod; /** Total number of active cubemaps including world. */ @@ -749,7 +699,7 @@ BLI_STATIC_ASSERT_ALIGN(CubemapInfoData, 16) */ struct CubemapData { /** Influence shape matrix (World -> Local). */ - mat4 influence_mat; + float4x4 influence_mat; /** Packed data in the last column of the influence_mat. */ #define _attenuation_factor influence_mat[0][3] #define _attenuation_type influence_mat[1][3] @@ -757,7 +707,7 @@ struct CubemapData { /** Layer of the cube array to sample. */ #define _layer influence_mat[3][3] /** Parallax shape matrix (World -> Local). */ - mat4 parallax_mat; + float4x4 parallax_mat; /** Packed data in the last column of the parallax_mat. */ #define _world_position_x parallax_mat[0][3] #define _world_position_y parallax_mat[1][3] @@ -781,9 +731,9 @@ BLI_STATIC_ASSERT_ALIGN(LightProbeInfoData, 16) struct HiZData { /** Scale factor to remove HiZBuffer padding. */ - vec2 uv_scale; + float2 uv_scale; /** Scale factor to convert from pixel space to Normalized Device Coordinates [-1..1]. */ - vec2 pixel_to_ndc; + float2 pixel_to_ndc; }; BLI_STATIC_ASSERT_ALIGN(HiZData, 16) @@ -813,11 +763,11 @@ BLI_STATIC_ASSERT_ALIGN(RaytraceData, 16) struct RaytraceBufferData { /** ViewProjection matrix used to render the previous frame. */ - mat4 history_persmat; + float4x4 history_persmat; /** False if the history buffer was just allocated and contains uninitialized data. */ - bool valid_history_diffuse; - bool valid_history_reflection; - bool valid_history_refraction; + bool1 valid_history_diffuse; + bool1 valid_history_reflection; + bool1 valid_history_refraction; int _pad0; }; BLI_STATIC_ASSERT_ALIGN(RaytraceData, 16) @@ -839,8 +789,8 @@ BLI_STATIC_ASSERT_ALIGN(RaytraceData, 16) struct SubsurfaceData { /** xy: 2D sample position [-1..1], zw: sample_bounds. */ - /* NOTE(fclem) Using vec4 for alignment. */ - vec4 samples[SSS_SAMPLE_MAX]; + /* NOTE(fclem) Using float4 for alignment. */ + float4 samples[SSS_SAMPLE_MAX]; /** Sample index after which samples are not randomly rotated anymore. */ int jitter_threshold; /** Number of samples precomputed in the set. */ @@ -873,33 +823,33 @@ BLI_STATIC_ASSERT_ALIGN(SubsurfaceData, 16) #ifndef __cplusplus /* For codestyle reasons, we do not declare samplers in lib files. Use a prototype instead. */ -vec4 utility_tx_fetch(vec2 texel, float layer); -vec4 utility_tx_sample(vec2 uv, float layer); +float4 utility_tx_fetch(float2 texel, float layer); +float4 utility_tx_sample(float2 uv, float layer); /* Fetch texel. Wrapping if above range. */ # define utility_tx_fetch_define(utility_tx_) \ - vec4 utility_tx_fetch(vec2 texel, float layer) \ + float4 utility_tx_fetch(float2 texel, float layer) \ { \ - return texelFetch(utility_tx_, ivec3(ivec2(texel) % UTIL_TEX_SIZE, layer), 0); \ + return texelFetch(utility_tx_, int3(int2(texel) % UTIL_TEX_SIZE, layer), 0); \ } /* Sample at uv position. Filtered & Wrapping enabled. */ # define utility_tx_sample_define(utility_tx_) \ - vec4 utility_tx_sample(vec2 uv, float layer) \ + float4 utility_tx_sample(float2 uv, float layer) \ { \ - return textureLod(utility_tx_, vec3(uv, layer), 0.0); \ + return textureLod(utility_tx_, float3(uv, layer), 0.0); \ } /* Stubs declarations if not using it. */ # define utility_tx_fetch_define_stub(utility_tx_) \ - vec4 utility_tx_fetch(vec2 texel, float layer) \ + float4 utility_tx_fetch(float2 texel, float layer) \ { \ - return vec4(0); \ + return float4(0); \ } # define utility_tx_sample_define_stub(utility_tx_) \ - vec4 utility_tx_sample(vec2 uv, float layer) \ + float4 utility_tx_sample(float2 uv, float layer) \ { \ - return vec4(0); \ + return float4(0); \ } #endif @@ -929,6 +879,5 @@ using ShadowTileMapDataBuf = draw::StorageArrayBuffer<ShadowTileMapData, SHADOW_ using SubsurfaceDataBuf = draw::UniformBuffer<SubsurfaceData>; using VelocityObjectBuf = draw::UniformBuffer<VelocityObjectData>; -# undef bool } // namespace blender::eevee #endif diff --git a/source/blender/draw/engines/eevee/eevee_shading.cc b/source/blender/draw/engines/eevee/eevee_shading.cc index 1eda76411bf..61e85590f9f 100644 --- a/source/blender/draw/engines/eevee/eevee_shading.cc +++ b/source/blender/draw/engines/eevee/eevee_shading.cc @@ -41,8 +41,8 @@ void BackgroundPass::sync(GPUMaterial *gpumat, GPUTexture *lookdev_tx) background_ps_ = DRW_pass_create("Background", state); /* Push a matrix at the same location as the camera. */ - mat4 camera_mat; - unit_m4(camera_mat); + float4x4 camera_mat; + camera_mat.identity(); copy_v3_v3(camera_mat[3], inst_.camera.data_get().viewinv[3]); DRWShadingGroup *grp = DRW_shgroup_material_create(gpumat, background_ps_); @@ -50,7 +50,7 @@ void BackgroundPass::sync(GPUMaterial *gpumat, GPUTexture *lookdev_tx) /* HACK(fclem) This particular texture has been left without resource to be set here. */ DRW_shgroup_uniform_texture(grp, "samp0", lookdev_tx); } - DRW_shgroup_call_obmat(grp, DRW_cache_fullscreen_quad_get(), camera_mat); + DRW_shgroup_call_obmat(grp, DRW_cache_fullscreen_quad_get(), camera_mat.ptr()); } void BackgroundPass::render(void) @@ -198,7 +198,7 @@ void ForwardPass::render(const DRWView *view, GPUFrameBuffer *view_fb) { if (inst_.raytracing.enabled()) { - ivec2 extent = {GPU_texture_width(gbuffer.depth_tx), GPU_texture_height(gbuffer.depth_tx)}; + int2 extent = {GPU_texture_width(gbuffer.depth_tx), GPU_texture_height(gbuffer.depth_tx)}; /* Reuse texture. */ gbuffer.ray_radiance_tx.acquire(extent, GPU_RGBA16F, gbuffer.owner); /* Copy combined buffer so we can sample from it. */ diff --git a/source/blender/draw/engines/eevee/eevee_shadow.cc b/source/blender/draw/engines/eevee/eevee_shadow.cc index 8fc6d732c4b..76fe9584666 100644 --- a/source/blender/draw/engines/eevee/eevee_shadow.cc +++ b/source/blender/draw/engines/eevee/eevee_shadow.cc @@ -101,8 +101,8 @@ void ShadowTileMap::sync_clipmap(const float3 &camera_position, viewmat = viewinv.inverted_affine(); winmat = winmat_get(nullptr); - mul_m4_m4m4(tilemat, tilemat_scale_bias_mat, winmat.ptr()); - mul_m4_m4m4(tilemat, tilemat, viewmat.ptr()); + mul_m4_m4m4(tilemat.ptr(), tilemat_scale_bias_mat, winmat.ptr()); + tilemat = tilemat * viewmat; } void ShadowTileMap::sync_cubeface( @@ -134,8 +134,8 @@ void ShadowTileMap::sync_cubeface( viewmat = float4x4(shadow_face_mat[cubeface]) * object_mat.inverted_affine(); winmat = winmat_get(nullptr); - mul_m4_m4m4(tilemat, tilemat_scale_bias_mat, winmat.ptr()); - mul_m4_m4m4(tilemat, tilemat, viewmat.ptr()); + mul_m4_m4m4(tilemat.ptr(), tilemat_scale_bias_mat, winmat.ptr()); + tilemat = tilemat * viewmat; /* Update corners. */ float4x4 viewinv = viewmat.inverted(); @@ -351,7 +351,7 @@ void ShadowCommon::free_resources() * \{ */ void ShadowPunctual::sync(eLightType light_type, - const mat4 &object_mat, + const float4x4 &object_mat, float cone_aperture, float near_clip, float far_clip, @@ -399,7 +399,7 @@ ShadowPunctual::operator ShadowData() { ShadowData data; cubeface_winmat_get(data.mat, near_, far_); - invert_m4(data.mat); + invert_m4(data.mat.ptr()); data.offset = random_offset_; data.bias = bias_; data.clip_near = near_; @@ -416,7 +416,7 @@ ShadowPunctual::operator ShadowData() * * \{ */ -void ShadowDirectional::sync(const mat4 &object_mat, float bias, float min_resolution) +void ShadowDirectional::sync(const float4x4 &object_mat, float bias, float min_resolution) { object_mat_ = float4x4(object_mat); /* Clear embedded custom data. */ @@ -492,8 +492,8 @@ ShadowDirectional::operator ShadowData() { ShadowData data; ShadowTileMap &last_level = *tilemaps.last(); - mul_m4_m4m4(data.mat, shadow_clipmap_scale_mat, last_level.winmat.ptr()); - mul_m4_m4m4(data.mat, data.mat, last_level.viewmat.ptr()); + mul_m4_m4m4(data.mat.ptr(), shadow_clipmap_scale_mat, last_level.winmat.ptr()); + mul_m4_m4m4(data.mat.ptr(), data.mat.ptr(), last_level.viewmat.ptr()); data.bias = bias_; data.clip_near = near_; data.clip_far = far_; @@ -654,7 +654,7 @@ void ShadowModule::end_sync(void) { /* Get the farthest point from camera to know what distance to cover. */ float3 farthest_point = float3(1.0f, 1.0f, 1.0f); - mul_project_m4_v3(inst_.camera.data_get().wininv, farthest_point); + mul_project_m4_v3(inst_.camera.data_get().wininv.ptr(), farthest_point); float far_dist = math::length(farthest_point); float near_dist = fabsf(inst_.camera.data_get().clip_near); float3 cam_position = inst_.camera.position(); @@ -1018,7 +1018,7 @@ void ShadowModule::set_view(const DRWView *view, GPUTexture *depth_tx) } #endif - ivec2 extent(GPU_texture_width(depth_tx), GPU_texture_height(depth_tx)); + int2 extent(GPU_texture_width(depth_tx), GPU_texture_height(depth_tx)); input_depth_tx_ = depth_tx; scan_dispatch_size_.x = divide_ceil_u(extent.x, SHADOW_DEPTH_SCAN_GROUP_SIZE); diff --git a/source/blender/draw/engines/eevee/eevee_shadow.hh b/source/blender/draw/engines/eevee/eevee_shadow.hh index 985bd28604a..fe1326037bf 100644 --- a/source/blender/draw/engines/eevee/eevee_shadow.hh +++ b/source/blender/draw/engines/eevee/eevee_shadow.hh @@ -79,7 +79,7 @@ struct AABB { void debug_draw(void) { BoundBox bb = *this; - vec4 color = {1, 0, 0, 1}; + float4 color = {1, 0, 0, 1}; DRW_debug_bbox(&bb, color); } @@ -115,14 +115,14 @@ struct AABB { float3 middle = center(); float3 halfdim = max - middle; BoundBox bb; - *reinterpret_cast<float3 *>(bb.vec[0]) = middle + halfdim * vec3(1, 1, 1); - *reinterpret_cast<float3 *>(bb.vec[1]) = middle + halfdim * vec3(-1, 1, 1); - *reinterpret_cast<float3 *>(bb.vec[2]) = middle + halfdim * vec3(-1, -1, 1); - *reinterpret_cast<float3 *>(bb.vec[3]) = middle + halfdim * vec3(1, -1, 1); - *reinterpret_cast<float3 *>(bb.vec[4]) = middle + halfdim * vec3(1, 1, -1); - *reinterpret_cast<float3 *>(bb.vec[5]) = middle + halfdim * vec3(-1, 1, -1); - *reinterpret_cast<float3 *>(bb.vec[6]) = middle + halfdim * vec3(-1, -1, -1); - *reinterpret_cast<float3 *>(bb.vec[7]) = middle + halfdim * vec3(1, -1, -1); + *reinterpret_cast<float3 *>(bb.vec[0]) = middle + halfdim * float3(1, 1, 1); + *reinterpret_cast<float3 *>(bb.vec[1]) = middle + halfdim * float3(-1, 1, 1); + *reinterpret_cast<float3 *>(bb.vec[2]) = middle + halfdim * float3(-1, -1, 1); + *reinterpret_cast<float3 *>(bb.vec[3]) = middle + halfdim * float3(1, -1, 1); + *reinterpret_cast<float3 *>(bb.vec[4]) = middle + halfdim * float3(1, 1, -1); + *reinterpret_cast<float3 *>(bb.vec[5]) = middle + halfdim * float3(-1, 1, -1); + *reinterpret_cast<float3 *>(bb.vec[6]) = middle + halfdim * float3(-1, -1, -1); + *reinterpret_cast<float3 *>(bb.vec[7]) = middle + halfdim * float3(1, -1, -1); return bb; } }; @@ -268,7 +268,7 @@ class ShadowPunctual : public ShadowCommon { /** Shape type. */ eLightType light_type_; /** Random position on the light. In world space. */ - vec3 random_offset_; + float3 random_offset_; /** Light position. */ float3 position_; /** Near and far clip distances. */ @@ -280,7 +280,7 @@ class ShadowPunctual : public ShadowCommon { ShadowPunctual(ShadowModule *shadows) : ShadowCommon(shadows){}; void sync(eLightType light_type, - const mat4 &object_mat, + const float4x4 &object_mat, float cone_aperture, float near_clip, float far_clip, @@ -298,14 +298,14 @@ class ShadowDirectional : public ShadowCommon { /** Near and far clip distances. For clipmap, when they are updated after sync. */ float near_, far_; /** Offset of the lowest clipmap relative to the highest one. */ - ivec2 base_offset_; + int2 base_offset_; /** Copy of object matrix. */ float4x4 object_mat_; public: ShadowDirectional(ShadowModule *shadows) : ShadowCommon(shadows){}; - void sync(const mat4 &object_mat, float bias, float min_resolution); + void sync(const float4x4 &object_mat, float bias, float min_resolution); void end_sync(int min_level, int max_level, const float3 &camera_position, diff --git a/source/blender/draw/engines/eevee/eevee_velocity.cc b/source/blender/draw/engines/eevee/eevee_velocity.cc index f42f09cf153..c3ab12b1b84 100644 --- a/source/blender/draw/engines/eevee/eevee_velocity.cc +++ b/source/blender/draw/engines/eevee/eevee_velocity.cc @@ -110,10 +110,10 @@ void VelocityModule::step_object_sync(Object *ob, ObjectKey &object_key) auto data = objects_steps.lookup_or_add_cb(object_key, add_cb); if (step_ == STEP_NEXT) { - copy_m4_m4(data->next_object_mat, ob->obmat); + data->next_object_mat = ob->obmat; } else if (step_ == STEP_PREVIOUS) { - copy_m4_m4(data->prev_object_mat, ob->obmat); + data->prev_object_mat = ob->obmat; } } @@ -121,9 +121,9 @@ void VelocityModule::step_object_sync(Object *ob, ObjectKey &object_key) void VelocityModule::step_swap(void) { for (VelocityObjectBuf *data : objects_steps.values()) { - copy_m4_m4(data->prev_object_mat, data->next_object_mat); + data->prev_object_mat = data->next_object_mat; /* Important: This let us known if object is missing from the next time step. */ - zero_m4(data->next_object_mat); + zero_m4(data->next_object_mat.ptr()); } camera_step.prev = static_cast<CameraData>(camera_step.next); } @@ -142,7 +142,7 @@ void VelocityModule::end_sync(void) for (auto item : objects_steps.items()) { /* Detect object deletion. Only do this on viewport as STEP_NEXT means current step. */ - if (inst_.is_viewport() && is_zero_m4(item.value->next_object_mat)) { + if (inst_.is_viewport() && is_zero_m4(item.value->next_object_mat.ptr())) { deleted_keys.append(item.key); delete item.value; } @@ -259,23 +259,23 @@ void VelocityPass::mesh_add(Object *ob, ObjectHandle &handle) if (!inst_.is_viewport()) { /* Fill missing matrices if the object was hidden in previous or next frame. */ - if (is_zero_m4(data->prev_object_mat)) { - copy_m4_m4(data->prev_object_mat, ob->obmat); + if (is_zero_m4(data->prev_object_mat.ptr())) { + copy_m4_m4(data->prev_object_mat.ptr(), ob->obmat); } /* Avoid drawing object that has no motions since object_moves is always true. */ if (/* !mb_geom->use_deform && */ /* Object deformation can happen without transform. */ - equals_m4m4(data->prev_object_mat, ob->obmat)) { + equals_m4m4(data->prev_object_mat.ptr(), ob->obmat)) { return; } } else { /* Fill missing matrices if the object was hidden in previous or next frame. */ - if (is_zero_m4(data->prev_object_mat)) { - copy_m4_m4(data->prev_object_mat, ob->obmat); + if (is_zero_m4(data->prev_object_mat.ptr())) { + data->prev_object_mat = ob->obmat; } - if (is_zero_m4(data->next_object_mat)) { - copy_m4_m4(data->next_object_mat, ob->obmat); + if (is_zero_m4(data->next_object_mat.ptr())) { + data->next_object_mat = ob->obmat; } // if (mb_geom->use_deform) { @@ -285,8 +285,8 @@ void VelocityPass::mesh_add(Object *ob, ObjectHandle &handle) /* Avoid drawing object that has no motions since object_moves is always true. */ if (/* !mb_geom->use_deform && */ /* Object deformation can happen without transform. */ - equals_m4m4(data->prev_object_mat, ob->obmat) && - equals_m4m4(data->next_object_mat, ob->obmat)) { + equals_m4m4(data->prev_object_mat.ptr(), ob->obmat) && + equals_m4m4(data->next_object_mat.ptr(), ob->obmat)) { return; } } diff --git a/source/blender/draw/engines/eevee/eevee_view.cc b/source/blender/draw/engines/eevee/eevee_view.cc index d147fabc3dc..3ec9a9563a1 100644 --- a/source/blender/draw/engines/eevee/eevee_view.cc +++ b/source/blender/draw/engines/eevee/eevee_view.cc @@ -48,7 +48,7 @@ void ShadingView::init() mb_.init(); } -void ShadingView::sync(ivec2 render_extent_) +void ShadingView::sync(int2 render_extent_) { if (inst_.camera.is_panoramic()) { int64_t render_pixel_count = render_extent_.x * (int64_t)render_extent_.y; @@ -70,20 +70,20 @@ void ShadingView::sync(ivec2 render_extent_) /* Create views. */ const CameraData &data = inst_.camera.data_get(); - float viewmat[4][4], winmat[4][4]; - const float(*viewmat_p)[4] = viewmat, (*winmat_p)[4] = winmat; + float4x4 viewmat, winmat; + const float(*viewmat_p)[4] = viewmat.ptr(), (*winmat_p)[4] = winmat.ptr(); if (inst_.camera.is_panoramic()) { /* TODO(fclem) Overscans. */ /* For now a mandatory 5% overscan for DoF. */ float side = data.clip_near * 1.05f; float near = data.clip_near; float far = data.clip_far; - perspective_m4(winmat, -side, side, -side, side, near, far); - mul_m4_m4m4(viewmat, face_matrix_, data.viewmat); + perspective_m4(winmat.ptr(), -side, side, -side, side, near, far); + viewmat = face_matrix_ * data.viewmat; } else { - viewmat_p = data.viewmat; - winmat_p = data.winmat; + viewmat_p = data.viewmat.ptr(); + winmat_p = data.winmat.ptr(); } main_view_ = DRW_view_create(viewmat_p, winmat_p, nullptr, nullptr, nullptr); @@ -209,16 +209,15 @@ void ShadingView::update_view(void) void LightProbeView::sync(Texture &color_tx, Texture &depth_tx, - const mat4 winmat, - const mat4 viewmat, + const float4x4 winmat, + const float4x4 viewmat, bool is_only_background) { - mat4 facemat; - mul_m4_m4m4(facemat, face_matrix_, viewmat); + float4x4 facemat = face_matrix_ * viewmat; is_only_background_ = is_only_background; - extent_ = ivec2(color_tx.width()); - view_ = DRW_view_create(facemat, winmat, nullptr, nullptr, nullptr); + extent_ = int2(color_tx.width()); + view_ = DRW_view_create(facemat.ptr(), winmat.ptr(), nullptr, nullptr, nullptr); view_fb_.ensure(GPU_ATTACHMENT_TEXTURE_LAYER(depth_tx, layer_), GPU_ATTACHMENT_TEXTURE_LAYER(color_tx, layer_)); diff --git a/source/blender/draw/engines/eevee/eevee_view.hh b/source/blender/draw/engines/eevee/eevee_view.hh index ddfbf403ff2..19f6f59adc8 100644 --- a/source/blender/draw/engines/eevee/eevee_view.hh +++ b/source/blender/draw/engines/eevee/eevee_view.hh @@ -92,7 +92,7 @@ class ShadingView { DRWView *render_view_ = nullptr; /** Render size of the view. Can change between scene sample eval. */ - ivec2 extent_ = {-1, -1}; + int2 extent_ = {-1, -1}; bool is_enabled_ = false; @@ -113,7 +113,7 @@ class ShadingView { void init(void); - void sync(ivec2 render_extent_); + void sync(int2 render_extent_); void render(void); @@ -150,7 +150,7 @@ class LightProbeView { /** DRWView of this face. */ DRWView *view_ = nullptr; /** Render size of the view. */ - ivec2 extent_ = {-1, -1}; + int2 extent_ = {-1, -1}; int layer_ = 0; bool is_only_background_ = false; @@ -170,8 +170,8 @@ class LightProbeView { void sync(Texture &color_tx, Texture &depth_tx, - const mat4 winmat, - const mat4 viewmat, + const float4x4 winmat, + const float4x4 viewmat, bool is_only_background); void render(void); @@ -205,7 +205,7 @@ class MainView { { } - void init(const ivec2 full_extent_) + void init(const int2 full_extent_) { /* TODO(fclem) parameter hidden in experimental. We need to figure out mipmap bias to preserve * texture crispiness. */ |