PostProcess.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "HashMap.h"
  26. #include "Object.h"
  27. class Texture2D;
  28. class XMLFile;
  29. /// Post-processing effect pass.
  30. class PostProcessPass : public RefCounted
  31. {
  32. public:
  33. /// Construct.
  34. PostProcessPass();
  35. /// Destruct.
  36. ~PostProcessPass();
  37. /// %Set vertex shader name.
  38. void SetVertexShader(const String& name);
  39. /// %Set pixel shader name.
  40. void SetPixelShader(const String& name);
  41. /// %Set texture name. This can be a named rendertarget, or a texture resource name.
  42. void SetTexture(TextureUnit unit, const String& name);
  43. /// %Set shader parameter.
  44. void SetShaderParameter(const String& name, const Vector4& value);
  45. /// Remove shader parameter.
  46. void RemoveShaderParameter(const String& name);
  47. /// %Set output rendertarget name.
  48. void SetOutput(const String& name);
  49. /// Clone the post-process pass.
  50. SharedPtr<PostProcessPass> Clone();
  51. /// Return vertex shader name.
  52. const String& GetVertexShader() const { return vertexShaderName_; }
  53. /// Return pixel shader name.
  54. const String& GetPixelShader() const { return pixelShaderName_; }
  55. /// Return texture name.
  56. const String& GetTexture(TextureUnit unit) const;
  57. /// Return all texture names.
  58. const String* GetTextures() const { return &textureNames_[0]; }
  59. /// Return shader parameter.
  60. const Vector4& GetShaderParameter(const String& name) const;
  61. /// Return all shader parameters.
  62. const HashMap<StringHash, Vector4>& GetShaderParameters() const { return shaderParameters_; }
  63. /// Return output rendertarget name.
  64. const String& GetOutput() const { return outputName_; }
  65. private:
  66. /// Vertex shader name.
  67. String vertexShaderName_;
  68. /// Pixel shader name.
  69. String pixelShaderName_;
  70. /// Textures.
  71. String textureNames_[MAX_MATERIAL_TEXTURE_UNITS];
  72. /// %Shader parameters.
  73. HashMap<StringHash, Vector4> shaderParameters_;
  74. /// Output rendertarget name.
  75. String outputName_;
  76. };
  77. /// Post-processing rendertarget info.
  78. struct PostProcessRenderTarget
  79. {
  80. /// Name.
  81. String name_;
  82. /// Texture format.
  83. unsigned format_;
  84. /// Size.
  85. IntVector2 size_;
  86. /// Divisor mode flag.
  87. bool sizeDivisor_;
  88. /// Filtering flag.
  89. bool filtered_;
  90. };
  91. /// Post-processing effect.
  92. class PostProcess : public Object
  93. {
  94. OBJECT(PostProcess);
  95. public:
  96. /// Construct.
  97. PostProcess(Context* context);
  98. /// Destruct.
  99. ~PostProcess();
  100. /// Load parameters from an XML file. Return true if successful.
  101. bool LoadParameters(XMLFile* file);
  102. /// %Set number of passes.
  103. void SetNumPasses(unsigned passes);
  104. /// Create a rendertarget. Width and height are either absolute pixels or viewport size divisors. Return true if successful.
  105. bool CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool sizeDivisor, bool filtered);
  106. /// Remove a rendertarget.
  107. void RemoveRenderTarget(const String& name);
  108. /// %Set global shader parameter.
  109. void SetShaderParameter(const String& name, const Vector4& value);
  110. /// Remove global shader parameter.
  111. void RemoveShaderParameter(const String& name);
  112. /// %Set active flag.
  113. void SetActive(bool active);
  114. /// Clone the post-process.
  115. SharedPtr<PostProcess> Clone();
  116. /// Return parameter XML file.
  117. XMLFile* GetParameters() const { return parameterSource_; }
  118. /// Return number of passes.
  119. unsigned GetNumPasses() const { return passes_.Size(); }
  120. /// Return pass by index.
  121. PostProcessPass* GetPass(unsigned index) const;
  122. /// Return if has a specific rendertarget.
  123. bool HasRenderTarget(const String& name) const;
  124. /// Return all rendertargets.
  125. const HashMap<StringHash, PostProcessRenderTarget>& GetRenderTargets() const { return renderTargets_; }
  126. /// Return shader parameter.
  127. const Vector4& GetShaderParameter(const String& name) const;
  128. /// Return all global shader parameters.
  129. const HashMap<StringHash, Vector4>& GetShaderParameters() const { return shaderParameters_; }
  130. /// Return active flag.
  131. bool IsActive() const { return active_; }
  132. private:
  133. /// Parameter XML file.
  134. SharedPtr<XMLFile> parameterSource_;
  135. /// Rendertargets.
  136. HashMap<StringHash, PostProcessRenderTarget> renderTargets_;
  137. /// Global shader parameters.
  138. HashMap<StringHash, Vector4> shaderParameters_;
  139. /// Effect passes.
  140. Vector<SharedPtr<PostProcessPass> > passes_;
  141. /// Active flag.
  142. bool active_;
  143. };