Global lighting

Registered by Ferdinand Majerech

We need global lighting(lighting affecting the whole map) to simulate things like time of day.

It should simulate a very distant light source orbiting around the map
(e.g. Sun or Moon "orbiting" the Earth).

It _might_ change its color based on the time day (e.g. member to Sun- duskDawnColor)

There should be up to 8 global lights
(due to OpenGL 1.x limitations - and - eight suns should be enough for everyone).

This will require quite a few changes:

class Light:
public virtual setColor(RGBA8 &)=0;
//no reason to be private?
public f32 intensity;
etc.

class GlobalLight : public Light
//can be changed to a quartenion or anything else
private Vector3 direction
//outside classes always communicate through vectors
public setDirection(Vector3 &)

class Sun
private GlobalLight* light
//period of orbit in seconds
public f32 period
//axis of orbit - could be quaternion or whatever
private Vector3 axis
public setAxis(Vector3 &)
//does stuff to keep direction of the light in line with time
public update()
etc.

Driver specific internals:
class GLGlobalLight: public GlobalLight
//can be any color format for implementation, e.g. RGB565
private RGBAf32 color;
public setColor(RGBA8 &)

Changes in VideoDriver interface:
createGlobalLight(RGBA8 &)
deleteGlobalLight(RGBA8 &)

Other changes needed:
level 1: All surfaces need a single simple normal value, that'd be the normal of a basic flat tile
This'd have an effect similar or identical to an ambient light.

level 2: Tiles should have normal values per vertex.
Basically, a whole tile would have a single normal that'd be identical for all its vertices,
for now. This will require modification of data used to draw in immediate mode, vertex arrays
mode as well as VBO mode.

level 3: Tiles would have simple normal maps. Needs multitexturing.

level 4: Other surfaces (units) would have normal maps- complete 3D lighting

Implementation notes:
SW driver can only implement level 1 (with a sane mind), and maybe shouldn't do it at all.
OpenGL fixed function mode has to use OpenGL builtin lights (limited to 8)
OpenGL shader mode has to use shader based lights.

Blueprint information

Status:
Started
Approver:
Ferdinand Majerech
Priority:
Medium
Drafter:
Ferdinand Majerech
Direction:
Needs approval
Assignee:
Catom Developers
Definition:
Discussion
Series goal:
Accepted for trunk
Implementation:
Needs Infrastructure
Milestone target:
None
Started by
Mak Nazečić-Andrlon

Related branches

Sprints

Whiteboard

Needs clearer implementation definition.

Why does the sun need to be a specialized class?

(Ferdinand Majerech)
Not every global light has to be a sun. There might be different effects using global directional light sources (such as lightning,
realistic nuke explosions, etc), and separation of GlobalLight from Sun allows for forward-compatibility with such potential additions.

Also, Sun is more of a game logic class than graphics, while GlobalLight is clearly graphics related.

As for implementation details, these should not be specified until the actual implementation is worked on.
It's the interface that matters.
There are many possible ways to implement this, especially on VideoDriver implementations' sides. For instance, the most obvious OpenGL implementation would be use of directional lights in fixed function and their custom shader implementation in shader mode. But there might be many different implementations that would "fake" the effect with much less performance cost.
SW driver, on the other hand, would need a completely different, probably watered down, implementation.

Even the implementation details shown in the blueprint are just an example.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.