| Home Page | Recent Changes | Preferences

Color Operators

Useful operators for the color Variable Type. This is an example of Scripting Operators.

See also RGB to HLS conversion and HLS to RGB conversion.

Due to the lack of any color operators, let's make a few:

// Lighten color by 1
static final preoperator color ++ ( out color A )
{
  A.R++;
  A.G++;
  A.B++;
  return A;
}
// Darken color by 1
static final preoperator color -- ( out color A )
{
  A.R--;
  A.G--;
  A.B--;
  return A;
}

// Postoperator version
static final postoperator color ++ ( out color A )
{
  local color Copy;
  Copy = A;
  A.R++;
  A.G++;
  A.B++;
  return Copy;
}

// Postoperator version
static final postoperator color -- ( out color A )
{
  local color Copy;
  Copy = A;
  A.R--;
  A.G--;
  A.B--;
  return Copy;
}

// Remember that averaging operator we just used? Now it's suddenly useful, so I've copied it into here
final operator(18) int : ( int A, int B )
{
  return (A + B) / 2;
}

// Interpolate 2 colors
static final operator(22) color Mix ( color A, color B )
{
  local Color Result;
  Result.R = A.R : B.R;
  Result.G = A.G : B.G;
  Result.B = A.B : B.B;
  return Result;
}

// UT Provides a * operator for colors, but no /. Ramp a color by a float
static final operator(16) color / ( color A, float B )
{
  local Color Result;
  Result.R = A.R / B;
  Result.G = A.G / B;
  Result.B = A.B / B;
  return Result;
}

// Same thing, but this one affects the color
static final operator(34) color /= ( out color A, float B )
{
  A = A / B;
  return A;
}

// UT Provides *, not *=, so let's implement it
static final operator(34) color *= ( out color A, float B )
{
  A = A * B;
  return A;
}

// Add a byte value to each component
static final operator(20) color + ( color A, byte B )
{
  local Color Result;
  Result.R = A.R + B;
  Result.G = A.G + B;
  Result.B = A.B + B;
  return Result;
}

// Subtract a byte value to each component
static final operator(20) color - ( color A, byte B )
{
  local Color Result;
  Result.R = A.R - B;
  Result.G = A.G - B;
  Result.B = A.B - B;
  return Result;
}

// Out versions of the operators
static final operator(34) color += ( out color A, byte B )
{
  A = A + B;
  return A;
}

static final operator(34) color -= ( out color A, byte B )
{
  A = A - B;
  return A;
}

// Out version of the operator UT provides
static final operator(34) color += ( out color A, color B )
{
  A = A + B;
  return A;
}

static final operator(34) color -= ( out color A, color B )
{
  A = A - B;
  return A;
}

Related Topics

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In