Skip to content

Instantly share code, notes, and snippets.

@aras-p
Created January 18, 2011 00:12
Show Gist options
  • Save aras-p/783759 to your computer and use it in GitHub Desktop.
Save aras-p/783759 to your computer and use it in GitHub Desktop.
Lighting texture creation
// lr,lg,lb - light color
// spec = specular power
int idx = 0;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x, idx+=4)
{
float vx = float(x) / width;
float vy = float(y) / height;
float nl = vx;
float nh = vy;
float s = powf (nh, spec);
data[idx+0] = nl * lr * 255.0f;
data[idx+1] = nl * lg * 255.0f;
data[idx+2] = nl * lb * 255.0f;
data[idx+3] = s * 255.0f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment