TC_Compute.compute 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060
  1. struct SplatCustom
  2. {
  3. float4 select;
  4. float4 map0;
  5. float4 map1;
  6. float4 map2;
  7. float4 map3;
  8. };
  9. struct ColorItem
  10. {
  11. float3 select;
  12. float4 color;
  13. };
  14. struct ItemMap
  15. {
  16. uint index;
  17. float density;
  18. float maskValue;
  19. float3 pos;
  20. };
  21. struct ItemSettings
  22. {
  23. int index;
  24. float randomPosition;
  25. float2 range;
  26. float opacity;
  27. };
  28. static const uint heightOutput = 0;
  29. RWStructuredBuffer<float> resultBuffer;
  30. RWStructuredBuffer<ItemMap> itemMapBuffer;
  31. RWStructuredBuffer<float4> itemColorBuffer;
  32. StructuredBuffer<ItemSettings> itemIndexBuffer;
  33. StructuredBuffer<float> rightBuffer;
  34. StructuredBuffer<float> maskBuffer;
  35. StructuredBuffer<ItemMap> rightItemMapBuffer;
  36. RWTexture2D<float> resultTex;
  37. RWTexture2D<float4> terrainTex;
  38. RWTexture2D<float4> splatmap0;
  39. RWTexture2D<float4> splatmap1;
  40. RWTexture2D<float4> splatmap2;
  41. RWTexture2D<float4> splatmap3;
  42. RWTexture2D<float4> splatPreviewTexClone;
  43. RWTexture2D<float4> splatPreviewTex;
  44. RWTexture2D<float4> previewTex;
  45. RWTexture2D<float4> previewTex2;
  46. Texture2D<float> resultTexRead;
  47. Texture2D<float4> terrainTexRead;
  48. Texture2D<float4> leftPreviewTex;
  49. Texture2D<float4> rightPreviewTex;
  50. Texture2D<float4> rightSplatmap0;
  51. Texture2D<float4> rightSplatmap1;
  52. Texture2D<float4> rightSplatmap2;
  53. Texture2D<float4> rightSplatmap3;
  54. Texture2D<float4> leftSplatmap0;
  55. Texture2D<float4> leftSplatmap1;
  56. Texture2D<float4> leftSplatmap2;
  57. Texture2D<float4> leftSplatmap3;
  58. Texture2D<float> tex1;
  59. Texture2D<float4> tex1b;
  60. Texture2D<float4> tex2b;
  61. StructuredBuffer<SplatCustom> splatMixBuffer;
  62. StructuredBuffer<ColorItem> colorMixBuffer;
  63. StructuredBuffer<float> localCurveKeys;
  64. StructuredBuffer<float4> localCurveCalc;
  65. float _Seed;
  66. float _Frequency;
  67. float _Lacunarity;
  68. float _Persistence;
  69. float _Amplitude;
  70. float _Warp0;
  71. float _Warp;
  72. float _Damp0;
  73. float _Damp;
  74. float _DampScale;
  75. uint _CellType;
  76. uint _DistanceFunction;
  77. uint _Octaves;
  78. uint localCurveKeysLength;
  79. float3 localGroupCurveRange;
  80. float3 worldCurveRange;
  81. float3 localCurveRange;
  82. StructuredBuffer<float> localGroupCurveKeys;
  83. StructuredBuffer<float4> localGroupCurveCalc;
  84. uint localGroupCurveKeysLength;
  85. StructuredBuffer<float> worldCurveKeys;
  86. StructuredBuffer<float4> worldCurveCalc;
  87. uint worldCurveKeysLength;
  88. uint outputId;
  89. uint terrainSplatLength;
  90. uint splatIndex;
  91. float terrainTexReadResolution;
  92. float terrainTexReadNormalResolution;
  93. uint resolutionX;
  94. uint resolutionY;
  95. float resExpandBorder;
  96. float2 topResolution;
  97. float2 bottomResolution;
  98. float shapeSize;
  99. float2 range;
  100. float defaultTerrainHeight;
  101. float2 texResolution;
  102. float2 resolutionPM;
  103. float2 resToPreview;
  104. float2 uv;
  105. float2 uvOffset;
  106. float2 uvScale;
  107. float2 terrainSize;
  108. float terrainHeight;
  109. uint doNormalize;
  110. uint preview;
  111. uint isClamp;
  112. uint isMirror;
  113. uint previewResolution;
  114. uint method; // 0 - none, 1 - add, 2 - subtract, 3 - overlay, 4 - Multiply, 4 - Divide, 5 - Difference, 6 - Average, 7 - Max, 8 - Min
  115. int mask;
  116. float mixValue;
  117. float overlay;
  118. uint itemCount;
  119. float3 offset, scale;
  120. float4 rot;
  121. float2 texID;
  122. SamplerState _LinearRepeat;
  123. SamplerState _LinearClamp;
  124. SamplerState _PointClamp;
  125. float4 colLayer;
  126. float4 colLayer2;
  127. float3 pos;
  128. float2 pos2;
  129. float3 posOffset;
  130. float2 areaPos;
  131. float2 totalAreaPos;
  132. float h;
  133. float2 snapOffset;
  134. float3 redChannel;
  135. float3 greenChannel;
  136. float3 blueChannel;
  137. float3 alphaChannel;
  138. #include "TC_Noise.cginc"
  139. #include "TC_NoisesAdvanced.cginc"
  140. float Evaluate(float t, uint curveKeysLength, StructuredBuffer<float> curveKeys, StructuredBuffer<float4> curveCalc)
  141. {
  142. // if (t > curveKeys[curveKeysLength - 1]) t = curveKeys[curveKeysLength - 1];
  143. // if (t < curveKeys[0]) t = curveKeys[0];
  144. t = clamp(t, curveKeys[0], curveKeys[curveKeysLength - 1]);
  145. uint i = 0;
  146. for (uint j = 1; j < curveKeysLength; j++) if (curveKeys[j] >= t) { i = j - 1; break; }
  147. return curveCalc[i].x * t * t * t + curveCalc[i].y * t * t + curveCalc[i].z * t + curveCalc[i].w;
  148. }
  149. void GetPos3(uint id)
  150. {
  151. pos2.y = (id / resolutionX);
  152. pos2.x = (id - (pos2.y * resolutionX));
  153. pos.y = 0;
  154. pos.xz = pos2.xy * resolutionPM.xy;
  155. texID = float2((pos.x + areaPos.x - totalAreaPos.x) * resToPreview.x, (pos.z + areaPos.y - totalAreaPos.y) * resToPreview.y);
  156. // texID = float2((pos.x / resolutionX) * previewResolution, (pos.z / resolutionY) * previewResolution);
  157. }
  158. void GetPos(uint id)
  159. {
  160. pos.z = (id / resolutionX);
  161. pos.y = 0;
  162. pos.x = (id - (pos.z * resolutionX));
  163. pos.xz *= resolutionPM.xy;
  164. texID = float2((pos.x + areaPos.x - totalAreaPos.x) * resToPreview.x, (pos.z + areaPos.y - totalAreaPos.y) * resToPreview.y);
  165. // texID = float2((pos.x / resolutionX) * previewResolution, (pos.z / resolutionY) * previewResolution);
  166. }
  167. void GetPosUV(uint id)
  168. {
  169. pos.z = id / resolutionX;
  170. pos.y = 0;
  171. pos.x = id - (pos.z * resolutionX);
  172. uv = float2(pos.x / (resolutionX - 1), pos.z / (resolutionY - 1)) + uvOffset;
  173. // uv += 1 / (resolutionX - 1);
  174. pos.xz *= resolutionPM.xy;
  175. texID = float2((pos.x + areaPos.x - totalAreaPos.x) * resToPreview.x, (pos.z + areaPos.y - totalAreaPos.y) * resToPreview.y);
  176. // texID = float2((pos.x / resolutionX) * previewResolution, (pos.z / resolutionY) * previewResolution);
  177. }
  178. void GetPos2(uint id)
  179. {
  180. pos2.y = (id / resolutionX);
  181. pos2.x = (id - (pos2.y * resolutionX));
  182. texID = float2(((pos2.x * resolutionPM.x) + areaPos.x - totalAreaPos.x) * resToPreview.x, ((pos2.y * resolutionPM.y) + areaPos.y - totalAreaPos.y) * resToPreview.y);
  183. }
  184. void GetWorldPos2(uint id)
  185. {
  186. pos2.y = (id / resolutionX);
  187. pos2.x = (id - (pos2.y * resolutionX));
  188. pos2 = (pos2 * resolutionPM) + areaPos;
  189. texID = (pos2 - totalAreaPos) * resToPreview;
  190. }
  191. void GetWorldPosUV2(uint id)
  192. {
  193. pos2.y = (id / resolutionX);
  194. pos2.x = (id - (pos2.y * resolutionX));
  195. uv = (pos2.xy / (resolutionX - 1)) + uvOffset;
  196. pos2 = (pos2 * resolutionPM) + areaPos;
  197. texID = (pos2 - totalAreaPos) * resToPreview;
  198. }
  199. void GetTexID(uint2 id)
  200. {
  201. texID = float2(((id.x * resolutionPM.x) + areaPos.x - totalAreaPos.x) * resToPreview.x, ((id.y * resolutionPM.y) + areaPos.y - totalAreaPos.y) * resToPreview.y);
  202. }
  203. void GetUV(uint id)
  204. {
  205. uv.y = (id / resolutionX);
  206. uv.x = (id - (uv.y * resolutionX));
  207. uv.x /= (resolutionX - 1);
  208. uv.y /= (resolutionY - 1);
  209. uv += uvOffset;
  210. }
  211. // TODO: If curve is default don't use it, but do clamp01.
  212. void ApplyLocalCurve()
  213. {
  214. h = clamp(h, localCurveRange.x, localCurveRange.y);
  215. h = (h - localCurveRange.x) / localCurveRange.z;
  216. h = Evaluate(h, localCurveKeysLength, localCurveKeys, localCurveCalc);
  217. }
  218. void ApplyLocalGroupCurve()
  219. {
  220. h = clamp(h, localGroupCurveRange.x, localGroupCurveRange.y);
  221. h = (h - localGroupCurveRange.x) / localGroupCurveRange.z;
  222. h = Evaluate(h, localGroupCurveKeysLength, localGroupCurveKeys, localGroupCurveCalc);
  223. }
  224. void ApplyWorldCurve()
  225. {
  226. h = clamp(h, worldCurveRange.x, worldCurveRange.y);
  227. h = (h - worldCurveRange.x) / worldCurveRange.z;
  228. h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  229. }
  230. void ApplyVertical()
  231. {
  232. if (localCurveKeysLength > 0) ApplyLocalCurve();
  233. if (localGroupCurveKeysLength > 0) ApplyLocalGroupCurve();
  234. if (mask == 0 && outputId == heightOutput)
  235. {
  236. h *= (defaultTerrainHeight / terrainHeight) * scale.y;
  237. h += offset.y / terrainHeight;
  238. }
  239. else
  240. {
  241. h *= scale.y;
  242. h += offset.y / defaultTerrainHeight;
  243. }
  244. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  245. }
  246. void ApplySplatVertical()
  247. {
  248. if (localCurveKeysLength > 0) ApplyLocalCurve();
  249. if (localGroupCurveKeysLength > 0) ApplyLocalGroupCurve();
  250. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  251. }
  252. void GetUV()
  253. {
  254. pos.xz -= offset.xz;
  255. pos = pos + 2.0 * cross(cross(pos, rot.xyz) + rot.w * pos, rot.xyz);
  256. pos.xz /= scale.xz;
  257. pos.xz += posOffset.xz;
  258. uv = pos.xz / (texResolution.xy - 1);
  259. uv += 0.5f;
  260. uv = lerp(uv, 0.9999 - uv, ceil(frac(floor(uv) * 0.5)) * isMirror);
  261. uv = lerp(frac(uv), uv, isClamp);
  262. }
  263. void GetUvShape()
  264. {
  265. pos.xz -= offset.xz;
  266. pos = pos + 2.0 * cross(cross(pos, rot.xyz) + rot.w * pos, rot.xyz);
  267. pos.xz /= scale.xz;
  268. uv = pos.xz / (texResolution.xy - 1);
  269. uv += 0.5f;
  270. uv = lerp(frac(uv), uv, isClamp);
  271. }
  272. void SetPreviewTex()
  273. {
  274. float4 color = float4(h, h, h, 1);
  275. if (h > 1.0001) color = lerp(float4(1, 0, 0, 1), float4(1, 0, 1, 1), saturate(h - 1));
  276. else if (h < -0.0001) color = lerp(float4(0, 1, 1, 1), float4(0, 0, 1, 1), saturate(-h));
  277. previewTex[texID] = color;
  278. }
  279. void SetPreviewTex2()
  280. {
  281. float4 color = float4(h, h, h, 1);
  282. if (h > 1.0001) color = lerp(float4(1, 0, 0, 1), float4(1, 0, 1, 1), saturate(h - 1));
  283. else if (h < -0.0001) color = lerp(float4(0, 1, 1, 1), float4(0, 0, 1, 1), saturate(-h));
  284. previewTex2[texID] = color;
  285. }
  286. void SetPreviewTexBoth()
  287. {
  288. float4 color = float4(h, h, h, 1);
  289. if (h > 1.0001) color = lerp(float4(1, 0, 0, 1), float4(1, 0, 1, 1), saturate(h - 1));
  290. else if (h < -0.0001) color = lerp(float4(0, 1, 1, 1), float4(0, 0, 1, 1), saturate(-h));
  291. previewTex[texID] = color;
  292. previewTex2[texID] = color;
  293. }
  294. float random(float p) {
  295. return frac(sin(p) * 10000.0);
  296. }
  297. float noise(float2 p) {
  298. return random(p.x + p.y * 10000.0);
  299. }
  300. float2 sw(float2 p) {return float2( floor(p.x) , floor(p.y) );}
  301. float2 se(float2 p) {return float2( ceil(p.x) , floor(p.y) );}
  302. float2 nw(float2 p) {return float2( floor(p.x) , ceil(p.y) );}
  303. float2 ne(float2 p) {return float2( ceil(p.x) , ceil(p.y) );}
  304. float smoothNoise(float2 p) {
  305. float2 inter = smoothstep(0., 1., frac(p));
  306. float s = lerp(noise(sw(p)), noise(se(p)), inter.x);
  307. float n = lerp(noise(nw(p)), noise(ne(p)), inter.x);
  308. return lerp(s, n, inter.y);
  309. return noise(nw(p));
  310. }
  311. float movingNoise(float2 p, float time) {
  312. float total = 0.0;
  313. total += smoothNoise(p - time);
  314. total += smoothNoise(p*2. + time) / 2.;
  315. total += smoothNoise(p*4. - time) / 4.;
  316. total += smoothNoise(p*8. + time) / 8.;
  317. total += smoothNoise(p*16. - time) / 16.;
  318. total /= 1. + 1./2. + 1./4. + 1./8. + 1./16.;
  319. return total;
  320. }
  321. float nestedNoise(float2 p, float time) {
  322. float x = movingNoise(p, time);
  323. float y = movingNoise(p + 100, time);
  324. return movingNoise(p + float2(x, y), time);
  325. }
  326. float Random(float2 co)
  327. {
  328. // co.x *= 4503.54332;
  329. // co.y *= 4794.23588;
  330. return frac(sin(dot(co.xy,float2(12.9898,78.233)))*43758.5453123);
  331. // float2 p = floor(co);
  332. // float2 f = frac(co);
  333. // f = f * f * (3.0 - 2.0 * f);
  334. // float n = p.x + p.y * 57.0;
  335. // float4 noise = float4(n, n + 1, n + 57.0, n + 58.0);
  336. // noise = frac(sin(noise)*437.585453);
  337. // return lerp(lerp(noise.x, noise.y, f.x), lerp(noise.z, noise.w, f.x), f.y);
  338. }
  339. // ==================================================================
  340. // ResultBuffer to tex
  341. #pragma kernel ResultBufferToTex
  342. [numthreads(8,8,1)]
  343. void ResultBufferToTex (uint2 id : SV_DispatchThreadID)
  344. {
  345. uint i = id.x + (id.y * resolutionX);
  346. h = saturate(resultBuffer[i]);
  347. resultTex[id] = h;
  348. resultBuffer[i] = h;
  349. }
  350. // ==================================================================
  351. // Terrain tex normal & height
  352. #pragma kernel TerrainTex
  353. [numthreads(8,8,1)]
  354. void TerrainTex (uint2 id : SV_DispatchThreadID)
  355. {
  356. // uint i = id.x + (id.y * resolutionX);
  357. float4 h;
  358. float2 s = float2(1.0 / (resolutionX * 1.0), 1.0 / (resolutionY * 1.0));
  359. float2 uv = float2(id.x / ((resolutionX - 1) * 1.0), id.y / ((resolutionY - 1) * 1.0));
  360. h[0] = resultTexRead.SampleLevel(_LinearClamp, uv + float2(0, -s.y), 0).r;
  361. h[1] = resultTexRead.SampleLevel(_LinearClamp, uv + float2(-s.x, 0), 0).r;
  362. h[2] = resultTexRead.SampleLevel(_LinearClamp, uv + float2(s.x, 0), 0).r;
  363. h[3] = resultTexRead.SampleLevel(_LinearClamp, uv + float2(0, s.y), 0).r;
  364. float3 n;
  365. n.z = ((h[0] - h[3]) * 4000) / resolutionPM.x;
  366. n.x = ((h[1] - h[2]) * 4000) / resolutionPM.y;
  367. n.y = 2 * (defaultTerrainHeight / terrainHeight);
  368. n = normalize(n) * 0.5 + 0.5;
  369. // n.xz = (n.xz + 1) * 0.5;
  370. float height = resultTexRead.SampleLevel(_PointClamp, uv, 0).r;
  371. height *= 65535;
  372. float h1 = floor(height / 256);
  373. float h2 = height - (h1 * 256);
  374. terrainTex[id] = float4(h1 / 255.0, h2 / 255.0, n.x, n.z); // idOffset
  375. // terrainTex[id] = float4(n.x, n.z, 0,0);
  376. }
  377. // ==================================================================
  378. // Terrain
  379. #pragma kernel TerrainHeight
  380. [numthreads(512,1,1)]
  381. void TerrainHeight (uint id : SV_DispatchThreadID)
  382. {
  383. GetPosUV(id);
  384. uv *= (terrainTexReadNormalResolution - 2);
  385. uv += resExpandBorder;
  386. uv /= (terrainTexReadResolution);
  387. uv += float2(1 / terrainTexReadResolution, 1 / terrainTexReadResolution);
  388. float2 h0 = terrainTexRead.SampleLevel(_LinearClamp, uv, 0).rg * 255;
  389. // float2 h0 = terrainTexRead[uint2(x, z)].rg * 255;
  390. h = ((h0.x * 256.0) + h0.y) / 65535.0;
  391. h /= (defaultTerrainHeight / terrainHeight);
  392. ApplySplatVertical();
  393. resultBuffer[id] = h;
  394. SetPreviewTex();
  395. }
  396. #pragma kernel TerrainAngle
  397. [numthreads(512,1,1)]
  398. void TerrainAngle (uint id : SV_DispatchThreadID)
  399. {
  400. GetPosUV(id);
  401. uv *= (terrainTexReadNormalResolution - 2);
  402. uv += resExpandBorder;
  403. uv /= (terrainTexReadResolution);
  404. uv += float2(1 / terrainTexReadResolution, 1 / terrainTexReadResolution);
  405. // h = 1 - ((terrainTexRead.SampleLevel(_LinearClamp, uv, 0).a - 0.5) * 2);
  406. float2 n = (terrainTexRead.SampleLevel(_LinearClamp, uv, 0).ba - 0.5) * 2;
  407. h = 1 - (sqrt(1 - dot(n, n)));// - 0.5) * 2);
  408. h = saturate(h + 0.00001);
  409. ApplySplatVertical();
  410. resultBuffer[id] = h;
  411. SetPreviewTex();
  412. }
  413. #pragma kernel TerrainConvexity
  414. [numthreads(512,1,1)]
  415. void TerrainConvexity (uint id : SV_DispatchThreadID)
  416. {
  417. GetPosUV(id);
  418. uv *= (terrainTexReadNormalResolution - 2);
  419. uv += resExpandBorder;
  420. uv /= (terrainTexReadResolution);
  421. uv += float2(1 / terrainTexReadResolution, 1 / terrainTexReadResolution);
  422. float2 h0 = terrainTexRead.SampleLevel(_LinearClamp, uv, 0).rg * 255;
  423. h = ((h0.x * 256.0) + h0.y) / 65535.0;
  424. h /= (defaultTerrainHeight / terrainHeight);
  425. h0 = terrainTexRead.SampleLevel(_LinearClamp, uv, itemCount).rg * 255;
  426. float ha = ((h0.x * 256.0) + h0.y) / 65535.0;
  427. ha /= (defaultTerrainHeight / terrainHeight);
  428. h = (h - ha) * (overlay * 10);
  429. ApplySplatVertical();
  430. resultBuffer[id] = h;
  431. SetPreviewTex();
  432. }
  433. #pragma kernel TerrainSplatmap0
  434. [numthreads(512,1,1)]
  435. void TerrainSplatmap0 (uint id : SV_DispatchThreadID)
  436. {
  437. GetPosUV(id);
  438. h = leftSplatmap0.SampleLevel(_LinearClamp, uv, 0)[splatIndex];
  439. ApplySplatVertical();
  440. resultBuffer[id] = h;
  441. SetPreviewTex();
  442. }
  443. #pragma kernel TerrainSplatmap1
  444. [numthreads(512,1,1)]
  445. void TerrainSplatmap1 (uint id : SV_DispatchThreadID)
  446. {
  447. GetPosUV(id);
  448. h = leftSplatmap1.SampleLevel(_LinearClamp, uv, 0)[splatIndex];
  449. ApplySplatVertical();
  450. resultBuffer[id] = h;
  451. SetPreviewTex();
  452. }
  453. #pragma kernel TerrainCollisionHeight
  454. [numthreads(512,1,1)]
  455. void TerrainCollisionHeight (uint id : SV_DispatchThreadID)
  456. {
  457. GetPosUV(id);
  458. float h0 = tex1.SampleLevel(_PointClamp, float2(uv.x, 1 - uv.y), 0).r;
  459. h0 *= 1 - step(1, h0);
  460. h0 -= 1 / terrainHeight;
  461. if (h0 >= range.x && h0 <= range.y) h = h0;
  462. // if (h == 1) h = rightBuffer[id];
  463. // h = min(h, rightBuffer[id]);
  464. resultBuffer[id] = h;
  465. SetPreviewTex();
  466. }
  467. #pragma kernel TerrainCollisionHeightInverted
  468. [numthreads(512,1,1)]
  469. void TerrainCollisionHeightInverted (uint id : SV_DispatchThreadID)
  470. {
  471. GetPosUV(id);
  472. float h0 = 1 - tex1.SampleLevel(_PointClamp, float2(uv.x, 1 - uv.y), 0).r;
  473. h0 *= 1 - step(1, h0);
  474. h0 -= 1 / terrainHeight;
  475. if (h0 >= range.x && h0 <= range.y) h = h0;
  476. // if (h == 1) h = rightBuffer[id];
  477. // h = min(h, rightBuffer[id]);
  478. resultBuffer[id] = h;
  479. SetPreviewTex();
  480. }
  481. #pragma kernel TerrainCollisionHeightInclude
  482. [numthreads(512,1,1)]
  483. void TerrainCollisionHeightInclude (uint id : SV_DispatchThreadID)
  484. {
  485. GetPosUV(id);
  486. float h0 = tex1.SampleLevel(_PointClamp, float2(uv.x, 1 - uv.y), 0).r;
  487. h0 *= 1 - step(1, h0);
  488. h0 -= 1 / terrainHeight;
  489. uv *= (terrainTexReadNormalResolution - 2);
  490. uv += resExpandBorder;
  491. uv /= (terrainTexReadResolution);
  492. uv += float2(1 / terrainTexReadResolution, 1 / terrainTexReadResolution);
  493. // float2 h0 = terrainTexRead.SampleLevel(_LinearClamp, uv, 0).rg * 255;
  494. // float height = ((h0.x * 256.0) + h0.y) / 65535.0;
  495. // height /= (defaultTerrainHeight / terrainHeight);
  496. h = rightBuffer[id];
  497. float deltaH = h0 - h;
  498. if (deltaH >= range.x && deltaH <= range.y) h = h0;
  499. // if (h == 1) h = rightBuffer[id];
  500. // h = min(h, rightBuffer[id]);
  501. resultBuffer[id] = h;
  502. SetPreviewTex();
  503. }
  504. #pragma kernel TerrainCollisionHeightIncludeInverted
  505. [numthreads(512,1,1)]
  506. void TerrainCollisionHeightIncludeInverted (uint id : SV_DispatchThreadID)
  507. {
  508. GetPosUV(id);
  509. float h0 = 1 - tex1.SampleLevel(_PointClamp, float2(uv.x, 1 - uv.y), 0).r;
  510. h0 *= 1 - step(1, h0);
  511. h0 -= 1 / terrainHeight;
  512. uv *= (terrainTexReadNormalResolution - 2);
  513. uv += resExpandBorder;
  514. uv /= (terrainTexReadResolution);
  515. uv += float2(1 / terrainTexReadResolution, 1 / terrainTexReadResolution);
  516. // float2 h0 = terrainTexRead.SampleLevel(_LinearClamp, uv, 0).rg * 255;
  517. // float height = ((h0.x * 256.0) + h0.y) / 65535.0;
  518. // height /= (defaultTerrainHeight / terrainHeight);
  519. h = rightBuffer[id];
  520. float deltaH = h0 - h;
  521. if (deltaH >= range.x && deltaH <= range.y) h = h0;
  522. // if (h == 1) h = rightBuffer[id];
  523. // h = min(h, rightBuffer[id]);
  524. resultBuffer[id] = h;
  525. SetPreviewTex();
  526. }
  527. #pragma kernel TerrainCollisionMask
  528. [numthreads(512,1,1)]
  529. void TerrainCollisionMask (uint id : SV_DispatchThreadID)
  530. {
  531. GetPosUV(id);
  532. h = tex1.SampleLevel(_PointClamp, float2(uv.x, 1 - uv.y), 0).r;
  533. h *= step(1, h);
  534. ApplySplatVertical();
  535. resultBuffer[id] = h;
  536. SetPreviewTex();
  537. }
  538. #pragma kernel TerrainCollisionMaskInverted
  539. [numthreads(512,1,1)]
  540. void TerrainCollisionMaskInverted (uint id : SV_DispatchThreadID)
  541. {
  542. GetPosUV(id);
  543. h = 1 - tex1.SampleLevel(_PointClamp, float2(uv.x, 1 - uv.y), 0).r;
  544. h *= step(1, h);
  545. ApplySplatVertical();
  546. resultBuffer[id] = h;
  547. SetPreviewTex();
  548. }
  549. // ==================================================================
  550. // File
  551. #pragma kernel RawImage
  552. [numthreads(512,1,1)]
  553. void RawImage (uint id : SV_DispatchThreadID)
  554. {
  555. GetPos(id);
  556. GetUV();
  557. h = 0;
  558. uv.y = 1 - uv.y;
  559. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  560. {
  561. // h = ((tex2.SampleLevel(_LinearClamp, uv, 0).r * 65280.0) + tex1.SampleLevel(_LinearClamp, uv, 0).a * 255) / 65535.0;
  562. h = tex1.SampleLevel(_LinearClamp, uv, 0).r;
  563. ApplyVertical();
  564. }
  565. resultBuffer[id] = h;
  566. SetPreviewTex();
  567. }
  568. #pragma kernel RawImageOSX
  569. [numthreads(512,1,1)]
  570. void RawImageOSX (uint id : SV_DispatchThreadID)
  571. {
  572. GetPos(id);
  573. GetUV();
  574. h = 0;
  575. uv.y = 1 - uv.y;
  576. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  577. {
  578. // h = ((tex2.SampleLevel(_LinearClamp, uv, 0).r * 65280.0) + tex1.SampleLevel(_LinearClamp, uv, 0).a * 255) / 65535.0;
  579. h = tex1b.SampleLevel(_LinearClamp, uv, 0).a / 255.0;
  580. h += tex2b.SampleLevel(_LinearClamp, uv, 0).a;
  581. ApplyVertical();
  582. }
  583. resultBuffer[id] = h;
  584. SetPreviewTex();
  585. }
  586. #pragma kernel ImageColor
  587. [numthreads(512,1,1)]
  588. void ImageColor (uint id : SV_DispatchThreadID)
  589. {
  590. GetPos(id);
  591. GetUV();
  592. h = 0;
  593. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  594. {
  595. float4 col = leftSplatmap0.SampleLevel(_PointClamp, uv, 0);
  596. if (col.r == redChannel.y && redChannel.x == 1) h = 1;
  597. if (col.g == greenChannel.y && greenChannel.x == 1) h = 1;
  598. if (col.b == blueChannel.y && blueChannel.x == 1) h = 1;
  599. if (col.a == alphaChannel.y && alphaChannel.x == 1) h = 1;
  600. ApplyVertical();
  601. }
  602. resultBuffer[id] = h;
  603. SetPreviewTex();
  604. }
  605. #pragma kernel ImageColorRange
  606. [numthreads(512,1,1)]
  607. void ImageColorRange (uint id : SV_DispatchThreadID)
  608. {
  609. GetPos(id);
  610. GetUV();
  611. h = 0;
  612. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  613. {
  614. float4 col = leftSplatmap0.SampleLevel(_LinearClamp, uv, 0);
  615. if (col.r >= redChannel.y && col.r <= redChannel.z && redChannel.x == 1) h = col.r;
  616. if (col.g >= greenChannel.y && col.g <= greenChannel.z && greenChannel.x == 1) h = max(h, col.g);
  617. if (col.b >= blueChannel.y && col.b <= blueChannel.z && blueChannel.x == 1) h = max(h, col.b);
  618. if (col.a >= alphaChannel.y && col.a <= alphaChannel.z && alphaChannel.x == 1) h = max(h, col.a);
  619. ApplyVertical();
  620. }
  621. resultBuffer[id] = h;
  622. SetPreviewTex();
  623. }
  624. // =================================================================
  625. // Shapes
  626. #pragma kernel ShapeGradient
  627. [numthreads(512, 1, 1)]
  628. void ShapeGradient(uint id : SV_DispatchThreadID)
  629. {
  630. GetPos(id);
  631. GetUvShape();
  632. h = 0;
  633. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  634. {
  635. h = pos.x / shapeSize;
  636. ApplyVertical();
  637. }
  638. resultBuffer[id] = h;
  639. SetPreviewTex();
  640. }
  641. #pragma kernel ShapeCircle
  642. [numthreads(512, 1, 1)]
  643. void ShapeCircle(uint id : SV_DispatchThreadID)
  644. {
  645. GetPos(id);
  646. GetUvShape();
  647. h = 0;
  648. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  649. {
  650. float2 p = float2(pos.x, pos.z);
  651. p = lerp((frac((p / terrainSize) + 0.5) - 0.5) * terrainSize, p, isClamp);
  652. h = saturate(1 - (length(p) / shapeSize));
  653. ApplyVertical();
  654. }
  655. resultBuffer[id] = h;
  656. SetPreviewTex();
  657. }
  658. #pragma kernel ShapeSquare
  659. [numthreads(512, 1, 1)]
  660. void ShapeSquare(uint id : SV_DispatchThreadID)
  661. {
  662. GetPos(id);
  663. GetUvShape();
  664. h = 0;
  665. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  666. {
  667. float2 p = float2(pos.x, pos.z);
  668. p = lerp((frac((p / terrainSize) + 0.5) - 0.5) * terrainSize, p, isClamp);
  669. float2 p2 = p;
  670. p2 = ((bottomResolution * 0.5) - abs(p2));
  671. p2 = p2 / ((bottomResolution - topResolution) * 0.5);
  672. if (abs(p.x / bottomResolution.x) > abs(p.y / bottomResolution.y)) h = p2.x; else h = p2.y;
  673. ApplyVertical();
  674. }
  675. resultBuffer[id] = h;
  676. SetPreviewTex();
  677. }
  678. #pragma kernel ShapeConstant
  679. [numthreads(512, 1, 1)]
  680. void ShapeConstant(uint id : SV_DispatchThreadID)
  681. {
  682. GetPos(id);
  683. GetUvShape();
  684. h = 0;
  685. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  686. {
  687. // h = 1;
  688. ApplyVertical();
  689. }
  690. resultBuffer[id] = h;
  691. SetPreviewTex();
  692. }
  693. #pragma kernel CurrentExpand
  694. [numthreads(512, 1, 1)]
  695. void CurrentExpand(uint id : SV_DispatchThreadID)
  696. {
  697. GetPos(id);
  698. GetUV();
  699. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  700. {
  701. h = rightBuffer[id];
  702. float hOld = h;
  703. h = max(h, rightBuffer[id + 1]);
  704. h = max(h, rightBuffer[id - 1]);
  705. h = max(h, rightBuffer[id + resolutionX]);
  706. h = max(h, rightBuffer[id - resolutionX]);
  707. h = lerp(hOld, h, saturate(scale.y));
  708. h = max(h, rightBuffer[(id + 1) - resolutionX] / 2);
  709. h = max(h, rightBuffer[(id - 1) - resolutionX] / 2);
  710. h = max(h, rightBuffer[(id + 1) + resolutionX] / 2);
  711. h = max(h, rightBuffer[(id - 1) + resolutionX] / 2);
  712. // ApplyVertical();
  713. }
  714. else h = rightBuffer[id];
  715. resultBuffer[id] = h;
  716. SetPreviewTexBoth();
  717. }
  718. #pragma kernel CurrentShrink
  719. [numthreads(512, 1, 1)]
  720. void CurrentShrink(uint id : SV_DispatchThreadID)
  721. {
  722. GetPos(id);
  723. GetUV();
  724. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  725. {
  726. h = rightBuffer[id];
  727. float hOld = h;
  728. h = min(h, rightBuffer[id + 1]);
  729. h = min(h, rightBuffer[id - 1]);
  730. h = min(h, rightBuffer[id + resolutionX]);
  731. h = min(h, rightBuffer[id - resolutionX]);
  732. h = lerp(hOld, h, saturate(scale.y));
  733. // h = min(h, rightBuffer[(id + 1) - resolutionX]);
  734. // h = min(h, rightBuffer[(id - 1) - resolutionX]);
  735. // h = min(h, rightBuffer[(id + 1) + resolutionX]);
  736. // h = min(h, rightBuffer[(id - 1) + resolutionX]);
  737. // ApplyVertical();
  738. }
  739. else h = rightBuffer[id];
  740. resultBuffer[id] = h;
  741. SetPreviewTexBoth();
  742. }
  743. #pragma kernel CurrentEdgeDetect
  744. [numthreads(512, 1, 1)]
  745. void CurrentEdgeDetect(uint id : SV_DispatchThreadID)
  746. {
  747. GetPos(id);
  748. GetUV();
  749. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  750. {
  751. h = rightBuffer[id];
  752. if (h < range.x || h > range.y) h = 0;
  753. else
  754. {
  755. h = max(h, rightBuffer[id + 1]);
  756. h = max(h, rightBuffer[id - 1]);
  757. h = max(h, rightBuffer[id + resolutionX]);
  758. h = max(h, rightBuffer[id - resolutionX]);
  759. h = max(h, rightBuffer[(id + 1) - resolutionX]);
  760. h = max(h, rightBuffer[(id - 1) - resolutionX]);
  761. h = max(h, rightBuffer[(id + 1) + resolutionX]);
  762. h = max(h, rightBuffer[(id - 1) + resolutionX]);
  763. }
  764. if (h > 0) h = 1;
  765. // ApplyVertical();
  766. }
  767. else h = rightBuffer[id];
  768. resultBuffer[id] = h;
  769. SetPreviewTexBoth();
  770. }
  771. #pragma kernel CurrentDistortion
  772. [numthreads(512, 1, 1)]
  773. void CurrentDistortion(uint id : SV_DispatchThreadID)
  774. {
  775. GetPos(id);
  776. GetUV();
  777. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  778. {
  779. pos.y += _Seed;
  780. float x = fBm(float3(pos.x, pos.y, 0), 6);
  781. x = x * shapeSize * 1;
  782. pos.y += 10;
  783. float y = fBm(float3(0, pos.y, pos.z), 6);
  784. y = y * shapeSize * 1;
  785. // y = 0;
  786. uint p1 = id + floor(x) + (floor(y) * resolutionX);
  787. uint p2 = p1 + 1;
  788. float h1 = rightBuffer[p1];
  789. float h2 = rightBuffer[p2];
  790. h1 = lerp(h1, h2, frac(x));
  791. p1 += resolutionX;
  792. p2 += resolutionX;
  793. float h3 = rightBuffer[p1];
  794. float h4 = rightBuffer[p2];
  795. h3 = lerp(h3, h4, frac(x));
  796. h3 = lerp(h1, h3, frac(y));
  797. h = h3;
  798. // ApplyVertical();
  799. }
  800. else h = rightBuffer[id];
  801. resultBuffer[id] = h;
  802. SetPreviewTexBoth();
  803. }
  804. // =============================================================================================
  805. // Portal
  806. RWTexture2D<float> rtOutput;
  807. StructuredBuffer<float> inputBuffer;
  808. #pragma kernel CopyComputeBufferToRenderTexture
  809. [numthreads(8, 8, 1)]
  810. void CopyComputeBufferToRenderTexture(uint2 id : SV_DispatchThreadID)
  811. {
  812. uint index = (id.y * resolutionX) + id.x;
  813. rtOutput[id] = inputBuffer[index];
  814. }
  815. #pragma kernel CopyComputeMaskBufferToRenderTexture
  816. [numthreads(8, 8, 1)]
  817. void CopyComputeMaskBufferToRenderTexture(uint2 id : SV_DispatchThreadID)
  818. {
  819. uint index = (id.y * resolutionX) + id.x;
  820. rtOutput[id] = inputBuffer[index] * maskBuffer[index];
  821. }
  822. int portalResolution;
  823. #pragma kernel Portal
  824. [numthreads(512,1,1)]
  825. void Portal (uint id : SV_DispatchThreadID)
  826. {
  827. GetPos(id);
  828. uv.y = floor(id / resolutionX);
  829. uv.x = floor(id - (uv.y * resolutionX));
  830. uv /= resolutionX;
  831. uv *= (portalResolution - (resExpandBorder * 2));
  832. uv += resExpandBorder;
  833. uv /= (portalResolution - 1);
  834. h = tex1.SampleLevel(_PointClamp, uv, 0).r * overlay;
  835. ApplySplatVertical();
  836. resultBuffer[id] = h;
  837. SetPreviewTex();
  838. }
  839. #pragma kernel CopyRenderTexture
  840. [numthreads(8,8,1)]
  841. void CopyRenderTexture (uint2 id : SV_DispatchThreadID)
  842. {
  843. splatmap1[id] = rightSplatmap1[id];
  844. }
  845. // =============================================================================================
  846. // Splat
  847. float4 map0;
  848. float4 map1;
  849. float4 map2;
  850. float4 map3;
  851. float4 previewColor;
  852. float total;
  853. float GetSplatValue(float v, uint i)
  854. {
  855. if (v < splatMixBuffer[i].select.y) return lerp(0, 1, saturate((v - splatMixBuffer[i].select.x) * splatMixBuffer[i].select.z));
  856. else return lerp(1, 0, saturate((v - splatMixBuffer[i].select.y) * splatMixBuffer[i].select.z));
  857. }
  858. void GetSplatCustomValue4(float v, uint i)
  859. {
  860. uint j = 0;
  861. float s = GetSplatValue(v, i);
  862. float n;
  863. n = splatMixBuffer[i].map0[0] * s; map0[0] += n; total += n;
  864. n = splatMixBuffer[i].map0[1] * s; map0[1] += n; total += n;
  865. n = splatMixBuffer[i].map0[2] * s; map0[2] += n; total += n;
  866. n = splatMixBuffer[i].map0[3] * s; map0[3] += n; total += n;
  867. }
  868. void GetSplatCustomValue8(float v, uint i)
  869. {
  870. uint j = 0;
  871. float s = GetSplatValue(v, i);
  872. float n;
  873. n = splatMixBuffer[i].map0[0] * s; map0[0] += n; total += n;
  874. n = splatMixBuffer[i].map0[1] * s; map0[1] += n; total += n;
  875. n = splatMixBuffer[i].map0[2] * s; map0[2] += n; total += n;
  876. n = splatMixBuffer[i].map0[3] * s; map0[3] += n; total += n;
  877. n = splatMixBuffer[i].map1[0] * s; map1[0] += n; total += n;
  878. n = splatMixBuffer[i].map1[1] * s; map1[1] += n; total += n;
  879. n = splatMixBuffer[i].map1[2] * s; map1[2] += n; total += n;
  880. n = splatMixBuffer[i].map1[3] * s; map1[3] += n; total += n;
  881. }
  882. void GetSplatCustomValue12(float v, uint i)
  883. {
  884. uint j = 0;
  885. float s = GetSplatValue(v, i);
  886. float n;
  887. n = splatMixBuffer[i].map0[0] * s; map0[0] += n; total += n;
  888. n = splatMixBuffer[i].map0[1] * s; map0[1] += n; total += n;
  889. n = splatMixBuffer[i].map0[2] * s; map0[2] += n; total += n;
  890. n = splatMixBuffer[i].map0[3] * s; map0[3] += n; total += n;
  891. n = splatMixBuffer[i].map1[0] * s; map1[0] += n; total += n;
  892. n = splatMixBuffer[i].map1[1] * s; map1[1] += n; total += n;
  893. n = splatMixBuffer[i].map1[2] * s; map1[2] += n; total += n;
  894. n = splatMixBuffer[i].map1[3] * s; map1[3] += n; total += n;
  895. n = splatMixBuffer[i].map2[0] * s; map2[0] += n; total += n;
  896. n = splatMixBuffer[i].map2[1] * s; map2[1] += n; total += n;
  897. n = splatMixBuffer[i].map2[2] * s; map2[2] += n; total += n;
  898. n = splatMixBuffer[i].map2[3] * s; map2[3] += n; total += n;
  899. }
  900. void GetSplatCustomValue16(float v, uint i)
  901. {
  902. uint j = 0;
  903. float s = GetSplatValue(v, i);
  904. float n;
  905. n = splatMixBuffer[i].map0[0] * s; map0[0] += n; total += n;
  906. n = splatMixBuffer[i].map0[1] * s; map0[1] += n; total += n;
  907. n = splatMixBuffer[i].map0[2] * s; map0[2] += n; total += n;
  908. n = splatMixBuffer[i].map0[3] * s; map0[3] += n; total += n;
  909. n = splatMixBuffer[i].map1[0] * s; map1[0] += n; total += n;
  910. n = splatMixBuffer[i].map1[1] * s; map1[1] += n; total += n;
  911. n = splatMixBuffer[i].map1[2] * s; map1[2] += n; total += n;
  912. n = splatMixBuffer[i].map1[3] * s; map1[3] += n; total += n;
  913. n = splatMixBuffer[i].map2[0] * s; map2[0] += n; total += n;
  914. n = splatMixBuffer[i].map2[1] * s; map2[1] += n; total += n;
  915. n = splatMixBuffer[i].map2[2] * s; map2[2] += n; total += n;
  916. n = splatMixBuffer[i].map2[3] * s; map2[3] += n; total += n;
  917. n = splatMixBuffer[i].map3[0] * s; map3[0] += n; total += n;
  918. n = splatMixBuffer[i].map3[1] * s; map3[1] += n; total += n;
  919. n = splatMixBuffer[i].map3[2] * s; map3[2] += n; total += n;
  920. n = splatMixBuffer[i].map3[3] * s; map3[3] += n; total += n;
  921. }
  922. #pragma kernel CalcSplat4
  923. [numthreads(512,1,1)]
  924. void CalcSplat4 (uint id : SV_DispatchThreadID)
  925. {
  926. GetPos2(id);
  927. float s = 0;
  928. map0 = float4(0, 0, 0, 0);
  929. int i = 0;
  930. total = 0;
  931. h = saturate(resultBuffer[id]);
  932. for (uint j = 0; j < itemCount; j++)
  933. {
  934. i = splatMixBuffer[j].select.w;
  935. s = GetSplatValue(h, j);
  936. if (i >= 0)
  937. {
  938. if (i < 2)
  939. {
  940. if (i == 0) { map0.x += s; total += s; }
  941. else { map0.y += s; total += s; }
  942. }
  943. else if (i == 2) { map0.z += s; total += s; }
  944. else { map0.w += s; total += s; }
  945. }
  946. else
  947. {
  948. GetSplatCustomValue4(h, j);
  949. }
  950. }
  951. map0 /= total;
  952. splatmap0[pos2] = map0;
  953. splatPreviewTex[texID] = (map0.x * itemColorBuffer[0]) + (map0.y * itemColorBuffer[1]) + (map0.z * itemColorBuffer[2]) + (map0.w * itemColorBuffer[3]);
  954. }
  955. #pragma kernel CalcSplat8
  956. [numthreads(512,1,1)]
  957. void CalcSplat8 (uint id : SV_DispatchThreadID)
  958. {
  959. GetPos2(id);
  960. float s = 0;
  961. map0 = float4(0, 0, 0, 0);
  962. map1 = float4(0, 0, 0, 0);
  963. int i = 0;
  964. total = 0;
  965. // total1 = 0;
  966. // float4 map2 = float4(0,0,0,0);
  967. // float4 map3 = float4(0,0,0,0);
  968. h = saturate(resultBuffer[id]);
  969. for (uint j = 0; j < itemCount; j++)
  970. {
  971. i = splatMixBuffer[j].select.w;
  972. s = GetSplatValue(h, j);
  973. if (i >= 0)
  974. {
  975. if (i < 4)
  976. {
  977. if (i < 2)
  978. {
  979. if (i == 0) { map0.x += s; total += s; }
  980. else { map0.y += s; total += s; }
  981. }
  982. else if (i == 2) { map0.z += s; total += s; }
  983. else { map0.w += s; total += s; }
  984. }
  985. else
  986. {
  987. if (i < 6)
  988. {
  989. if (i == 4) { map1.x += s; total += s; }
  990. else { map1.y += s; total += s; }
  991. }
  992. else if (i == 6) { map1.z += s; total += s; }
  993. else { map1.w += s; total += s; }
  994. }
  995. }
  996. else
  997. {
  998. GetSplatCustomValue8(h, j);
  999. }
  1000. }
  1001. map0 /= total;
  1002. map1 /= total;
  1003. splatmap0[pos2] = map0;
  1004. splatmap1[pos2] = map1;
  1005. splatPreviewTex[texID] = (map0.x * itemColorBuffer[0]) + (map0.y * itemColorBuffer[1]) + (map0.z * itemColorBuffer[2]) + (map0.w * itemColorBuffer[3]) + (map1.x * itemColorBuffer[4]) + (map1.y * itemColorBuffer[5]) + (map1.z * itemColorBuffer[6]) + (map1.w * itemColorBuffer[7]);
  1006. // previewTex[texID] = float4(splatmap0.x, splatmap0.y, splatmap0.z, 1);
  1007. }
  1008. #pragma kernel CalcSplat12
  1009. [numthreads(512,1,1)]
  1010. void CalcSplat12 (uint id : SV_DispatchThreadID)
  1011. {
  1012. GetPos2(id);
  1013. float s = 0;
  1014. map0 = float4(0, 0, 0, 0);
  1015. map1 = float4(0, 0, 0, 0);
  1016. map2 = float4(0, 0, 0, 0);
  1017. int i = 0;
  1018. total = 0;
  1019. h = saturate(resultBuffer[id]);
  1020. for (uint j = 0; j < itemCount; j++)
  1021. {
  1022. i = splatMixBuffer[j].select.w;
  1023. s = GetSplatValue(h, j);
  1024. if (i >= 0)
  1025. {
  1026. if (i < 4)
  1027. {
  1028. if (i < 2)
  1029. {
  1030. if (i == 0) { map0.x += s; total += s; }
  1031. else { s = map0.y += s; total += s; }
  1032. }
  1033. else if (i == 2) { s = map0.z += s; total += s; }
  1034. else { s = map0.w += s; total += s; }
  1035. }
  1036. else if (i < 8)
  1037. {
  1038. if (i < 6)
  1039. {
  1040. if (i == 4) { s = map1.x += s; total += s; }
  1041. else { s = map1.y += s; total += s; }
  1042. }
  1043. else if (i == 6) { s = map1.z += s; total += s; }
  1044. else { s = map1.w += s; total += s; }
  1045. }
  1046. else if (i < 12)
  1047. {
  1048. if (i < 10)
  1049. {
  1050. if (i == 8) { s = map2.x += s; total += s; }
  1051. else { s = map2.y += s; total += s; }
  1052. }
  1053. else if (i == 10) { s = map2.z += s; total += s; }
  1054. else { s = map2.w += s; total += s; }
  1055. }
  1056. }
  1057. else
  1058. {
  1059. GetSplatCustomValue12(h, j);
  1060. }
  1061. }
  1062. map0 /= total;
  1063. map1 /= total;
  1064. map2 /= total;
  1065. splatmap0[pos2] = map0;
  1066. splatmap1[pos2] = map1;
  1067. splatmap2[pos2] = map2;
  1068. splatPreviewTex[texID] = (map0.x * itemColorBuffer[0]) + (map0.y * itemColorBuffer[1]) + (map0.z * itemColorBuffer[2]) + (map0.w * itemColorBuffer[3]) +
  1069. (map1.x * itemColorBuffer[4]) + (map1.y * itemColorBuffer[5]) + (map1.z * itemColorBuffer[6]) + (map1.w * itemColorBuffer[7]) +
  1070. (map2.x * itemColorBuffer[8]) + (map2.y * itemColorBuffer[9]) + (map2.z * itemColorBuffer[10]) + (map2.w * itemColorBuffer[11]);
  1071. // previewTex[texID] = float4(splatmap0.x, splatmap0.y, splatmap0.z, 1);
  1072. }
  1073. #pragma kernel CalcSplat16
  1074. [numthreads(512,1,1)]
  1075. void CalcSplat16 (uint id : SV_DispatchThreadID)
  1076. {
  1077. GetPos2(id);
  1078. float s = 0;
  1079. map0 = float4(0, 0, 0, 0);
  1080. map1 = float4(0, 0, 0, 0);
  1081. map2 = float4(0, 0, 0, 0);
  1082. map3 = float4(0, 0, 0, 0);
  1083. int i = 0;
  1084. total = 0;
  1085. h = saturate(resultBuffer[id]);
  1086. for (uint j = 0; j < itemCount; j++)
  1087. {
  1088. i = splatMixBuffer[j].select.w;
  1089. if (i >= 0)
  1090. {
  1091. if (i < 8)
  1092. {
  1093. if (i < 4)
  1094. {
  1095. if (i < 2)
  1096. {
  1097. if (i == 0) { s = GetSplatValue(h, j); map0.x += s; total += s; }
  1098. else { s = GetSplatValue(h, j); map0.y += s; total += s; }
  1099. }
  1100. else if (i == 2) { s = GetSplatValue(h, j); map0.z += s; total += s; }
  1101. else { s = GetSplatValue(h, j); map0.w += s; total += s; }
  1102. }
  1103. else if (i < 6)
  1104. {
  1105. if (i == 4) { s = GetSplatValue(h, j); map1.x += s; total += s; }
  1106. else { s = GetSplatValue(h, j); map1.y += s; total += s; }
  1107. }
  1108. else if (i == 6) { s = GetSplatValue(h, j); map1.z += s; total += s; }
  1109. else { s = GetSplatValue(h, j); map1.w += s; total += s; }
  1110. }
  1111. else
  1112. {
  1113. if (i < 12)
  1114. {
  1115. if (i < 10)
  1116. {
  1117. if (i == 8) { s = GetSplatValue(h, j); map2.x += s; total += s; }
  1118. else { s = GetSplatValue(h, j); map2.y += s; total += s; }
  1119. }
  1120. else if (i == 10) { s = GetSplatValue(h, j); map2.z += s; total += s; }
  1121. else { s = GetSplatValue(h, j); map2.w += s; total += s; }
  1122. }
  1123. else if (i < 14)
  1124. {
  1125. if (i == 12) { s = GetSplatValue(h, j); map3.x += s; total += s; }
  1126. else { s = GetSplatValue(h, j); map3.y += s; total += s; }
  1127. }
  1128. else if (i == 14) { s = GetSplatValue(h, j); map3.z += s; total += s; }
  1129. else { s = GetSplatValue(h, j); map3.w += s; total += s; }
  1130. }
  1131. }
  1132. else
  1133. {
  1134. GetSplatCustomValue16(h, j);
  1135. }
  1136. }
  1137. map0 /= total;
  1138. map1 /= total;
  1139. map2 /= total;
  1140. map3 /= total;
  1141. splatmap0[pos2] = map0;
  1142. splatmap1[pos2] = map1;
  1143. splatmap2[pos2] = map2;
  1144. splatmap3[pos2] = map3;
  1145. splatPreviewTex[texID] = (map0.x * itemColorBuffer[0]) + (map0.y * itemColorBuffer[1]) + (map0.z * itemColorBuffer[2]) + (map0.w * itemColorBuffer[3]) +
  1146. (map1.x * itemColorBuffer[4]) + (map1.y * itemColorBuffer[5]) + (map1.z * itemColorBuffer[6]) + (map1.w * itemColorBuffer[7]) +
  1147. (map2.x * itemColorBuffer[8]) + (map2.y * itemColorBuffer[9]) + (map2.z * itemColorBuffer[10]) + (map2.w * itemColorBuffer[11]) +
  1148. (map3.x * itemColorBuffer[12]) + (map3.y * itemColorBuffer[13]) + (map3.z * itemColorBuffer[14]) + (map3.w * itemColorBuffer[15]);
  1149. // previewTex[texID] = float4(splatmap0.x, splatmap0.y, splatmap0.z, 1);
  1150. }
  1151. float GetColorValue(float v, uint i)
  1152. {
  1153. float3 select = colorMixBuffer[i].select;
  1154. if (v < select.y) return lerp(0, 1, saturate((v - select.x) * select.z));
  1155. else return lerp(1, 0, saturate((v - select.y) * select.z));
  1156. }
  1157. #pragma kernel CalcColor
  1158. [numthreads(512,1,1)]
  1159. void CalcColor (uint id : SV_DispatchThreadID)
  1160. {
  1161. GetPos2(id);
  1162. float s = 0;
  1163. total = 0;
  1164. float4 color;
  1165. h = saturate(resultBuffer[id]);
  1166. for (uint i = 0; i < itemCount; i++)
  1167. {
  1168. s = GetColorValue(h, i);
  1169. color += colorMixBuffer[i].color * s;
  1170. total += s;
  1171. }
  1172. color /= total;
  1173. splatmap0[pos2] = color;
  1174. // Do tex id
  1175. splatPreviewTex[texID] = color;
  1176. }
  1177. #pragma kernel CalcColorTex
  1178. [numthreads(512,1,1)]
  1179. void CalcColorTex (uint id : SV_DispatchThreadID)
  1180. {
  1181. GetPos3(id);
  1182. GetUV();
  1183. h = saturate(resultBuffer[id]);
  1184. float4 color = float4(0,0,0,1);
  1185. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  1186. {
  1187. color = leftSplatmap0.SampleLevel(_LinearClamp, uv, 0) * overlay * colLayer;
  1188. float greyColor = color.r * 0.3 + color.g * 0.59 + color.b * 0.11;
  1189. color = lerp(float4(greyColor, greyColor, greyColor, 1), color, mixValue); // Saturation
  1190. }
  1191. previewTex[texID] = color;
  1192. color.a *= h;
  1193. splatmap0[pos2] = color;
  1194. // Do tex id
  1195. splatPreviewTex[texID] = color;
  1196. }
  1197. #pragma kernel NormalizeSplat4
  1198. [numthreads(8,8,1)]
  1199. void NormalizeSplat4(uint2 id : SV_DispatchThreadID)
  1200. {
  1201. // uint pos1d = (id.y * resolutionX) + id.x;
  1202. GetTexID(id);
  1203. float4 s0 = leftSplatmap0[id];
  1204. float4 previewColor = leftPreviewTex[texID];
  1205. float total = s0.x + s0.y + s0.z + s0.w;
  1206. s0 /= total;
  1207. previewColor /= total;
  1208. splatmap0[id] = s0;
  1209. splatPreviewTex[texID] = previewColor;
  1210. }
  1211. #pragma kernel NormalizeSplat8
  1212. [numthreads(8,8,1)]
  1213. void NormalizeSplat8 (uint2 id : SV_DispatchThreadID)
  1214. {
  1215. // uint pos1d = (id.y * resolutionX) + id.x;
  1216. GetTexID(id);
  1217. float4 s0 = leftSplatmap0[id];
  1218. float4 s1 = leftSplatmap1[id];
  1219. float4 previewColor = leftPreviewTex[texID];
  1220. float total = s0.x + s0.y + s0.z + s0.w + s1.x + s1.y + s1.z + s1.w;
  1221. s0 /= total;
  1222. s1 /= total;
  1223. previewColor /= total;
  1224. splatmap0[id] = s0;
  1225. splatmap1[id] = s1;
  1226. splatPreviewTex[texID] = previewColor;
  1227. }
  1228. #pragma kernel NormalizeSplat12
  1229. [numthreads(8,8,1)]
  1230. void NormalizeSplat12 (uint2 id : SV_DispatchThreadID)
  1231. {
  1232. // uint pos1d = (id.y * resolutionX) + id.x;
  1233. GetTexID(id);
  1234. float4 s0 = leftSplatmap0[id];
  1235. float4 s1 = leftSplatmap1[id];
  1236. float4 s2 = leftSplatmap2[id];
  1237. float4 previewColor = leftPreviewTex[texID];
  1238. float total = s0.x + s0.y + s0.z + s0.w + s1.x + s1.y + s1.z + s1.w + s2.x + s2.y + s2.z + s2.w;
  1239. s0 /= total;
  1240. s1 /= total;
  1241. s2 /= total;
  1242. previewColor /= total;
  1243. splatmap0[id] = s0;
  1244. splatmap1[id] = s1;
  1245. splatmap2[id] = s2;
  1246. splatPreviewTex[texID] = previewColor;
  1247. }
  1248. #pragma kernel NormalizeSplat16
  1249. [numthreads(8,8,1)]
  1250. void NormalizeSplat16 (uint2 id : SV_DispatchThreadID)
  1251. {
  1252. // uint pos1d = (id.y * resolutionX) + id.x;
  1253. GetTexID(id);
  1254. float4 s0 = leftSplatmap0[id];
  1255. float4 s1 = leftSplatmap1[id];
  1256. float4 s2 = leftSplatmap2[id];
  1257. float4 s3 = leftSplatmap3[id];
  1258. float4 previewColor = leftPreviewTex[texID];
  1259. float total = s0.x + s0.y + s0.z + s0.w + s1.x + s1.y + s1.z + s1.w + s2.x + s2.y + s2.z + s2.w + s3.x + s3.y + s3.z + s3.w;
  1260. s0 /= total;
  1261. s1 /= total;
  1262. s2 /= total;
  1263. s3 /= total;
  1264. previewColor /= total;
  1265. splatmap0[id] = s0;
  1266. splatmap1[id] = s1;
  1267. splatmap2[id] = s2;
  1268. splatmap3[id] = s3;
  1269. splatPreviewTex[texID] = previewColor;
  1270. }
  1271. #pragma kernel CalcObject
  1272. [numthreads(512,1,1)]
  1273. void CalcObject (uint id : SV_DispatchThreadID)
  1274. {
  1275. GetWorldPosUV2(id);
  1276. float v = resultBuffer[id];
  1277. uint index = 0;
  1278. float density = 0;
  1279. float random = Random(pos2);
  1280. bool found = false;
  1281. for (uint i = 0; i < itemCount; i++)
  1282. {
  1283. if (v <= (itemIndexBuffer[i].range.y + ((random - 0.5) * mixValue))) { found = true; break;}
  1284. index++;
  1285. }
  1286. if (!found) index--;
  1287. density = itemIndexBuffer[index].opacity;
  1288. float place = step(random + 0.00001, density);
  1289. itemMapBuffer[id].index = itemIndexBuffer[index].index;
  1290. itemMapBuffer[id].density = density * place;
  1291. itemMapBuffer[id].maskValue = 1;
  1292. splatPreviewTex[texID] = itemColorBuffer[index] * place;
  1293. previewTex[texID] = colLayer * saturate(density + 0.5) * place;
  1294. float random2 = Random(pos2 + float2(997.5, 0));
  1295. float2 uvPos = (saturate(float2(random, random2)) / resolutionX) * itemIndexBuffer[index].randomPosition;
  1296. uvPos += 0.5 / resolutionX;
  1297. float2 uv2 = (uv + uvPos) * (terrainTexReadNormalResolution - 1);
  1298. uv2 += resExpandBorder;
  1299. uv2 /= (terrainTexReadResolution - 1);
  1300. float2 h0 = terrainTexRead.SampleLevel(_LinearClamp, uv2, 0).rg * 255.0;
  1301. h0.x *= 256.0;
  1302. h = (h0.x + h0.y) / 65535.0;
  1303. itemMapBuffer[id].pos = float3(uvPos.x, h, uvPos.y);
  1304. }
  1305. #pragma kernel CalcObjectPosition
  1306. [numthreads(512,1,1)]
  1307. void CalcObjectPosition (uint id : SV_DispatchThreadID)
  1308. {
  1309. GetWorldPosUV2(id);
  1310. float random = Random(pos2);
  1311. float density = itemMapBuffer[id].maskValue * itemMapBuffer[id].density;
  1312. itemMapBuffer[id].density = density;
  1313. if (density > 0)
  1314. {
  1315. int index = itemMapBuffer[id].index;
  1316. float random2 = Random(pos2 + float2(997.5, 0));
  1317. float randomPositionValue = resultBuffer[index];
  1318. float halfPixel = 0.5 / resolutionX;
  1319. // uv += halfPixel;
  1320. // uv -= snapOffset;
  1321. float2 uvPos = ((saturate(float2(random, random2)) - 0.5) / (resolutionX)) * randomPositionValue;
  1322. float2 uv2 = (uv + uvPos) * (terrainTexReadNormalResolution - 1);
  1323. uv2 += resExpandBorder;
  1324. uv2 /= (terrainTexReadResolution - 1);
  1325. float2 h0 = terrainTexRead.SampleLevel(_LinearClamp, uv2, 0).rg * 255.0;
  1326. h0.x *= 256.0;
  1327. h = (h0.x + h0.y) / 65535.0;
  1328. itemMapBuffer[id].pos = float3(uvPos.x, h, uvPos.y);
  1329. }
  1330. }
  1331. // =============================================================================================
  1332. // Item Tex Methods
  1333. #pragma kernel MethodItemTexMask
  1334. [numthreads(512,1,1)]
  1335. void MethodItemTexMask (uint id : SV_DispatchThreadID)
  1336. {
  1337. GetPos2(id);
  1338. float random = Random(pos2) + 0.00001;
  1339. uint id2 = (itemMapBuffer[id].pos.x * resolutionX) + (itemMapBuffer[id].pos.z * resolutionY * resolutionX);
  1340. float maskValue = maskBuffer[id];
  1341. h = itemMapBuffer[id].maskValue * maskValue;
  1342. float place = step(random, h * itemMapBuffer[id].density);
  1343. itemMapBuffer[id].maskValue = h * place;
  1344. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1345. // h = lerp(h, saturate(h), mask);
  1346. splatPreviewTex[texID] = colLayer * saturate(h + 0.5) * place;
  1347. }
  1348. #pragma kernel MethodItemTex0Mask
  1349. [numthreads(512,1,1)]
  1350. void MethodItemTex0Mask (uint id : SV_DispatchThreadID)
  1351. {
  1352. GetPos2(id);
  1353. float random = Random(pos2) + 0.00001;
  1354. uint id2 = (itemMapBuffer[id].pos.x * resolutionX) + (itemMapBuffer[id].pos.z * resolutionY * resolutionX);
  1355. float maskValue = maskBuffer[id];
  1356. h = itemMapBuffer[id].maskValue * maskValue;
  1357. float place = step(random, h * itemMapBuffer[id].density);
  1358. itemMapBuffer[id].maskValue = h * place;
  1359. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1360. // h = lerp(h, saturate(h), mask);
  1361. // resultBuffer[id] = h;
  1362. splatPreviewTex[texID] = leftPreviewTex[texID] * saturate(maskValue + 0.5) * place;
  1363. }
  1364. #pragma kernel MethodItemTexLerp
  1365. [numthreads(512,1,1)]
  1366. void MethodItemTexLerp (uint id : SV_DispatchThreadID)
  1367. {
  1368. GetPos2(id);
  1369. float v = 0;
  1370. if (overlay < 1 && overlay != 0) v = Random(pos2) + 0.00001;
  1371. float maskValue;
  1372. if (v <= overlay && overlay != 0)
  1373. {
  1374. float density = rightItemMapBuffer[id].density;
  1375. maskValue = rightItemMapBuffer[id].maskValue;
  1376. itemMapBuffer[id].index = rightItemMapBuffer[id].index;
  1377. itemMapBuffer[id].pos = rightItemMapBuffer[id].pos;
  1378. itemMapBuffer[id].density = density;
  1379. itemMapBuffer[id].maskValue = maskValue;
  1380. previewColor = rightPreviewTex[texID];
  1381. splatmap0[texID] = colLayer2 * saturate(maskValue + 0.5f) * (1 - step(density, 0));
  1382. }
  1383. else
  1384. {
  1385. previewColor = leftPreviewTex[texID];
  1386. maskValue = itemMapBuffer[id].maskValue;
  1387. splatmap0[texID] = colLayer2 * saturate(maskValue + 0.5f) * (1 - step(itemMapBuffer[id].density * maskValue, 0));
  1388. }
  1389. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1390. splatPreviewTex[texID] = previewColor;
  1391. splatPreviewTexClone[texID] = previewColor;
  1392. }
  1393. #pragma kernel MethodItemTexLerpMask
  1394. [numthreads(512,1,1)]
  1395. void MethodItemTexLerpMask (uint id : SV_DispatchThreadID)
  1396. {
  1397. GetPos2(id);
  1398. float maskValue = maskBuffer[id];
  1399. overlay *= maskValue;
  1400. float v = 0;
  1401. if (overlay < 1 && overlay != 0) v = Random(pos2);
  1402. if (v <= overlay && overlay != 0)
  1403. {
  1404. float rightMaskValue = rightItemMapBuffer[id].maskValue * maskValue;
  1405. float density = rightItemMapBuffer[id].density;
  1406. itemMapBuffer[id].index = rightItemMapBuffer[id].index;
  1407. itemMapBuffer[id].pos = rightItemMapBuffer[id].pos;
  1408. itemMapBuffer[id].density = density;
  1409. itemMapBuffer[id].maskValue = rightMaskValue;
  1410. previewColor = colLayer * colLayer * saturate(maskValue + 0.5) * itemMapBuffer[id].maskValue;
  1411. previewTex2[texID] = previewColor;
  1412. splatmap0[texID] = colLayer2 * saturate(rightMaskValue + 0.5f) * (1 - step(density, 0));
  1413. }
  1414. else
  1415. {
  1416. previewColor = leftPreviewTex[texID];
  1417. previewTex2[texID] = float4(0, 0, 0, 0);
  1418. float leftMaskValue = itemMapBuffer[id].maskValue;
  1419. splatmap0[texID] = colLayer2 * saturate(leftMaskValue + 0.5f) * (1 - step(itemMapBuffer[id].density * leftMaskValue, 0));
  1420. }
  1421. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1422. splatPreviewTex[texID] = previewColor;
  1423. splatPreviewTexClone[texID] = previewColor;
  1424. }
  1425. #pragma kernel MethodItemTexMax
  1426. [numthreads(512,1,1)]
  1427. void MethodItemTexMax (uint id : SV_DispatchThreadID)
  1428. {
  1429. GetPos2(id);
  1430. float maskValue = itemMapBuffer[id].maskValue;
  1431. float rightMaskValue = rightItemMapBuffer[id].maskValue;
  1432. if (maskValue < rightMaskValue)
  1433. {
  1434. float density = rightItemMapBuffer[id].density;
  1435. itemMapBuffer[id].index = rightItemMapBuffer[id].index;
  1436. itemMapBuffer[id].pos = rightItemMapBuffer[id].pos;
  1437. itemMapBuffer[id].density = density;
  1438. itemMapBuffer[id].maskValue = rightMaskValue;
  1439. previewColor = rightPreviewTex[texID];
  1440. splatmap0[texID] = colLayer2 * saturate(rightMaskValue + 0.5f) * (1 - step(density, 0));
  1441. }
  1442. else
  1443. {
  1444. previewColor = leftPreviewTex[texID];
  1445. splatmap0[texID] = colLayer2 * saturate(maskValue + 0.5f) * (1 - step(itemMapBuffer[id].density * maskValue, 0));
  1446. }
  1447. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1448. splatPreviewTex[texID] = previewColor;
  1449. splatPreviewTexClone[texID] = previewColor;
  1450. // splatPreviewTex[texID] = float4(0,1,0,1);
  1451. }
  1452. #pragma kernel MethodItemTexMin
  1453. [numthreads(512,1,1)]
  1454. void MethodItemTexMin (uint id : SV_DispatchThreadID)
  1455. {
  1456. GetPos2(id);
  1457. float maskValue = itemMapBuffer[id].maskValue;
  1458. float rightMaskValue = rightItemMapBuffer[id].maskValue;
  1459. if (maskValue < rightMaskValue && maskValue == 0)
  1460. {
  1461. float density = rightItemMapBuffer[id].density;
  1462. itemMapBuffer[id].index = rightItemMapBuffer[id].index;
  1463. itemMapBuffer[id].pos = rightItemMapBuffer[id].pos;
  1464. itemMapBuffer[id].density = density;
  1465. itemMapBuffer[id].maskValue = rightMaskValue;
  1466. previewColor = rightPreviewTex[texID];
  1467. splatmap0[texID] = colLayer2 * saturate(maskValue + 0.5f) * (1 - step(density, 0));
  1468. }
  1469. else
  1470. {
  1471. previewColor = leftPreviewTex[texID];
  1472. splatmap0[texID] = colLayer2 * saturate(maskValue + 0.5f) * (1 - step(itemMapBuffer[id].density * maskValue, 0));
  1473. }
  1474. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1475. splatPreviewTex[texID] = previewColor;
  1476. splatPreviewTexClone[texID] = previewColor;
  1477. }
  1478. // =============================================================================================
  1479. // Tex Methods
  1480. #pragma kernel MethodTexAdd
  1481. [numthreads(512,1,1)]
  1482. void MethodTexAdd (uint id : SV_DispatchThreadID)
  1483. {
  1484. GetPos(id);
  1485. h = resultBuffer[id] + rightBuffer[id];
  1486. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1487. // h = lerp(h, saturate(h), mask);
  1488. resultBuffer[id] = h;
  1489. SetPreviewTex();
  1490. }
  1491. #pragma kernel MethodTexSubtract
  1492. [numthreads(512,1,1)]
  1493. void MethodTexSubtract (uint id : SV_DispatchThreadID)
  1494. {
  1495. GetPos(id);
  1496. // h = lerp(resultBuffer[id], resultBuffer[id] - rightBuffer[id], saturate(1 - resultBuffer[id]));
  1497. h = resultBuffer[id] - rightBuffer[id];
  1498. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1499. // h = lerp(h, saturate(h), mask);
  1500. resultBuffer[id] = h;
  1501. SetPreviewTex();
  1502. }
  1503. #pragma kernel MethodTexLerp
  1504. [numthreads(512,1,1)]
  1505. void MethodTexLerp (uint id : SV_DispatchThreadID)
  1506. {
  1507. GetPos(id);
  1508. h = lerp(resultBuffer[id], rightBuffer[id], overlay);
  1509. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1510. // h = lerp(h, saturate(h), mask);
  1511. resultBuffer[id] = h;
  1512. SetPreviewTex();
  1513. }
  1514. #pragma kernel MethodTexLerpMask
  1515. [numthreads(512,1,1)]
  1516. void MethodTexLerpMask (uint id : SV_DispatchThreadID)
  1517. {
  1518. GetPos(id);
  1519. float maskValue = maskBuffer[id];
  1520. float rightBufferValue = rightBuffer[id];
  1521. h = lerp(resultBuffer[id], rightBufferValue, overlay * maskValue);
  1522. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1523. // h = lerp(h, saturate(h), mask);
  1524. resultBuffer[id] = h;
  1525. SetPreviewTex();
  1526. h = rightBufferValue * maskValue;
  1527. SetPreviewTex2();
  1528. }
  1529. #pragma kernel MethodTexMultiply
  1530. [numthreads(512,1,1)]
  1531. void MethodTexMultiply (uint id : SV_DispatchThreadID)
  1532. {
  1533. GetPos(id);
  1534. h = resultBuffer[id] * rightBuffer[id];
  1535. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1536. // h = lerp(h, saturate(h), mask);
  1537. resultBuffer[id] = h;
  1538. SetPreviewTex();
  1539. }
  1540. #pragma kernel MethodTexDivide
  1541. [numthreads(512,1,1)]
  1542. void MethodTexDivide (uint id : SV_DispatchThreadID)
  1543. {
  1544. GetPos(id);
  1545. h = resultBuffer[id] / rightBuffer[id];
  1546. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1547. // h = lerp(h, saturate(h), mask);
  1548. resultBuffer[id] = h;
  1549. SetPreviewTex();
  1550. }
  1551. #pragma kernel MethodTexDifference
  1552. [numthreads(512,1,1)]
  1553. void MethodTexDifference (uint id : SV_DispatchThreadID)
  1554. {
  1555. GetPos(id);
  1556. h = abs(resultBuffer[id] - rightBuffer[id]);
  1557. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1558. // h = lerp(h, saturate(h), mask);
  1559. resultBuffer[id] = h;
  1560. SetPreviewTex();
  1561. }
  1562. #pragma kernel MethodTexAverage
  1563. [numthreads(512,1,1)]
  1564. void MethodTexAverage (uint id : SV_DispatchThreadID)
  1565. {
  1566. GetPos(id);
  1567. h = resultBuffer[id] + (rightBuffer[id] / itemCount);
  1568. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1569. // h = lerp(h, saturate(h), mask);
  1570. resultBuffer[id] = h;
  1571. SetPreviewTex();
  1572. }
  1573. #pragma kernel MethodTexMax
  1574. [numthreads(512,1,1)]
  1575. void MethodTexMax (uint id : SV_DispatchThreadID)
  1576. {
  1577. GetPos(id);
  1578. h = max(resultBuffer[id], rightBuffer[id]);
  1579. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1580. // h = lerp(h, saturate(h), mask);
  1581. resultBuffer[id] = h;
  1582. SetPreviewTex();
  1583. }
  1584. #pragma kernel MethodTexMin
  1585. [numthreads(512,1,1)]
  1586. void MethodTexMin (uint id : SV_DispatchThreadID)
  1587. {
  1588. GetPos(id);
  1589. h = min(resultBuffer[id], rightBuffer[id]);
  1590. if (worldCurveKeysLength > 0) ApplyWorldCurve();
  1591. // h = lerp(h, saturate(h), mask);
  1592. resultBuffer[id] = h;
  1593. SetPreviewTex();
  1594. }
  1595. // =============================================================================================
  1596. // Multi Methods
  1597. void Normalize()
  1598. {
  1599. total = map0.x + map0.y + map0.z + map0.w + map1.x + map1.y + map1.z + map1.w + map2.x + map2.y + map2.z + map2.w + map3.x + map3.y + map3.z + map3.w;
  1600. map0 /= total;
  1601. map1 /= total;
  1602. map2 /= total;
  1603. map3 /= total;
  1604. }
  1605. void NormalizeTex()
  1606. {
  1607. total = map0.x + map0.y + map0.z + map0.w + map1.x + map1.y + map1.z + map1.w + map2.x + map2.y + map2.z + map2.w + map3.x + map3.y + map3.z + map3.w;
  1608. map0 /= total;
  1609. map1 /= total;
  1610. map2 /= total;
  1611. map3 /= total;
  1612. previewColor /= total;
  1613. }
  1614. #pragma kernel MultiMethodAdd
  1615. [numthreads(8,8,1)]
  1616. void MultiMethodAdd (uint2 id : SV_DispatchThreadID)
  1617. {
  1618. map0 = leftSplatmap0[id] + rightSplatmap0[id];
  1619. map1 = leftSplatmap1[id] + rightSplatmap1[id];
  1620. map2 = leftSplatmap2[id] + rightSplatmap2[id];
  1621. map3 = leftSplatmap3[id] + rightSplatmap3[id];
  1622. if (doNormalize == 1) Normalize();
  1623. splatmap0[id] = map0;
  1624. splatmap1[id] = map1;
  1625. splatmap2[id] = map2;
  1626. splatmap3[id] = map3;
  1627. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1628. // h = lerp(h, saturate(h), mask);
  1629. // splatmap0[id] *= h;
  1630. // splatmap1[id] *= h;
  1631. }
  1632. #pragma kernel MultiMethodMultiplyBuffer
  1633. [numthreads(8,8,1)]
  1634. void MultiMethodMultiplyBuffer (uint2 id : SV_DispatchThreadID)
  1635. {
  1636. uint pos1d = (id.y * resolutionX) + id.x;
  1637. GetTexID(id);
  1638. map0 = leftSplatmap0[id] * rightBuffer[pos1d];
  1639. map1 = leftSplatmap1[id] * rightBuffer[pos1d];
  1640. map2 = leftSplatmap2[id] * rightBuffer[pos1d];
  1641. map3 = leftSplatmap3[id] * rightBuffer[pos1d];
  1642. previewColor = leftPreviewTex[texID] * rightBuffer[pos1d];
  1643. if (doNormalize == 1) NormalizeTex();
  1644. splatmap0[id] = map0;
  1645. splatmap1[id] = map1;
  1646. splatmap2[id] = map2;
  1647. splatmap3[id] = map3;
  1648. splatPreviewTex[texID] = previewColor;
  1649. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1650. // h = lerp(h, saturate(h), mask);
  1651. // splatmap0[id] *= h;
  1652. // splatmap1[id] *= h;
  1653. }
  1654. #pragma kernel MultiMethodTexAdd
  1655. [numthreads(8,8,1)]
  1656. void MultiMethodTexAdd (uint2 id : SV_DispatchThreadID)
  1657. {
  1658. map0 = leftSplatmap0[id] + rightSplatmap0[id];
  1659. map1 = leftSplatmap1[id] + rightSplatmap1[id];
  1660. map2 = leftSplatmap2[id] + rightSplatmap2[id];
  1661. map3 = leftSplatmap3[id] + rightSplatmap3[id];
  1662. GetTexID(id);
  1663. previewColor = leftPreviewTex[texID] + rightPreviewTex[texID];
  1664. if (doNormalize == 1) NormalizeTex();
  1665. splatmap0[id] = map0;
  1666. splatmap1[id] = map1;
  1667. splatmap2[id] = map2;
  1668. splatmap3[id] = map3;
  1669. splatPreviewTex[texID] = previewColor;
  1670. splatPreviewTexClone[texID] = previewColor;
  1671. }
  1672. #pragma kernel MultiMethodTexSubtract
  1673. [numthreads(8,8,1)]
  1674. void MultiMethodTexSubtract (uint2 id : SV_DispatchThreadID)
  1675. {
  1676. map0 = leftSplatmap0[id] - rightSplatmap0[id];
  1677. map1 = leftSplatmap1[id] - rightSplatmap1[id];
  1678. map2 = leftSplatmap2[id] - rightSplatmap2[id];
  1679. map3 = leftSplatmap3[id] - rightSplatmap3[id];
  1680. GetTexID(id);
  1681. previewColor = leftPreviewTex[texID] - rightPreviewTex[texID];
  1682. if (doNormalize == 1) NormalizeTex();
  1683. splatmap0[id] = map0;
  1684. splatmap1[id] = map1;
  1685. splatmap2[id] = map2;
  1686. splatmap3[id] = map3;
  1687. splatPreviewTex[texID] = previewColor;
  1688. splatPreviewTexClone[texID] = previewColor;
  1689. }
  1690. #pragma kernel MultiMethodTexLerp
  1691. [numthreads(8,8,1)]
  1692. void MultiMethodTexLerp (uint2 id : SV_DispatchThreadID)
  1693. {
  1694. map0 = lerp(leftSplatmap0[id], rightSplatmap0[id], overlay);
  1695. map1 = lerp(leftSplatmap1[id], rightSplatmap1[id], overlay);
  1696. map2 = lerp(leftSplatmap2[id], rightSplatmap2[id], overlay);
  1697. map3 = lerp(leftSplatmap3[id], rightSplatmap3[id], overlay);
  1698. GetTexID(id);
  1699. previewColor = lerp(leftPreviewTex[texID], rightPreviewTex[texID], overlay);
  1700. if (doNormalize == 1) NormalizeTex();
  1701. splatmap0[id] = map0;
  1702. splatmap1[id] = map1;
  1703. splatmap2[id] = map2;
  1704. splatmap3[id] = map3;
  1705. splatPreviewTex[texID] = previewColor;
  1706. splatPreviewTexClone[texID] = previewColor;
  1707. }
  1708. #pragma kernel MultiMethodTexLerpMask
  1709. [numthreads(8,8,1)]
  1710. void MultiMethodTexLerpMask (uint2 id : SV_DispatchThreadID)
  1711. {
  1712. uint pos1d = (id.y * resolutionX) + id.x;
  1713. float maskValue = maskBuffer[pos1d];
  1714. float lerpValue = maskValue * overlay;
  1715. map0 = lerp(leftSplatmap0[id], rightSplatmap0[id], lerpValue);
  1716. map1 = lerp(leftSplatmap1[id], rightSplatmap1[id], lerpValue);
  1717. map2 = lerp(leftSplatmap2[id], rightSplatmap2[id], lerpValue);
  1718. map3 = lerp(leftSplatmap3[id], rightSplatmap3[id], lerpValue);
  1719. GetTexID(id);
  1720. float4 colRightPreview = rightPreviewTex[texID];
  1721. previewColor = lerp(leftPreviewTex[texID], colRightPreview, lerpValue);
  1722. if (doNormalize == 1) NormalizeTex();
  1723. splatmap0[id] = map0;
  1724. splatmap1[id] = map1;
  1725. splatmap2[id] = map2;
  1726. splatmap3[id] = map3;
  1727. splatPreviewTex[texID] = previewColor;
  1728. splatPreviewTexClone[texID] = previewColor;
  1729. previewTex2[texID] = colRightPreview * maskValue;
  1730. }
  1731. #pragma kernel MultiMethodTexMultiply
  1732. [numthreads(8,8,1)]
  1733. void MultiMethodTexMultiply (uint2 id : SV_DispatchThreadID)
  1734. {
  1735. map0 = leftSplatmap0[id] * rightSplatmap0[id];
  1736. map1 = leftSplatmap1[id] * rightSplatmap1[id];
  1737. map2 = leftSplatmap2[id] * rightSplatmap2[id];
  1738. map3 = leftSplatmap3[id] * rightSplatmap3[id];
  1739. GetTexID(id);
  1740. previewColor = leftPreviewTex[texID] * rightPreviewTex[texID];
  1741. if (doNormalize == 1) NormalizeTex();
  1742. splatmap0[id] = map0;
  1743. splatmap1[id] = map1;
  1744. splatmap2[id] = map2;
  1745. splatmap3[id] = map3;
  1746. splatPreviewTex[texID] = previewColor;
  1747. splatPreviewTexClone[texID] = previewColor;
  1748. }
  1749. #pragma kernel MultiMethodTexDivide
  1750. [numthreads(8,8,1)]
  1751. void MultiMethodTexDivide (uint2 id : SV_DispatchThreadID)
  1752. {
  1753. map0 = leftSplatmap0[id] / rightSplatmap0[id];
  1754. map1 = leftSplatmap1[id] / rightSplatmap1[id];
  1755. map2 = leftSplatmap2[id] / rightSplatmap2[id];
  1756. map3 = leftSplatmap3[id] / rightSplatmap3[id];
  1757. GetTexID(id);
  1758. previewColor = leftPreviewTex[texID] / rightPreviewTex[texID];
  1759. if (doNormalize == 1) NormalizeTex();
  1760. splatmap0[id] = map0;
  1761. splatmap1[id] = map1;
  1762. splatmap2[id] = map2;
  1763. splatmap3[id] = map3;
  1764. splatPreviewTex[texID] = previewColor;
  1765. splatPreviewTexClone[texID] = previewColor;
  1766. }
  1767. #pragma kernel MultiMethodTexDifference
  1768. [numthreads(8,8,1)]
  1769. void MultiMethodTexDifference (uint2 id : SV_DispatchThreadID)
  1770. {
  1771. map0 = abs(leftSplatmap0[id] - rightSplatmap0[id]);
  1772. map1 = abs(leftSplatmap1[id] - rightSplatmap1[id]);
  1773. map2 = abs(leftSplatmap2[id] - rightSplatmap2[id]);
  1774. map3 = abs(leftSplatmap3[id] - rightSplatmap3[id]);
  1775. GetTexID(id);
  1776. previewColor = abs(leftPreviewTex[texID] - rightPreviewTex[texID]);
  1777. if (doNormalize == 1) NormalizeTex();
  1778. splatmap0[id] = map0;
  1779. splatmap1[id] = map1;
  1780. splatmap2[id] = map2;
  1781. splatmap3[id] = map3;
  1782. splatPreviewTex[texID] = previewColor;
  1783. splatPreviewTexClone[texID] = previewColor;
  1784. }
  1785. #pragma kernel MultiMethodTexAverage
  1786. [numthreads(8,8,1)]
  1787. void MultiMethodTexAverage (uint2 id : SV_DispatchThreadID)
  1788. {
  1789. map0 = leftSplatmap0[id] + (rightSplatmap0[id] / itemCount);
  1790. map1 = leftSplatmap1[id] + (rightSplatmap1[id] / itemCount);
  1791. map2 = leftSplatmap2[id] + (rightSplatmap2[id] / itemCount);
  1792. map3 = leftSplatmap3[id] + (rightSplatmap3[id] / itemCount);
  1793. GetTexID(id);
  1794. previewColor = leftPreviewTex[texID] + (rightPreviewTex[texID] / itemCount);
  1795. if (doNormalize == 1) NormalizeTex();
  1796. splatmap0[id] = map0;
  1797. splatmap1[id] = map1;
  1798. splatmap2[id] = map2;
  1799. splatmap3[id] = map3;
  1800. splatPreviewTex[texID] = previewColor;
  1801. splatPreviewTexClone[texID] = previewColor;
  1802. }
  1803. #pragma kernel MultiMethodTexMax
  1804. [numthreads(8,8,1)]
  1805. void MultiMethodTexMax (uint2 id : SV_DispatchThreadID)
  1806. {
  1807. map0 = max(leftSplatmap0[id], rightSplatmap0[id]);
  1808. map1 = max(leftSplatmap1[id], rightSplatmap1[id]);
  1809. map2 = max(leftSplatmap2[id], rightSplatmap2[id]);
  1810. map3 = max(leftSplatmap3[id], rightSplatmap3[id]);
  1811. GetTexID(id);
  1812. previewColor = max(leftPreviewTex[texID], rightPreviewTex[texID]);
  1813. if (doNormalize == 1) NormalizeTex();
  1814. splatmap0[id] = map0;
  1815. splatmap1[id] = map1;
  1816. splatmap2[id] = map2;
  1817. splatmap3[id] = map3;
  1818. splatPreviewTex[texID] = previewColor;
  1819. splatPreviewTexClone[texID] = previewColor;
  1820. }
  1821. #pragma kernel MultiMethodTexMin
  1822. [numthreads(8,8,1)]
  1823. void MultiMethodTexMin (uint2 id : SV_DispatchThreadID)
  1824. {
  1825. map0 = min(leftSplatmap0[id], rightSplatmap0[id]);
  1826. map1 = min(leftSplatmap1[id], rightSplatmap1[id]);
  1827. map2 = min(leftSplatmap2[id], rightSplatmap2[id]);
  1828. map3 = min(leftSplatmap3[id], rightSplatmap3[id]);
  1829. GetTexID(id);
  1830. previewColor = min(leftPreviewTex[texID], rightPreviewTex[texID]);
  1831. if (doNormalize == 1) NormalizeTex();
  1832. splatmap0[id] = map0;
  1833. splatmap1[id] = map1;
  1834. splatmap2[id] = map2;
  1835. splatmap3[id] = map3;
  1836. splatPreviewTex[texID] = previewColor;
  1837. splatPreviewTexClone[texID] = previewColor;
  1838. }
  1839. // =============================================================================================
  1840. // Color Methods
  1841. #pragma kernel ColorMethodMultiplyBuffer
  1842. [numthreads(8,8,1)]
  1843. void ColorMethodMultiplyBuffer (uint2 id : SV_DispatchThreadID)
  1844. {
  1845. uint pos1d = (id.y * resolutionX) + id.x;
  1846. float rightBufferValue = rightBuffer[pos1d];
  1847. splatmap0[id] = leftSplatmap0[id] * rightBufferValue;
  1848. GetTexID(id);
  1849. previewColor = leftPreviewTex[texID] * rightBufferValue;
  1850. splatPreviewTex[texID] = previewColor;
  1851. // if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1852. // h = lerp(h, saturate(h), mask);
  1853. // splatmap0[id] *= h;
  1854. // splatmap1[id] *= h;
  1855. }
  1856. #pragma kernel ColorMethodTexAdd
  1857. [numthreads(8,8,1)]
  1858. void ColorMethodTexAdd (uint2 id : SV_DispatchThreadID)
  1859. {
  1860. splatmap0[id] = leftSplatmap0[id] + rightSplatmap0[id];
  1861. GetTexID(id);
  1862. previewColor = leftPreviewTex[texID] + rightPreviewTex[texID];
  1863. splatPreviewTex[texID] = previewColor;
  1864. splatPreviewTexClone[texID] = previewColor;
  1865. }
  1866. #pragma kernel ColorMethodTexSubtract
  1867. [numthreads(8,8,1)]
  1868. void ColorMethodTexSubtract (uint2 id : SV_DispatchThreadID)
  1869. {
  1870. splatmap0[id] = leftSplatmap0[id] - rightSplatmap0[id];
  1871. GetTexID(id);
  1872. previewColor = leftPreviewTex[texID] - rightPreviewTex[texID];
  1873. splatPreviewTex[texID] = previewColor;
  1874. splatPreviewTexClone[texID] = previewColor;
  1875. }
  1876. #pragma kernel ColorMethodTexLerp
  1877. [numthreads(8,8,1)]
  1878. void ColorMethodTexLerp (uint2 id : SV_DispatchThreadID)
  1879. {
  1880. splatmap0[id] = lerp(leftSplatmap0[id], rightSplatmap0[id], overlay);
  1881. GetTexID(id);
  1882. previewColor = lerp(leftPreviewTex[texID], rightPreviewTex[texID], overlay);
  1883. splatPreviewTex[texID] = previewColor;
  1884. splatPreviewTexClone[texID] = previewColor;
  1885. }
  1886. #pragma kernel ColorMethodTexLerpMask
  1887. [numthreads(8,8,1)]
  1888. void ColorMethodTexLerpMask (uint2 id : SV_DispatchThreadID)
  1889. {
  1890. uint pos1d = (id.y * resolutionX) + id.x;
  1891. float maskBufferValue = maskBuffer[pos1d];
  1892. float m = maskBufferValue * overlay;
  1893. splatmap0[id] = lerp(leftSplatmap0[id], rightSplatmap0[id], m);;
  1894. GetTexID(id);
  1895. float4 colRightPreview = rightPreviewTex[texID];
  1896. previewColor = lerp(leftPreviewTex[texID], colRightPreview, m);
  1897. previewTex2[texID] = colRightPreview * maskBufferValue;
  1898. splatPreviewTex[texID] = previewColor;
  1899. splatPreviewTexClone[texID] = previewColor;
  1900. }
  1901. #pragma kernel ColorMethodTexMultiply
  1902. [numthreads(8,8,1)]
  1903. void ColorMethodTexMultiply (uint2 id : SV_DispatchThreadID)
  1904. {
  1905. splatmap0[id] = leftSplatmap0[id] * rightSplatmap0[id];
  1906. GetTexID(id);
  1907. previewColor = leftPreviewTex[texID] * rightPreviewTex[texID];
  1908. splatPreviewTex[texID] = previewColor;
  1909. }
  1910. #pragma kernel ColorMethodTexDivide
  1911. [numthreads(8,8,1)]
  1912. void ColorMethodTexDivide (uint2 id : SV_DispatchThreadID)
  1913. {
  1914. splatmap0[id] = leftSplatmap0[id] / rightSplatmap0[id];
  1915. GetTexID(id);
  1916. previewColor = leftPreviewTex[texID] / rightPreviewTex[texID];
  1917. splatPreviewTex[texID] = previewColor;
  1918. }
  1919. #pragma kernel ColorMethodTexDifference
  1920. [numthreads(8,8,1)]
  1921. void ColorMethodTexDifference (uint2 id : SV_DispatchThreadID)
  1922. {
  1923. splatmap0[id] = abs(leftSplatmap0[id] - rightSplatmap0[id]);
  1924. GetTexID(id);
  1925. previewColor = abs(leftPreviewTex[texID] - rightPreviewTex[texID]);
  1926. splatPreviewTex[texID] = previewColor;
  1927. }
  1928. #pragma kernel ColorMethodTexAverage
  1929. [numthreads(8,8,1)]
  1930. void ColorMethodTexAverage (uint2 id : SV_DispatchThreadID)
  1931. {
  1932. splatmap0[id] = leftSplatmap0[id] + (rightSplatmap0[id] / itemCount);
  1933. GetTexID(id);
  1934. previewColor = leftPreviewTex[texID] + (rightPreviewTex[texID] / itemCount);
  1935. splatPreviewTex[texID] = previewColor;
  1936. }
  1937. #pragma kernel ColorMethodTexMax
  1938. [numthreads(8,8,1)]
  1939. void ColorMethodTexMax (uint2 id : SV_DispatchThreadID)
  1940. {
  1941. splatmap0[id] = max(leftSplatmap0[id], rightSplatmap0[id]);
  1942. GetTexID(id);
  1943. previewColor = max(leftPreviewTex[texID], rightPreviewTex[texID]);
  1944. splatPreviewTex[texID] = previewColor;
  1945. }
  1946. #pragma kernel ColorMethodTexMin
  1947. [numthreads(8,8,1)]
  1948. void ColorMethodTexMin (uint2 id : SV_DispatchThreadID)
  1949. {
  1950. splatmap0[id] = min(leftSplatmap0[id], rightSplatmap0[id]);
  1951. GetTexID(id);
  1952. previewColor = min(leftPreviewTex[texID], rightPreviewTex[texID]);
  1953. splatPreviewTex[texID] = previewColor;
  1954. }
  1955. // =============================================================================================
  1956. // Methods
  1957. #pragma kernel MethodAdd
  1958. [numthreads(512,1,1)]
  1959. void MethodAdd (uint id : SV_DispatchThreadID)
  1960. {
  1961. h = resultBuffer[id] + rightBuffer[id];
  1962. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1963. // h = lerp(h, saturate(h), mask);
  1964. resultBuffer[id] = h;
  1965. }
  1966. #pragma kernel MethodSubtract
  1967. [numthreads(512,1,1)]
  1968. void MethodSubtract (uint id : SV_DispatchThreadID)
  1969. {
  1970. h = resultBuffer[id] - rightBuffer[id];
  1971. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1972. // h = lerp(h, saturate(h), mask);
  1973. resultBuffer[id] = h;
  1974. }
  1975. #pragma kernel MethodLerp
  1976. [numthreads(512,1,1)]
  1977. void MethodLerp (uint id : SV_DispatchThreadID)
  1978. {
  1979. h = lerp(resultBuffer[id], rightBuffer[id], overlay);
  1980. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1981. // h = lerp(h, saturate(h), mask);
  1982. resultBuffer[id] = h;
  1983. }
  1984. #pragma kernel MethodLerpMask
  1985. [numthreads(512,1,1)]
  1986. void MethodLerpMask (uint id : SV_DispatchThreadID)
  1987. {
  1988. h = lerp(resultBuffer[id], rightBuffer[id], overlay * maskBuffer[id]);
  1989. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1990. // h = lerp(h, saturate(h), mask);
  1991. resultBuffer[id] = h;
  1992. }
  1993. #pragma kernel MethodMultiply
  1994. [numthreads(512,1,1)]
  1995. void MethodMultiply (uint id : SV_DispatchThreadID)
  1996. {
  1997. h = resultBuffer[id] * rightBuffer[id];
  1998. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  1999. // h = lerp(h, saturate(h), mask);
  2000. resultBuffer[id] = h;
  2001. }
  2002. #pragma kernel MethodDivide
  2003. [numthreads(512,1,1)]
  2004. void MethodDivide (uint id : SV_DispatchThreadID)
  2005. {
  2006. h = resultBuffer[id] / rightBuffer[id];
  2007. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  2008. // h = lerp(h, saturate(h), mask);
  2009. resultBuffer[id] = h;
  2010. }
  2011. #pragma kernel MethodDifference
  2012. [numthreads(512,1,1)]
  2013. void MethodDifference (uint id : SV_DispatchThreadID)
  2014. {
  2015. h = abs(resultBuffer[id] - rightBuffer[id]);
  2016. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  2017. // h = lerp(h, saturate(h), mask);
  2018. resultBuffer[id] = h;
  2019. }
  2020. #pragma kernel MethodAverage
  2021. [numthreads(512,1,1)]
  2022. void MethodAverage (uint id : SV_DispatchThreadID)
  2023. {
  2024. h = resultBuffer[id] + (rightBuffer[id] / itemCount);
  2025. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  2026. // h = lerp(h, saturate(h), mask);
  2027. resultBuffer[id] = h;
  2028. }
  2029. #pragma kernel MethodMax
  2030. [numthreads(512,1,1)]
  2031. void MethodMax (uint id : SV_DispatchThreadID)
  2032. {
  2033. h = max(resultBuffer[id], rightBuffer[id]);
  2034. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  2035. // h = lerp(h, saturate(h), mask);
  2036. resultBuffer[id] = h;
  2037. }
  2038. #pragma kernel MethodMin
  2039. [numthreads(512,1,1)]
  2040. void MethodMin (uint id : SV_DispatchThreadID)
  2041. {
  2042. h = min(resultBuffer[id], rightBuffer[id]);
  2043. if (worldCurveKeysLength > 0) h = Evaluate(h, worldCurveKeysLength, worldCurveKeys, worldCurveCalc);
  2044. // h = lerp(h, saturate(h), mask);
  2045. resultBuffer[id] = h;
  2046. }
  2047. // =================================================================
  2048. // Noise
  2049. #pragma kernel NoiseRandom
  2050. [numthreads(512, 1, 1)]
  2051. void NoiseRandom(uint id : SV_DispatchThreadID)
  2052. {
  2053. GetPos(id);
  2054. GetUV();
  2055. h = 0;
  2056. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  2057. {
  2058. pos.xz += _Seed;
  2059. pos.xz *= _Frequency;
  2060. h = Random(pos.xz);
  2061. ApplyVertical();
  2062. }
  2063. resultBuffer[id] = h;
  2064. SetPreviewTex();
  2065. }
  2066. #pragma kernel CurrentBlurNormal
  2067. [numthreads(512, 1, 1)]
  2068. void CurrentBlurNormal(uint id : SV_DispatchThreadID)
  2069. {
  2070. GetPos(id);
  2071. GetUV();
  2072. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  2073. {
  2074. float h1 = rightBuffer[id + 1];
  2075. h1 += rightBuffer[id - 1];
  2076. h1 += rightBuffer[id + resolutionX];
  2077. h1 += rightBuffer[id - resolutionX];
  2078. // h += rightBuffer[id];
  2079. h1 /= 4;
  2080. float h2 = rightBuffer[id];
  2081. if (localCurveKeysLength > 0) h = Evaluate(1 - h2, localCurveKeysLength, localCurveKeys, localCurveCalc);
  2082. h = lerp(h1, h2, saturate(h));
  2083. // ApplyVertical();
  2084. }
  2085. else h = rightBuffer[id];
  2086. resultBuffer[id] = h;
  2087. SetPreviewTexBoth();
  2088. }
  2089. #pragma kernel CurrentBlurOutward
  2090. [numthreads(512, 1, 1)]
  2091. void CurrentBlurOutward(uint id : SV_DispatchThreadID)
  2092. {
  2093. GetPos(id);
  2094. GetUV();
  2095. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  2096. {
  2097. float h1 = rightBuffer[id + 1];
  2098. h1 += rightBuffer[id - 1];
  2099. h1 += rightBuffer[id + resolutionX];
  2100. h1 += rightBuffer[id - resolutionX];
  2101. // h += rightBuffer[id];
  2102. h1 /= 4;
  2103. float h2 = rightBuffer[id];
  2104. h1 = max(h1, h2);
  2105. if (localCurveKeysLength > 0) h = Evaluate(1 - h2, localCurveKeysLength, localCurveKeys, localCurveCalc);
  2106. h = lerp(h1, h2, saturate(h));
  2107. // ApplyVertical();
  2108. }
  2109. else h = rightBuffer[id];
  2110. resultBuffer[id] = h;
  2111. SetPreviewTexBoth();
  2112. }
  2113. #pragma kernel CurrentBlurInward
  2114. [numthreads(512, 1, 1)]
  2115. void CurrentBlurInward(uint id : SV_DispatchThreadID)
  2116. {
  2117. GetPos(id);
  2118. GetUV();
  2119. if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1)
  2120. {
  2121. float h1 = rightBuffer[id + 1];
  2122. h1 += rightBuffer[id - 1];
  2123. h1 += rightBuffer[id + resolutionX];
  2124. h1 += rightBuffer[id - resolutionX];
  2125. // h += rightBuffer[id];
  2126. h1 /= 4;
  2127. float h2 = rightBuffer[id];
  2128. h1 = min(h1, h2);
  2129. if (localCurveKeysLength > 0) h = Evaluate(1 - h2, localCurveKeysLength, localCurveKeys, localCurveCalc);
  2130. h = lerp(h1, h2, saturate(h));
  2131. // ApplyVertical();
  2132. }
  2133. else h = rightBuffer[id];
  2134. resultBuffer[id] = h;
  2135. SetPreviewTexBoth();
  2136. }
  2137. // Perlin TextureLookup
  2138. // =================================================================
  2139. #pragma kernel NoisePerlin1
  2140. [numthreads(512, 1, 1)]
  2141. void NoisePerlin1(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2142. #pragma kernel NoisePerlin2
  2143. [numthreads(512, 1, 1)]
  2144. void NoisePerlin2(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 2); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2145. #pragma kernel NoisePerlin3
  2146. [numthreads(512, 1, 1)]
  2147. void NoisePerlin3(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 3); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2148. #pragma kernel NoisePerlin4
  2149. [numthreads(512, 1, 1)]
  2150. void NoisePerlin4(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 4); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2151. #pragma kernel NoisePerlin5
  2152. [numthreads(512, 1, 1)]
  2153. void NoisePerlin5(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 5); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2154. #pragma kernel NoisePerlin6
  2155. [numthreads(512, 1, 1)]
  2156. void NoisePerlin6(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 6); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2157. #pragma kernel NoisePerlin7
  2158. [numthreads(512, 1, 1)]
  2159. void NoisePerlin7(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 7); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2160. #pragma kernel NoisePerlin8
  2161. [numthreads(512, 1, 1)]
  2162. void NoisePerlin8(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 8); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2163. #pragma kernel NoisePerlin9
  2164. [numthreads(512, 1, 1)]
  2165. void NoisePerlin9(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 9); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2166. #pragma kernel NoisePerlin10
  2167. [numthreads(512, 1, 1)]
  2168. void NoisePerlin10(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 10); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2169. #pragma kernel NoisePerlin11
  2170. [numthreads(512, 1, 1)]
  2171. void NoisePerlin11(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 11); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2172. #pragma kernel NoisePerlin12
  2173. [numthreads(512, 1, 1)]
  2174. void NoisePerlin12(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = fBm(pos, 12); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2175. // Billow TextureLookup
  2176. // =================================================================
  2177. #pragma kernel NoiseBillow1
  2178. [numthreads(512, 1, 1)]
  2179. void NoiseBillow1(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2180. #pragma kernel NoiseBillow2
  2181. [numthreads(512, 1, 1)]
  2182. void NoiseBillow2(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 2); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2183. #pragma kernel NoiseBillow3
  2184. [numthreads(512, 1, 1)]
  2185. void NoiseBillow3(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 3); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2186. #pragma kernel NoiseBillow4
  2187. [numthreads(512, 1, 1)]
  2188. void NoiseBillow4(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 4); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2189. #pragma kernel NoiseBillow5
  2190. [numthreads(512, 1, 1)]
  2191. void NoiseBillow5(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 5); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2192. #pragma kernel NoiseBillow6
  2193. [numthreads(512, 1, 1)]
  2194. void NoiseBillow6(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 6); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2195. #pragma kernel NoiseBillow7
  2196. [numthreads(512, 1, 1)]
  2197. void NoiseBillow7(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 7); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2198. #pragma kernel NoiseBillow8
  2199. [numthreads(512, 1, 1)]
  2200. void NoiseBillow8(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 8); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2201. #pragma kernel NoiseBillow9
  2202. [numthreads(512, 1, 1)]
  2203. void NoiseBillow9(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 9); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2204. #pragma kernel NoiseBillow10
  2205. [numthreads(512, 1, 1)]
  2206. void NoiseBillow10(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 10); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2207. #pragma kernel NoiseBillow11
  2208. [numthreads(512, 1, 1)]
  2209. void NoiseBillow11(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 11); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2210. #pragma kernel NoiseBillow12
  2211. [numthreads(512, 1, 1)]
  2212. void NoiseBillow12(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = turbulence(pos, 12); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2213. // MultiFractal TextureLookup
  2214. // =================================================================
  2215. #pragma kernel NoiseMultiFractal1
  2216. [numthreads(512, 1, 1)]
  2217. void NoiseMultiFractal1(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2218. #pragma kernel NoiseMultiFractal2
  2219. [numthreads(512, 1, 1)]
  2220. void NoiseMultiFractal2(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 2, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2221. #pragma kernel NoiseMultiFractal3
  2222. [numthreads(512, 1, 1)]
  2223. void NoiseMultiFractal3(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 3, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2224. #pragma kernel NoiseMultiFractal4
  2225. [numthreads(512, 1, 1)]
  2226. void NoiseMultiFractal4(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 4, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2227. #pragma kernel NoiseMultiFractal5
  2228. [numthreads(512, 1, 1)]
  2229. void NoiseMultiFractal5(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 5, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2230. #pragma kernel NoiseMultiFractal6
  2231. [numthreads(512, 1, 1)]
  2232. void NoiseMultiFractal6(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 6, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2233. #pragma kernel NoiseMultiFractal7
  2234. [numthreads(512, 1, 1)]
  2235. void NoiseMultiFractal7(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 7, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2236. #pragma kernel NoiseMultiFractal8
  2237. [numthreads(512, 1, 1)]
  2238. void NoiseMultiFractal8(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 8, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2239. #pragma kernel NoiseMultiFractal9
  2240. [numthreads(512, 1, 1)]
  2241. void NoiseMultiFractal9(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 9, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2242. #pragma kernel NoiseMultiFractal10
  2243. [numthreads(512, 1, 1)]
  2244. void NoiseMultiFractal10(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 10, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2245. #pragma kernel NoiseMultiFractal11
  2246. [numthreads(512, 1, 1)]
  2247. void NoiseMultiFractal11(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 11, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2248. #pragma kernel NoiseMultiFractal12
  2249. [numthreads(512, 1, 1)]
  2250. void NoiseMultiFractal12(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = ridgedmf(pos, 12, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2251. // Noise IQ
  2252. // =================================================================
  2253. #pragma kernel NoiseIQNormal
  2254. [numthreads(512, 1, 1)]
  2255. void NoiseIQNormal(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = IQNormal(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2256. #pragma kernel NoiseIQSimplex
  2257. [numthreads(512, 1, 1)]
  2258. void NoiseIQSimplex(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = IQSimplex(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2259. #pragma kernel NoiseIQValue
  2260. [numthreads(512, 1, 1)]
  2261. void NoiseIQValue(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = IQValue(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2262. // Noise Swiss
  2263. // =================================================================
  2264. #pragma kernel NoiseSwissNormal
  2265. [numthreads(512, 1, 1)]
  2266. void NoiseSwissNormal(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = SwissNormal(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2267. #pragma kernel NoiseSwissSimplex
  2268. [numthreads(512, 1, 1)]
  2269. void NoiseSwissSimplex(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = SwissSimplex(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2270. #pragma kernel NoiseSwissValue
  2271. [numthreads(512, 1, 1)]
  2272. void NoiseSwissValue(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = SwissValue(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2273. // Noise Jordan
  2274. // =================================================================
  2275. #pragma kernel NoiseJordanNormal
  2276. [numthreads(512, 1, 1)]
  2277. void NoiseJordanNormal(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = JordanNormal(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2278. #pragma kernel NoiseJordanSimplex
  2279. [numthreads(512, 1, 1)]
  2280. void NoiseJordanSimplex(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = JordanSimplex(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2281. // void NoiseJordanSimplex(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = jordanTurbulence(pos.xz, pos.y, _Octaves, _Lacunarity, _Frequency, 0.8, 0.5, 0.4, 0.35, 1.0, 0.8, 1.0); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2282. #pragma kernel NoiseJordanValue
  2283. [numthreads(512, 1, 1)]
  2284. void NoiseJordanValue(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = JordanValue(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2285. // Noise Perlin
  2286. // =================================================================
  2287. #pragma kernel NoisePerlinNormal
  2288. [numthreads(512, 1, 1)]
  2289. void NoisePerlinNormal(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = PerlinNormal(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2290. #pragma kernel NoisePerlinSimplex
  2291. [numthreads(512, 1, 1)]
  2292. void NoisePerlinSimplex(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = PerlinSimplex(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2293. #pragma kernel NoisePerlinValue
  2294. [numthreads(512, 1, 1)]
  2295. void NoisePerlinValue(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = PerlinValue(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2296. // Noise Billow
  2297. // =================================================================
  2298. #pragma kernel NoiseBillowNormal
  2299. [numthreads(512, 1, 1)]
  2300. void NoiseBillowNormal(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = BillowNormal(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2301. #pragma kernel NoiseBillowSimplex
  2302. [numthreads(512, 1, 1)]
  2303. void NoiseBillowSimplex(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = BillowSimplex(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2304. #pragma kernel NoiseBillowValue
  2305. [numthreads(512, 1, 1)]
  2306. void NoiseBillowValue(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = BillowValue(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2307. // Noise Ridged
  2308. // =================================================================
  2309. #pragma kernel NoiseRidgedNormal
  2310. [numthreads(512, 1, 1)]
  2311. void NoiseRidgedNormal(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = RidgedNormal(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2312. #pragma kernel NoiseRidgedSimplex
  2313. [numthreads(512, 1, 1)]
  2314. void NoiseRidgedSimplex(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = RidgedSimplex(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2315. #pragma kernel NoiseRidgedValue
  2316. [numthreads(512, 1, 1)]
  2317. void NoiseRidgedValue(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = RidgedValue(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2318. // Noise Cell
  2319. // =================================================================
  2320. #pragma kernel NoiseCellNormal
  2321. [numthreads(512, 1, 1)]
  2322. void NoiseCellNormal(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = CellNormal(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2323. #pragma kernel NoiseCellFast
  2324. [numthreads(512, 1, 1)]
  2325. void NoiseCellFast(uint id : SV_DispatchThreadID) { GetPos(id); GetUV(); h = 0; if (uv.x >= 0 && uv.x <= 1 && uv.y >= 0 && uv.y <= 1) { pos.y += _Seed; h = CellFast(); ApplyVertical(); } resultBuffer[id] = h; SetPreviewTex(); }
  2326. //float4 GetHeightNormal()
  2327. //{
  2328. // uv *= (terrainTexReadNormalResolution);
  2329. // uv += resExpandBorder;
  2330. // uv /= (terrainTexReadResolution);
  2331. //
  2332. // float4 s = terrainTexRead.SampleLevel(_LinearClamp, uv, 0);
  2333. //
  2334. // float2 h0 = s.rg * 255;
  2335. // float height = ((h0.x * 256.0) + h0.y) / 65535.0;
  2336. // height /= (defaultTerrainHeight / terrainHeight);
  2337. //
  2338. // float2 n = (s.ba - 0.5) * 2;
  2339. // float nY = 1 - (sqrt(1 - dot(n, n)) * 1);
  2340. //
  2341. // return float4(height, n.x, nY, n.y);
  2342. //}
  2343. //uint PosToId(float3 pos)
  2344. //{
  2345. // pos.xz /= resolutionPM.xy;
  2346. //
  2347. // return round(pos.x) + (round(pos.z) * resolutionX);
  2348. //}
  2349. //
  2350. //#pragma kernel Erosion
  2351. //[numthreads(512, 1, 1)]
  2352. //void Erosion(uint id : SV_DispatchThreadID)
  2353. //{
  2354. // GetPosUV(id);
  2355. //
  2356. // float4 hn = GetHeightNormal();
  2357. //
  2358. // pos.y = hn[0];
  2359. //
  2360. // float strength = 0.01f;
  2361. // float sink = 0;
  2362. //
  2363. // for (int i = 0; i < 100; i++)
  2364. // {
  2365. // strength += (hn.z - 0.5) * 0.01f;
  2366. // id = PosToId(pos);
  2367. // sink += strength;
  2368. // resultBuffer[id] = sink;
  2369. //
  2370. // pos.xz += hn.yw;
  2371. // hn = GetHeightNormal();
  2372. // }
  2373. //}