light.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2011-2013 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 __LIGHT_H__
  17. #define __LIGHT_H__
  18. #include "kernel/kernel_types.h"
  19. #include "graph/node.h"
  20. #include "util/util_ies.h"
  21. #include "util/util_thread.h"
  22. #include "util/util_types.h"
  23. #include "util/util_vector.h"
  24. CCL_NAMESPACE_BEGIN
  25. class Device;
  26. class DeviceScene;
  27. class Object;
  28. class Progress;
  29. class Scene;
  30. class Shader;
  31. class Light : public Node {
  32. public:
  33. NODE_DECLARE;
  34. Light();
  35. LightType type;
  36. float3 strength;
  37. float3 co;
  38. float3 dir;
  39. float size;
  40. float angle;
  41. float3 axisu;
  42. float sizeu;
  43. float3 axisv;
  44. float sizev;
  45. bool round;
  46. Transform tfm;
  47. int map_resolution;
  48. float spot_angle;
  49. float spot_smooth;
  50. bool cast_shadow;
  51. bool use_mis;
  52. bool use_diffuse;
  53. bool use_glossy;
  54. bool use_transmission;
  55. bool use_scatter;
  56. bool is_portal;
  57. bool is_enabled;
  58. Shader *shader;
  59. int samples;
  60. int max_bounces;
  61. uint random_id;
  62. void tag_update(Scene *scene);
  63. /* Check whether the light has contribution the the scene. */
  64. bool has_contribution(Scene *scene);
  65. };
  66. class LightManager {
  67. public:
  68. bool use_light_visibility;
  69. bool need_update;
  70. LightManager();
  71. ~LightManager();
  72. /* IES texture management */
  73. int add_ies(ustring ies);
  74. int add_ies_from_file(ustring filename);
  75. void remove_ies(int slot);
  76. void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
  77. void device_free(Device *device, DeviceScene *dscene);
  78. void tag_update(Scene *scene);
  79. /* Check whether there is a background light. */
  80. bool has_background_light(Scene *scene);
  81. protected:
  82. /* Optimization: disable light which is either unsupported or
  83. * which doesn't contribute to the scene or which is only used for MIS
  84. * and scene doesn't need MIS.
  85. */
  86. void disable_ineffective_light(Scene *scene);
  87. void device_update_points(Device *device, DeviceScene *dscene, Scene *scene);
  88. void device_update_distribution(Device *device,
  89. DeviceScene *dscene,
  90. Scene *scene,
  91. Progress &progress);
  92. void device_update_background(Device *device,
  93. DeviceScene *dscene,
  94. Scene *scene,
  95. Progress &progress);
  96. void device_update_ies(DeviceScene *dscene);
  97. /* Check whether light manager can use the object as a light-emissive. */
  98. bool object_usable_as_light(Object *object);
  99. struct IESSlot {
  100. IESFile ies;
  101. uint hash;
  102. int users;
  103. };
  104. vector<IESSlot *> ies_slots;
  105. thread_mutex ies_mutex;
  106. };
  107. CCL_NAMESPACE_END
  108. #endif /* __LIGHT_H__ */