postFXFile.cs.template 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. $PostFX::@@::modColor = "1 1 1 1";
  23. singleton ShaderData( @@_Shader )
  24. {
  25. DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl";
  26. DXPixelShaderFile = "./@@P.hlsl";
  27. OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl";
  28. OGLPixelShaderFile = "./@@P.glsl";
  29. samplerNames[0] = "$inputTex";
  30. pixVersion = 3.0;
  31. };
  32. singleton GFXStateBlockData( @@_StateBlock )
  33. {
  34. samplersDefined = true;
  35. samplerStates[0] = SamplerClampLinear;
  36. samplerStates[1] = SamplerClampLinear;
  37. samplerStates[2] = SamplerClampLinear;
  38. samplerStates[3] = SamplerClampLinear;
  39. blendDefined = true;
  40. blendDest = GFXBlendOne;
  41. blendSrc = GFXBlendZero;
  42. zDefined = true;
  43. zEnable = false;
  44. zWriteEnable = false;
  45. cullDefined = true;
  46. cullMode = GFXCullNone;
  47. };
  48. function @@::setShaderConsts( %this )
  49. {
  50. %this.setShaderConst( "$modColor", $PostFX::@@::modColor );
  51. }
  52. function @@::preProcess( %this )
  53. {
  54. }
  55. function @@::onAdd(%this)
  56. {
  57. //Register the postFX with the manager
  58. PostFXManager.registerPostEffect(%this);
  59. }
  60. function @@::onEnabled( %this )
  61. {
  62. $PostFX::@@::Enabled = true;
  63. return true;
  64. }
  65. function @@::onDisabled( %this )
  66. {
  67. $PostFX::@@::Enabled = false;
  68. return true;
  69. }
  70. //This is used to populate the PostFXEditor's settings so the post FX can be edited
  71. //This is automatically polled for any postFX that has been registered(in our onAdd) and the settings
  72. //are thus exposed for editing
  73. function @@::populatePostFXSettings(%this)
  74. {
  75. PostEffectEditorInspector.startGroup("@@ - General");
  76. PostEffectEditorInspector.addCallbackField("$PostFX::@@::Enabled", "Enabled", "bool", "", $PostFX::@@::Enabled, "", "toggle@@");
  77. PostEffectEditorInspector.addField("$PostFX::@@::modColor", "Modifier Color", "colorI", "", $PostFX::@@::modColor, "");
  78. PostEffectEditorInspector.endGroup();
  79. }
  80. //This is called back from our callbackField defined in populatePostFXSettings to
  81. //Allow us to easily toggle the postFX and have it respond immediately
  82. function PostEffectEditorInspector::toggle@@(%this)
  83. {
  84. if($PostFX::@@::Enabled)
  85. @@.enable();
  86. else
  87. @@.disable();
  88. }
  89. //This function is called when the post FX is loaded via a postFX preset file. It's used to do any special-case onload work
  90. //At minimum, it ensures that if the preset indicates it should be enabled, it actually enables the postFX object itself
  91. function @@::applyFromPreset(%this)
  92. {
  93. if($PostFX::@@::Enabled)
  94. %this.enable();
  95. else
  96. %this.disable();
  97. }
  98. //This function writes out the postFX's settings to the edited preset file
  99. function @@::savePresetSettings(%this)
  100. {
  101. PostFXManager::savePresetSetting("$PostFX::@@::Enabled");
  102. PostFXManager::savePresetSetting("$PostFX::@@::modColor");
  103. }
  104. //Our actual postFX
  105. singleton PostEffect( @@ )
  106. {
  107. isEnabled = false;
  108. allowReflectPass = false;
  109. // Resolve the HDR before we render any editor stuff
  110. // and before we resolve the scene to the backbuffer.
  111. renderTime = "PFXBeforeBin";
  112. renderBin = "EditorBin";
  113. renderPriority = 9999;
  114. // The bright pass generates a bloomed version of
  115. // the scene for pixels which are brighter than a
  116. // fixed threshold value.
  117. //
  118. // This is then used in the final HDR combine pass
  119. // at the end of this post effect chain.
  120. shader = @@_Shader;
  121. stateBlock = @@_StateBlock;
  122. texture[0] = "$backBuffer";
  123. target = "$backBuffer";
  124. targetFormat = "GFXFormatR16G16B16A16F";
  125. targetScale = "1 1";
  126. };