UberScalarMath - 图1

    1. shader UberScalarMath (
    2. int operation = 0
    3. [[
    4. string label = "Operation",
    5. string widget = "popup",
    6. string options = "\
    7. Add|Subtract|Multiply|Divide|Multiply Add|Power|Logarithm|Square Root|\
    8. Inverse Square Root|Absolute|Exponent|Minimum|Maximum|Less Than|\
    9. Greater Than|Sign|Compare|Round|Floor|\
    10. Ceil|Truncate|Fraction|Modulo|Wrap|Snap|Ping-Pong|Sine|Cosine|Tangent|\
    11. Arcsine|Arccosine|Arctangent|Arctan2|Hyperbolic Sine|Hyperbolic Cosine|\
    12. Hyperbolic Tangent|To Radians|To Degrees"
    13. ]],
    14. float input1 = 0.0
    15. [[
    16. float min = -1000.0,
    17. float max = 1000.0,
    18. float sensitivity = 0.1
    19. ]],
    20. float input2 = 0.0
    21. [[
    22. float min = -1000.0,
    23. float max = 1000.0,
    24. float sensitivity = 0.1
    25. ]],
    26. float input3 = 0.0
    27. [[
    28. float min = -1000.0,
    29. float max = 1000.0,
    30. float sensitivity = 0.1
    31. ]],
    32. output float Out = 0.0,
    33. ) {
    34. // Add
    35. // input1 = Value 1, input2 = Value 2
    36. if (operation == 0) {
    37. Out = input1 + input2;
    38. }
    39. //Subtract
    40. // input1 = Value 1, input2 = Value 2
    41. else if (operation == 1) {
    42. Out = input1 - input2;
    43. }
    44. // Multiply
    45. // input1 = Value 1, input2 = Value 2
    46. else if (operation == 2) {
    47. Out = input1 * input2;
    48. }
    49. // Divide
    50. // input1 = Value 1, input2 = Value 2
    51. else if (operation == 3) {
    52. Out = input1 / input2;
    53. }
    54. // Multiply Add
    55. // input1 = Value, input2 = Multiplier, input3 = Addend
    56. else if (operation == 4) {
    57. float temp = input1 * input2;
    58. Out = input3 + temp;
    59. }
    60. // Power
    61. // input1 = Base, input2 = Exponent
    62. else if (operation == 5) {
    63. Out = pow(input1, input2);
    64. }
    65. // Logarithm
    66. // input1 = Value, input2 = Base
    67. else if (operation == 6) {
    68. Out = log(input1, input2);
    69. }
    70. // Square Root
    71. // input1 = Value
    72. else if (operation == 7) {
    73. Out = sqrt(input1);
    74. }
    75. // Inverse Square Root
    76. // input1 = Value
    77. else if (operation == 8) {
    78. Out = inversesqrt(input1);
    79. }
    80. // Absolute
    81. // input1 = Value
    82. else if (operation == 9) {
    83. Out = abs(input1);
    84. }
    85. // Exponent
    86. // input1 = Value
    87. else if (operation == 10) {
    88. Out = exp(input1);
    89. }
    90. // Minimum
    91. // input1 = Value 1, input2 = Value 2
    92. else if (operation == 11) {
    93. Out = min(input1, input2);
    94. }
    95. // Maximum
    96. // input1 = Value 1, input2 = Value 2
    97. else if (operation == 12) {
    98. Out = max(input1, input2);
    99. }
    100. // Less Than
    101. // input1 = Value, input2 = Threshold
    102. else if (operation == 13) {
    103. Out = select(1.0, 0.0, input1 < input2);
    104. }
    105. // Greater Than
    106. // input1 = Value, input2 = Threshold
    107. else if (operation == 14) {
    108. Out = select(1.0, 0.0, input1 > input2);
    109. }
    110. // Sign
    111. // input1 = Value
    112. else if (operation == 15) {
    113. Out = sign(input1);
    114. }
    115. // Compare
    116. // input1 = Value 1, input2 = Value 2, input3 = Epsilon
    117. else if (operation == 16) {
    118. Out = select(1.0, 0.0, (input1 - input2) <= input3);
    119. }
    120. // Round
    121. // input1 = Value
    122. else if (operation == 17) {
    123. Out = round(input1);
    124. }
    125. // Floor
    126. // input1 = Value
    127. else if (operation == 18) {
    128. Out = floor(input1);
    129. }
    130. // Ceil
    131. // input1 = Value
    132. else if (operation == 19) {
    133. Out = ceil(input1);
    134. }
    135. // Truncate
    136. // input1 = Value
    137. else if (operation == 20) {
    138. Out = trunc(input1);
    139. }
    140. // Fraction
    141. // input1 = Value
    142. else if (operation == 21) {
    143. float temp = trunc(input1);
    144. Out = input1 - temp;
    145. }
    146. // Modulo
    147. // input1 = Value 1, input2 = Value 2
    148. else if (operation == 22) {
    149. Out = mod(input1, input2);
    150. }
    151. // Wrap
    152. // input1 = Value, input2 = Min, input3 = Max
    153. else if (operation == 23) {
    154. Out = fmod(((fmod((input1 - input2), (input3 - input2))) + (input3 - input2)), (input3 - input2)) + input2;
    155. }
    156. // Snap
    157. // input1 = Value, input2 = Increment
    158. else if (operation == 24) {
    159. Out = (input1 + (input2 / 2)) - fmod((input1 + (input2 / 2)), input2);
    160. }
    161. // Ping-Pong
    162. // input1 = Value, input2 = Scale
    163. else if (operation == 25) {
    164. Out = 0.0 + fabs(fmod((input1 + input2), (input2 * 2)) - input2);
    165. }
    166. // Sine
    167. // input1 = Value
    168. else if (operation == 26) {
    169. Out = sin(input1);
    170. }
    171. // Cosine
    172. // input1 = Value
    173. else if (operation == 27) {
    174. Out = cos(input1);
    175. }
    176. // Tangent
    177. // input1 = Value
    178. else if (operation == 28) {
    179. Out = tan(input1);
    180. }
    181. // Arcsine
    182. // input1 = Value
    183. else if (operation == 29) {
    184. Out = asin(input1);
    185. }
    186. // input1 = Value
    187. // Arccosine
    188. else if (operation == 30) {
    189. Out = acos(input1);
    190. }
    191. // Arctangent
    192. // input1 = Value
    193. else if (operation == 31) {
    194. Out = atan(input1);
    195. }
    196. // Arctan2
    197. // input1 = Value 1, input2 = Value 2
    198. else if (operation == 32) {
    199. Out = atan2(input1, input2);
    200. }
    201. // Hyperbolic Sine
    202. // input1 = Value
    203. else if (operation == 33) {
    204. Out = sinh(input1);
    205. }
    206. // Hyperbolic Cosine
    207. // input1 = Value
    208. else if (operation == 34) {
    209. Out = cosh(input1);
    210. }
    211. // Hyperbolic Tangent
    212. // input1 = Value
    213. else if (operation == 35) {
    214. Out = tanh(input1);
    215. }
    216. // To Radians
    217. // input1 = Value
    218. else if (operation == 36) {
    219. Out = radians(input1);
    220. }
    221. // To Degrees
    222. // input1 = Value
    223. else if (operation == 37) {
    224. Out = degrees(input1);
    225. }
    226. }