Ok guys I recently had the urge to create a per-pixel lighting system. I don’t know GLSL (though I want to learn it soon) but I still wanted to do some lighting stuff. I came up with this:
public void renderLight(Vector2f pos /*position of light */){
float transparency = 0, trans1, trans2, trans3, trans4, trans5; //5 levels of lumosity
trans1 = .1f;
trans2 = .2f;
trans3 = .4f;
trans4 = 7f;
trans5 = 1;
for(int x = 0; x < Display.getWidth(); x++){
for(int y = 0; y < Display.getHeight(); y++){
//get distance between current pixel and light source
Vector2f distance, currentPos = new Vector2f(x, y);
currentPos.sub(pos);
distance = new Vector2f(Math.abs(pos.getX() - currentPos.getX()), Math.abs(pos.getY() - currentPos.getY()));
if(distance.getLength() <= 5){
transparency = trans1; //current pixel is 5 pixels away from source
}else if(distance.getLength() <= 10){
transparency = trans2; //current pixel is 10 pixels away from source
}else if(distance.getLength() <= 20){
transparency = trans3; //current pixel is 20 pixels away from source
}else if(distance.getLength() <= 35){
transparency = trans4; //current pixel is 35 pixels away from source
}else if(distance.getLength() >= 50){
transparency = trans5; //current pixel is 50 or more pixels away from source
}
glColor4f(0, 0, 0, transparency);
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
}
}
}
Pretty simple I know. But I’m really proud of it because I’ve always thought smooth lighting was impossible without shaders. Now obviously the point of per-pixel lighting is for it to be smooth, and I only have 5 levels of lumosity for each pixel. Also you can’t customize the strength of the light. Sure the light doesn’t cast a shadow, and this system might be really slow. But what I’m asking here is how to make it more smooth (lumosity fades out gradually instead of having 5 levels) and how to customize the strength of the light. Thanks guys!!!