Lighting

Engine Nine supports two distinct lighting techniques: Forward Lighting and Deferred Lighting. Each lighting technique has it’s pros and cons. An application needs to choose the right lighting technique based on the usage pattern. In general, deferred lighting is more expensive then forward lighting and it is not equally supported on all platforms. A scene that contains a lot of dynamic lights of variant types should use deferred lighting, while a scene that uses just one directional light source should use forward lighting.

 

Forward Lighting

Enable forward lighting is simple and straightforward, just add a DirectionalLight to the scene and set the DiffuseColor, Direction, SpecularColor accordingly. Add an AmbientLight to avoid the scene looking too dark on the back areas.

<Scene xmlns="http://schemas.microsoft.com/nine/2011/xaml">     
    <AmbientLight AmbientLightColor="0.2, 0.2, 0.2" />
    <DirectionalLight DiffuseColor="0.8, 0.8, 0.8" Direction="-1, -1, -1" />    
</Scene>

The next step is to make sure the material used by all the object has lighting turned on. For BasicMaterial, set LightingEnabled property to true and optionally enable PreferPerPixelLighting.

<Model Source="{ContentReference Assets/Tank}" Material="{BasicMaterial LightingEnabled=True, PreferPerPixelLighting=True}"/>

For material groups, make sure to include a DirectionalMaterialPart at the end.

<Model Source="{ContentReference Assets/Tank}">
    <Model.Material>
        <MaterialGroup>
            <DiffuseMaterialPart />
            <DirectionalLightMaterialPart />
        </MaterialGroup>
    </Model.Material>
</Model>

 

Deferred Lighting

Deferred lighting is only supported on Windows and Xbox where HiDef profile is present. Enable deferred lighting is as simple as forward lighting, assign a MaterialGroup to the material and add a DeferredLightsMaterialPart to that material group.

<Model Source="{ContentReference Assets/Tank}" Transform.Scale="0.05,0.05,0.05">
    <Model.Material>
        <MaterialGroup>
            <DiffuseMaterialPart />
            <DeferredLightsMaterialPart />
        </MaterialGroup>
    </Model.Material>
</Model>

Arbitrary number of lights can be added to the scene when deferred lighting is enabled, including PointLight and SpotLight:

<PointLight Name="Light1" DiffuseColor="0, 1, 0" Transform.Position="-20, 2, 20" />
<PointLight Name="Light2" DiffuseColor="1, 0, 0" Transform.Position="20, 2, 20" />
<PointLight Name="Light3" DiffuseColor="0, 0, 1" Transform.Position="-20, 2, -20" />
<SpotLight Name="Light4" DiffuseColor="1, 1, 1" Transform.Position="0, 2 , -20" OuterAngle="{Degrees 30}" InnerAngle="{Degrees 10}" Range="25" />

image

Last edited Sep 29, 2012 at 9:53 AM by yufeih, version 8

Comments

No comments yet.