Saturday, May 26, 2012

Burning the midnight oil... part 2

Since my last post where I spoke about the number boards I was working on , I ran into a creative block. I could not figure out how to make them light up and turn off with the headlights. Then today, after getting home from some shopping with the kids, it hit me (it wasn't the shopping, but the coming home part that did it). Since the numbers are static for this model I can light them up just like I did with the ditch lights. It was absurdly simple at this point, and within 45 minutes I had the model and LUA all hooked up.

There are actually three model layers where the numbers are. All three are single sided planes just 0.01" apart from each other. The first is a plain TexDiff filter with no alpha, Diffuse: 35, Ambient: 4, this is the 'light off' layer. The next uses Tex filter, Diffuse: 60, Ambient: 35, this is the 'light on' layer. Finally I have a mask layer which frames the numbers and blocks the light of the Tex layer (if there is a better way I have no idea how to do it). It does look good though as it gives it the illusion that numbers are behind "something". This used TexDiff filter with Transparency, Diffuse: 35, Ambient:4. All three layers pull from the same texture area, the first two ignore the alpha channel, the mask does not, and thus the numbers can show through.
In the LUA I had to add the logic to turn on and off the the first and second layers when the headlights turned on and off. This means I had to create my model with nodes I could control. Instead of trying to explain the hierarchy I will snap a screenshot.

And here is a sample of how my texture is laid out:

Now remember that all nodes are 'on' when you load up the engine. So in the Initialise function I need to turn off the lit number layer:
function Initialise ()

   -- Turn off the number boards by default
   Call("DMV_WingBoard01Rt:ActivateNode", "number_board_on", 0)
   Call("DMV_WingBoard01Lt:ActivateNode", "number_board_on", 0)


Then I need to detect when the headlights switch on and off, this happens in the OnControlValueChange function.
function OnControlValueChange ( name, index, value )  
   if Call( "*:ControlExists", name, index ) then
      -- if the headlights are on turn on the number boards
      if name == "Headlights" then
         if value == 0 then
            Call("DMV_WingBoard01Rt:ActivateNode", "number_board_on", 0)
            Call("DMV_WingBoard01Lt:ActivateNode", "number_board_on", 0)
            Call("DMV_WingBoard01Rt:ActivateNode", "number_board_off", 1)
            Call("DMV_WingBoard01Lt:ActivateNode", "number_board_off", 1)
            Call("DMV_WingBoard01Rt:ActivateNode", "number_board_on", 1)
            Call("DMV_WingBoard01Lt:ActivateNode", "number_board_on", 1)
            Call("DMV_WingBoard01Rt:ActivateNode", "number_board_off", 0)
            Call("DMV_WingBoard01Lt:ActivateNode", "number_board_off", 0)
So why didn't I just use 'value' to turn on and off the lights? Because for headlights 1 is forward, and 2 is rear, and 0 is both off. Also I figured out an old problem that Kali was trying to tell me when I first showed him my ditch lights. He was trying to explain that he was seeing some Z-order fighting between the on and off layers. I couldn't see it, so I chalked it up to a difference between how our video cards rendered the model. Well, now I know different. In the LUA I deactivate the 'off' layer when the lights turn on, and vice versa.

Oh, and ignore the third stack, its nothing... no really, just pretend its not there... 

No comments:

Post a Comment