PostProcess.h 5.7 KB

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