forked from blender/blender
Fix rendering of Final render for Storm delegate #61
@ -2,6 +2,7 @@
|
|||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
#include <pxr/imaging/glf/drawTarget.h>
|
#include <pxr/imaging/glf/drawTarget.h>
|
||||||
|
#include <pxr/imaging/hd/light.h>
|
||||||
|
|
||||||
#include "BKE_lib_id.h"
|
#include "BKE_lib_id.h"
|
||||||
#include "BLI_timecode.h"
|
#include "BLI_timecode.h"
|
||||||
@ -143,8 +144,16 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
|
|
||||||
GPU_framebuffer_bind(framebuffer);
|
GPU_framebuffer_bind(framebuffer);
|
||||||
|
|
||||||
float clear_color[4] = {0.1f, 0.1f, 0.1f, 1.0f};
|
float clear_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0);
|
pxr::VtValue world_color = scene_delegate_->GetLightParamValue(
|
||||||
|
scene_delegate_->GetDelegateID().AppendElementString("World"), pxr::HdLightTokens->color);
|
||||||
|
if (!world_color.IsEmpty()) {
|
||||||
|
auto &c = world_color.Get<pxr::GfVec3f>();
|
||||||
|
clear_color[0] = c[0];
|
||||||
|
clear_color[1] = c[1];
|
||||||
|
clear_color[2] = c[2];
|
||||||
|
}
|
||||||
|
GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0f);
|
||||||
|
|
||||||
// Generate vertex array
|
// Generate vertex array
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
@ -193,153 +202,4 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
GPU_texture_free(tex_depth);
|
GPU_texture_free(tex_depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinalEngineGL::render0(Depsgraph *depsgraph)
|
|
||||||
{
|
|
||||||
prepare_for_render(depsgraph);
|
|
||||||
|
|
||||||
GLuint fbo = 0, tex_color = 0, tex_depth = 0;
|
|
||||||
glGenFramebuffers(1, &fbo);
|
|
||||||
glGenTextures(1, &tex_color);
|
|
||||||
glGenTextures(1, &tex_depth);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
|
||||||
|
|
||||||
// Set tex_color as GL_COLOR_ATTACHMENT0
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tex_color);
|
|
||||||
glTexImage2D(
|
|
||||||
GL_TEXTURE_2D, 0, GL_RGBA32F, resolution_[0], resolution_[1], 0, GL_RGBA, GL_FLOAT, 0);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_color, 0);
|
|
||||||
|
|
||||||
|
|
||||||
GLuint rbo = 0;
|
|
||||||
glGenRenderbuffers(1, &rbo);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, resolution_[0], resolution_[1]);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
||||||
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
|
||||||
|
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
|
||||||
printf("ERROR::FRAMEBUFFER:: Framebuffer is not complete!\n");
|
|
||||||
}
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
|
|
||||||
//// Set tex_depth as GL_DEPTH_ATTACHMENT
|
|
||||||
//glBindTexture(GL_TEXTURE_2D, tex_depth);
|
|
||||||
//glTexImage2D(GL_TEXTURE_2D,
|
|
||||||
// 0,
|
|
||||||
// GL_DEPTH_COMPONENT32,
|
|
||||||
// resolution_[0],
|
|
||||||
// resolution_[1],
|
|
||||||
// 0,
|
|
||||||
// GL_DEPTH_COMPONENT,
|
|
||||||
// GL_FLOAT,
|
|
||||||
// 0);
|
|
||||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
////glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex_depth, 0);
|
|
||||||
|
|
||||||
// Generate vertex array
|
|
||||||
GLuint vao;
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
|
||||||
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
|
||||||
//glClearDepthf(1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
//glDepthFunc(GL_LESS);
|
|
||||||
|
|
||||||
engine_->Execute(render_index_.get(), &tasks_);
|
|
||||||
|
|
||||||
std::vector<float> &pixels = render_images_["Combined"];
|
|
||||||
char elapsed_time[32];
|
|
||||||
double time_begin = PIL_check_seconds_timer();
|
|
||||||
float percent_done = 0.0;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (RE_engine_test_break(bl_engine_)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
percent_done = renderer_percent_done();
|
|
||||||
|
|
||||||
BLI_timecode_string_from_time_simple(
|
|
||||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
|
||||||
|
|
||||||
notify_status(percent_done / 100.0,
|
|
||||||
scene_name_ + ": " + layer_name_,
|
|
||||||
std::string("Render Time: ") + elapsed_time +
|
|
||||||
" | Done: " + std::to_string(int(percent_done)) + "%");
|
|
||||||
|
|
||||||
if (render_task_delegate_->is_converged()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tex_color);
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
|
||||||
update_render_result();
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tex_color);
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
|
||||||
update_render_result();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FinalEngineGL::render1(Depsgraph *depsgraph)
|
|
||||||
{
|
|
||||||
prepare_for_render(depsgraph);
|
|
||||||
|
|
||||||
auto d = pxr::GlfDrawTarget::New(resolution_);
|
|
||||||
d->Bind();
|
|
||||||
d->AddAttachment("color", GL_RGBA, GL_FLOAT, GL_RGBA32F);
|
|
||||||
d->AddAttachment("depth", GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32);
|
|
||||||
|
|
||||||
// Generate vertex array
|
|
||||||
GLuint vao;
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
engine_->Execute(render_index_.get(), &tasks_);
|
|
||||||
|
|
||||||
std::vector<float> &pixels = render_images_["Combined"];
|
|
||||||
char elapsed_time[32];
|
|
||||||
double time_begin = PIL_check_seconds_timer();
|
|
||||||
float percent_done = 0.0;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (RE_engine_test_break(bl_engine_)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
percent_done = renderer_percent_done();
|
|
||||||
|
|
||||||
BLI_timecode_string_from_time_simple(
|
|
||||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
|
||||||
|
|
||||||
notify_status(percent_done / 100.0,
|
|
||||||
scene_name_ + ": " + layer_name_,
|
|
||||||
std::string("Render Time: ") + elapsed_time +
|
|
||||||
" | Done: " + std::to_string(int(percent_done)) + "%");
|
|
||||||
|
|
||||||
if (render_task_delegate_->is_converged()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint t = d->GetAttachment("color")->GetGlTextureName();
|
|
||||||
glBindTexture(GL_TEXTURE_2D, t);
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
|
||||||
update_render_result();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -30,8 +30,6 @@ class FinalEngineGL : public FinalEngine {
|
|||||||
public:
|
public:
|
||||||
using FinalEngine::FinalEngine;
|
using FinalEngine::FinalEngine;
|
||||||
|
|
||||||
void render0(Depsgraph *depsgraph);
|
|
||||||
void render1(Depsgraph *depsgraph);
|
|
||||||
void render(Depsgraph *depsgraph) override;
|
void render(Depsgraph *depsgraph) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user