8#include <pxr/base/gf/camera.h>
9#include <pxr/imaging/glf/drawTarget.h>
10#include <pxr/usd/usdGeom/camera.h>
63 float camera_points[4][3];
66 float screen_points[4][2];
67 for (
int i = 0;
i < 4;
i++) {
68 float world_location[] = {
69 camera_points[
i][0], camera_points[
i][1], camera_points[
i][2], 1.0f};
70 mul_m4_v4(camera_obj->object_to_world().ptr(), world_location);
73 if (world_location[3] > 0.0) {
75 screen_width * 0.5f * (world_location[0] / world_location[3]);
77 screen_height * 0.5f * (world_location[1] / world_location[3]);
82 float x1_f = std::min(
83 {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
84 float x2_f = std::max(
85 {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
86 float y1_f = std::min(
87 {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
88 float y2_f = std::max(
89 {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
92 float x = x1_f,
y = y1_f;
93 float dx = x2_f - x1_f, dy = y2_f - y1_f;
116 border = pxr::GfVec4i(x1, y1, x2, y2);
139 float coords[8] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0};
162 if (buffer ==
nullptr) {
169 if (buffer->GetFormat() == pxr::HdFormat::HdFormatFloat16Vec4) {
170 texture_format = blender::gpu::TextureFormat::SFLOAT_16_16_16_16;
174 texture_format = blender::gpu::TextureFormat::SFLOAT_32_32_32_32;
186 if (texture_ ==
nullptr) {
196 void *
data = buffer->Map();
202 const pxr::GfVec4d &viewport,
228 if (view_settings.
width() * view_settings.
height() == 0) {
234 pxr::GfVec4d viewport(0.0, 0.0, view_settings.
width(), view_settings.
height());
255 pxr::GfVec4d draw_viewport(view_settings.
border[0],
262 draw_texture_.draw(shader, draw_viewport, gpu_task->
get_aov_texture(pxr::HdAovTokens->color));
265 draw_texture_.create_from_buffer(
267 draw_texture_.draw(shader, draw_viewport);
276 char elapsed_time[32];
284 std ::string(
"Time: ") + elapsed_time +
285 " | Done: " + std::to_string(
int(percent_done)) +
"%",
290 notify_status(percent_done / 100.0, std::string(
"Time: ") + elapsed_time,
"Rendering Done");
301 const std::string &info,
302 const std::string &
status)
Camera data-block and utility functions.
void BKE_camera_view_frame(const struct Scene *scene, const struct Camera *camera, float r_vec[4][3])
void * CTX_wm_region_data(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
void mul_m4_v4(const float mat[4][4], float r[4])
Platform independent time functions.
double BLI_time_now_seconds(void)
size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double time_seconds) ATTR_NONNULL()
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
void GPU_batch_discard(blender::gpu::Batch *batch)
blender::gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, blender::gpu::VertBuf *vertex_buf, blender::gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
void GPU_batch_draw(blender::gpu::Batch *batch)
void GPU_batch_set_shader(blender::gpu::Batch *batch, blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
blender::gpu::FrameBuffer * GPU_framebuffer_active_get()
void GPU_matrix_scale_2f(float x, float y)
void GPU_matrix_translate_2f(float x, float y)
int GPU_shader_get_sampler_binding(blender::gpu::Shader *shader, const char *name)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(blender::gpu::Shader *sh, const char *name, int value)
blender::gpu::Shader * GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
int GPU_texture_height(const blender::gpu::Texture *texture)
blender::gpu::TextureFormat GPU_texture_format(const blender::gpu::Texture *texture)
int GPU_texture_width(const blender::gpu::Texture *texture)
@ GPU_TEXTURE_USAGE_GENERAL
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_bind(blender::gpu::Texture *texture, int unit)
void GPU_texture_free(blender::gpu::Texture *texture)
void GPU_texture_update(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void GPU_vertbuf_attr_fill(blender::gpu::VertBuf *, uint a_idx, const void *data)
static blender::gpu::VertBuf * GPU_vertbuf_create_with_format(const GPUVertFormat &format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
BMesh const char void * data
BPy_StructRNA * depsgraph
void draw(gpu::Shader *shader, const pxr::GfVec4d &viewport, blender::gpu::Texture *tex=nullptr)
blender::gpu::Texture * texture() const
void create_from_buffer(pxr::HdRenderBuffer *buffer)
RenderEngine * bl_engine_
float renderer_percent_done()
pxr::HdTaskSharedPtrVector tasks()
std::unique_ptr< RenderTaskDelegate > render_task_delegate_
std::unique_ptr< io::hydra::CameraDelegate > free_camera_delegate_
std::unique_ptr< pxr::HdRenderIndex > render_index_
std::unique_ptr< LightTasksDelegate > light_tasks_delegate_
std::unique_ptr< pxr::HdEngine > engine_
blender::gpu::Texture * get_aov_texture(pxr::TfToken const &aov_key)
void notify_status(float progress, const std::string &info, const std::string &status) override
void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info)
static pxr::GfCamera gf_camera(const CameraParams ¶ms, const pxr::GfVec2i &res, const pxr::GfVec4f &border)
ViewSettings(bContext *context)