bokeh_dof.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**************************************************************************/
  2. /* bokeh_dof.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef BOKEH_DOF_RD_H
  31. #define BOKEH_DOF_RD_H
  32. #include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
  33. #include "servers/rendering/renderer_rd/shaders/effects/bokeh_dof.glsl.gen.h"
  34. #include "servers/rendering/renderer_rd/shaders/effects/bokeh_dof_raster.glsl.gen.h"
  35. #include "servers/rendering/renderer_scene_render.h"
  36. #include "servers/rendering_server.h"
  37. namespace RendererRD {
  38. class BokehDOF {
  39. private:
  40. bool prefer_raster_effects;
  41. struct BokehPushConstant {
  42. uint32_t size[2];
  43. float z_far;
  44. float z_near;
  45. uint32_t orthogonal;
  46. float blur_size;
  47. float blur_scale;
  48. uint32_t steps;
  49. uint32_t blur_near_active;
  50. float blur_near_begin;
  51. float blur_near_end;
  52. uint32_t blur_far_active;
  53. float blur_far_begin;
  54. float blur_far_end;
  55. uint32_t second_pass;
  56. uint32_t half_size;
  57. uint32_t use_jitter;
  58. float jitter_seed;
  59. uint32_t use_physical_near;
  60. uint32_t use_physical_far;
  61. float blur_size_near;
  62. float blur_size_far;
  63. uint32_t pad[2];
  64. };
  65. enum BokehMode {
  66. BOKEH_GEN_BLUR_SIZE,
  67. BOKEH_GEN_BOKEH_BOX,
  68. BOKEH_GEN_BOKEH_BOX_NOWEIGHT,
  69. BOKEH_GEN_BOKEH_HEXAGONAL,
  70. BOKEH_GEN_BOKEH_HEXAGONAL_NOWEIGHT,
  71. BOKEH_GEN_BOKEH_CIRCULAR,
  72. BOKEH_COMPOSITE,
  73. BOKEH_MAX
  74. };
  75. struct Bokeh {
  76. BokehPushConstant push_constant;
  77. BokehDofShaderRD compute_shader;
  78. BokehDofRasterShaderRD raster_shader;
  79. RID shader_version;
  80. RID compute_pipelines[BOKEH_MAX];
  81. PipelineCacheRD raster_pipelines[BOKEH_MAX];
  82. } bokeh;
  83. public:
  84. struct BokehBuffers {
  85. // bokeh buffers
  86. // textures
  87. Size2i base_texture_size;
  88. RID base_texture;
  89. RID depth_texture;
  90. RID secondary_texture;
  91. RID half_texture[2];
  92. // raster only
  93. RID base_fb;
  94. RID secondary_fb; // with weights
  95. RID half_fb[2]; // with weights
  96. RID base_weight_fb;
  97. RID weight_texture[4];
  98. };
  99. BokehDOF(bool p_prefer_raster_effects);
  100. ~BokehDOF();
  101. void bokeh_dof_compute(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
  102. void bokeh_dof_raster(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
  103. };
  104. } // namespace RendererRD
  105. #endif // BOKEH_DOF_RD_H