Skip to content

Commit 37ca986

Browse files
committed
remap added (no tests)
Signed-off-by: Sparsh-N <sparsh.nair@hotmail.com>
1 parent 73e4209 commit 37ca986

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/doc/languagespec.tex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,12 @@ \subsection{Mathematical functions}
31223122
$ x*(1-\alpha) + y*(\alpha) $
31233123
\apiend
31243124

3125+
\apiitem{\emph{type} {\ce remap} (\emph{type} value, \emph{type} minIn, \emph{type} maxIn, \emph{type} minOut, \emph{type} maxOut) \\
3126+
\emph{type} {\ce remap} (\emph{type} value, \emph{type} minIn, \emph{type} maxIn, \emph{float} minOut, \emph{float} maxOut)}
3127+
\indexapi{remap()}
3128+
The {\cf remap} function takes the {\cf value} in range {\cf (minIn, minOut)} and shifts it to corresponding value in range {\cf (maxIn, maxOut)}.
3129+
\apiend
3130+
31253131
\apiitem{\emph{type} {\ce select} (\emph{type} x, \emph{type} y, \emph{type} cond) \\
31263132
\emph{type} {\ce select} (\emph{type} x, \emph{type} y, float cond) \\
31273133
\emph{type} {\ce select} (\emph{type} x, \emph{type} y, int cond)}

src/shaders/stdosl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ int isfinite (float x) BUILTIN;
184184
float erf (float x) BUILTIN;
185185
float erfc (float x) BUILTIN;
186186

187+
// Currently, only implemented for 'vector' and 'float' types.
188+
#if 0
189+
// normal remap(normal x, normal minIn, normal maxIn, normal minOut, normal maxOut) { return 1; }
190+
vector remap(vector x, vector minIn, vector maxIn, float minOut, float maxOut) { return minOut + (x - minIn) * (maxOut - minOut) / (maxIn - minIn); }
191+
vector remap(vector x, vector minIn, vector maxIn, vector minOut, vector maxOut) { return minOut + (x - minIn) * (maxOut - minOut) / (maxIn - minIn); }
192+
// point remap(point x, point minIn, point maxIn, point minOut, point maxOut) { return 1; }
193+
// color remap(color x, color minIn, color maxIn, color minOut, color maxOut) { return 1; }
194+
float remap(float x, float minIn, float maxIn, float minOut, float maxOut) { return minOut + (x - minIn) * (maxOut - minOut) / (maxIn - minIn); }
195+
#else
196+
vector remap (vector x, vector minIn, vector maxIn, float minOut, float maxOut) BUILTIN;
197+
vector remap (vector x, vector minIn, vector maxIn, vector minOut, vector maxOut) BUILTIN;
198+
float remap (float x, float minIn, float maxIn, float minOut, float maxOut) BUILTIN;
199+
#endif
200+
closure color remap (closure x, closure minIn, closure maxIn, float minOut, float maxOut) { return minOut + (x - minIn) * (maxOut - minOut) / (maxIn - minIn); }
201+
closure color remap (closure x, closure minIn, closure maxIn, closure minOut, closure maxOut) { return minOut + (x - minIn) * (maxOut - minOut) / (maxIn - minIn); }
202+
187203
// Vector functions
188204

189205
vector cross (vector a, vector b) BUILTIN;

0 commit comments

Comments
 (0)