shdbumpdiff.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/shdbumpdiff.cpp $*
  25. * *
  26. * $Author:: Kenny_m
  27. *
  28. * $Modtime:: 6/03/02 8:12a $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dx8fvf.h"
  36. #include "dx8wrapper.h"
  37. #include "assetmgr.h"
  38. #include "shdbumpdiff.h"
  39. #include "shd6bumpdiff.h"
  40. #include "shd7bumpdiff.h"
  41. #include "shd8bumpdiff.h"
  42. #include "editable.h"
  43. #include "shdclassids.h"
  44. #include "shddeffactory.h"
  45. #include "shdinterface.h"
  46. #include "persistfactory.h"
  47. #include "wwhack.h"
  48. DECLARE_FORCE_LINK(BumpDiffShader);
  49. REGISTER_SHDDEF(ShdBumpDiffDefClass,SHDDEF_CLASSID_BUMPDIFF,"Bump Diffuse");
  50. // static member
  51. ShdVersion ShdBumpDiffDefClass::Version;
  52. // Save-Load methods for ShdDefClass
  53. enum
  54. {
  55. CHUNKID_VARIABLES = 0x16490450,
  56. VARID_TEXTURE_NAME = 0x00,
  57. VARID_BUMP_MAP_NAME,
  58. VARID_AMBIENT_COLOR,
  59. VARID_DIFFUSE_COLOR,
  60. VARID_DIFFUSE_BUMPINESS,
  61. };
  62. ShdBumpDiffDefClass::ShdBumpDiffDefClass()
  63. : ShdDefClass(SHDDEF_CLASSID_BUMPDIFF),
  64. Ambient(1,1,1),
  65. Diffuse(1,1,1),
  66. Diffuse_Bumpiness(1,0)
  67. {
  68. NAMED_TEXTURE_FILENAME_PARAM(ShdBumpDiffDefClass, TextureName, "Base Map", "Targa Files", ".tga");
  69. NAMED_TEXTURE_FILENAME_PARAM(ShdBumpDiffDefClass, BumpMapName, "Bump Map", "Targa Files", ".tga");
  70. NAMED_EDITABLE_PARAM(ShdBumpDiffDefClass, ParameterClass::TYPE_COLOR, Ambient, "Ambient");
  71. NAMED_EDITABLE_PARAM(ShdBumpDiffDefClass, ParameterClass::TYPE_COLOR, Diffuse, "Diffuse");
  72. NAMED_EDITABLE_PARAM(ShdBumpDiffDefClass, ParameterClass::TYPE_FLOAT, Diffuse_Bumpiness.X, "Diffuse Bump Scale");
  73. NAMED_EDITABLE_PARAM(ShdBumpDiffDefClass, ParameterClass::TYPE_FLOAT, Diffuse_Bumpiness.Y, "Diffuse Bump Bias");
  74. }
  75. ShdBumpDiffDefClass::ShdBumpDiffDefClass(const ShdBumpDiffDefClass& that)
  76. : ShdDefClass(that),
  77. Ambient(that.Ambient),
  78. Diffuse(that.Diffuse),
  79. Diffuse_Bumpiness(that.Diffuse_Bumpiness)
  80. {
  81. TextureName=that.TextureName;
  82. BumpMapName=that.BumpMapName;
  83. }
  84. ShdBumpDiffDefClass::~ShdBumpDiffDefClass()
  85. {
  86. }
  87. bool ShdBumpDiffDefClass::Is_Valid_Config(StringClass &message)
  88. {
  89. return true;
  90. }
  91. bool ShdBumpDiffDefClass::Save(ChunkSaveClass &csave)
  92. {
  93. ShdDefClass::Save(csave);
  94. csave.Begin_Chunk(CHUNKID_VARIABLES);
  95. bool retval = true;
  96. // only save the file name
  97. char fname[_MAX_PATH];
  98. _splitpath(TextureName,NULL,NULL,fname,NULL);
  99. strcat(fname,".tga");
  100. TextureName=fname;
  101. WRITE_MICRO_CHUNK_WWSTRING(csave, VARID_TEXTURE_NAME, TextureName);
  102. _splitpath(BumpMapName,NULL,NULL,fname,NULL);
  103. strcat(fname,".tga");
  104. BumpMapName=fname;
  105. WRITE_MICRO_CHUNK_WWSTRING(csave, VARID_BUMP_MAP_NAME, BumpMapName);
  106. WRITE_MICRO_CHUNK(csave, VARID_AMBIENT_COLOR, Ambient);
  107. WRITE_MICRO_CHUNK(csave, VARID_DIFFUSE_COLOR, Diffuse);
  108. WRITE_MICRO_CHUNK(csave, VARID_DIFFUSE_BUMPINESS, Diffuse_Bumpiness);
  109. csave.End_Chunk();
  110. return retval;
  111. }
  112. bool ShdBumpDiffDefClass::Load(ChunkLoadClass &cload)
  113. {
  114. ShdDefClass::Load(cload);
  115. // Loop through all the microchunks that define the variables
  116. while (cload.Open_Chunk()) {
  117. switch (cload.Cur_Chunk_ID())
  118. {
  119. case CHUNKID_VARIABLES:
  120. while (cload.Open_Micro_Chunk())
  121. {
  122. switch (cload.Cur_Micro_Chunk_ID())
  123. {
  124. READ_MICRO_CHUNK_WWSTRING(cload, VARID_TEXTURE_NAME, TextureName);
  125. READ_MICRO_CHUNK_WWSTRING(cload, VARID_BUMP_MAP_NAME, BumpMapName);
  126. READ_MICRO_CHUNK(cload, VARID_AMBIENT_COLOR, Ambient);
  127. READ_MICRO_CHUNK(cload, VARID_DIFFUSE_COLOR, Diffuse);
  128. READ_MICRO_CHUNK(cload, VARID_DIFFUSE_BUMPINESS, Diffuse_Bumpiness);
  129. }
  130. cload.Close_Micro_Chunk();
  131. }
  132. break;
  133. default:
  134. break;
  135. }
  136. cload.Close_Chunk();
  137. }
  138. return true;
  139. }
  140. void ShdBumpDiffDefClass::Init()
  141. {
  142. // select shader version
  143. if ((DX8Wrapper::Get_Current_Caps()->Get_Pixel_Shader_Major_Version())==1 &&
  144. (DX8Wrapper::Get_Current_Caps()->Get_Pixel_Shader_Minor_Version())>=1)
  145. {
  146. Version.Set(SHDVER_8);
  147. }
  148. else if (DX8Wrapper::Get_Current_Caps()->Support_Dot3())
  149. {
  150. Version.Set(SHDVER_7);
  151. }
  152. else
  153. {
  154. Version.Set(SHDVER_6);
  155. }
  156. switch (Version.Get())
  157. {
  158. case SHDVER_8 : Shd8BumpDiffClass::Init(); break;
  159. case SHDVER_7 : Shd7BumpDiffClass::Init(); break;
  160. case SHDVER_6 : Shd6BumpDiffClass::Init(); break;
  161. }
  162. }
  163. void ShdBumpDiffDefClass::Shutdown()
  164. {
  165. switch (Version.Get())
  166. {
  167. case SHDVER_8 : Shd8BumpDiffClass::Shutdown(); break;
  168. case SHDVER_7 : Shd7BumpDiffClass::Shutdown(); break;
  169. case SHDVER_6 : Shd6BumpDiffClass::Shutdown(); break;
  170. }
  171. }
  172. ShdInterfaceClass* ShdBumpDiffDefClass::Create() const
  173. {
  174. switch (Version.Get())
  175. {
  176. case SHDVER_8 : return new Shd8BumpDiffClass(this); break;
  177. case SHDVER_7 : return new Shd7BumpDiffClass(this); break;
  178. case SHDVER_6 : return new Shd6BumpDiffClass(this); break;
  179. }
  180. return NULL;
  181. }