bokeh_dof.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. namespace RendererRD {
  36. class BokehDOF {
  37. private:
  38. bool prefer_raster_effects;
  39. struct BokehPushConstant {
  40. uint32_t size[2];
  41. float z_far;
  42. float z_near;
  43. uint32_t orthogonal;
  44. float blur_size;
  45. float blur_scale;
  46. uint32_t steps;
  47. uint32_t blur_near_active;
  48. float blur_near_begin;
  49. float blur_near_end;
  50. uint32_t blur_far_active;
  51. float blur_far_begin;
  52. float blur_far_end;
  53. uint32_t second_pass;
  54. uint32_t half_size;
  55. uint32_t use_jitter;
  56. float jitter_seed;
  57. uint32_t use_physical_near;
  58. uint32_t use_physical_far;
  59. float blur_size_near;
  60. float blur_size_far;
  61. uint32_t pad[2];
  62. };
  63. enum BokehMode {
  64. BOKEH_GEN_BLUR_SIZE,
  65. BOKEH_GEN_BOKEH_BOX,
  66. BOKEH_GEN_BOKEH_BOX_NOWEIGHT,
  67. BOKEH_GEN_BOKEH_HEXAGONAL,
  68. BOKEH_GEN_BOKEH_HEXAGONAL_NOWEIGHT,
  69. BOKEH_GEN_BOKEH_CIRCULAR,
  70. BOKEH_COMPOSITE,
  71. BOKEH_MAX
  72. };
  73. struct Bokeh {
  74. BokehPushConstant push_constant;
  75. BokehDofShaderRD compute_shader;
  76. BokehDofRasterShaderRD raster_shader;
  77. RID shader_version;
  78. RID compute_pipelines[BOKEH_MAX];
  79. PipelineCacheRD raster_pipelines[BOKEH_MAX];
  80. } bokeh;
  81. public:
  82. struct BokehBuffers {
  83. // bokeh buffers
  84. // textures
  85. Size2i base_texture_size;
  86. RID base_texture;
  87. RID depth_texture;
  88. RID secondary_texture;
  89. RID half_texture[2];
  90. // raster only
  91. RID base_fb;
  92. RID secondary_fb; // with weights
  93. RID half_fb[2]; // with weights
  94. RID base_weight_fb;
  95. RID weight_texture[4];
  96. };
  97. BokehDOF(bool p_prefer_raster_effects);
  98. ~BokehDOF();
  99. void bokeh_dof_compute(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
  100. void bokeh_dof_raster(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
  101. };
  102. } // namespace RendererRD
  103. #endif // BOKEH_DOF_RD_H