34 if (
view.is_persp()) {
36 for (
auto &pix : pix_z) {
37 pix = (-winmat[3][2] / -pix) - winmat[2][2];
38 pix =
clamp_f(pix * 0.5f + 0.5f, 0.0f, 1.0f);
43 const float near =
view.near_clip();
44 const float far =
view.far_clip();
45 const float range_inv = 1.0f /
fabsf(far - near);
46 for (
auto &pix : pix_z) {
47 pix = (pix + near) * range_inv;
73 const bool use_separated_pass)
86 if (!pix_z || !pix_col) {
88 engine,
"Warning: To render Grease Pencil, enable Combined and Depth passes.");
97 const bool do_region = (!use_separated_pass) && !(rect->
xmin == 0 && rect->
ymin == 0 &&
99 const bool do_clear_z = !pix_z || do_region;
100 const bool do_clear_col = use_separated_pass || (!pix_col) || do_region;
112 gpu::TextureFormat::SFLOAT_32_DEPTH,
int2(
size), usage, do_region ?
nullptr : pix_z);
121 gpu::TextureFormat::SFLOAT_16_16_16_16,
int2(
size), usage, do_region ?
nullptr : pix_col);
127 if (do_clear_z || do_clear_col) {
131 const float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
157 const char *viewname,
186 for (
int i = 0;
i < pix_num;
i++) {
187 if (ro_buffer_data[
i] == 1.0f) {
188 ro_buffer_data[
i] = 1e10f;
191 ro_buffer_data[
i] = ro_buffer_data[
i] * 2.0f - 1.0f;
192 ro_buffer_data[
i] = winmat[3][2] / (ro_buffer_data[
i] + winmat[2][2]);
200 float range =
fabsf(far - near);
202 for (
int i = 0;
i < pix_num;
i++) {
203 if (ro_buffer_data[
i] == 1.0f) {
204 ro_buffer_data[
i] = 1e10f;
207 ro_buffer_data[
i] = ro_buffer_data[
i] * range - near;
214 const char *viewname,
262 cdf[u] /= cdf.
last();
273 const float x =
clamp_f(u /
float(inverted_cdf.
size() - 1), 1e-5f, 1.0f - 1e-5f);
276 const float t = (
x - cdf[
i]) / (cdf[
i] - cdf[
i - 1]);
277 inverted_cdf[u] = (
float(
i) + t) /
float(cdf.
size() - 1);
286 const float shutter_time,
287 const float frame_time,
290 switch (shutter_position) {
304 time *= shutter_time;
316 const bool separated_pass)
320 const float aa_radius =
clamp_f(scene->
r.
gauss, 0.0f, 100.0f);
322 const bool motion_blur_enabled = (scene->
r.
mode &
R_MBLUR) != 0 &&
326 const int motion_steps_count =
330 const int aa_per_step = total_step_count / motion_steps_count;
335 const int initial_frame = scene->
r.
cfra;
336 const float initial_subframe = scene->
r.
subframe;
337 const float frame_time = initial_frame + initial_subframe;
340 if (motion_blur_enabled) {
347 for (
float &scene_time : time_steps) {
349 shutter_position, shutter_time, frame_time, scene_time);
354 time_steps.
first() = frame_time;
358 for (
const float time : time_steps) {
361 if (motion_blur_enabled) {
384 for ([[maybe_unused]]
const int i :
IndexRange(aa_per_step)) {
399 const float weight = 1.0f / (1.0f + sample_i);
406 if (motion_blur_enabled) {
General operations, lookup, etc. for blender objects.
#define BLI_assert_msg(a, msg)
MINLINE uint ceil_to_multiple_u(uint a, uint b)
MINLINE float clamp_f(float value, float min, float max)
MINLINE int max_ii(int a, int b)
void window_translate_m4(float winmat[4][4], float perspmat[4][4], float x, float y)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ GREASE_PENCIL_AS_SEPARATE_PASS
#define RE_PASSNAME_COMBINED
#define RE_PASSNAME_DEPTH
#define RE_PASSNAME_GREASE_PENCIL
#define GPU_ATTACHMENT_TEXTURE(_texture)
void GPU_framebuffer_read_color(blender::gpu::FrameBuffer *fb, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
#define GPU_ATTACHMENT_NONE
void GPU_framebuffer_clear_depth(blender::gpu::FrameBuffer *fb, float clear_depth)
void GPU_framebuffer_clear_color(blender::gpu::FrameBuffer *fb, const float clear_col[4])
void GPU_framebuffer_read_depth(blender::gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void GPU_texture_update_sub(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
void GPU_texture_update(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
BMesh const char void * data
BPy_StructRNA * depsgraph
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
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 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(blender::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)
const float4x4 & winmat(int view_id=0) const
float near_clip(int view_id=0) const
static View & default_get()
float far_clip(int view_id=0) const
const DRWContext * DRW_context_get()
void DRW_render_object_iter(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(blender::draw::ObjectRef &, RenderEngine *, Depsgraph *)> callback)
int DRW_object_visibility_in_active_context(const Object *ob)
void DRW_render_set_time(RenderEngine *engine, Depsgraph *depsgraph, int frame, float subframe)
blender::draw::Manager * DRW_manager_get()
void RE_GetCameraModelMatrix(const Render *re, const Object *camera, float r_modelmat[4][4])
void RE_GetCameraWindow(Render *re, const Object *camera, float r_winmat[4][4])
Object * RE_GetCamera(Render *re)
void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
void RE_engine_set_error_message(RenderEngine *engine, const char *msg)
void * MEM_dupallocN(const void *vmemh)
static void render_set_view(RenderEngine *engine, const Depsgraph *depsgraph, const float2 aa_offset=float2{0.0f})
static void render_result_separated_pass(float *data, Instance &instance, const rcti *rect)
static void render_result_combined(RenderLayer *rl, const char *viewname, Instance &instance, const rcti *rect)
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 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)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
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)
RenderPass * RE_pass_find_by_name(RenderLayer *rl, const char *name, const char *viewname)
const char * RE_GetActiveRenderView(Render *re)
float * RE_RenderLayerGetPass(RenderLayer *rl, const char *name, const char *viewname)
blender::float2 viewport_size_get() const
ImBufFloatBuffer float_buffer
float motion_blur_shutter
struct CurveMapping mblur_shutter_curve
struct SceneGpencil grease_pencil_settings
const c_style_mat & ptr() const
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)