Ignore:
Timestamp:
12/08/08 18:48:21 (16 years ago)
Author:
mattausch
Message:

worked on lense flare

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/lenseFlare.cg

    r3213 r3214  
    77 
    88 
     9inline float2 ComputeTexCoords(float2 tex, float2 v, float dist, float scale, float distScale) 
     10{ 
     11        const float2 center = float2(.5f, .5f); 
     12        const float2 newPos = -v * dist * distScale; 
     13        //const float2 newPos = v * dist * distScale; 
     14 
     15        //return (tex - center - newPos) / scale + newPos + center; 
     16        return (tex - center) / scale + center + newPos / scale; 
     17        //return tex / scale - center;// + center + newPos; 
     18} 
     19 
     20 
     21inline float4 ComputeColor(sampler2D tex, float2 texCoords, float2 v, float dist, float scale, float distScale) 
     22{ 
     23        const float2 newTexCoords = ComputeTexCoords(texCoords, v, dist, scale, distScale); 
     24        return tex2Dlod(tex, float4(newTexCoords, 0, 0)); 
     25} 
     26 
    927 
    1028float4 LenseFlare(fragment IN,  
     
    1432                                  uniform sampler2D flareTex3, 
    1533                                  uniform sampler2D flareTex4, 
     34                                  uniform sampler2D flareTex5, 
    1635                                  uniform float2 vectorToLight, // vector to current light position 
    1736                                  uniform float distanceToLight // distance to current light position 
     
    2140        const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0)); 
    2241         
    23         const float scale = 0.5f; 
    24         const float center = float2(.5f, .5f); 
    25         const float2 newPos = vectorToLight * distanceToLight; 
     42        const float scale = 0.3f; 
    2643 
    27         const float2 newTexCoords = (IN.texCoords - center) / scale + center - newPos; 
     44        float4 flare[8]; 
    2845 
    29         const float4 flare1 = tex2Dlod(flareTex1, float4(newTexCoords, 0, 0)); 
     46        flare[0] = ComputeColor(flareTex1, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, 1.0f); 
     47        flare[1] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 0.7f * scale, 1.0f / 3.0f); 
     48        flare[2] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, 0.25f * scale, 0.7f); 
     49        flare[3] = ComputeColor(flareTex4, IN.texCoords, vectorToLight, distanceToLight, .7f * scale, -1.0f / 2.0f); 
     50        flare[4] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, .4f * scale, -1.0f / 6.0f); 
    3051 
    31         float4 result; 
     52        flare[5] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .1f * scale, 0.5f); 
     53        flare[6] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .2f * scale, -0.25f); 
    3254 
    33         result.w = color.w; 
     55        flare[7] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, -1.0f); 
    3456 
    35         //const float factor = 0.9f; 
    36         //result.xyz = lerp(color.xyz, flare1.xyz, factor); 
    37         //result.xyz = color.xyz * (1.0f - flare1.w) + flare1.xyz * flare1.w; 
    38         result.xyz = color.xyz + flare1.xyz; 
     57        float4 result = color; 
     58 
     59        //result.xyz = float3(0); 
     60        for (int i = 0; i < 8; ++ i) 
     61                result.xyz += flare[i].xyz; 
    3962 
    4063        return result; 
Note: See TracChangeset for help on using the changeset viewer.