ExamplePostEffect.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. singleton ShaderData( ExamplePostEffect_Shader )
  23. {
  24. DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl";
  25. DXPixelShaderFile = $Core:modulePath @ "ExamplePostEffectP.hlsl";
  26. OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl";
  27. OGLPixelShaderFile = $Core:modulePath @ "ExamplePostEffectP.glsl";
  28. samplerNames[0] = "$inputTex";
  29. pixVersion = 3.0;
  30. };
  31. singleton GFXStateBlockData( ExamplePostEffect_StateBlock )
  32. {
  33. samplersDefined = true;
  34. samplerStates[0] = SamplerClampLinear;
  35. samplerStates[1] = SamplerClampLinear;
  36. samplerStates[2] = SamplerClampLinear;
  37. samplerStates[3] = SamplerClampLinear;
  38. blendDefined = true;
  39. blendDest = GFXBlendOne;
  40. blendSrc = GFXBlendZero;
  41. zDefined = true;
  42. zEnable = false;
  43. zWriteEnable = false;
  44. cullDefined = true;
  45. cullMode = GFXCullNone;
  46. };
  47. function ExamplePostEffect::setShaderConsts( %this )
  48. {
  49. }
  50. function ExamplePostEffect::preProcess( %this )
  51. {
  52. }
  53. function ExamplePostEffect::onAdd(%this)
  54. {
  55. //Register the postFX with the manager
  56. PostFXManager.registerPostEffect(%this);
  57. }
  58. function ExamplePostEffect::onEnabled( %this )
  59. {
  60. return true;
  61. }
  62. function ExamplePostEffect::onDisabled( %this )
  63. {
  64. }
  65. //This is used to populate the PostFXEditor's settings so the post FX can be edited
  66. //This is automatically polled for any postFX that has been registered(in our onAdd) and the settings
  67. //are thus exposed for editing
  68. function ExamplePostEffect::populatePostFXSettings(%this)
  69. {
  70. PostEffectEditorInspector.startGroup("ExamplePostEffect - General");
  71. PostEffectEditorInspector.addField("$PostFXManager::Settings::EnabledExamplePostEffect", "Enabled", "bool", "", $PostFXManager::PostFX::EnableExamplePostEffect, "");
  72. PostEffectEditorInspector.endGroup();
  73. }
  74. //This function pair(applyFromPreset and settingsApply) are done the way they are, with the separated variables
  75. //so that we can effectively store the 'settings' away from the live variables that the postFX's actually utilize
  76. //when rendering. This allows us to modify things but still leave room for reverting or temporarily applying them
  77. function ExamplePostEffect::applyFromPreset(%this)
  78. {
  79. //ExamplePostEffect Settings
  80. $PostFXManager::PostFX::EnableExamplePostEffect = $PostFXManager::Settings::EnabledExamplePostEffect;
  81. if($PostFXManager::PostFX::EnableExamplePostEffect)
  82. %this.enable();
  83. else
  84. %this.disable();
  85. }
  86. function ExamplePostEffect::settingsApply(%this)
  87. {
  88. $PostFXManager::Settings::EnabledExamplePostEffect = $PostFXManager::PostFX::EnableExamplePostEffect;
  89. }
  90. singleton PostEffect( ExamplePostEffect )
  91. {
  92. isEnabled = false;
  93. allowReflectPass = false;
  94. // Resolve the HDR before we render any editor stuff
  95. // and before we resolve the scene to the backbuffer.
  96. renderTime = "PFXBeforeBin";
  97. renderBin = "EditorBin";
  98. renderPriority = 9999;
  99. // The bright pass generates a bloomed version of
  100. // the scene for pixels which are brighter than a
  101. // fixed threshold value.
  102. //
  103. // This is then used in the final HDR combine pass
  104. // at the end of this post effect chain.
  105. shader = ExamplePostEffect_Shader;
  106. stateBlock = ExamplePostEffect_StateBlock;
  107. texture[0] = "$backBuffer";
  108. target = "$outTex";
  109. targetFormat = "GFXFormatR16G16B16A16F";
  110. targetScale = "1 1";
  111. };