source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/lenseFlare.cg @ 3215

Revision 3215, 2.4 KB checked in by mattausch, 16 years ago (diff)

worked on lense flare, cleaned up code a little bit

RevLine 
[3212]1#include "../shaderenv.h"
2
3struct fragment
4{
5        float2 texCoords:  TEXCOORD0;
6};
7
[3213]8
[3214]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;
[3213]14
[3214]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
27
[3213]28float4 LenseFlare(fragment IN,
29                                  uniform sampler2D colorsTex,
30                                  uniform sampler2D flareTex1,
31                                  uniform sampler2D flareTex2,
32                                  uniform sampler2D flareTex3,
33                                  uniform sampler2D flareTex4,
[3214]34                                  uniform sampler2D flareTex5,
[3213]35                                  uniform float2 vectorToLight, // vector to current light position
[3215]36                                  uniform float distanceToLight, // distance to current light position
37                                  uniform float sunVisiblePixels
[3213]38                                  ): COLOR
[3212]39{
40        // center color
[3213]41        const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0));
[3212]42       
[3214]43        const float scale = 0.3f;
[3212]44
[3214]45        float4 flare[8];
[3212]46
[3214]47        flare[0] = ComputeColor(flareTex1, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, 1.0f);
48        flare[1] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 0.7f * scale, 1.0f / 3.0f);
49        flare[2] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, 0.25f * scale, 0.7f);
50        flare[3] = ComputeColor(flareTex4, IN.texCoords, vectorToLight, distanceToLight, .7f * scale, -1.0f / 2.0f);
51        flare[4] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, .4f * scale, -1.0f / 6.0f);
[3213]52
[3214]53        flare[5] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .1f * scale, 0.5f);
54        flare[6] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .2f * scale, -0.25f);
[3213]55
[3214]56        flare[7] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, -1.0f);
[3213]57
[3214]58        float4 result = color;
[3213]59
[3214]60        //result.xyz = float3(0);
[3215]61        sunVisiblePixels = clamp(sunVisiblePixels, .0f, 100.0f) * 0.01f;
62
[3214]63        for (int i = 0; i < 8; ++ i)
[3215]64                result.xyz += flare[i].xyz * sunVisiblePixels;
[3214]65
[3213]66        return result;
[3212]67}
Note: See TracBrowser for help on using the repository browser.