Material.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. /******************************************************************************/
  4. /******************************************************************************/
  5. bool EditMaterial::hasBumpMap()C {return bump_map.is() /*|| bump_from_color && color_map.is()*/;}
  6. bool EditMaterial::hasNormalMap()C {return normal_map.is() || hasBumpMap();}
  7. bool EditMaterial::hasDetailMap()C {return detail_color.is() || detail_bump.is() || detail_normal.is();}
  8. bool EditMaterial::hasBase1Tex()C {return hasNormalMap() || specular_map.is() || glow_map.is();}
  9. uint EditMaterial::baseTex()C {return (color_map.is() ? BT_COLOR : 0)|(alpha_map.is() ? BT_ALPHA : 0)|(hasBumpMap() ? BT_BUMP : 0)|(hasNormalMap() ? BT_NORMAL : 0)|(specular_map.is() ? BT_SPECULAR : 0)|(glow_map.is() ? BT_GLOW : 0);}
  10. bool EditMaterial::usesTexAlpha()C {return tech!=MTECH_DEFAULT && (color_map.is() || alpha_map.is());}
  11. bool EditMaterial::usesTexBump()C {return (bump >EPS_MATERIAL_BUMP || 1) && hasBumpMap ();}
  12. bool EditMaterial::usesTexNormal()C {return rough >EPS_COL && hasNormalMap();}
  13. bool EditMaterial::usesTexGlow()C {return glow >EPS_COL && glow_map.is ();}
  14. bool EditMaterial::usesTexDetail()C {return det_power>EPS_COL && hasDetailMap();}
  15. bool EditMaterial::wantTanBin()C
  16. {
  17. return usesTexBump ()
  18. || usesTexNormal()
  19. || usesTexDetail();
  20. }
  21. bool EditMaterial::equal(C EditMaterial &src)C
  22. {
  23. return flip_normal_y_time==src.flip_normal_y_time && high_quality_ios_time==src.high_quality_ios_time
  24. && color_map_time==src.color_map_time && alpha_map_time==src.alpha_map_time && bump_map_time==src.bump_map_time && normal_map_time==src.normal_map_time && specular_map_time==src.specular_map_time && glow_map_time==src.glow_map_time
  25. && detail_map_time==src.detail_map_time && macro_map_time==src.macro_map_time && reflection_map_time==src.reflection_map_time && light_map_time==src.light_map_time
  26. && cull_time==src.cull_time && tech_time==src.tech_time && downsize_tex_mobile_time==src.downsize_tex_mobile_time
  27. && color_time==src.color_time && ambient_time==src.ambient_time && spec_time==src.spec_time && sss_time==src.sss_time && rough_bump_time==src.rough_bump_time
  28. && glow_time==src.glow_time && tex_scale_time==src.tex_scale_time && detail_time==src.detail_time && reflection_time==src.reflection_time;
  29. }
  30. bool EditMaterial::newer(C EditMaterial &src)C
  31. {
  32. return flip_normal_y_time>src.flip_normal_y_time || high_quality_ios_time>src.high_quality_ios_time
  33. || color_map_time>src.color_map_time || alpha_map_time>src.alpha_map_time || bump_map_time>src.bump_map_time || normal_map_time>src.normal_map_time || specular_map_time>src.specular_map_time || glow_map_time>src.glow_map_time
  34. || detail_map_time>src.detail_map_time || macro_map_time>src.macro_map_time || reflection_map_time>src.reflection_map_time || light_map_time>src.light_map_time
  35. || cull_time>src.cull_time || tech_time>src.tech_time || downsize_tex_mobile_time>src.downsize_tex_mobile_time
  36. || color_time>src.color_time || ambient_time>src.ambient_time || spec_time>src.spec_time || sss_time>src.sss_time || rough_bump_time>src.rough_bump_time
  37. || glow_time>src.glow_time || tex_scale_time>src.tex_scale_time || detail_time>src.detail_time || reflection_time>src.reflection_time;
  38. }
  39. void EditMaterial::reset() {T=EditMaterial();}
  40. void EditMaterial::resetAlpha()
  41. {
  42. switch(tech)
  43. {
  44. case MTECH_ALPHA_TEST:
  45. case MTECH_GRASS :
  46. case MTECH_LEAF : color.w=0.5f; break;
  47. default: color.w=1; break;
  48. }
  49. color_time.getUTC();
  50. }
  51. void EditMaterial::separateNormalMap(C TimeStamp &time)
  52. {
  53. if(!normal_map.is() && hasNormalMap()) // if normal map is not specified, but is created from some other map
  54. {
  55. normal_map="<bump>"; // set normal map from bump map
  56. if(!ForcesMono(bump_map))SetTransform(normal_map, "grey"); // force grey scale, in case 'bump_map' may be RGB
  57. normal_map_time=time;
  58. }
  59. }
  60. void EditMaterial::separateBaseTexs(C Project &proj, C TimeStamp &time)
  61. {
  62. if(!alpha_map.is() && color_map.is() && hasBase1Tex()) // if alpha map not specified, but may come from color map, and will go to Base1 texture, #MaterialTextureChannelOrder
  63. {
  64. Image color; if(proj.loadImages(color, color_map))if(HasAlpha(color)) // if color has alpha
  65. {
  66. alpha_map="<color>"; // set alpha map from color map
  67. SetTransform(alpha_map, "channel", "a");
  68. alpha_map_time=time;
  69. }
  70. }
  71. separateNormalMap(time);
  72. }
  73. void EditMaterial::cleanupMaps()
  74. { // no need to adjust time because this is called after maps have been changed
  75. if( alpha_map=="<color>") alpha_map.clear();
  76. if(normal_map=="<bump>" )normal_map.clear();
  77. }
  78. void EditMaterial::newData()
  79. {
  80. flip_normal_y_time++; high_quality_ios_time++;
  81. color_map_time++; alpha_map_time++; bump_map_time++; normal_map_time++; specular_map_time++; glow_map_time++;
  82. detail_map_time++; macro_map_time++; reflection_map_time++; light_map_time++;
  83. cull_time++; tech_time++; downsize_tex_mobile_time++;
  84. color_time++; ambient_time++; spec_time++; sss_time++; rough_bump_time++; glow_time++; tex_scale_time++; detail_time++; reflection_time++;
  85. }
  86. void EditMaterial::create(C Material &src, C TimeStamp &time)
  87. {
  88. cull=src.cull; cull_time=time;
  89. tech=src.technique; tech_time=time;
  90. color=src.color; color_time=time;
  91. ambient=src.ambient; ambient_time=time;
  92. specular=src.specular; spec_time=time;
  93. sss=src.sss; sss_time=time;
  94. glow=src.glow; glow_time=time;
  95. rough=src.rough; rough_bump_time=time;
  96. bump=src.bump; rough_bump_time=time;
  97. tex_scale=src.tex_scale; tex_scale_time=time;
  98. det_scale=src.det_scale; detail_time=time;
  99. det_power=src.det_power; detail_time=time;
  100. reflection=src.reflect; reflection_time=time;
  101. base_0_tex=src. base_0.id();
  102. base_1_tex=src. base_1.id();
  103. detail_tex=src. detail_map.id();
  104. macro_tex=src. macro_map.id();
  105. reflection_tex=src.reflection_map.id();
  106. light_tex=src. light_map.id();
  107. }
  108. void EditMaterial::copyTo(Material &dest, C Project &proj)C
  109. {
  110. dest.cull=cull;
  111. dest.technique=tech;
  112. dest.color=color;
  113. dest.ambient=ambient;
  114. dest.specular=specular;
  115. dest.sss=sss;
  116. dest.glow=glow;
  117. dest.rough=rough;
  118. dest.bump=bump;
  119. dest.tex_scale=tex_scale;
  120. dest.det_scale=det_scale;
  121. dest.det_power=det_power;
  122. dest.reflect=reflection;
  123. dest. base_0 =proj.texPath( base_0_tex);
  124. dest. base_1 =proj.texPath( base_1_tex);
  125. dest. detail_map=proj.texPath( detail_tex);
  126. dest. macro_map=proj.texPath( macro_tex);
  127. dest.reflection_map=proj.texPath(reflection_tex);
  128. dest. light_map=proj.texPath( light_tex);
  129. dest.validate();
  130. }
  131. void EditMaterial::copyTo(Edit::Material &dest)C
  132. {
  133. dest.technique=tech;
  134. dest.downsize_tex_mobile=downsize_tex_mobile;
  135. dest.cull=cull;
  136. dest.flip_normal_y=flip_normal_y;
  137. dest.high_quality_ios=high_quality_ios;
  138. dest.color=color;
  139. dest.ambient=ambient;
  140. dest.specular=specular;
  141. dest.glow=glow;
  142. dest.roughness=rough;
  143. dest.bump=bump;
  144. dest.reflection=reflection;
  145. dest. color_map=Edit::FileParams::Decode(color_map);
  146. dest. alpha_map=Edit::FileParams::Decode(alpha_map);
  147. dest. bump_map=Edit::FileParams::Decode(bump_map);
  148. dest. normal_map=Edit::FileParams::Decode(normal_map);
  149. dest. specular_map=Edit::FileParams::Decode(specular_map);
  150. dest. glow_map=Edit::FileParams::Decode(glow_map);
  151. dest.reflection_map=Edit::FileParams::Decode(reflection_map);
  152. dest. detail_color =Edit::FileParams::Decode(detail_color);
  153. dest. detail_bump =Edit::FileParams::Decode(detail_bump);
  154. dest. detail_normal=Edit::FileParams::Decode(detail_normal);
  155. dest. macro_map =Edit::FileParams::Decode(macro_map);
  156. dest. light_map =Edit::FileParams::Decode(light_map);
  157. }
  158. uint EditMaterial::sync(C Edit::Material &src)
  159. {
  160. TimeStamp time; time.getUTC();
  161. uint changed=0;
  162. changed|=CHANGED_PARAM*SyncByValue( tech_time, time, tech , src.technique );
  163. changed|=CHANGED_PARAM*SyncByValue( cull_time, time, cull , src.cull );
  164. changed|= SyncByValue( flip_normal_y_time, time, flip_normal_y , src.flip_normal_y )*(CHANGED_PARAM|CHANGED_BASE|CHANGED_FNY); // set CHANGED_BASE too because this should trigger reloading base textures
  165. changed|=CHANGED_PARAM*SyncByValue( high_quality_ios_time, time, high_quality_ios , src.high_quality_ios );
  166. changed|=CHANGED_PARAM*SyncByValue(downsize_tex_mobile_time, time, downsize_tex_mobile, src.downsize_tex_mobile);
  167. changed|=CHANGED_PARAM*SyncByValueEqual( color_time, time, color, src. color);
  168. changed|=CHANGED_PARAM*SyncByValueEqual( ambient_time, time, ambient, src. ambient);
  169. changed|=CHANGED_PARAM*SyncByValueEqual( spec_time, time, specular, src. specular);
  170. changed|=CHANGED_PARAM*SyncByValueEqual( glow_time, time, glow, src. glow);
  171. changed|=CHANGED_PARAM*SyncByValueEqual(rough_bump_time, time, rough, src. roughness);
  172. changed|=CHANGED_PARAM*SyncByValueEqual(rough_bump_time, time, bump, src. bump);
  173. changed|=CHANGED_PARAM*SyncByValueEqual(reflection_time, time, reflection, src.reflection);
  174. changed|=CHANGED_BASE *SyncByValue( color_map_time, time, color_map, Edit::FileParams::Encode(ConstCast(src. color_map)));
  175. changed|=CHANGED_BASE *SyncByValue( alpha_map_time, time, alpha_map, Edit::FileParams::Encode(ConstCast(src. alpha_map)));
  176. changed|=CHANGED_BASE *SyncByValue( bump_map_time, time, bump_map, Edit::FileParams::Encode(ConstCast(src. bump_map)));
  177. changed|=CHANGED_BASE *SyncByValue( normal_map_time, time, normal_map, Edit::FileParams::Encode(ConstCast(src. normal_map)));
  178. changed|=CHANGED_BASE *SyncByValue( specular_map_time, time, specular_map, Edit::FileParams::Encode(ConstCast(src. specular_map)));
  179. changed|=CHANGED_BASE *SyncByValue( glow_map_time, time, glow_map, Edit::FileParams::Encode(ConstCast(src. glow_map)));
  180. changed|=CHANGED_REFL *SyncByValue(reflection_map_time, time, reflection_map, Edit::FileParams::Encode(ConstCast(src.reflection_map)));
  181. changed|=CHANGED_DET *SyncByValue( detail_map_time, time, detail_color , Edit::FileParams::Encode(ConstCast(src. detail_color )));
  182. changed|=CHANGED_DET *SyncByValue( detail_map_time, time, detail_bump , Edit::FileParams::Encode(ConstCast(src. detail_bump )));
  183. changed|=CHANGED_DET *SyncByValue( detail_map_time, time, detail_normal, Edit::FileParams::Encode(ConstCast(src. detail_normal)));
  184. changed|=CHANGED_MACRO*SyncByValue( macro_map_time, time, macro_map, Edit::FileParams::Encode(ConstCast(src. macro_map)));
  185. changed|=CHANGED_LIGHT*SyncByValue( light_map_time, time, light_map, Edit::FileParams::Encode(ConstCast(src. light_map)));
  186. return changed;
  187. }
  188. uint EditMaterial::sync(C EditMaterial &src)
  189. {
  190. uint changed=0;
  191. changed|=Sync(flip_normal_y_time, src.flip_normal_y_time, flip_normal_y, src.flip_normal_y)*(CHANGED_PARAM|CHANGED_BASE|CHANGED_FNY); // set CHANGED_BASE too because this should trigger reloading base textures
  192. changed|=Sync( color_map_time, src. color_map_time, color_map, src. color_map)*CHANGED_BASE;
  193. changed|=Sync( alpha_map_time, src. alpha_map_time, alpha_map, src. alpha_map)*CHANGED_BASE;
  194. changed|=Sync( bump_map_time, src. bump_map_time, bump_map, src. bump_map)*CHANGED_BASE;
  195. changed|=Sync( normal_map_time, src. normal_map_time, normal_map, src. normal_map)*CHANGED_BASE;
  196. changed|=Sync(specular_map_time, src.specular_map_time, specular_map, src.specular_map)*CHANGED_BASE;
  197. changed|=Sync( glow_map_time, src. glow_map_time, glow_map, src. glow_map)*CHANGED_BASE;
  198. if(changed&CHANGED_BASE)
  199. {
  200. base_0_tex=src.base_0_tex;
  201. base_1_tex=src.base_1_tex;
  202. }
  203. if(Sync(reflection_map_time, src.reflection_map_time))
  204. {
  205. changed|=CHANGED_REFL;
  206. reflection_map=src.reflection_map;
  207. reflection_tex=src.reflection_tex;
  208. }
  209. if(Sync(detail_map_time, src.detail_map_time))
  210. {
  211. changed|=CHANGED_DET;
  212. detail_color =src.detail_color;
  213. detail_bump =src.detail_bump;
  214. detail_normal=src.detail_normal;
  215. detail_tex =src.detail_tex;
  216. }
  217. if(Sync(macro_map_time, src.macro_map_time))
  218. {
  219. changed|=CHANGED_MACRO;
  220. macro_map=src.macro_map;
  221. macro_tex=src.macro_tex;
  222. }
  223. if(Sync(light_map_time, src.light_map_time))
  224. {
  225. changed|=CHANGED_LIGHT;
  226. light_map=src.light_map;
  227. light_tex=src.light_tex;
  228. }
  229. changed|=Sync( cull_time, src. cull_time, cull, src. cull)*CHANGED_PARAM;
  230. changed|=Sync( tech_time, src. tech_time, tech, src. tech)*CHANGED_PARAM;
  231. changed|=Sync( high_quality_ios_time, src. high_quality_ios_time, high_quality_ios, src. high_quality_ios)*CHANGED_PARAM;
  232. changed|=Sync(downsize_tex_mobile_time, src.downsize_tex_mobile_time, downsize_tex_mobile, src.downsize_tex_mobile)*CHANGED_PARAM;
  233. changed|=Sync( color_time, src. color_time, color , src.color )*CHANGED_PARAM;
  234. changed|=Sync( ambient_time, src. ambient_time, ambient , src.ambient )*CHANGED_PARAM;
  235. changed|=Sync( spec_time, src. spec_time, specular , src.specular )*CHANGED_PARAM;
  236. changed|=Sync( sss_time, src. sss_time, sss , src.sss )*CHANGED_PARAM;
  237. changed|=Sync( glow_time, src. glow_time, glow , src.glow )*CHANGED_PARAM;
  238. changed|=Sync( tex_scale_time, src. tex_scale_time, tex_scale , src.tex_scale )*CHANGED_PARAM;
  239. changed|=Sync(reflection_time, src.reflection_time, reflection, src.reflection)*CHANGED_PARAM;
  240. if(Sync(rough_bump_time, src.rough_bump_time))
  241. {
  242. changed|=CHANGED_PARAM;
  243. rough=src.rough;
  244. bump =src.bump ;
  245. }
  246. if(Sync(detail_time, src.detail_time))
  247. {
  248. changed|=CHANGED_PARAM;
  249. det_scale=src.det_scale;
  250. det_power=src.det_power;
  251. }
  252. return changed;
  253. }
  254. uint EditMaterial::undo(C EditMaterial &src)
  255. {
  256. uint changed=0;
  257. changed|=Undo(flip_normal_y_time, src.flip_normal_y_time, flip_normal_y, src.flip_normal_y)*(CHANGED_PARAM|CHANGED_BASE|CHANGED_FNY); // set CHANGED_BASE too because this should trigger reloading base textures
  258. changed|=Undo( color_map_time, src. color_map_time, color_map, src. color_map)*CHANGED_BASE;
  259. changed|=Undo( alpha_map_time, src. alpha_map_time, alpha_map, src. alpha_map)*CHANGED_BASE;
  260. changed|=Undo( bump_map_time, src. bump_map_time, bump_map, src. bump_map)*CHANGED_BASE;
  261. changed|=Undo( normal_map_time, src. normal_map_time, normal_map, src. normal_map)*CHANGED_BASE;
  262. changed|=Undo(specular_map_time, src.specular_map_time, specular_map, src.specular_map)*CHANGED_BASE;
  263. changed|=Undo( glow_map_time, src. glow_map_time, glow_map, src. glow_map)*CHANGED_BASE;
  264. if(changed&CHANGED_BASE)
  265. {
  266. base_0_tex=src.base_0_tex;
  267. base_1_tex=src.base_1_tex;
  268. }
  269. if(Undo(reflection_map_time, src.reflection_map_time))
  270. {
  271. changed|=CHANGED_REFL;
  272. reflection_map=src.reflection_map;
  273. reflection_tex=src.reflection_tex;
  274. }
  275. if(Undo(detail_map_time, src.detail_map_time))
  276. {
  277. changed|=CHANGED_DET;
  278. detail_color =src.detail_color;
  279. detail_bump =src.detail_bump;
  280. detail_normal=src.detail_normal;
  281. detail_tex =src.detail_tex;
  282. }
  283. if(Undo(macro_map_time, src.macro_map_time))
  284. {
  285. changed|=CHANGED_MACRO;
  286. macro_map=src.macro_map;
  287. macro_tex=src.macro_tex;
  288. }
  289. if(Undo(light_map_time, src.light_map_time))
  290. {
  291. changed|=CHANGED_LIGHT;
  292. light_map=src.light_map;
  293. light_tex=src.light_tex;
  294. }
  295. changed|=Undo( cull_time, src. cull_time, cull, src. cull)*CHANGED_PARAM;
  296. changed|=Undo( tech_time, src. tech_time, tech, src. tech)*CHANGED_PARAM;
  297. changed|=Undo( high_quality_ios_time, src. high_quality_ios_time, high_quality_ios, src. high_quality_ios)*CHANGED_PARAM;
  298. changed|=Undo(downsize_tex_mobile_time, src.downsize_tex_mobile_time, downsize_tex_mobile, src.downsize_tex_mobile)*CHANGED_PARAM;
  299. changed|=Undo( color_time, src. color_time, color , src.color )*CHANGED_PARAM;
  300. changed|=Undo( ambient_time, src. ambient_time, ambient , src.ambient )*CHANGED_PARAM;
  301. changed|=Undo( spec_time, src. spec_time, specular , src.specular )*CHANGED_PARAM;
  302. changed|=Undo( sss_time, src. sss_time, sss , src.sss )*CHANGED_PARAM;
  303. changed|=Undo( glow_time, src. glow_time, glow , src.glow )*CHANGED_PARAM;
  304. changed|=Undo( tex_scale_time, src. tex_scale_time, tex_scale , src.tex_scale )*CHANGED_PARAM;
  305. changed|=Undo(reflection_time, src.reflection_time, reflection, src.reflection)*CHANGED_PARAM;
  306. if(Undo(rough_bump_time, src.rough_bump_time))
  307. {
  308. changed|=CHANGED_PARAM;
  309. rough=src.rough;
  310. bump =src.bump ;
  311. }
  312. if(Undo(detail_time, src.detail_time))
  313. {
  314. changed|=CHANGED_PARAM;
  315. det_scale=src.det_scale;
  316. det_power=src.det_power;
  317. }
  318. return changed;
  319. }
  320. bool EditMaterial::save(File &f)C
  321. {
  322. f.cmpUIntV(10);
  323. f<<flip_normal_y<<cull<<high_quality_ios<<tech<<downsize_tex_mobile;
  324. f<<color<<ambient<<specular<<sss<<glow<<rough<<bump<<tex_scale<<det_scale<<det_power<<reflection;
  325. f<<base_0_tex<<base_1_tex<<detail_tex<<macro_tex<<reflection_tex<<light_tex;
  326. f<<color_map<<alpha_map<<bump_map<<normal_map<<specular_map<<glow_map
  327. <<detail_color<<detail_bump<<detail_normal
  328. <<macro_map
  329. <<reflection_map
  330. <<light_map;
  331. f<<flip_normal_y_time<<high_quality_ios_time;
  332. f<<color_map_time<<alpha_map_time<<bump_map_time<<normal_map_time<<specular_map_time<<glow_map_time;
  333. f<<detail_map_time<<macro_map_time<<reflection_map_time<<light_map_time;
  334. f<<cull_time<<tech_time<<downsize_tex_mobile_time;
  335. f<<color_time<<ambient_time<<spec_time<<sss_time<<rough_bump_time<<glow_time<<tex_scale_time<<detail_time<<reflection_time;
  336. return f.ok();
  337. }
  338. bool EditMaterial::load(File &f)
  339. {
  340. bool bump_from_color=false; byte mip_map_blur; TimeStamp mip_map_blur_time, bump_from_color_time;
  341. reset(); switch(f.decUIntV())
  342. {
  343. case 10:
  344. {
  345. f>>flip_normal_y>>cull>>high_quality_ios>>tech>>downsize_tex_mobile;
  346. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  347. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  348. f>>color_map>>alpha_map>>bump_map>>normal_map>>specular_map>>glow_map
  349. >>detail_color>>detail_bump>>detail_normal
  350. >>macro_map
  351. >>reflection_map
  352. >>light_map;
  353. f>>flip_normal_y_time>>high_quality_ios_time;
  354. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  355. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  356. f>>cull_time>>tech_time>>downsize_tex_mobile_time;
  357. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  358. }break;
  359. case 9:
  360. {
  361. f>>flip_normal_y>>cull>>high_quality_ios>>tech>>downsize_tex_mobile;
  362. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  363. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  364. GetStr2(f, color_map); GetStr2(f, alpha_map); GetStr2(f, bump_map); GetStr2(f, normal_map); GetStr2(f, specular_map); GetStr2(f, glow_map);
  365. GetStr2(f, detail_color); GetStr2(f, detail_bump); GetStr2(f, detail_normal);
  366. GetStr2(f, macro_map);
  367. GetStr2(f, reflection_map);
  368. GetStr2(f, light_map);
  369. f>>flip_normal_y_time>>high_quality_ios_time;
  370. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  371. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  372. f>>cull_time>>tech_time>>downsize_tex_mobile_time;
  373. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  374. }break;
  375. case 8:
  376. {
  377. f>>bump_from_color>>flip_normal_y>>cull>>high_quality_ios>>tech>>downsize_tex_mobile;
  378. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  379. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  380. GetStr2(f, color_map); GetStr2(f, alpha_map); GetStr2(f, bump_map); GetStr2(f, normal_map); GetStr2(f, specular_map); GetStr2(f, glow_map);
  381. GetStr2(f, detail_color); GetStr2(f, detail_bump); GetStr2(f, detail_normal);
  382. GetStr2(f, macro_map);
  383. GetStr2(f, reflection_map);
  384. GetStr2(f, light_map);
  385. f>>bump_from_color_time>>flip_normal_y_time>>high_quality_ios_time;
  386. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  387. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  388. f>>cull_time>>tech_time>>downsize_tex_mobile_time;
  389. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  390. }break;
  391. case 7:
  392. {
  393. f>>bump_from_color>>flip_normal_y>>cull>>high_quality_ios>>tech>>downsize_tex_mobile>>mip_map_blur;
  394. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  395. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  396. GetStr2(f, color_map); GetStr2(f, alpha_map); GetStr2(f, bump_map); GetStr2(f, normal_map); GetStr2(f, specular_map); GetStr2(f, glow_map);
  397. GetStr2(f, detail_color); GetStr2(f, detail_bump); GetStr2(f, detail_normal);
  398. GetStr2(f, macro_map);
  399. GetStr2(f, reflection_map);
  400. GetStr2(f, light_map);
  401. f>>bump_from_color_time>>flip_normal_y_time>>high_quality_ios_time;
  402. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  403. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  404. f>>cull_time>>tech_time>>downsize_tex_mobile_time>>mip_map_blur_time;
  405. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  406. }break;
  407. case 6:
  408. {
  409. f>>bump_from_color>>flip_normal_y>>cull>>tech>>downsize_tex_mobile>>mip_map_blur;
  410. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  411. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  412. GetStr2(f, color_map); GetStr2(f, alpha_map); GetStr2(f, bump_map); GetStr2(f, normal_map); GetStr2(f, specular_map); GetStr2(f, glow_map);
  413. GetStr2(f, detail_color); GetStr2(f, detail_bump); GetStr2(f, detail_normal);
  414. GetStr2(f, macro_map);
  415. GetStr2(f, reflection_map);
  416. GetStr2(f, light_map);
  417. f>>bump_from_color_time>>flip_normal_y_time;
  418. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  419. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  420. f>>cull_time>>tech_time>>downsize_tex_mobile_time>>mip_map_blur_time;
  421. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  422. }break;
  423. case 5:
  424. {
  425. byte max_tex_size; f>>bump_from_color>>flip_normal_y>>cull>>tech>>max_tex_size>>mip_map_blur; downsize_tex_mobile=(max_tex_size>=1 && max_tex_size<=10);
  426. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  427. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  428. GetStr2(f, color_map); GetStr2(f, alpha_map); GetStr2(f, bump_map); GetStr2(f, normal_map); GetStr2(f, specular_map); GetStr2(f, glow_map);
  429. GetStr2(f, detail_color); GetStr2(f, detail_bump); GetStr2(f, detail_normal);
  430. GetStr2(f, macro_map);
  431. GetStr2(f, reflection_map);
  432. GetStr2(f, light_map);
  433. f>>bump_from_color_time>>flip_normal_y_time;
  434. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  435. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  436. f>>cull_time>>tech_time>>downsize_tex_mobile_time>>mip_map_blur_time;
  437. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  438. }break;
  439. case 4:
  440. {
  441. byte max_tex_size; f>>bump_from_color>>flip_normal_y>>cull>>tech>>max_tex_size>>mip_map_blur; downsize_tex_mobile=(max_tex_size>=1 && max_tex_size<=10);
  442. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  443. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  444. GetStr(f, color_map); GetStr(f, alpha_map); GetStr(f, bump_map); GetStr(f, normal_map); GetStr(f, specular_map); GetStr(f, glow_map);
  445. GetStr(f, detail_color); GetStr(f, detail_bump); GetStr(f, detail_normal);
  446. GetStr(f, macro_map);
  447. GetStr(f, reflection_map);
  448. GetStr(f, light_map);
  449. f>>bump_from_color_time>>flip_normal_y_time;
  450. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  451. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  452. f>>cull_time>>tech_time>>downsize_tex_mobile_time>>mip_map_blur_time;
  453. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  454. }break;
  455. case 3:
  456. {
  457. f>>bump_from_color>>flip_normal_y>>cull>>tech>>mip_map_blur;
  458. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  459. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  460. GetStr(f, color_map); GetStr(f, alpha_map); GetStr(f, bump_map); GetStr(f, normal_map); GetStr(f, specular_map); GetStr(f, glow_map);
  461. GetStr(f, detail_color); GetStr(f, detail_bump); GetStr(f, detail_normal);
  462. GetStr(f, macro_map);
  463. GetStr(f, reflection_map);
  464. GetStr(f, light_map);
  465. f>>bump_from_color_time>>flip_normal_y_time;
  466. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  467. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  468. f>>cull_time>>tech_time>>mip_map_blur_time;
  469. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  470. }break;
  471. case 2:
  472. {
  473. f>>bump_from_color>>flip_normal_y>>cull>>tech;
  474. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  475. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex>>light_tex;
  476. GetStr(f, color_map); GetStr(f, alpha_map); GetStr(f, bump_map); GetStr(f, normal_map); GetStr(f, specular_map); GetStr(f, glow_map);
  477. GetStr(f, detail_color); GetStr(f, detail_bump); GetStr(f, detail_normal);
  478. GetStr(f, macro_map);
  479. GetStr(f, reflection_map);
  480. GetStr(f, light_map);
  481. f>>bump_from_color_time>>flip_normal_y_time;
  482. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  483. f>>detail_map_time>>macro_map_time>>reflection_map_time>>light_map_time;
  484. f>>cull_time>>tech_time;
  485. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  486. }break;
  487. case 1:
  488. {
  489. f>>bump_from_color>>flip_normal_y>>cull>>tech;
  490. f>>color>>ambient>>specular>>sss>>glow>>rough>>bump>>tex_scale>>det_scale>>det_power>>reflection;
  491. f>>base_0_tex>>base_1_tex>>detail_tex>>macro_tex>>reflection_tex;
  492. GetStr(f, color_map); GetStr(f, alpha_map); GetStr(f, bump_map); GetStr(f, normal_map); GetStr(f, specular_map); GetStr(f, glow_map);
  493. GetStr(f, detail_color); GetStr(f, detail_bump); GetStr(f, detail_normal);
  494. GetStr(f, macro_map);
  495. GetStr(f, reflection_map);
  496. light_map.clear();
  497. f>>bump_from_color_time>>flip_normal_y_time;
  498. f>>color_map_time>>alpha_map_time>>bump_map_time>>normal_map_time>>specular_map_time>>glow_map_time;
  499. f>>detail_map_time>>macro_map_time>>reflection_map_time;
  500. f>>cull_time>>tech_time;
  501. f>>color_time>>ambient_time>>spec_time>>sss_time>>rough_bump_time>>glow_time>>tex_scale_time>>detail_time>>reflection_time;
  502. }break;
  503. case 0: break; // empty, this requires 'reset' to be called before
  504. default: goto error;
  505. }
  506. if(f.ok())
  507. {
  508. if(bump_from_color && !bump_map.is() && color_map.is()){bump_map=BumpFromColTransform(color_map, 3); if(!bump_map_time.is())bump_map_time++;}
  509. return true;
  510. }
  511. error:
  512. reset(); return false;
  513. }
  514. bool EditMaterial::load(C Str &name)
  515. {
  516. File f; if(f.readTry(name))return load(f);
  517. reset(); return false;
  518. }
  519. EditMaterial::EditMaterial() : flip_normal_y(false), cull(true), high_quality_ios(false), downsize_tex_mobile(0), tech(MTECH_DEFAULT), color(1, 1, 1, 1), ambient(0, 0, 0), specular(0), sss(0), glow(0), rough(0), bump(0), tex_scale(1), det_scale(4), det_power(0.3f), reflection(0.2f), base_0_tex(UIDZero), base_1_tex(UIDZero), detail_tex(UIDZero), macro_tex(UIDZero), reflection_tex(UIDZero), light_tex(UIDZero) {}
  520. /******************************************************************************/