1 | #include "../shaderenv.h"
|
---|
2 |
|
---|
3 | struct fragment
|
---|
4 | {
|
---|
5 | float2 texCoords: TEXCOORD0;
|
---|
6 | };
|
---|
7 |
|
---|
8 |
|
---|
9 | inline 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 |
|
---|
21 | inline 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 |
|
---|
28 | float4 LenseFlare(fragment IN,
|
---|
29 | uniform sampler2D colorsTex,
|
---|
30 | uniform sampler2D flareTex1,
|
---|
31 | uniform sampler2D flareTex2,
|
---|
32 | uniform sampler2D flareTex3,
|
---|
33 | uniform sampler2D flareTex4,
|
---|
34 | uniform sampler2D flareTex5,
|
---|
35 | uniform float2 vectorToLight, // vector to current light position
|
---|
36 | uniform float distanceToLight, // distance to current light position
|
---|
37 | uniform float sunVisiblePixels
|
---|
38 | ): COLOR
|
---|
39 | {
|
---|
40 | // center color
|
---|
41 | const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0));
|
---|
42 |
|
---|
43 | const float scale = 0.3f;
|
---|
44 |
|
---|
45 | float4 flare[8];
|
---|
46 |
|
---|
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);
|
---|
52 |
|
---|
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);
|
---|
55 |
|
---|
56 | flare[7] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, -1.0f);
|
---|
57 |
|
---|
58 | float4 result = color;
|
---|
59 |
|
---|
60 | //result.xyz = float3(0);
|
---|
61 | sunVisiblePixels = clamp(sunVisiblePixels, .0f, 100.0f) * 0.01f;
|
---|
62 |
|
---|
63 | for (int i = 0; i < 8; ++ i)
|
---|
64 | result.xyz += flare[i].xyz * sunVisiblePixels;
|
---|
65 |
|
---|
66 | return result;
|
---|
67 | } |
---|