<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MQuandt.Blog &#187; ambient lights</title>
	<atom:link href="http://mquandt.com/blog/tag/ambient-lights/feed/" rel="self" type="application/rss+xml" />
	<link>http://mquandt.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 25 Jan 2012 14:21:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='mquandt.com' port='80' path='/blog/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>[LPP] Ambient Lights</title>
		<link>http://mquandt.com/blog/2010/04/lpp-ambient-lights/</link>
		<comments>http://mquandt.com/blog/2010/04/lpp-ambient-lights/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 01:32:01 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[DirectX]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[ambient lights]]></category>
		<category><![CDATA[light pre pass]]></category>

		<guid isPermaLink="false">http://mquandt.com/blog/2010/04/lpp-ambient-lights/</guid>
		<description><![CDATA[Ambient lights are used in modern games to fake the indirect illumination that exists in the real world. By adding a generally very weak light to the scene, we can avoid the 100% black shadows that really should not exist, all at a very low cost compared to proper indirect illumination or baked ambient light &#8230; <a href="http://mquandt.com/blog/2010/04/lpp-ambient-lights/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ambient lights are used in modern games to fake the indirect illumination that exists in the real world. By adding a generally very weak light to the scene, we can avoid the 100% black shadows that really should not exist, all at a very low cost compared to proper indirect illumination or baked ambient light maps.</p>
<p>I have found that the simplest way to integrate these ambient lights into the Light Pre Pass system, and allow for other elements to change the lights throughout the game is to create a new light type that fits into the normal lighting model.</p>
<p>This is probably the simplest type out there, you just create a full screen quad and render it using a shader that writes the colour information directly to the light buffer. All we have to pass to the shader is the colour and intensity. (you could always pre-compute this, but beware of the byte-&gt;int32 auto promotion C# does)</p>
<p> <span id="more-101"></span>
<p>Here is the C# class:</p>
<pre class="brush: csharp;">public class AmbientLight
{
    public Color Color { get; set; }

    public bool Enabled { get; set; }

    private int intensity = 100;

    public int Intensity
    {
        get { return intensity; }
        set { intensity = value; }
    }

    private Effect shader;

    public AmbientLight(Color col, int intensity)
    {
        this.Color = col;
        this.Enabled = true;
        this.intensity = intensity;
    }

    public void LoadContent(ContentManager content)
    {
        shader = content.Load&lt;Effect&gt;(@&quot;Effects\Lights\l_ambient&quot;);
    }

    public void DrawLight(Renderer caller)
    {
        if (!Enabled)
            return;

        shader.Begin();
        shader.Parameters.TrySet(&quot;LightColor&quot;, Color.ToVector3());
        shader.Parameters.TrySet(&quot;Intensity&quot;, intensity);

        shader.CurrentTechnique.Passes[0].Begin();
        caller.FSQ.Draw();
        shader.CurrentTechnique.Passes[0].End();

        shader.End();
    }
}</pre>
<p>and the shader:</p>
<pre class="brush: cpp;">float3 LightColor;
float Intensity;

float4 vs_main(in float4 pos : POSITION) : POSITION
{
    return pos;
}

float4 ps_main() : COLOR
{
    return float4(LightColor * (Intensity / 100), 0);
}

technique AmbientLight
{
    pass p0
    {
        VertexShader = compile vs_2_0 vs_main();
        PixelShader = compile ps_2_0 ps_main();
    }
}</pre>
<p>I am in the middle of a crunch at work, and so future posts will be slow until it is all over. (That is why this one took a while to come out) I have not had the chance to do much work on my own XNA code, let alone tutorials. <img src='http://mquandt.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks for your patience, I cannot wait to get back to XNA. (and I cannot wait for XNA 4.0 with HiDef)</p>
]]></content:encoded>
			<wfw:commentRss>http://mquandt.com/blog/2010/04/lpp-ambient-lights/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

