37 for (
auto &pix : pix_z) {
38 pix = (-winmat[3][2] / -pix) - winmat[2][2];
39 pix =
clamp_f(pix * 0.5f + 0.5f, 0.0f, 1.0f);
46 const float range_inv = 1.0f /
fabsf(far - near);
47 for (
auto &pix : pix_z) {
48 pix = (pix + near) * range_inv;
55 const Depsgraph *depsgraph,
74 const bool use_separated_pass)
87 if (!pix_z || !pix_col) {
89 "Warning: To correctly render occluded Grease Pencil objects, "
90 "enable Combined and Depth passes.");
95 pix_z = MEM_dupalloc(pix_z);
99 const bool has_full_rect = (rect->
xmin == 0 && rect->
ymin == 0 && rect->
xmax == size.x &&
100 rect->
ymax == size.y);
101 const bool do_region = !use_separated_pass && !has_full_rect;
102 const bool do_clear_z = !pix_z || do_region;
103 const bool do_clear_col = use_separated_pass || (!pix_col) || do_region;
115 gpu::TextureFormat::SFLOAT_32_DEPTH,
int2(size), usage, do_region ?
nullptr : pix_z);
124 gpu::TextureFormat::SFLOAT_16_16_16_16,
int2(size), usage, do_region ?
nullptr : pix_col);
130 if (do_clear_z || do_clear_col) {
154 MEM_SAFE_DELETE(pix_z);
159 const char *viewname,
188 for (
int i = 0; i < pix_num; i++) {
189 if (ro_buffer_data[i] == 1.0f) {
190 ro_buffer_data[i] = 1e10f;
193 ro_buffer_data[i] = ro_buffer_data[i] * 2.0f - 1.0f;
194 ro_buffer_data[i] = winmat[3][2] / (ro_buffer_data[i] + winmat[2][2]);
202 float range =
fabsf(far - near);
204 for (
int i = 0; i < pix_num; i++) {
205 if (ro_buffer_data[i] == 1.0f) {
206 ro_buffer_data[i] = 1e10f;
209 ro_buffer_data[i] = ro_buffer_data[i] * range - near;
247 cdf[u] /= cdf.
last();
258 const float x =
clamp_f(u /
float(inverted_cdf.
size() - 1), 1e-5f, 1.0f - 1e-5f);
261 const float t = (
x - cdf[i]) / (cdf[i] - cdf[i - 1]);
262 inverted_cdf[u] = (
float(i) + t) /
float(cdf.
size() - 1);
271 const float shutter_time,
272 const float frame_time,
275 switch (shutter_position) {
289 time *= shutter_time;
295 Depsgraph *depsgraph,
301 const bool separated_pass)
305 const float aa_radius =
clamp_f(scene->
r.
gauss, 0.0f, 100.0f);
307 const bool motion_blur_enabled = (scene->
r.
mode &
R_MBLUR) != 0 &&
311 const int motion_steps_count =
315 const int aa_per_step = total_step_count / motion_steps_count;
320 const int initial_frame = scene->
r.
cfra;
321 const float initial_subframe = scene->
r.
subframe;
322 const float frame_time = initial_frame + initial_subframe;
325 if (motion_blur_enabled) {
332 for (
float &scene_time : time_steps) {
334 shutter_position, shutter_time, frame_time, scene_time);
339 time_steps.
first() = frame_time;
343 for (
const float time : time_steps) {
346 if (motion_blur_enabled) {
369 for ([[maybe_unused]]
const int i :
IndexRange(aa_per_step)) {
384 const float weight = 1.0f / (1.0f + sample_i);
391 if (motion_blur_enabled) {
402 Depsgraph *depsgraph = draw_ctx->
depsgraph;
417 render_frame(engine, depsgraph, draw_ctx, render_layer, rect, inst, manager,
false);
424 render_frame(engine, depsgraph, draw_ctx, render_layer, rect, inst, manager,
true);
General operations, lookup, etc. for blender objects.
#define RE_PASSNAME_COMBINED
#define RE_PASSNAME_DEPTH
#define RE_PASSNAME_GREASE_PENCIL
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
#define BLI_assert_msg(a, msg)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
const T & last(const int64_t n=0) const
IndexRange index_range() const
constexpr IndexRange()=default
constexpr IndexRange drop_front(int64_t n) const
void ensure(GPUAttachment depth=GPU_ATTACHMENT_NONE, GPUAttachment color1=GPU_ATTACHMENT_NONE, GPUAttachment color2=GPU_ATTACHMENT_NONE, GPUAttachment color3=GPU_ATTACHMENT_NONE, GPUAttachment color4=GPU_ATTACHMENT_NONE, GPUAttachment color5=GPU_ATTACHMENT_NONE, GPUAttachment color6=GPU_ATTACHMENT_NONE, GPUAttachment color7=GPU_ATTACHMENT_NONE, GPUAttachment color8=GPU_ATTACHMENT_NONE)
void begin_sync(Object *object_active=nullptr)
bool ensure_2d(gpu::TextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
int3 size(int miplvl=0) const
static void default_set(const float4x4 &view_mat, const float4x4 &win_mat)
bool is_persp(int view_id=0) const
const float4x4 & winmat(int view_id=0) const
static View & default_get()
float near_clip(int view_id=0) const
float far_clip(int view_id=0) const
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
static void render_set_view(RenderEngine *engine, const Depsgraph *depsgraph, const float2 aa_offset=float2{0.0f})
static void cdf_invert(Array< float > &cdf, Array< float > &inverted_cdf)
static void render_frame(RenderEngine *engine, Depsgraph *depsgraph, const DRWContext *draw_ctx, RenderLayer *render_layer, const rcti rect, gpencil::Instance &inst, Manager &manager, const bool separated_pass)
static void render_result_color(ImBuf *ibuf, Instance &instance, const rcti *rect)
static void remap_depth(const View &view, MutableSpan< float > pix_z)
static void cdf_from_curvemapping(const CurveMapping &curve, Array< float > &cdf)
static float shutter_time_to_scene_time(const int shutter_position, const float shutter_time, const float frame_time, float time)
static void render_init_buffers(const DRWContext *draw_ctx, Instance &inst, RenderEngine *engine, RenderLayer *render_layer, const rcti *rect, const bool use_separated_pass)
static void render_result_z(const DRWContext *draw_ctx, RenderLayer *rl, const char *viewname, Instance &instance, const rcti *rect)
CartesianBasis invert(const CartesianBasis &basis)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_framebuffer_read_color(gpu::FrameBuffer *fb, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
MINLINE float fractf(float a)
void window_translate_m4(float winmat[4][4], float perspmat[4][4], float x, float y)
void GPU_framebuffer_clear_color(gpu::FrameBuffer *fb, const double4 clear_col)
void RE_GetCameraWindow(Render *re, const Object *camera, float r_winmat[4][4])
ImBuf * RE_RenderLayerGetPassImBuf(RenderLayer *rl, const char *name, const char *viewname)
MINLINE int max_ii(int a, int b)
@ GREASE_PENCIL_AS_SEPARATE_PASS
MatBase< float, 4, 4 > float4x4
int DRW_object_visibility_in_active_context(const Object *ob)
void DRW_render_object_iter(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(draw::ObjectRef &, RenderEngine *, Depsgraph *)> callback)
void DRW_render_set_time(RenderEngine *engine, Depsgraph *depsgraph, int frame, float subframe)
void GPU_texture_update_sub(gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth, uint unpack_row_length=0)
const char * RE_GetActiveRenderView(Render *re)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
void RE_GetCameraModelMatrix(const Render *re, const Object *camera, float r_modelmat[4][4])
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void BKE_curvemapping_changed(CurveMapping *cumap, bool rem_doubles)
void IMB_partial_update_mark_full(ImBuf *ibuf)
const DRWContext * DRW_context_get()
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
void GPU_framebuffer_clear_depth(gpu::FrameBuffer *fb, float clear_depth)
RenderPass * RE_pass_find_by_name(RenderLayer *rl, const char *name, const char *viewname)
void RE_engine_set_error_message(RenderEngine *engine, const char *msg)
void RE_create_render_pass(RenderResult *rr, const char *name, int channels, const char *chan_id, const char *layername, const char *viewname, const bool allocate)
draw::Manager * DRW_manager_get()
MINLINE uint ceil_to_multiple_u(uint a, uint b)
void GPU_framebuffer_read_depth(gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
MINLINE float clamp_f(float value, float min, float max)
Object * RE_GetCamera(Render *re)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float2 viewport_size_get() const
float * float_data_for_write()
const c_style_mat & ptr() const
struct CurveMapping mblur_shutter_curve
float motion_blur_shutter
struct SceneGpencil grease_pencil_settings
eViewLayerGreasePencilFlags grease_pencil_flags
static void render_to_image(RenderEngine *engine, RenderLayer *render_layer, const rcti rect)
void draw(Manager &manager) final
static float2 antialiasing_sample_get(int sample_index, int sample_count)
void object_sync(ObjectRef &ob_ref, Manager &manager) final
void antialiasing_accumulate(Manager &manager, float alpha)