Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Hashes.hlsl 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. void Hash_Tchou_2_1_uint(uint2 v, out uint o)
  2. {
  3. // ~6 alu (2 mul)
  4. v.y ^= 1103515245U;
  5. v.x += v.y;
  6. v.x *= v.y;
  7. v.x ^= v.x >> 5u;
  8. v.x *= 0x27d4eb2du;
  9. o = v.x;
  10. }
  11. void Hash_Tchou_2_1_float(float2 i, out float o)
  12. {
  13. uint r;
  14. uint2 v = (uint2) (int2) round(i);
  15. Hash_Tchou_2_1_uint(v, r);
  16. o = (r >> 8) * (1.0 / float(0x00ffffff));
  17. }
  18. void Hash_Tchou_2_1_half(half2 i, out half o)
  19. {
  20. uint r;
  21. uint2 v = (uint2) (int2) round(i);
  22. Hash_Tchou_2_1_uint(v, r);
  23. o = (r >> 8) * (1.0 / float(0x00ffffff));
  24. }
  25. void Hash_Tchou_2_3_uint(uint2 q, out uint3 o)
  26. {
  27. // ~10 alu (2 mul)
  28. uint3 v;
  29. v.xy = q;
  30. v.y ^= 1103515245U;
  31. v.x += v.y;
  32. v.x *= v.y;
  33. v.x ^= v.x >> 5u;
  34. v.x *= 0x27d4eb2du;
  35. v.y ^= (v.x << 3u);
  36. v.z = v.x ^ (v.y << 5u);
  37. o = v;
  38. }
  39. void Hash_Tchou_2_3_float(float2 i, out float3 o)
  40. {
  41. uint3 r;
  42. uint2 v = (uint2) (int2) round(i);
  43. Hash_Tchou_2_3_uint(v, r);
  44. o = (r >> 8) * (1.0 / float(0x00ffffff));
  45. }
  46. void Hash_Tchou_2_3_half(half2 i, out half3 o)
  47. {
  48. uint3 r;
  49. uint2 v = (uint2) (int2) round(i);
  50. Hash_Tchou_2_3_uint(v, r);
  51. o = (r >> 8) * (1.0 / float(0x00ffffff));
  52. }
  53. void Hash_Tchou_2_2_uint(uint2 v, out uint2 o)
  54. {
  55. // ~8 alu (2 mul)
  56. v.y ^= 1103515245U;
  57. v.x += v.y;
  58. v.x *= v.y;
  59. v.x ^= v.x >> 5u;
  60. v.x *= 0x27d4eb2du;
  61. v.y ^= (v.x << 3u);
  62. o = v;
  63. }
  64. void Hash_Tchou_2_2_float(float2 i, out float2 o)
  65. {
  66. uint2 r;
  67. uint2 v = (uint2) (int2) round(i);
  68. Hash_Tchou_2_2_uint(v, r);
  69. o = (r >> 8) * (1.0 / float(0x00ffffff));
  70. }
  71. void Hash_Tchou_2_2_half(half2 i, out half2 o)
  72. {
  73. uint2 r;
  74. uint2 v = (uint2) (int2) round(i);
  75. Hash_Tchou_2_2_uint(v, r);
  76. o = (r >> 8) * (1.0 / float(0x00ffffff));
  77. }
  78. void Hash_Tchou_3_1_uint(uint3 v, out uint o)
  79. {
  80. // ~15 alu (3 mul)
  81. v.x ^= 1103515245U;
  82. v.y ^= v.x + v.z;
  83. v.y = v.y * 134775813;
  84. v.z += v.x ^ v.y;
  85. v.y += v.x ^ v.z;
  86. v.x += v.y * v.z;
  87. v.x = v.x * 0x27d4eb2du;
  88. o = v.x;
  89. }
  90. void Hash_Tchou_3_1_float(float3 i, out float o)
  91. {
  92. uint r;
  93. uint3 v = (uint3) (int3) round(i);
  94. Hash_Tchou_3_1_uint(v, r);
  95. o = (r >> 8) * (1.0 / float(0x00ffffff));
  96. }
  97. void Hash_Tchou_3_1_half(half3 i, out half o)
  98. {
  99. uint r;
  100. uint3 v = (uint3) (int3) round(i);
  101. Hash_Tchou_3_1_uint(v, r);
  102. o = (r >> 8) * (1.0 / float(0x00ffffff));
  103. }
  104. void Hash_Tchou_3_3_uint(uint3 v, out uint3 o)
  105. {
  106. // ~15 alu (3 mul)
  107. v.x ^= 1103515245U;
  108. v.y ^= v.x + v.z;
  109. v.y = v.y * 134775813;
  110. v.z += v.x ^ v.y;
  111. v.y += v.x ^ v.z;
  112. v.x += v.y * v.z;
  113. v.x = v.x * 0x27d4eb2du;
  114. v.z ^= v.x << 3;
  115. v.y += v.z << 3;
  116. o = v;
  117. }
  118. void Hash_Tchou_3_3_float(float3 i, out float3 o)
  119. {
  120. uint3 r, v = (uint3) (int3) round(i);
  121. Hash_Tchou_3_3_uint(v, r);
  122. o = (r >> 8) * (1.0 / float(0x00ffffff));
  123. }
  124. void Hash_Tchou_3_3_half(half3 i, out half3 o)
  125. {
  126. uint3 r, v = (uint3) (int3) round(i);
  127. Hash_Tchou_3_3_uint(v, r);
  128. o = (r >> 8) * (1.0 / float(0x00ffffff));
  129. }
  130. void Hash_LegacySine_2_1_float(float2 i, out float o)
  131. {
  132. float angle = dot(i, float2(12.9898, 78.233));
  133. #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN) || defined(SHADER_API_WEBGPU))
  134. // 'sin()' has bad precision on Mali GPUs for inputs > 10000
  135. angle = fmod(angle, TWO_PI); // Avoid large inputs to sin()
  136. #endif
  137. o = frac(sin(angle)*43758.5453);
  138. }
  139. void Hash_LegacySine_2_1_half(half2 i, out half o)
  140. {
  141. half angle = dot(i, half2(12.9898, 78.233));
  142. #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN) || defined(SHADER_API_WEBGPU))
  143. // 'sin()' has bad precision on Mali GPUs for inputs > 10000
  144. angle = fmod(angle, TWO_PI); // Avoid large inputs to sin()
  145. #endif
  146. o = frac(sin(angle)*43758.5453);
  147. }
  148. void Hash_BetterSine_2_1_float(float2 i, out float o)
  149. {
  150. float angle = dot(i, float2(12.9898, 78.233) / 1000.0f);
  151. #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN) || defined(SHADER_API_WEBGPU))
  152. // 'sin()' has bad precision on Mali GPUs for inputs > 10000
  153. angle = fmod(angle, TWO_PI); // Avoid large inputs to sin()
  154. #endif
  155. o = frac(sin(angle)*43758.5453);
  156. }
  157. void Hash_BetterSine_2_1_half(half2 i, out half o)
  158. {
  159. float angle = dot(i, half2(12.9898, 78.233) / 1000.0f);
  160. #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN) || defined(SHADER_API_WEBGPU))
  161. // 'sin()' has bad precision on Mali GPUs for inputs > 10000
  162. angle = fmod(angle, TWO_PI); // Avoid large inputs to sin()
  163. #endif
  164. o = frac(sin(angle)*43758.5453);
  165. }
  166. void Hash_LegacySine_2_2_float(float2 i, out float2 o)
  167. {
  168. float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
  169. float2 angles = mul(i, m);
  170. #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN) || defined(SHADER_API_WEBGPU))
  171. // 'sin()' has bad precision on Mali GPUs for inputs > 10000
  172. angles = fmod(angles, TWO_PI); // Avoid large inputs to sin()
  173. #endif
  174. o = frac(sin(angles));
  175. }
  176. void Hash_LegacySine_2_2_half(half2 i, out half2 o)
  177. {
  178. half2x2 m = half2x2(15.27, 47.63, 99.41, 89.98);
  179. half2 angles = mul(i, m);
  180. #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN) || defined(SHADER_API_WEBGPU))
  181. // 'sin()' has bad precision on Mali GPUs for inputs > 10000
  182. angles = fmod(angles, TWO_PI); // Avoid large inputs to sin()
  183. #endif
  184. o = frac(sin(angles));
  185. }
  186. void Hash_LegacyMod_2_1_float(float2 i, out float o)
  187. {
  188. // Permutation and hashing used in webgl-nosie goo.gl/pX7HtC
  189. i = i % 289;
  190. // need full precision, otherwise half overflows when p > 1
  191. float x = float(34 * i.x + 1) * i.x % 289 + i.y;
  192. x = (34 * x + 1) * x % 289;
  193. x = frac(x / 41) * 2 - 1;
  194. o = x;
  195. }
  196. void Hash_LegacyMod_2_1_half(half2 i, out half o)
  197. {
  198. // Permutation and hashing used in webgl-nosie goo.gl/pX7HtC
  199. i = i % 289;
  200. // need full precision, otherwise half overflows when p > 1
  201. float x = float(34 * i.x + 1) * i.x % 289 + i.y;
  202. x = (34 * x + 1) * x % 289;
  203. x = frac(x / 41) * 2 - 1;
  204. o = x;
  205. }