This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/intern/cycles/scene/bake.cpp
Phoenix Katsch b475506cfb Cycles: add option to bake specular from active camera viewpoint
Previously it would bake viewed from above the surface. The new option can be
useful when the baked result is meant to be viewed from a fixed viewpoint or
with limited camera motion.

Some effort is made to give a continuous reflection on parts of the surface
invisible to the camera, but this is necessarily only a rough approximation.

Differential Revision: https://developer.blender.org/D15921
2022-10-03 21:59:31 +02:00

103 lines
2.1 KiB
C++

/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include "scene/bake.h"
#include "scene/integrator.h"
#include "scene/mesh.h"
#include "scene/object.h"
#include "scene/shader.h"
#include "scene/stats.h"
#include "session/buffers.h"
#include "util/foreach.h"
CCL_NAMESPACE_BEGIN
BakeManager::BakeManager()
{
need_update_ = true;
use_camera_ = false;
}
BakeManager::~BakeManager()
{
}
bool BakeManager::get_baking() const
{
return !object_name.empty();
}
void BakeManager::set(Scene *scene, const std::string &object_name_)
{
object_name = object_name_;
/* create device and update scene */
scene->film->tag_modified();
scene->integrator->tag_update(scene, Integrator::UPDATE_ALL);
need_update_ = true;
}
void BakeManager::set_use_camera(const bool use_camera)
{
if (use_camera_ != use_camera) {
use_camera_ = use_camera;
need_update_ = true;
}
}
void BakeManager::device_update(Device * /*device*/,
DeviceScene *dscene,
Scene *scene,
Progress & /* progress */)
{
if (!need_update())
return;
KernelBake *kbake = &dscene->data.bake;
memset(kbake, 0, sizeof(*kbake));
kbake->use_camera = use_camera_;
if (!object_name.empty()) {
scoped_callback_timer timer([scene](double time) {
if (scene->update_stats) {
scene->update_stats->bake.times.add_entry({"device_update", time});
}
});
kbake->use = true;
int object_index = 0;
foreach (Object *object, scene->objects) {
const Geometry *geom = object->get_geometry();
if (object->name == object_name && geom->geometry_type == Geometry::MESH) {
kbake->object_index = object_index;
kbake->tri_offset = geom->prim_offset;
break;
}
object_index++;
}
}
need_update_ = false;
}
void BakeManager::device_free(Device * /*device*/, DeviceScene * /*dscene*/)
{
}
void BakeManager::tag_update()
{
need_update_ = true;
}
bool BakeManager::need_update() const
{
return need_update_;
}
CCL_NAMESPACE_END