Author Topic: About lighting in NWN - ambient/diffuse settings and what they do  (Read 1566 times)

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0


               

Some of you may have noticed that the NWmax exporter plugin by default sets the ambient and diffuse setting of all materials (and consequently, all objects) to pure white (rgb value of 255,255,255). OldManBeard's excellent CM3 utility also features an option that allows to do this for you in bulk operation. And finally, it's the setting on most of Bioware's own models.

But why is this?

In the following, I'll try to make a case for why these settings are in fact more or less always preferable, and in this process, explain what these settings actually do.

First of all, a little heads up on a technical aspect. Often, instead of referring to the rgb (colour) settings in terms of three times 0-255 values that you have in 3DSMax/Gmax (e.g. 255,255,255), I'll use the way it's used in the model format itself, where each colour channel is set by a value from 0 to 1 (e.g. "1 1 1" or "0.5 0.5 1"). It means more or less the same though, except 1 is 255, 0.5 is 127 and 0 is 0.

Also, for several of the examples, I will use the following texture, containing all shades of grey from entirely black to pure white:

texture_small_zpsdfd95040.jpg

This allows us to objectively assess how the lighting affects our objects.


About lighting in NWN

Generally, there are three forms of lighting in NWN. Two are set by area settings, namely the area diffuse light and area ambient light. I'll explain how they behave in turn:

  • Area ambient light differs from the other forms of light in that it is always applied equally to all parts of an object (even what faces downwards).
  • Area diffuse light is directional, always coming from the north east and high above the area. It illuminates the parts of a model that face directly toward the lightsource the most, and gradually less as the angle to the lightsource increase. Parts that are facing away from the lightsource won't receive any illumination at all.
  • The third kind of light is the dynamic light that is mainly generated from effects in game, including items emitting light worn by the player or a NPC. Beyond the fact that the lightsource is centered on a specific object within the game, the dynamic light otherwise behave in the same way as the area diffuse light.

The following image shows the different types of lighting as they are rendered in game:

 

light_types_zps5bb52e4a.jpg

 

However, the perceived lighting on the specific rendered model is further determined by the individual model objects ambient and diffuse settings (specified in the material editor in 3dSMax/Gmax). The ambient setting works as a modifier on how much the area ambient light will light up the object, whereas the diffuse setting both determines how much the area diffuse lighting and the dynamic lighting generated in game will light up an object. As already mentioned, in the raw model ASCII file the object settings allows for ambient and diffuse from 0 0 0 to 1 1 1, each number representing one colour channel (red, green, blue), and in 3dSmax/Gmax, the settings range from 0 to 255. These settings work as basic modifiers - an ambient setting of 127, 127, 127 will make area ambient light only apply half as much on the object as the area ambient light will apply on objects with a setting of 255, 255, 255 (as 127 is halfway along the 0 to 255 range).

When NWN calculates the lighting perceived by the player, all three types of light are adjusted by the model object ambient/diffuse settings as explained above, then afterwards added on top of each other to determine the final lighting of an object. If we disregard colouring for now, we can simply refer to the light generated in percent: at 100%, the texture on the object will render without any darkening (i.e. as it appears in an external editor, such as Photoshop). An important point to note here is NWN will never overbright, meaning that it'll never brighten a texture beyond 100% - if the ambient, diffuse and dynamic lighting with object modifiers combines to more than 100%, it'll still only be illuminated to 100%. This also mean that even beyond 100% combined lighting, darker part of a texture will never appear lighter than they are on the texture itself.


Practical implications - illumination and darkening

The first implication of how lighting in NWN works is that when you texture an object, you should always design your texture so that it reflects how the object looks when fully illuminated since NWN will never brighten the texture for you. But conversely, this also means that for either type of lighting in NWN on it's own (area diffuse, ambient or dynamic lighting) to be able to fully illuminate the texture, it is necessary to have both ambient and diffuse settings on the object set to 1 1 1 (i.e. 255, 255, 255 in 3DsMax/Gmax). Refer to the following image:

squares_compared_zps23684c4e.jpg

The objects that has a setting of 0.5 0.5 0.5 in an area with either solely diffuse or ambient lighting (even if pure white), it's brightest part will only be a mid-toned grey. The same applies for dynamic lighting, which (as mentioned above) has the consequence that the object will never be able to be fully illuminated by dynamic lighting in areas that have the torch lit only setting (area ambient and diffuse set to none).

It may at times perhaps be tempting to use a setting lower than 1 1 1 if you actually wanted to darken the texture on your object. However that will in turn have the consequence that in areas that contain both area ambient, area diffuse and perhaps even dynamic lighting, chances are that the darkening effect you are relying on is lost. This is especially problematic since it would make your object react differently to varying lighting conditions compared to other NWN objects, both making it seem inconsistent and unrealistic, as it would seem to take more light to fully illuminate the object.

Additionally, darkening an object by using settings lower than 1 1 1 will be a very brute form of making a texture appear darker as it basically works as a simple modifier equally applied all over the texture. It'll seem more muddled and flat, lacking in nuances and detail (you basically just narrow the range of light as seen on these histograms). There are much better ways of darkening a texture using programs like Photoshop or Gimp, first of all allowing you to make certain features of a texture remain bright when it makes sense, but also to do a more gradual, adaptive darkening that reduce the sense of flattening by preserving some highlights.

The following is an example of creating a darker variant of the flesh golem by lowering the ambient/diffuse settings compared to making a new texture:

flesh_darkening_zps46843a3b.jpg

It might seem minor, but if you pay close attention you should be able notice that there's more nuances in the textures of the flesh golem to the right. The changes I did here are also very simple and could be even better tailored - all I did was toy with the lightness/contrast settings.


Using model ambient/diffuse to adjust the colour of an object

Another thing you may have considered to use the object lighting settings for is to change the colour of an object. But again it's easy to argue that the drawbacks surpass the benefits (the only two benefits are in fact slightly less work and not having to load an additional texture into video memory, but the latter should be negligible with the amount people have today). On the other hand, when you try to change the colour of an object by modifying the lighting settings, you will again  apply it as a modifier to the entire texture evenly, generating a flattening effect - and additionally, it will always entail some general darkening of the object. This is because you can only reduce how much light from a certain channel applies to the object, and not increase the amount of light from other channels to compensate.

The following is an example of trying to create more flesh-like variations of the flesh golem, to the left by changing the model ambient/diffuse settings, and to the right by editing the texture:

flesh_retinting_zps9030d021.jpg

You should hopefully be able to notice that the texture golem on the left appears both darker and much more flat.

Using the ambient/diffuse settings to recolour a model is additionally problematic because you again risk losing the effect when the object is seen under a combination of several types of bright light:

flesh_retinting_bright_zpsafbc65dc.jpg

Notice how it's now turning somewhat green again.


Conclusion

All this may seem a bit technical, but the simple conclusion is that no matter whether you want to darken or change the hue of a model, it is always preferable to do so by editing the texture rather than the lighting settings on the model objects. The only exception is when you deliberately want an object to appear somehow unnatural. Otherwise, you will both make the model texture seem more "flat" and the model much darker than other NWN models under varying lighting circumstances.

Granted, Bioware have themselves at times used editing the model object lighting settings to darken models, but it is assumable to reduce the amount of different textures used. This is much less of an issue today (read: not an issue at all).

In some cases, it may also often seem a rather minor difference whether you darken using editing the texture or the model, but then again, it's not that much different in terms how much work it entails - and if you are to do something, you might as well do it right.

And finally, if you feel your model is too bright when viewed in game and consequently seem a bit flat, it is quite possibly simply because most of the default lighting settings in NWN are rather bright. Try to lower them a bit manually, especially the ambient setting, and you should notice that the objects appear more lively and better shaded - both your own and Bioware's default.

As closing remark, I hope you enjoyed reading this and that some of you even found it useful. Please leave any comments, questions, corrections and concerns below '<img'>


               
               

               


                     Modifié par Zarathustra217, 06 mars 2014 - 01:29 .
                     
                  


            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #1 on: February 22, 2014, 10:58:19 am »


               

-



               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #2 on: February 23, 2014, 12:53:44 pm »


               A question that is tempting to ask in this context is whether it would then be possible to improve existing Bioware (and other) models that use model object darkening by instead darkening the texture.

To an extend, it will always be a subjective assessment to determine that, but it's my personal opinion that it would nearly always be justifiable to consider this an improvement. To exemplify this, let's look at the Bioware Sea Hag model. This is how it appears in game (left side is area with half ambient/half diffuse, and right side is using dynamic lighting only):

'Image

All object nodes on this model have the default 3dSMAX settings of ~0.588 0.588 0.588 - and as you may notice, the texture does appear somewhat flat and muddled. It is tempting to suspect that the darkening here is due to an oversight by the modeller since it's left at the defaults, but that will remain speculative. Let's try to crank up the ambient/diffuse settings to 1 1 1 still though. This yields the following result:

'Image

To the attentive eye, it may seem like a few more details are starting to stand out, but now the model also seems quite bright. Perhaps the modeller then brightened the texture to compensate for the model lighting settings? Allowing ourselves to assume that, we can then do some manual darkening of the texture in Photoshop, here simply by shifting the levels slightly:

'Image

The change in texture looks as following (original to the left, new to the right):

'Image

And this is the model as it appears in game:

'Image

Of course, one can not objectively claim that this is an improvement, so I'll leave it up to the individual to make up their own opinion of whether it is. But keep in mind too that our changed model also reacts more naturally and consistently in terms of different lighting conditions in NWN, which in itself is a good argument for considering it better.
               
               

               


                     Modifié par Zarathustra217, 23 février 2014 - 02:47 .
                     
                  


            

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #3 on: February 23, 2014, 11:06:45 pm »


               argghhhh... brain death initiated by attempting to read and comprehend the intentions here along with all of the "but if you do this, OR if you do that" types of statements.... '<img'>

Please, create a much simpler version without all of the conditionals so that maybe, just maybe, I can understand what point(s) you are attempting to make?

From what I am reading and assuming, you are stating that adjusting the texture gives you more power and better results, leaving the lighting for the actual in game lighting effects to be more effective?   IE to not adjust the lighting bits on the individual mdl itself, but to allow the builder to adjust those on a per area basis?

Am I close?  ':blink:'
               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #4 on: February 24, 2014, 06:45:53 am »


               Hah, yeah, I'm sorry, I'll try to make it a bit more comprehensible. In writing it, I constantly realised more things to convey, but I think that ended up making it too dense.

Anyway, you are completely spot on in terms of what you've derived from it. I'll make it into four simple points for clarity:

1. Using all white for ambient/diffuse on your models assures the most consistent and realistic lighting behaviour of the models in game.

2. If you as modeller try to tune how the model is shaded through the model ambient/diffuse settings, it'll make your model react differently to area lighting settings compared to most other models in game. The consequence is that it will then often be impossible for the area designer to find a setting that will fit both your model and other models at once.

3. As a consequence, it is always better to darken or tint a model by editing the textures. Remember though, that since NWN never brightens beyond how the texture looks on it's own, you should still design your texture to reflect how it would appear when fully illuminated.

4. When you import your model in game, the default NWN area lighting will often make the model seem flat, lacking shading, but this is simply because the default area lighting settings are bright. I would personally recommend that you view your model in an area with the Exterior, Overcast setting and in an area with the torch-lit only setting where you can assess how it reacts to exclusively  being exposed to dynamic light.
               
               

               


                     Modifié par Zarathustra217, 24 février 2014 - 03:35 .
                     
                  


            

Legacy_Grymlorde

  • Sr. Member
  • ****
  • Posts: 362
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #5 on: February 25, 2014, 05:03:37 pm »


               

Excellent article! I appreciate the examples as visuals help greatly to explain the concepts.


 


Any chance of a follow-up article in the Toolset forum on best ways to use ambient and diffuse lighting? I've seen so many modules with poor lighting and I'm curious to learn what lighting you've used in your Ravenloft server.



               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #6 on: February 28, 2014, 02:35:39 am »


               

Thank you '<img'>


Yeah, I did actually consider that. I'll see if I can do a write up next week (and perhaps even update the one here).



               
               

               
            

Legacy_PLUSH HYENA of DOOM

  • Hero Member
  • *****
  • Posts: 995
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #7 on: March 01, 2014, 03:50:10 am »


               

I would agree entirely - using ambient/diffuse/specular settings on a model rather than altering a texture is more or less always a bad idea.


 


I've been altering ambient/diffuse/specular settings in both original BioWare and CC Models for years. For example - for some blisteringly unfathomable reason, more or less all the crates in the BioWare Rural Tileset are freakishly dark. Especially obvious next to luminously yellow haybales in the Barn groups. I reset all the crates to ambient/diffuse 111 specular 000 about five years back and suddenly they looked like decent crates instead of Blobs from the Abyss of Ultimate Darkness. New crate textures helped too.


 


That's just one minor example. I also changed the settings (added them as they were missing in some cases) in thegeorge's NWN2 Placeable conversions (and edited many of the textures quite a bit) and those houses and so on blend into NWN1 and look way better as a result.


It's definitely worth taking the time to hunt out mutated ambient/diffuse settings and hit them with bricks because they're eeeeeeevil and can make things look completely rubbish which, when the settings are rendered sane, suddenly look actually quite good.


 


Hunt them down, kill them, kill them!



               
               

               
            

Legacy_NWN_baba yaga

  • Hero Member
  • *****
  • Posts: 1944
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #8 on: March 01, 2014, 08:55:43 am »


               

Can someone please tell me for what the "specular" setting is really about. I never saw any difference whatever value there was. So either it´s just a gimmick


or something i simply overlooked for many years. A simple screenshot would be enough.



               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #9 on: March 01, 2014, 09:08:24 am »


               

It's usually a setting that determines the generations of highlights, but as far as I've been able to determine, in NWN, the specular settings do nothing at all.



               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #10 on: March 03, 2014, 11:45:21 pm »


               

Just a small addition for whoever finds it relevant:

NWN lighting is vertex lighting


Contrary to most modern games, NWN does not calculate lighting on each spot on the surface of objects (per-pixel lighting). Instead it only calculates the lighting at each vertex of a model, and then shade each face by a gradient between the light level at each of its three vertices, as shown here:

vertextutvertexbase.jpg


When modelling, the main consequence of this is that you should generally avoid very large faces, because it may often result in poor shading whenever no vertices of a given face are near a given light source even though the central area of the face is.


Compare these two models:

tesselate1_zpsdd715d5f.jpg


Model 1 is simply two large faces, whereas Model 2 has the same outline, but is instead composed of 32 faces.


Now let's see how they react to dynamic lighting in game:

tesselate2_zpse779ea75.jpg


Even if it may not seem like a huge difference (and it can perhaps even be hard to determine which one you prefer), the main thing to notice here is that the light cone seems more like a square than being circular on Model 1.


 


But the real, major difference becomes apparent when we move into the middle of the models:

tesselate3_zps9cd10c99.jpg


Model 1 now obviously seem much more dark than Model 2, hardly receiving any illumination by the torch - even if my character is standing right on top of it. What happens is that even if we are in close proximity to the model surfaces of Model 1, we are far away from all the model vertices, and thus, the model isn't really illuminated.


In terms of dynamic lighting, smaller faces are therefore always preferable as it gives the most precise illumination. But it should of course be weighted against the performance impact of having more faces. so don't go overboard either. In my personal experience, the main thing to look out for in this regard is faces with edges longer than 1.5-2 meters.



               
               

               
            

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #11 on: March 04, 2014, 05:43:15 am »


               

Now that post I believe, at least in my personal opinion, is the most informative of any post I have seen on how the ambient light is handled.  Too bad that Aurora is no longer under development etc, as I believe the community could have attained much higher results had the engine been updated to a fully 64 bit system, and given the possibilities of using multiple textures for a given object, as they do in more modern engines, like they did with Skyrim, and the game prior to that.  If OUR community had been given the power(s) of the newer engine and been able to keep the server aspect powers of NWN at the same time, wow, just imagine how much better our PW's would be.


 


Alas, no company truly wants to give the communities that power as it removes their cash cows of DLC's etc.  That, and of course, the hacker mentality that we see in various games and community projects out there.    That hacking I am referring to, is NOT the beneficial sort that most of the NWN community performs, but the less than useful power gaming sort that none of us really appreciates.


 


Anyway, thank you for the graphical explanation of how NWN handles lighting across multiple faces, and it truly shows the built in limitations of the game while still explaining why we can't always get what we wish for.



               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #12 on: March 04, 2014, 10:43:44 am »


               

Yeah, it's a shame that peachykeen didn't finish his nwshader/voodooshader as that would have allowed for bringing NWN very close to modern games. It's open source so perhaps someone could pick up on it, but my personal experiences with cg is very limited (I think that's what it's mainly written in.)


 


Anyway, thanks again, I'll eventually move that post up to be the second post for overview (the one I edited out).



               
               

               
            

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #13 on: March 05, 2014, 01:42:12 am »


               

Keep up the good work Zarathustra (odd name, and nothing I can use to help me figure out what it means or stands for)


Anyway, I always attempt to encourage folks with their own various CC projects, and most especially those that are attempting to share their knowledge and or insights with the rest of us lowly folks out here.


 


I have been itching to start creating some additional tutorial stuff lately, but I can't get my 3dsmax to work correctly inside windows 8.1.  A friend has mentioned that he has a copy of max9 on flash drive and will be dropping that off to me something in the fairly near future (I hope).  Once that arrives, I can start digging back into things here a bit, if the community doesn't decide that I need to just move on to other things and groups of folks.  I could go on explaining that, but this is not the correct location for such conversations.  Maybe sometime in the next few months, I will be able to dig back into screenshotting and compiling various things again.  I sincerely HATE the Windows 8.1 user interface, and more particularly this friggin 'app' idea... geeze, this is a desktop OS, Not a friggin interface to a cell phone that has no capability of using anything at all.  Msloth should have kept the two separate completely.  Instead, they pissed off both groups... Phone/tablet users and desktop users that really utilize the power of the entire system not just a 4 square inch view-port of a window.  Arghhh... frustration showing up again, I apologize.


               
               

               
            

Legacy_Michael DarkAngel

  • Hero Member
  • *****
  • Posts: 627
  • Karma: +0/-0
About lighting in NWN - ambient/diffuse settings and what they do
« Reply #14 on: March 05, 2014, 04:32:57 am »


               


Keep up the good work Zarathustra (odd name, and nothing I can use to help me figure out what it means or stands for)




 


Comes from the title of a book by Friedrich Nietzsche.  Or perhaps a tone poem by Richard Strauss inspired by the book.  Or possibly even another name for the Zoroastrianism founder Zoroaster.


 


And then again... it may not be any of the above.


 


icon_zdevil.gif


 MDA