Blender  V2.93
bake.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2014 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "render/bake.h"
18 #include "render/buffers.h"
19 #include "render/integrator.h"
20 #include "render/mesh.h"
21 #include "render/object.h"
22 #include "render/shader.h"
23 #include "render/stats.h"
24 
25 #include "util/util_foreach.h"
26 
28 
30 {
32  return 1;
33  }
34  else if (type == SHADER_EVAL_NORMAL) {
35  /* Only antialias normal if mesh has bump mapping. */
36  if (object->get_geometry()) {
37  foreach (Node *node, object->get_geometry()->get_used_shaders()) {
38  Shader *shader = static_cast<Shader *>(node);
39  if (shader->has_bump) {
40  return scene->integrator->get_aa_samples();
41  }
42  }
43  }
44 
45  return 1;
46  }
47  else {
48  return scene->integrator->get_aa_samples();
49  }
50 }
51 
52 /* Keep it synced with kernel_bake.h logic */
53 static int shader_type_to_pass_filter(ShaderEvalType type, int pass_filter)
54 {
55  const int component_flags = pass_filter &
57 
58  switch (type) {
59  case SHADER_EVAL_AO:
60  return BAKE_FILTER_AO;
61  case SHADER_EVAL_SHADOW:
62  return BAKE_FILTER_DIRECT;
64  return BAKE_FILTER_DIFFUSE | component_flags;
65  case SHADER_EVAL_GLOSSY:
66  return BAKE_FILTER_GLOSSY | component_flags;
68  return BAKE_FILTER_TRANSMISSION | component_flags;
70  return pass_filter;
71  default:
72  return 0;
73  }
74 }
75 
77 {
78  type = SHADER_EVAL_BAKE;
79  pass_filter = 0;
80 
81  need_update_ = true;
82 }
83 
85 {
86 }
87 
89 {
90  return !object_name.empty();
91 }
92 
94  const std::string &object_name_,
95  ShaderEvalType type_,
96  int pass_filter_)
97 {
98  object_name = object_name_;
99  type = type_;
100  pass_filter = shader_type_to_pass_filter(type_, pass_filter_);
101 
104 
105  if (type == SHADER_EVAL_UV) {
106  /* force UV to be available */
108  }
109 
110  /* force use_light_pass to be true if we bake more than just colors */
111  if (pass_filter & ~BAKE_FILTER_COLOR) {
113  }
114 
115  /* create device and update scene */
116  scene->film->tag_modified();
118 
119  need_update_ = true;
120 }
121 
123  DeviceScene *dscene,
124  Scene *scene,
125  Progress & /* progress */)
126 {
127  if (!need_update())
128  return;
129 
130  scoped_callback_timer timer([scene](double time) {
131  if (scene->update_stats) {
132  scene->update_stats->bake.times.add_entry({"device_update", time});
133  }
134  });
135 
136  KernelIntegrator *kintegrator = &dscene->data.integrator;
137  KernelBake *kbake = &dscene->data.bake;
138 
139  kbake->type = type;
140  kbake->pass_filter = pass_filter;
141 
142  int object_index = 0;
143  foreach (Object *object, scene->objects) {
144  const Geometry *geom = object->get_geometry();
145  if (object->name == object_name && geom->geometry_type == Geometry::MESH) {
146  kbake->object_index = object_index;
147  kbake->tri_offset = geom->prim_offset;
148  kintegrator->aa_samples = aa_samples(scene, object, type);
149  break;
150  }
151 
152  object_index++;
153  }
154 
155  need_update_ = false;
156 }
157 
158 void BakeManager::device_free(Device * /*device*/, DeviceScene * /*dscene*/)
159 {
160 }
161 
163 {
164  need_update_ = true;
165 }
166 
168 {
169  return need_update_;
170 }
171 
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static CCL_NAMESPACE_BEGIN int aa_samples(Scene *scene, Object *object, ShaderEvalType type)
Definition: bake.cpp:29
static int shader_type_to_pass_filter(ShaderEvalType type, int pass_filter)
Definition: bake.cpp:53
bool get_baking()
Definition: bake.cpp:88
~BakeManager()
Definition: bake.cpp:84
bool need_update() const
Definition: bake.cpp:167
void set(Scene *scene, const std::string &object_name, ShaderEvalType type, int pass_filter)
Definition: bake.cpp:93
void device_free(Device *device, DeviceScene *dscene)
Definition: bake.cpp:158
BakeManager()
Definition: bake.cpp:76
void tag_update()
Definition: bake.cpp:162
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
Definition: bake.cpp:122
Definition: device.h:293
Type geometry_type
Definition: geometry.h:78
@ MESH
Definition: geometry.h:73
size_t prim_offset
Definition: geometry.h:102
void tag_update(Scene *scene, uint32_t flag)
Definition: integrator.cpp:292
static void add(PassType type, vector< Pass > &passes, const char *name=NULL)
Definition: film.cpp:103
Definition: shader.h:80
OperationNode * node
double time
Scene scene
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
@ PASS_UV
Definition: kernel_types.h:354
@ PASS_BAKE_DIFFERENTIAL
Definition: kernel_types.h:394
@ PASS_LIGHT
Definition: kernel_types.h:378
@ PASS_BAKE_PRIMITIVE
Definition: kernel_types.h:393
ShaderEvalType
Definition: kernel_types.h:196
@ SHADER_EVAL_DIFFUSE
Definition: kernel_types.h:218
@ SHADER_EVAL_TRANSMISSION
Definition: kernel_types.h:220
@ SHADER_EVAL_GLOSSY
Definition: kernel_types.h:219
@ SHADER_EVAL_UV
Definition: kernel_types.h:205
@ SHADER_EVAL_ROUGHNESS
Definition: kernel_types.h:206
@ SHADER_EVAL_SHADOW
Definition: kernel_types.h:217
@ SHADER_EVAL_AO
Definition: kernel_types.h:215
@ SHADER_EVAL_NORMAL
Definition: kernel_types.h:204
@ SHADER_EVAL_BAKE
Definition: kernel_types.h:200
@ SHADER_EVAL_COMBINED
Definition: kernel_types.h:216
@ BAKE_FILTER_TRANSMISSION
Definition: kernel_types.h:441
@ BAKE_FILTER_DIFFUSE
Definition: kernel_types.h:439
@ BAKE_FILTER_DIRECT
Definition: kernel_types.h:436
@ BAKE_FILTER_INDIRECT
Definition: kernel_types.h:437
@ BAKE_FILTER_AO
Definition: kernel_types.h:443
@ BAKE_FILTER_COLOR
Definition: kernel_types.h:438
@ BAKE_FILTER_GLOSSY
Definition: kernel_types.h:440
Definition: node.h:98
ustring name
Definition: node.h:174
void tag_modified()
Definition: node.cpp:786
Film * film
Definition: scene.h:229
vector< Pass > passes
Definition: scene.h:239
vector< Object * > objects
Definition: scene.h:234
Integrator * integrator
Definition: scene.h:231
SceneUpdateStats * update_stats
Definition: scene.h:270