Okay, as nobody reply, i do. Some guys asked me the same thing several times, so i'm sure they did such code for gta4, first try to find it. For my opinion much better to compute such effects based on entire image, not just detecting sun. But if only for sun, you can't do much if game use ldr colors, because brightness is very similar between each pixels, better forget the idea. In case of hdr data when sun is very intense, you need to write in one line on side of screen horizontal scanned data, then scan that line and produce one pixel only. Position of bright area must be computed as weighted blending of pixels and by ignoring some of pixels, like this:
Code:
float3 color=0;
float weight=0.000000001;
for (int i=0; i<256; i++)
{
float3 tempcolor=tex2D(colorsampler, somecoordoffsetedcomputedfromindex);
float tempgray=dot(tempcolor.xyz, 0.333);
float tempweight=0;
if (tempgray>MINSUNBRIGHTNESS) tempweight=1;
tempcolor*=tempweight;
weight+=tempweight;
}
color/=weight;
return color;
This code only read pixels which are sun or any huge intensity values, but absolutely the same way must be used to get uv instead of color, so somecoordoffsetedcomputedfromindex used.