customShaderFeature.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #include "shadergen/CustomShaderFeature.h"
  23. #include "shaderGen/HLSL/customFeatureHLSL.h"
  24. #include "math/mathIO.h"
  25. #include "scene/sceneRenderState.h"
  26. #include "core/stream/bitStream.h"
  27. #include "materials/sceneData.h"
  28. #include "gfx/gfxDebugEvent.h"
  29. #include "gfx/gfxTransformSaver.h"
  30. #include "renderInstance/renderPassManager.h"
  31. IMPLEMENT_CONOBJECT(CustomShaderFeatureData);
  32. ConsoleDocClass(CustomShaderFeatureData,
  33. "@brief An example scene object which renders using a callback.\n\n"
  34. "This class implements a basic SceneObject that can exist in the world at a "
  35. "3D position and render itself. Note that CustomShaderFeatureData handles its own "
  36. "rendering by submitting itself as an ObjectRenderInst (see "
  37. "renderInstance\renderPassmanager.h) along with a delegate for its render() "
  38. "function. However, the preffered rendering method in the engine is to submit "
  39. "a MeshRenderInst along with a Material, vertex buffer, primitive buffer, and "
  40. "transform and allow the RenderMeshMgr handle the actual rendering. You can "
  41. "see this implemented in RenderMeshExample.\n\n"
  42. "See the C++ code for implementation details.\n\n"
  43. "@ingroup Examples\n");
  44. //-----------------------------------------------------------------------------
  45. // Object setup and teardown
  46. //-----------------------------------------------------------------------------
  47. CustomShaderFeatureData::CustomShaderFeatureData()
  48. {
  49. }
  50. CustomShaderFeatureData::~CustomShaderFeatureData()
  51. {
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Object Editing
  55. //-----------------------------------------------------------------------------
  56. void CustomShaderFeatureData::initPersistFields()
  57. {
  58. // SceneObject already handles exposing the transform
  59. Parent::initPersistFields();
  60. }
  61. bool CustomShaderFeatureData::onAdd()
  62. {
  63. if (!Parent::onAdd())
  64. return false;
  65. mFeatureHLSL = new CustomFeatureHLSL();
  66. mFeatureHLSL->mOwner = this;
  67. return true;
  68. }
  69. void CustomShaderFeatureData::onRemove()
  70. {
  71. Parent::onRemove();
  72. }
  73. //Shadergen setup functions
  74. void CustomShaderFeatureData::addVariable(String name, String type, String defaultValue)
  75. {
  76. mFeatureHLSL->addVariable(name, type, defaultValue);
  77. }
  78. void CustomShaderFeatureData::addUniform(String name, String type, String defaultValue, U32 arraySize)
  79. {
  80. mFeatureHLSL->addUniform(name, type, defaultValue, arraySize);
  81. }
  82. void CustomShaderFeatureData::addSampler(String name, String type, U32 arraySize)
  83. {
  84. mFeatureHLSL->addSampler(name, type, arraySize);
  85. }
  86. void CustomShaderFeatureData::addTexture(String name, String type, String samplerState, U32 arraySize)
  87. {
  88. mFeatureHLSL->addTexture(name, type, samplerState, arraySize);
  89. }
  90. void CustomShaderFeatureData::writeLine(String format, S32 argc, ConsoleValueRef *argv)
  91. {
  92. /*mOnObject = onObject;
  93. mArgc = argc;
  94. mArgv = new ConsoleValueRef[argc];
  95. for (int i = 0; i<argc; i++)
  96. {
  97. mArgv[i].value = new ConsoleValue();
  98. mArgv[i].value->type = ConsoleValue::TypeInternalString;
  99. mArgv[i].value->init();
  100. if (argv)
  101. {
  102. mArgv[i].value->setStringValue((const char*)argv[i]);
  103. }
  104. }*/
  105. mFeatureHLSL->writeLine(format, argc, argv);
  106. }
  107. /*//Actual shader processing
  108. void CustomShaderFeatureData::processVert(Vector<ShaderComponent*> &componentList,
  109. const MaterialFeatureData &fd)
  110. {
  111. mFeatureHLSL.processVert(componentList, fd);
  112. }
  113. void CustomShaderFeatureData::processPix(Vector<ShaderComponent*> &componentList,
  114. const MaterialFeatureData &fd)
  115. {
  116. mFeatureHLSL.processPix(componentList, fd);
  117. }
  118. void CustomShaderFeatureData::setTexData(Material::StageData &stageDat,
  119. const MaterialFeatureData &fd,
  120. RenderPassData &passData,
  121. U32 &texIndex)
  122. {
  123. mFeatureHLSL.setTexData(stageDat, fd, passData, texIndex);
  124. }*/
  125. DefineEngineMethod(CustomShaderFeatureData, addVariable, void, (String name, String type, String defaultValue), ("", "", ""), "")
  126. {
  127. object->addVariable(name, type, defaultValue);
  128. }
  129. DefineEngineMethod(CustomShaderFeatureData, addUniform, void, (String name, String type, String defaultValue, U32 arraySize), ("", "", "", 0), "")
  130. {
  131. object->addUniform(name, type, defaultValue, arraySize);
  132. }
  133. DefineEngineMethod(CustomShaderFeatureData, addSampler, void, (String name, U32 arraySize), ("", 0), "")
  134. {
  135. object->addSampler(name, "", arraySize);
  136. }
  137. DefineEngineMethod(CustomShaderFeatureData, addTexture, void, (String name, String type, String samplerState, U32 arraySize), ("", "", 0), "")
  138. {
  139. object->addTexture(name, type, samplerState, arraySize);
  140. }
  141. ConsoleMethod(CustomShaderFeatureData, writeLine, void, 3, 0, "( string format, string args... ) Dynamically call a method on an object.\n"
  142. "@param method Name of method to call.\n"
  143. "@param args Zero or more arguments for the method.\n"
  144. "@return The result of the method call.")
  145. {
  146. object->writeLine(argv[2], argc - 3, argv + 3);
  147. }