UberVectorMath - 图1

    1. shader UberScalarMath (
    2. int operation = 0
    3. [[
    4. string label = "Operation",
    5. string widget = "popup",
    6. int connectable = 0,
    7. string options = "\
    8. Add|Subtract|Multiply|Divide|Multiply Add|Cross Product|Project|\
    9. Reflect|Refract|Faceforward|Dot Product|Distance|Length|Scale|\
    10. Normalize|Wrap|Snap|Floor|Ceil|Modulo|Fraction|Absolute|Minimum|\
    11. Maximum|Sine|Cosine|Tangent"
    12. ]],
    13. vector input1 = 0.0
    14. [[
    15. vector min = -1000.0,
    16. vector max = 1000.0
    17. ]],
    18. vector input2 = 0.0
    19. [[
    20. vector min = -1000.0,
    21. vector max = 1000.0
    22. ]],
    23. vector input3 = 0.0
    24. [[
    25. vector min = -1000.0,
    26. vector max = 1000.0
    27. ]],
    28. output vector Out = color(0.0, 0.0, 0.0),
    29. ) {
    30. // Add
    31. // input1 = Value 1, input2 = Value 2
    32. if (operation == 0) {
    33. Out = input1 + input2;
    34. }
    35. //Subtract
    36. // input1 = Value 1, input2 = Value 2
    37. else if (operation == 1) {
    38. Out = input1 - input2;
    39. }
    40. // Multiply
    41. // input1 = Value 1, input2 = Value 2
    42. else if (operation == 2) {
    43. Out = input1 * input2;
    44. }
    45. // Divide
    46. // input1 = Value 1, input2 = Value 2
    47. else if (operation == 3) {
    48. Out = input1 / input2;
    49. }
    50. // Multiply Add
    51. // input1 = Value, input2 = Multiplier, input3 = Addend
    52. else if (operation == 4) {
    53. vector temp = input1 * input2;
    54. Out = input3 + temp;
    55. }
    56. // Cross Product
    57. // input1 = Value 1, input2 = Value 2
    58. else if (operation == 5) {
    59. Out = cross(input1, input2);
    60. }
    61. // Project
    62. // input1 = Vector to project, input2 = Vector to project on
    63. else if (operation == 6) {
    64. Out = (dot(input1, input2) / pow(length(input2), 2)) * input2;
    65. }
    66. // Reflect
    67. // input1 = Incident Vector, input2 = Surface Orientation (normalized)
    68. else if (operation == 7) {
    69. Out = reflect(input1, normalize(input2));
    70. }
    71. // Refract
    72. // input1 = Incident Vector, input2 = Surface Orientation, input3 = IOR
    73. else if (operation == 8) {
    74. Out = refract(input1, input2, input3[0]);
    75. }
    76. // Faceforward
    77. // input1 = Value, input2 = Incident Vector, input3 = Reference Normal
    78. else if (operation == 9) {
    79. Out = faceforward(input1, input2, input3);
    80. }
    81. // Dot Product
    82. // input1 = Value 1, input2 = Value 2
    83. else if (operation == 10) {
    84. Out = dot(input1, input2);
    85. }
    86. // Distance
    87. // input1 = Value 1, input2 = Value 2
    88. else if (operation == 11) {
    89. Out = distance(input1, input2);
    90. }
    91. // Length
    92. // input1 = Value 1
    93. else if (operation == 12) {
    94. Out = length(input1);
    95. }
    96. // Scale
    97. // input1 = Value, input2 = Scale (Float)
    98. else if (operation == 13) {
    99. Out = input1 * input2;
    100. }
    101. // Normalize
    102. // input1 = Value
    103. else if (operation == 14) {
    104. Out = normalize(input1);
    105. }
    106. // Wrap
    107. // input1 = Value, input2 = Min, input3 = Max
    108. else if (operation == 15) {
    109. Out = fmod(((fmod((input1 - input2), (input3 - input2))) + (input3 - input2)), (input3 - input2)) + input2;
    110. }
    111. // Snap
    112. // input1 = Value, input2 = Increment
    113. else if (operation == 16) {
    114. Out = (input1 + (input2 / 2)) - fmod((input1 + (input2 / 2)), input2);
    115. }
    116. // Floor
    117. // input1 = Value
    118. else if (operation == 17) {
    119. Out = floor(input1);
    120. }
    121. // Ceil
    122. // input1 = Value
    123. else if (operation == 18) {
    124. Out = ceil(input1);
    125. }
    126. // Modulo
    127. // input1 = Value 1, input2 = Value 2
    128. else if (operation == 19) {
    129. Out = mod(input1, input2);
    130. }
    131. // Fraction
    132. // input1 = Value
    133. else if (operation == 20) {
    134. vector temp = trunc(input1);
    135. Out = input1 - temp;
    136. }
    137. // Absolute
    138. // input1 = Value
    139. else if (operation == 21) {
    140. Out = abs(input1);
    141. }
    142. // Minimum
    143. // input1 = Value 1, input2 = Value 2
    144. else if (operation == 22) {
    145. Out = min(input1, input2);
    146. }
    147. // Maximum
    148. // input1 = Value 1, input2 = Value 2
    149. else if (operation == 23) {
    150. Out = max(input1, input2);
    151. }
    152. // Sine
    153. // input1 = Value
    154. else if (operation == 24) {
    155. Out = sin(input1);
    156. }
    157. // Cosine
    158. // input1 = Value
    159. else if (operation == 25) {
    160. Out = cos(input1);
    161. }
    162. // Tangent
    163. // input1 = Value
    164. else if (operation == 26) {
    165. Out = tan(input1);
    166. }
    167. }