00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
#ifndef SHLIBCLAMPIMPL_HPP
00028
#define SHLIBCLAMPIMPL_HPP
00029
00030
#include "ShLibClamp.hpp"
00031
#include "ShInstructions.hpp"
00032
#include "ShAttrib.hpp"
00033
#include "ShLibMiscImpl.hpp"
00034
00035
namespace SH {
00036
00037
template<
int N,
typename T>
00038
inline
00039 ShGeneric<N, T>
abs(
const ShGeneric<N, T>& var)
00040 {
00041 ShAttrib<N, SH_TEMP, T> t;
00042 shABS(t, var);
00043
return t;
00044 }
00045
00046
template<
int N,
typename T>
00047
inline
00048 ShGeneric<N, T>
ceil(
const ShGeneric<N, T>& var)
00049 {
00050 ShAttrib<N, SH_TEMP, T> t;
00051 shCEIL(t, var);
00052
return t;
00053 }
00054
00055
template<
int N,
typename T>
00056
inline
00057 ShGeneric<N, T>
floor(
const ShGeneric<N, T>& var)
00058 {
00059 ShAttrib<N, SH_TEMP, T> t;
00060 shFLR(t, var);
00061
return t;
00062 }
00063
00064
template<
int N,
typename T>
00065
inline
00066 ShGeneric<N, T>
round(
const ShGeneric<N, T>& var)
00067 {
00068 ShAttrib<N, SH_TEMP, T> t;
00069 shRND(t, var);
00070
return t;
00071 }
00072
00073
template<
int N,
typename T>
00074
inline
00075 ShGeneric<N, T>
mod(
const ShGeneric<N, T>& left,
const ShGeneric<N, T>& right)
00076 {
00077 ShAttrib<N, SH_TEMP, T> t;
00078 shMOD(t, left, right);
00079
return t;
00080 }
00081
template<
int N,
typename T>
00082
inline
00083 ShGeneric<N, T>
mod(
const ShGeneric<N, T>& left,
const ShGeneric<1, T>& right)
00084 {
00085 ShAttrib<N, SH_TEMP, T> t;
00086 shMOD(t, left, right);
00087
return t;
00088 }
00089
template<
typename T>
00090
inline
00091 ShGeneric<1, T>
mod(
const ShGeneric<1, T>& left,
const ShGeneric<1, T>& right)
00092 {
00093 ShAttrib<1, SH_TEMP, T> t;
00094 shMOD(t, left, right);
00095
return t;
00096 }
00097
00098
template<
int N,
typename T>
00099
inline
00100 ShGeneric<N, T> operator%(
const ShGeneric<N, T>& left,
const ShGeneric<N, T>& right)
00101 {
00102
return mod(left, right);
00103 }
00104
template<
int N,
typename T>
00105
inline
00106 ShGeneric<N, T> operator%(
const ShGeneric<N, T>& left,
const ShGeneric<1, T>& right)
00107 {
00108
return mod(left, right);
00109 }
00110
template<
typename T>
00111
inline
00112 ShGeneric<1, T> operator%(
const ShGeneric<1, T>& left,
const ShGeneric<1, T>& right)
00113 {
00114
return mod(left, right);
00115 }
00116
00117
template<
int N,
typename T>
00118
inline
00119 ShGeneric<N, T>
frac(
const ShGeneric<N, T>& var)
00120 {
00121 ShAttrib<N, SH_TEMP, T> t;
00122 shFRAC(t, var);
00123
return t;
00124 }
00125
00126
template<
int N,
typename T>
00127
inline
00128 ShGeneric<N, T>
pos(
const ShGeneric<N, T>& var)
00129 {
00130
return max(var, fillcast<N>(0.0f));
00131 }
00132
00133
template<
int N,
typename T>
00134
inline
00135 ShGeneric<N, T>
max(
const ShGeneric<N, T>& left,
const ShGeneric<N, T>& right)
00136 {
00137 ShAttrib<N, SH_TEMP, T> t;
00138 shMAX(t, left, right);
00139
return t;
00140 }
00141
00142
template<
int N,
typename T>
00143
inline
00144 ShGeneric<N, T>
min(
const ShGeneric<N, T>& left,
const ShGeneric<N, T>& right)
00145 {
00146 ShAttrib<N, SH_TEMP, T> t;
00147 shMIN(t, left, right);
00148
return t;
00149 }
00150
00151
template<
int N,
typename T>
00152 ShGeneric<1, T>
max(
const ShGeneric<N, T>& a)
00153 {
00154
int lhswz[N/2 + N%2];
00155
for (
int i = 0; i < N/2 + N%2; i++) {
00156 lhswz[i] = i;
00157 }
00158
int rhswz[N/2];
00159
for (
int i = 0; i < N/2; i++) {
00160 rhswz[i] = i + N/2 + N%2;
00161 }
00162
00163
return max(
max(a.template swiz<N/2 + N%2>(lhswz)), max(a.template swiz<N/2>(rhswz)));
00164 }
00165
00166
template<
typename T>
00167 ShGeneric<1, T>
max(
const ShGeneric<1, T>& a)
00168 {
00169
return a;
00170 }
00171
00172
template<
int N,
typename T>
00173 ShGeneric<1, T>
min(
const ShGeneric<N, T>& a)
00174 {
00175
int lhswz[N/2 + N%2];
00176
for (
int i = 0; i < N/2 + N%2; i++) {
00177 lhswz[i] = i;
00178 }
00179
int rhswz[N/2];
00180
for (
int i = 0; i < N/2; i++) {
00181 rhswz[i] = i + N/2 + N%2;
00182 }
00183
00184
return min(
min(a.template swiz<N/2 + N%2>(lhswz)), min(a.template swiz<N/2>(rhswz)));
00185 }
00186
00187
template<
typename T>
00188 ShGeneric<1, T>
min(
const ShGeneric<1, T>& a)
00189 {
00190
return a;
00191 }
00192
00193
template<
int N,
typename T>
00194
inline
00195 ShGeneric<N, T>
clamp(
const ShGeneric<N, T>& a,
00196
const ShGeneric<N, T>& b,
const ShGeneric<N, T>& c)
00197 {
00198
return min(
max(a, b), c);
00199 }
00200
template<
int N,
typename T>
00201
inline
00202 ShGeneric<N, T>
clamp(
const ShGeneric<N, T>& a,
00203
const ShGeneric<1, T>& b,
const ShGeneric<1, T>& c)
00204 {
00205
return min(
max(a, fillcast<N>(b)), fillcast<N>(c));
00206 }
00207
00208
template<
typename T>
00209
inline
00210 ShGeneric<1, T>
clamp(
const ShGeneric<1, T>& a,
00211
const ShGeneric<1, T>& b,
const ShGeneric<1, T>& c)
00212 {
00213
return min(
max(a, b), c);
00214 }
00215
00216
template<
int N,
typename T>
00217
inline
00218 ShGeneric<N, T>
sat(
const ShGeneric<N, T>& a)
00219 {
00220
return min(a, fillcast<N>(ShConstAttrib1f(1.0)));
00221 }
00222
00223
template<
int N,
typename T>
00224
inline
00225 ShGeneric<N, T>
sign(
const ShGeneric<N, T>& var)
00226 {
00227 ShAttrib<N, SH_TEMP, T> t;
00228 shSGN(t, var);
00229
return t;
00230 }
00231
00232 }
00233
00234
#endif