bake.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef __BAKE_H__
  17. #define __BAKE_H__
  18. #include "device/device.h"
  19. #include "render/scene.h"
  20. #include "util/util_progress.h"
  21. #include "util/util_vector.h"
  22. CCL_NAMESPACE_BEGIN
  23. class BakeData {
  24. public:
  25. BakeData(const int object, const size_t tri_offset, const size_t num_pixels);
  26. ~BakeData();
  27. void set(int i, int prim, float uv[2], float dudx, float dudy, float dvdx, float dvdy);
  28. void set_null(int i);
  29. int object();
  30. size_t size();
  31. uint4 data(int i);
  32. uint4 differentials(int i);
  33. bool is_valid(int i);
  34. private:
  35. int m_object;
  36. size_t m_tri_offset;
  37. size_t m_num_pixels;
  38. vector<int> m_primitive;
  39. vector<float> m_u;
  40. vector<float> m_v;
  41. vector<float> m_dudx;
  42. vector<float> m_dudy;
  43. vector<float> m_dvdx;
  44. vector<float> m_dvdy;
  45. };
  46. class BakeManager {
  47. public:
  48. BakeManager();
  49. ~BakeManager();
  50. bool get_baking();
  51. void set_baking(const bool value);
  52. BakeData *init(const int object, const size_t tri_offset, const size_t num_pixels);
  53. void set_shader_limit(const size_t x, const size_t y);
  54. bool bake(Device *device,
  55. DeviceScene *dscene,
  56. Scene *scene,
  57. Progress &progress,
  58. ShaderEvalType shader_type,
  59. const int pass_filter,
  60. BakeData *bake_data,
  61. float result[]);
  62. void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
  63. void device_free(Device *device, DeviceScene *dscene);
  64. static int shader_type_to_pass_filter(ShaderEvalType type, const int pass_filter);
  65. static int aa_samples(Scene *scene, BakeData *bake_data, ShaderEvalType type);
  66. bool need_update;
  67. size_t total_pixel_samples;
  68. private:
  69. BakeData *m_bake_data;
  70. bool m_is_baking;
  71. size_t m_shader_limit;
  72. };
  73. CCL_NAMESPACE_END
  74. #endif /* __BAKE_H__ */