Howto:Multi-channel lightmap: Difference between revisions

 
(13 intermediate revisions by 5 users not shown)
Line 3: Line 3:
The advantage of the first family of techniques (to which the deferred approach of [[Project Rembrandt]] belongs) is that it can treat movement of the lights relative to the scene - but because light needs to be computed every frame, the computation is very simple (secondary lights do not cast shadows, lit surfaces do not re-emit diffuse light into the scene,...).  
The advantage of the first family of techniques (to which the deferred approach of [[Project Rembrandt]] belongs) is that it can treat movement of the lights relative to the scene - but because light needs to be computed every frame, the computation is very simple (secondary lights do not cast shadows, lit surfaces do not re-emit diffuse light into the scene,...).  


Lightmaps on the other hand only work for a static scene, but since they can be computed offline with the help of raytracing software (which can run for hours if needed), secondary shadows and multiple reflections of light on bright surfaces are not an issue. In addition, runtime a lightmap corresponds to just a texture lookup, i.e. is very performance-friendly.
Lightmaps on the other hand only work for a static scene, but since they can be computed offline with the help of raytracing software (which can run for hours if needed), secondary shadows and multiple reflections of light on bright surfaces are not an issue. In addition, at runtime a lightmap corresponds to just a texture lookup, i.e. is very performance-friendly.


For many situations where a light on an airplane illuminates that airplane (both in interior and in exterior view), lightmaps thus are a useful technique.
For many situations where a light on an airplane illuminates that airplane (both in interior and in exterior view), lightmaps thus are a useful technique and can lead to graphically very impressive outcomes:
 
[[File:Shuttle lightmap.jpg|800px|Example of a raytracer generated lightmap for the Space Shuttle cockpit]]


FG supports both single channel maps (the rgb value of the lightmap encodes the full color of the light at that pixel) and multi-channel lightmaps. In these, each r,g,b and a of the lightmap texture specify intensity of the light, the color (which can then not vary across the lightspot) has to be supplied per channel as a parameter.  
FG supports both single channel maps (the rgb value of the lightmap encodes the full color of the light at that pixel) and multi-channel lightmaps. In these, each r,g,b and a of the lightmap texture specify intensity of the light, the color (which can then not vary across the lightspot) has to be supplied per channel as a parameter.  


Lightmaps are supported in FG by model-combined-deferred.eff (for exterior views), model-interior.eff (cockpit interiors, ALS only) and glass.eff (for reflections of a lit cockpit in the glass, ALS only).
Lightmaps are supported in FG by:
* {{Fgdata effect|model-combined-deferred.eff}} (for exterior views)
* {{Fgdata effect|model-interior.eff}} (cockpit interiors, [[ALS]] only) and  
* {{Fgdata effect|glass.eff}} (for reflections of a lit cockpit in the glass, [[ALS]] only).




Line 33: Line 38:


Using Blender, it would be wise to work from a copy of your original blend file to use for the lightmap creation so as not to disturb the original.
Using Blender, it would be wise to work from a copy of your original blend file to use for the lightmap creation so as not to disturb the original.
Because of the nature of the lightmap effect and the way it is applied using shaders, it is required to have all the objects to be influenced by the same lightmap also mapped to the same texture.  
Because of the nature of the lightmap effect and the way it is applied using shaders, it is required to have all the objects to be influenced by the same lightmap also mapped to the same texture. In most cases UV-texture mapping should not overlap, ie: don't map multiple objects to the same texture space. This will cause a problem when baking the lightmap by causing the bake to apply two different light conditions to the same texture space. Also, I have had issues where a panel or object on top of another will cause issues with the bake, you can get a shadow on an object that should be in full light. I don't know if this is an "order of operation" bug in Blender or if it was due to incorrectly unwrapping the objects texture map.
 
Tip: Other blends that use a different coordinate space must be converted to the same coordinate space as the final blend that you are creating the lightmap from and also be mapped to the same texture sheet if you want to apply a single lightmap to all those object. This obviously can be a real challenge if using generic instruments.
Tip: Other blends that use a different coordinate space must be converted to the same coordinate space as the final blend that you are creating the lightmap from and also be mapped to the same texture sheet if you want to apply a single lightmap to all those object. This obviously can be a real challenge if using generic instruments.


Line 141: Line 147:
[[File:Gimp8a.jpg|600px|Saving the baked image]]
[[File:Gimp8a.jpg|600px|Saving the baked image]]


== Creating a lightmap or multi-channel lightmap using AC3D ==
Creating a lightmap texture using AC3d requires the same preparations to the mesh and texture layout as described by the previous section for Blender. Place a light in the scene and select all surfaces that use the same texture. De-select everything else. You can preview the result of the light position by disabling the headlight option in the 3D menu.
[[File:Ac3dpanel.jpg|800px|AC3d panel with one light source]]
When you're satisfied wit the result go to Tools and select Render To Texture. Set the texture width and height to the same widht and hight of the original texture covering the surfaces and select Lights and Shadows from the Render option. By pressing Render AC3D will generate a lightmap texture sheet that matches the original texture at a file location of your choice.
[[File:Ac3dlightmap.jpg|800px|AC3d panel lightmap]]
The best end result is achieved by combining the original texture and the lightmap texture using the hard-light filter in Gimp.


== Using Gimp to construct a multi-channel lightmap from baked Blender images ==
== Using Gimp to construct a multi-channel lightmap from baked Blender images ==
Line 170: Line 188:




Change the color selector to black by clicking on it and choosing r = 0, g = 0, b = 0, apply.
Change the color selector to black by clicking on it and choosing r = 0, g = 0, b = 0, apply. You should now have a simi-transparent layer that will become the alpha channel of the four-channel lightmap.


[[File:Tutorial 08.jpg|400px|Color to alpha details]]
[[File:Tutorial 08.jpg|400px|Color to alpha details]]
Line 192: Line 210:




While there may be other ways to do this step, I used a mask to add the alpha channel created previously back in. The order here is tricky. First add a layer mask for the alpha channel to be copied into later.
While there may be other ways to do this step, I used a mask to add the alpha channel that we created previously back into the final four channel image. The order here is tricky. First add a layer mask to the three channel layer you created previously by "addition" for the alpha channel to be copied into later.


[[File:Tutorial 12.jpg|400px|Add layer mask for alpha channel]]
[[File:Tutorial 12.jpg|400px|Add layer mask for alpha channel]]
Line 202: Line 220:




Copy the greyscale layer you want to put in the alpha channel to the clipboard.
Copy the greyscale layer you want to become the alpha channel to the clipboard.


[[File:Tutorial 14.jpg|400px|Copy the alpha layer]]
[[File:Tutorial 14.jpg|400px|Copy the alpha layer]]
Line 251: Line 269:




Aircraft/SpaceShuttle/Models/cockpit.xml
{{fg aircraft file|path=SpaceShuttle/Models/cockpit.xml}}
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<effect>
<effect>
Line 266: Line 284:




Aircraft/SpaceShuttle/Models/Effects/Interior/shuttle-interior.eff
{{fg aircraft file|path=SpaceShuttle/Models/Effects/Interior/shuttle-interior.eff}}
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
Line 272: Line 290:
<PropertyList>
<PropertyList>
     <name>Effects/shuttle-interior</name>
     <name>Effects/shuttle-interior</name>
     <inherits-from>Aircraft/SpaceShuttle/Effects/model-interior</inherits-from>
     <inherits-from>Effects/model-interior</inherits-from>
     <parameters>
     <parameters>
         <lightmap-enabled type="int">1</lightmap-enabled>
         <lightmap-enabled type="int">1</lightmap-enabled>
Line 298: Line 316:
Note:
Note:


lm-F1-F2-F3-F4.png is the multi-channel (four channel) rgba lightmap.
<code>lm-F1-F2-F3-F4.png</code> is the multi-channel (four channel) rgba lightmap.
   
   
lightmap-factor allows you to control the intensity of the lightmap effect.
lightmap-factor allows you to control the intensity of the lightmap effect.
It is adjusted by a property created in the -set file (/fdm/jsbsim/systems/light/cabinlight#-intensity).
It is adjusted by a property created in the <code>*-set.xml</code> file (<code>/fdm/jsbsim/systems/light/cabinlight#-intensity</code>).
 


== Extending the multi-channel lightmap to use 8 channels or 2 X 4 rgba channels ==
== Extending the multi-channel lightmap to use 8 channels or 2 X 4 rgba channels ==


The multi-channel lightmap effect can be extended relatively easy to allow for as many as 8 light sources. The SpaceShuttle was extended to use 8 lights in the cockpit.
The multi-channel lightmap effect can be extended relatively easy to allow for as many as 8 light sources. The SpaceShuttle was extended to use 8 lights in the cockpit.
But because it is out of the scope of this tutorial I will just refer you to look at the following files to see how it is accomplished.
But because it is out of the scope of this tutorial I will just refer you to look at the following files to see how it is accomplished.
Extending the multi-channel lightmap to allow for more lights should only be undertaken by experienced developers that are somewhat familiar with the XML effects wrapper and GLSL code.
Extending the multi-channel lightmap to allow for more lights should only be undertaken by experienced developers that are somewhat familiar with the XML effects wrapper and GLSL code as it requires to have shader code aircraft-side.  
 
 
Aircraft/SpaceShuttle/Models/Effects/Interior/shuttle-interior.eff
 
Aircraft/SpaceShuttle/Effects/model-interior-extended.eff
 
Aircraft/SpaceShuttle/Shaders/model-interior-ALS-extended-lightmap.frag


* {{fg aircraft file|path=SpaceShuttle/Models/Effects/Interior/shuttle-interior.eff}}
* {{fg aircraft file|path=SpaceShuttle/Effects/model-interior-extended.eff}}
* {{fg aircraft file|path=SpaceShuttle/Shaders/model-interior-ALS-extended-lightmap.frag}}


You can compare the above files against their counterparts to see the differences and how it was extended.  
You can compare the above files against their counterparts to see the differences and how it was extended.  


 
* {{fg aircraft file|path=SpaceShuttle/Models/Effects/Interior/shuttle-interior.eff}} (the above example file)
Aircraft/SpaceShuttle/Models/Effects/Interior/shuttle-interior.eff (the above example file)
* {{fgdata effect|model-interior.eff}}
 
* {{fg root file|Shaders/model-interior-ALS-detailed.frag}}
fgdata/Effects/model-interior.eff
 
fgdata/Shaders/model-interior-ALS-detailed.frag
 


== Additional reading ==
== Additional reading ==
Line 333: Line 341:
[http://www.science-and-fiction.org/rendering/glsl_10.html Scalar maps in GLSL] - the interior working of lightmaps explained with code examples.
[http://www.science-and-fiction.org/rendering/glsl_10.html Scalar maps in GLSL] - the interior working of lightmaps explained with code examples.


[http://http://www.science-and-fiction.org/rendering/glsl_12.html Light intensity] - some context on the problem of correctly adding lights in the scene.
[http://www.science-and-fiction.org/rendering/glsl_12.html Light intensity] - some context on the problem of correctly adding lights in the scene.
 
[[Category:Howto]]
128

edits