Skip to content

Commit 5c4eeb3

Browse files
committed
Add support for color2, vector2, color4 and vector4 types
Signed-off-by: Sparsh-N <sparsh.nair@hotmail.com>
1 parent 1fd4c56 commit 5c4eeb3

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/shaders/color2.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ color2 mix(color2 a, color2 b, float x )
183183
mix(a.a, b.a, x));
184184
}
185185

186+
color2 unmix(color2 a, color2 b, float x )
187+
{
188+
return color2(unmix(a.r, b.r, x),
189+
unmix(a.a, b.a, x));
190+
}
191+
186192
color2 smoothstep(color2 edge0, color2 edge1, color2 c)
187193
{
188194
return color2(smoothstep(edge0.r, edge1.r, c.r),

src/shaders/color4.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ color4 mix(color4 a, color4 b, float x )
183183
mix(a.a, b.a, x));
184184
}
185185

186+
color4 unmix(color4 a, color4 b, float x )
187+
{
188+
return color4(unmix(a.rgb, b.rgb, x),
189+
unmix(a.a, b.a, x));
190+
}
191+
186192
color4 smoothstep(color4 edge0, color4 edge1, color4 c)
187193
{
188194
return color4(smoothstep(edge0.rgb, edge1.rgb, c.rgb),

src/shaders/stdosl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ float mix (float x, float y, float a) BUILTIN;
164164
closure color mix (closure color x, closure color y, float a) { return x*(1-a) + y*a; }
165165
closure color mix (closure color x, closure color y, color a) { return x*(1-a) + y*a; }
166166

167-
#if 0
167+
#if 0 // Assuming x != y
168168
normal unmix (normal x, normal y, normal a) { return (a - x) / (y - x); }
169169
normal unmix (normal x, normal y, float a) { return (a - x) / (y - x); }
170170
vector unmix (vector x, vector y, vector a) { return (a - x) / (y - x); }
@@ -185,8 +185,8 @@ color unmix (color x, color y, color a) BUILTIN;
185185
color unmix (color x, color y, float a) BUILTIN;
186186
float unmix (float x, float y, float a) BUILTIN;
187187
#endif
188-
closure color unmix (closure color x, closure color y, float a) { return (a - x) / (y - x); }
189-
closure color unmix (closure color x, closure color y, color a) { return (a - x) / (y - x); }
188+
// closure color unmix (closure color x, closure color y, float a) { return (a - x) / (y - x); }
189+
// closure color unmix (closure color x, closure color y, color a) { return (a - x) / (y - x); }
190190

191191
// TODO: ADD REMAP FROM MIX AND UNMIX
192192

src/shaders/vector2.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ vector2 mix(vector2 a, vector2 b, float x )
182182
return vector2 (mix(a.x, b.x, x), mix(a.y, b.y, x));
183183
}
184184

185+
vector2 unmix(vector2 a, vector2 b, float x )
186+
{
187+
return vector2 (unmix(a.x, b.x, x), unmix(a.y, b.y, x));
188+
}
189+
185190
float dot(vector2 a, vector2 b)
186191
{
187192
return (a.x * b.x + a.y * b.y);

src/shaders/vector4.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ vector4 mix(vector4 value1, vector4 value2, float x )
209209
mix( value1.w, value2.w, x));
210210
}
211211

212+
vector4 unmix(vector4 value1, vector4 value2, float x )
213+
{
214+
return vector4 (unmix( value1.x, value2.x, x),
215+
unmix( value1.y, value2.y, x),
216+
unmix( value1.z, value2.z, x),
217+
unmix( value1.w, value2.w, x));
218+
}
219+
212220
vector vec4ToVec3(vector4 v)
213221
{
214222
return vector(v.x, v.y, v.z) / v.w;

0 commit comments

Comments
 (0)