PostProcess.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "GraphicsDefs.h"
  25. #include "Object.h"
  26. class Texture2D;
  27. class XMLFile;
  28. /// Post-processing effect pass.
  29. class PostProcessPass : public RefCounted
  30. {
  31. public:
  32. /// Construct.
  33. PostProcessPass();
  34. /// Destruct.
  35. ~PostProcessPass();
  36. /// %Set vertex shader name.
  37. void SetVertexShader(const String& name);
  38. /// %Set pixel shader name.
  39. void SetPixelShader(const String& name);
  40. /// %Set texture name. This can be a named rendertarget, or a texture resource name.
  41. void SetTexture(TextureUnit unit, const String& name);
  42. /// %Set shader parameter.
  43. void SetShaderParameter(const String& name, const Vector4& value);
  44. /// Remove shader parameter.
  45. void RemoveShaderParameter(const String& name);
  46. /// %Set output rendertarget name.
  47. void SetOutput(const String& name);
  48. /// Clone the post-process pass.
  49. SharedPtr<PostProcessPass> Clone();
  50. /// Return vertex shader name.
  51. const String& GetVertexShader() const { return vertexShaderName_; }
  52. /// Return pixel shader name.
  53. const String& GetPixelShader() const { return pixelShaderName_; }
  54. /// Return texture name.
  55. const String& GetTexture(TextureUnit unit) const;
  56. /// Return all texture names.
  57. const String* GetTextures() const { return &textureNames_[0]; }
  58. /// Return shader parameter.
  59. const Vector4& GetShaderParameter(const String& name) const;
  60. /// Return all shader parameters.
  61. const HashMap<StringHash, Vector4>& GetShaderParameters() const { return shaderParameters_; }
  62. /// Return output rendertarget name.
  63. const String& GetOutput() const { return outputName_; }
  64. private:
  65. /// Vertex shader name.
  66. String vertexShaderName_;
  67. /// Pixel shader name.
  68. String pixelShaderName_;
  69. /// Textures.
  70. String textureNames_[MAX_MATERIAL_TEXTURE_UNITS];
  71. /// %Shader parameters.
  72. HashMap<StringHash, Vector4> shaderParameters_;
  73. /// Output rendertarget name.
  74. String outputName_;
  75. };
  76. /// Post-processing rendertarget info.
  77. struct PostProcessRenderTarget
  78. {
  79. /// Name.
  80. String name_;
  81. /// Texture format.
  82. unsigned format_;
  83. /// Size.
  84. IntVector2 size_;
  85. /// Divisor mode flag.
  86. bool sizeDivisor_;
  87. /// Filtering flag.
  88. bool filtered_;
  89. };
  90. /// Post-processing effect.
  91. class PostProcess : public Object
  92. {
  93. OBJECT(PostProcess);
  94. public:
  95. /// Construct.
  96. PostProcess(Context* context);
  97. /// Destruct.
  98. ~PostProcess();
  99. /// Load parameters from an XML file. Return true if successful.
  100. bool LoadParameters(XMLFile* file);
  101. /// %Set number of passes.
  102. void SetNumPasses(unsigned passes);
  103. /// Create a rendertarget. Width and height are either absolute pixels or viewport size divisors. Return true if successful.
  104. bool CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool sizeDivisor, bool filtered);
  105. /// Remove a rendertarget.
  106. void RemoveRenderTarget(const String& name);
  107. /// %Set global shader parameter.
  108. void SetShaderParameter(const String& name, const Vector4& value);
  109. /// Remove global shader parameter.
  110. void RemoveShaderParameter(const String& name);
  111. /// %Set active flag.
  112. void SetActive(bool active);
  113. /// Clone the post-process.
  114. SharedPtr<PostProcess> Clone();
  115. /// Return parameter XML file.
  116. XMLFile* GetParameters() const { return parameterSource_; }
  117. /// Return number of passes.
  118. unsigned GetNumPasses() const { return passes_.Size(); }
  119. /// Return pass by index.
  120. PostProcessPass* GetPass(unsigned index) const;
  121. /// Return if has a specific rendertarget.
  122. bool HasRenderTarget(const String& name) const;
  123. /// Return all rendertargets.
  124. const HashMap<StringHash, PostProcessRenderTarget>& GetRenderTargets() const { return renderTargets_; }
  125. /// Return shader parameter.
  126. const Vector4& GetShaderParameter(const String& name) const;
  127. /// Return all global shader parameters.
  128. const HashMap<StringHash, Vector4>& GetShaderParameters() const { return shaderParameters_; }
  129. /// Return active flag.
  130. bool IsActive() const { return active_; }
  131. private:
  132. /// Parameter XML file.
  133. SharedPtr<XMLFile> parameterSource_;
  134. /// Rendertargets.
  135. HashMap<StringHash, PostProcessRenderTarget> renderTargets_;
  136. /// Global shader parameters.
  137. HashMap<StringHash, Vector4> shaderParameters_;
  138. /// Effect passes.
  139. Vector<SharedPtr<PostProcessPass> > passes_;
  140. /// Active flag.
  141. bool active_;
  142. };