Report article RSS Feed Renderer changes and updates

I fixed the non-shader-based rendering mode so that its lighting matches the shader mode - the difference is that it allows the sunlight to be brighter than pure white (by a maximum factor of 2). I've also been experimenting with specular lighting, so this seems like a good opportunity to show some vaguely pretty pictures of the lighting system.

Posted by Mythos_Ruler on Apr 5th, 2012

Day 18

I finished and committed those renderer changes (74 files changed, 2315 lines inserted, 3503 lines deleted).

In general, there ought to be no visible changes. The exception is that I fixed the non-shader-based rendering mode so that its lighting matches the shader mode - the difference is that it allows the sunlight to be brighter than pure white (by a maximum factor of 2). I've also been experimenting with specular lighting, so this seems like a good opportunity to show some vaguely pretty pictures of the lighting system. (This is all very technically simple - other games have been doing this for most of a decade, but at least we're advancing a little bit.)

The first component is the basic textures for models and terrain: (click images for larger higher-quality versions)

Then there's the diffuse lighting - surfaces that are facing towards the sun are bright, surfaces that are perpendicular to the sun or facing away are dark:

The scenario designer can control the colour and brightness of the sun, which affects this diffuse lighting.

Surfaces that aren't lit directly by the sun shouldn't be totally black - they'd still be lit by light bouncing off nearby objects. As a (very rough) approximation, we add an ambient lighting component:

The scenario designer can control the colour and brightness again, with separate values for terrain and for models to give them more control over the final appearance.

Finally there's the shadows:

All these components get multiplied and added to produce the final result:

This is what the game currently looks like. If you compare it against the first image, you can see that some parts of the scene are brighter than the unlit textures - that's what happens when the ambient plus diffuse lighting is brighter than pure white. (OpenGL generally clamps colours to the range [0, 1] so you can't exceed white, so what we actually do is compute all the ambient and diffuse lighting at 50% of its desired value and then multiply everything by 2 just before drawing it onto the screen.)

I also added some shader code to do specular lighting, to simulate the sun reflecting off shiny surfaces. For testing I've applied it to every model, which looks like:

and that gets added to all the previous lighting so you end up with:

Unlike diffuse lighting, specular depends on the position of the camera, so it looks better in motion. Also it obviously shouldn't be applied to every model, and should preferably be controlled by a new specular texture for models that want it (so e.g. the metal parts of a soldier's texture could be marked as highly reflective and the cloth parts as non-reflective), but that should be easy to add thanks to the changes I made to the renderer, and then it might allow some nicer artistic effects.

Performance of fancier lighting is a potential concern, since it does extra computation (in this case a vector normalisation and an exponentiation) for every single pixel that's drawn. In practice, with specular lighting applied across an entire 1024x768 screen, the extra cost on an Intel GMA 4500MHD on Linux (which is barely fast enough to run the game decently anyway) looks to be about 2msec/frame, while on Intel HD Graphics 3000 on Windows it's too small to easily measure. So it should probably be optional to help the bottom-end hardware, but is fine for anything slightly more advanced than that.

-- Philip [aka Ykkrosh] 

Post comment Comments
AirborneSn1p3r
AirborneSn1p3r Apr 6 2012, 11:18am says:

good to see some really nice lighting :)

+3 votes     reply to comment
Immudelki
Immudelki Apr 6 2012, 11:41am says:

Even if every game uses that nowadays, it's really interesting to read that, thanks ;D

+4 votes     reply to comment
Rafhaelbass
Rafhaelbass Apr 7 2012, 11:24am says:

Too better!

+2 votes     reply to comment
ZeusLT
ZeusLT Apr 7 2012, 5:35pm says:

I want more of technical stuff.

+3 votes     reply to comment
Orac|
Orac| Apr 8 2012, 5:44am says:

I think that the buildings still looks a bit bright, but the armour is looking really nice and shiny.

+1 vote     reply to comment
Mythos_Ruler
Mythos_Ruler Apr 8 2012, 5:40pm replied:

Oh, the specular mapping will go through hours and hours of tweaking. Rest assured. :)

+1 vote     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

News
Browse
News
Report Abuse
Report article
Related Games
0 A.D. Empires Ascendant
0 A.D. Empires Ascendant Indie Single & Multiplayer Real Time Strategy
Related Engines
Pyrogenesis
Pyrogenesis GPL TBD
Related Groups
Wildfire Games
Wildfire Games Developer & Publisher with 20 members