#include "../shaderenv.h" struct fragment { float2 texCoords: TEXCOORD0; }; inline float2 ComputeTexCoords(float2 tex, float2 v, float dist, float scale, float distScale) { const float2 center = float2(.5f, .5f); const float2 newPos = -v * dist * distScale; //const float2 newPos = v * dist * distScale; //return (tex - center - newPos) / scale + newPos + center; return (tex - center) / scale + center + newPos / scale; //return tex / scale - center;// + center + newPos; } inline float4 ComputeColor(sampler2D tex, float2 texCoords, float2 v, float dist, float scale, float distScale) { const float2 newTexCoords = ComputeTexCoords(texCoords, v, dist, scale, distScale); return tex2Dlod(tex, float4(newTexCoords, 0, 0)); } float4 LenseFlare(fragment IN, uniform sampler2D colorsTex, uniform sampler2D flareTex1, uniform sampler2D flareTex2, uniform sampler2D flareTex3, uniform sampler2D flareTex4, uniform sampler2D flareTex5, uniform float2 vectorToLight, // vector to current light position uniform float distanceToLight, // distance to current light position uniform float sunVisiblePixels ): COLOR { // center color const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0)); const float scale = 0.3f; float4 flare[8]; flare[0] = ComputeColor(flareTex1, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, 1.0f); flare[1] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 0.7f * scale, 1.0f / 3.0f); flare[2] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, 0.25f * scale, 0.7f); flare[3] = ComputeColor(flareTex4, IN.texCoords, vectorToLight, distanceToLight, .7f * scale, -1.0f / 2.0f); flare[4] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, .4f * scale, -1.0f / 6.0f); flare[5] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .1f * scale, 0.5f); flare[6] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .2f * scale, -0.25f); flare[7] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, -1.0f); float4 result = color; //result.xyz = float3(0); sunVisiblePixels = clamp(sunVisiblePixels, .0f, 100.0f) * 0.01f; for (int i = 0; i < 8; ++ i) result.xyz += flare[i].xyz * sunVisiblePixels; return result; }