Thursday 12 August 2010

Light PrePass: Neon Lights !

A couple of days ago I was wondering what kind of new light types I would be able to model with the Light Prepass renderer that I wouldn't be able to implement easily with a standard forward renderer...

I came up with the simple idea of neon lights I could model with a line segment and a radius of influence. The main algorithm would be to find for each fragment the closest point on the neon segment which is easily done in the pixel shader :

float4 findClosestPointOnSegemntFromPoint(
    float4 vA,        // start of the neon segment
    float4 vB,        // end of the neon segment
    float vP          // point to light    )
{
    float4 dir = normalize( vB - vA );      // direction vector of the segment
    float len = distance( vA, vB );         // length of the segment

    float t = dot( (P - vA), dir );         // distance of the closest point P on the seg from the origin
    float normalized_t = t / len;           // points belonging to the segment will be in [0;1]
    normalized_t = saturate( normalized_t );// discatding points not belonging to the segment

    float4 vClosestPoint = vA + dir * len * normalized_t;        // Closest point !
   
    return vClosestPoint;
}

 Then I simply use this point as if it was the source of a point light. The results are actually quite nice:



The main issue will be to cast shadows from this type of lights but I can probably live without.

In conclusion, deferred rendering is definitely cool!

No comments:

Post a Comment