Howto:Illuminate faces: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
Line 40: Line 40:
Now every time you will export to AC3D format all the materials will get the emis property the same value as their mirror color.<br/>
Now every time you will export to AC3D format all the materials will get the emis property the same value as their mirror color.<br/>
''Attention !'' Generally blender creates new material setting mirror property to white color (1 1 1), before exporting you have to set all the non illuminating surfaces material mirror color to black (0 0 0) otherwise all the object will be like a big white thing in your scene.<br/>
''Attention !'' Generally blender creates new material setting mirror property to white color (1 1 1), before exporting you have to set all the non illuminating surfaces material mirror color to black (0 0 0) otherwise all the object will be like a big white thing in your scene.<br/>
''Warning !'' The import from an ac3d file does not take in consideration of the MIRCOL_AS_EMIS set to True. Blender will make a media of the values and set it to the emis property (Instead of the mirror color).
''Warning !'' The import from an ac3d file does not take in consideration of the MIRCOL_AS_EMIS set to True. Blender will make a media of the values and set it to the emis property (Instead of the mirror color). Fortunately this will be fixed with upcoming Blender version 2.49.


==Variations==
==Variations==

Revision as of 20:13, 9 January 2009

Imagine you see a skyline with a countless amount of lights. Somewhere in front of you there's a stretched row of lights. That's the runway you will land on. That's how you will experience a flight in the dark of the night. In reality. But in FlightGear there aren't much illuminated buildings. So here's a howto that teaches you how to make lights and illuminated buildings. Enjoy!

Basics

To make something of your building, airport, plane or what else illuminate we need an .xml file. In that .xml file we will place some stuff. Every animation (lighting is an animation) starts with the <animation> tag. Followed by the type of animation. For illumination we use the material-type. Now comes a very important part: the objects. Here we need to place the objects that should react on the animation. If we have a building with a antenne on top of it and we only want the antenne to illuminate we need to make that a seperate object. So every part that you wants to be illuminated should be seperated. You could do that in Blender, SketchUp or any other software you're using. Last part is the emisson part. The emission will tell FlightGear in what color the object should be illuminated. Using the tree colours (red, green and blue) you could make any color you want. If we did everthing as described above with a red light we will get something like:

<animation>
<type>material</type> 
<object-name>Light1</object-name>
<object-name>Light2</object-name>
<emission>	
<red>1</red>	
<green>0</green>	
<blue>0</blue>
</emission>
</animation>

Blender users

White lights

Blender emit property location

Blender users may create illuminated faces directly from blender itself. But what makes a face to be illuminated in Flightgear ? Well, Flightgear can not take full advantage of all the properties a blender surface can take (fgfs is not a full featured rendering program nor wants to be), there is anyway a method to make faces in blender emit light by their own. First of all we have to remember that whatever program we are using to model an object if we want to use it in Flightgear we have to export it in AC3D format. Materials in AC3D format have line like this one:

MATERIAL "MaterialName" rgb 1 0 0 amb 0.5 0.5 0.5 emis 0 0 0 spec 1 0.9999 0.9999 shi 32 trans 0

Look at the 3 numbers after the emis word (0 0 0). this tells that this material does not emit any light by itself. This is the common row we get when exporting an object in AC3D format from blender. If we wish to illuminate it we can take advantage of the Emit material property under the Shaders panel. If we want a slight emission we can give a value like 0.4 to it. We will get a surface that will emit white light:

MATERIAL "MaterialName" rgb 1 0 0 amb 0.5 0.5 0.5 emis 0.4 0.4 0.4 spec 1 0.9999 0.9999 shi 32 trans 0

Using the blender emit property we can obtain always illuminated surfaces without using any xml configuration file. Just remember that this surface will always emit light in every moment of the day.

Colored lights

Colored lights can be obtained from blender using a trick of the ac3d default exporter script. We will not use the emit property anymore, but we will use the mirror color of a material as emission color. So after having set the material mirror color to the considered value we have to teach the exporter to use it and convert it to an emis property. This is done by setting the property MIRCOL_AS_EMIS to True under the Blender registry. The Blender registry is a folder generally located in $HOME/.blender/bpydata/config . Here you will probably find an ac3d_export.cfg file. Edit it and change the row:

'MIRCOL_AS_EMIS': False,

to

'MIRCOL_AS_EMIS': True,

Now every time you will export to AC3D format all the materials will get the emis property the same value as their mirror color.
Attention ! Generally blender creates new material setting mirror property to white color (1 1 1), before exporting you have to set all the non illuminating surfaces material mirror color to black (0 0 0) otherwise all the object will be like a big white thing in your scene.
Warning ! The import from an ac3d file does not take in consideration of the MIRCOL_AS_EMIS set to True. Blender will make a media of the values and set it to the emis property (Instead of the mirror color). Fortunately this will be fixed with upcoming Blender version 2.49.

Variations

The light we made above is always illuminated. Below I placed some variations that make the light only illuminate at dark or in changing colors.

Illuminate during dark

If you want a face to illuminate during dark we use the sun angle property (/sim/time/sun-angle-rad). A common value where our face should start illuminate is 1.57. But you could change the value if you want to illuminate earlier or later. Depends on your needs.

To turn lights on if the sky is dark:

<animation>
<type>material</type> 
<object-name>Light</object-name>
<condition>		
<greater-than>		
<property>/sim/time/sun-angle-rad</property>
<value>1.57</value>
</greater-than>
</condition>
<emission>	
<red>1</red>	
<green>0</green>	
<blue>0</blue>
</emission>
</animation>

And to turn the lights off during day:

<animation>
<type>material</type> 
<object-name>Light</object-name>
<condition>		
<less-than-equals>		
<property>/sim/time/sun-angle-rad</property>
<value>1.57</value>
</less-than-equals>
</condition>
<emission>	
<red>0</red>	
<green>0</green>	
<blue>0</blue>
</emission>
</animation>

Changing illumination color

Sometimes there are lights that change colours every now and then. It's not very hard to implent this in FlightGear. There are multiple ways to do this, but we will use the /sim/time/utc/ property. The example below changes color from red, green to blue every. We specified that the color should be red at every time behind 0 second. So if the time is 15:20:05 the color will be red. But at 22:01:21 color will be changed to green. Using this you could even make the lighting color be different every second of the day. Antoher possibility is a light that illuminates only between two specified times like from 21:00:00 till 6:30:00.

<animation>
<type>material</type>
<object-name>Light</object-name>
<condition>	
<equals>		
<property>/sim/time/utc/second</property>				
<value>0</value>	
</equals>
</condition>
<emission>
<red>1</red>	
<green>0</green>	
<blue>0</blue>	
</emission>
</animation>
<animation>
<type>material</type>
<object-name>Light</object-name>
<condition>	
<equals>		
<property>/sim/time/utc/second</property>				
<value>20</value>	
</equals>
</condition>
<emission>
<red>0</red>	
<green>1</green>	
<blue>0</blue>	
</emission>
</animation>
<animation>
<type>material</type>
<object-name>Light</object-name>
<condition>	
<equals>		
<property>/sim/time/utc/second</property>				
<value>40</value>	
</equals>
</condition>
<emission>
<red>0</red>	
<green>0</green>	
<blue>1</blue>	
</emission>
</animation>

Changing texture if illuminated

To change the texture of an illuminated face we add one single row to the file.

NOTE: This does not work with any version newer than v1.0!

<animation>
<type>material</type> 
<object-name>Light</object-name>
<condition>		
<greater-than>		
<property>/sim/time/sun-angle-rad</property>
<value>1.57</value>
</greater-than>
</condition>
<emission>	
<red>1</red>	
<green>1</green>	
<blue>1</blue>
</emission>
<texture>Light_lit.rgb</texture>
</animation>
<animation>
<type>material</type> 
<object-name>Light</object-name>
<condition>		
<less-than-equals>		
<property>/sim/time/sun-angle-rad</property>
<value>1.57</value>
</less-than-equals>
</condition>
<emission>	
<red>1</red>	
<green>1</green>	
<blue>1</blue>
</emission>
<texture>Light.rgb</texture>
</animation>