After many tests, I succeeded to stop the shafts at nights, there is still some light samples but almost invisible.
Now (from months) I'm trying to calculate vertical (Y axis) center of the rays.
I already know how to do that but not at all in game hours, if a I make correct Y position (center) when is sunrise, sunset (horizon position of the sun) then when is midday, 9:00 or 18:00 o'clock the Y position (center) is still below from the sun and reverse if the Y center is correct at 9:00, midday and 18:00 o'clock then when is sunrise, sunset (horizon position of the sun) the shafts center will be above the sun
This picture is example when Y position is not correct at sunrise, sunset:
https://photouploads.com/images/1e7e24.jpg
Here the sun is on the ground but the shafts center is already above the sun.
Here is the code that I've made with descriptions:
float2 sundir=SunDirection.xy/SunDirection.w;//.w !=0. It negative when sun is on back side
float sunvis=(sundir.xy*-0.455); // X visibility of the shafts
sunvis=saturate((0.25-sundir.y*0.222)-pow(sunvis, 4.9))*0.153; // color and power and vertical visibility of the shafts
if (SunDirection.w<0.0) sunvis=0.0; //No shafts from the back side of the sky dome
_oC0.xyz+=sunvis;
float2 sunpos = 0.5; //X position of the shafts
float2 _v1 = 0;
float maxi = 0;
int count = 0;
float4 ratio = 0.081; //Power and X position of the shafts
float deltax = 0.37 / ratio; //Power of the shafts
int samplex = 25 * ratio; // X position
for(int i = 1; i <= 25; i++)
{
for(int j = 1; j <= samplex; j++)
{
r3 = tex2D(s2, _v1.xy);
r2.x = saturate(cross(r5.xyz, 0.003) - 10.0);
if((r5.x >= maxi) && r5.x)
{
maxi = r5.x;
sunpos.x += _v1.x*0.5; //X position
sunpos.y += _v1.y*0.5; //Y position, but not the center
count ++;
}
_v1.xy = sundir.xy; //Like this, the shafts will not move when you horizontally move the mouse(camera)
}
_v1.x = (2.11 + sundir.x); //X center
_v1.y *= (0.5+0.5)*ScreenSize.w; //Like this, the shafts will not move when you vertically move the mouse(camera)
}
if(sunvis) sunpos.xy /= count--;
float4 color;
r11=r0 + r11;
float2 ScreenLightPos;
ScreenLightPos.x = sunpos.x; //X position
ScreenLightPos.y = (sunpos.y*0.5+0.089)-_v1.y; //Now here if +0.089 is bigger, like +0.3; +0.4, Y Center will be correct at sunset, sunrise and incorrect at daytime and reverse
float2 texCoord = _v0; //Shafts, HDR
float2 deltaTexCoord = (texCoord.xy - ScreenLightPos.xy);
deltaTexCoord *= ScreenSize.w / NUM_SAMPLES * Density;
float4 Bloom_Sun;
Bloom_Sun=(Bloom_Amount*8.5)/deltax;
if(maxi)
{
for(int x = 0; x < NUM_SAMPLES; x++)
{
texCoord -= deltaTexCoord;
float4 sample = tex2D(s0, texCoord.xy);
if(sample.w) sample.xyz = 0.0;
else
{
sample = tex2D(s2, texCoord.xy);
sample.w = saturate(dot(sample.xyz*0.5, 0.4444+sunvis) - 2); // Like this and my timecyc.dat Godrays will stop at 21:00 and start at 5:40
if(sample.w == 0) sample.xyz = 0.0;
sample.r *= GodRays_Color_R;
sample.g *= GodRays_Color_G;
sample.b *= GodRays_Color_B;
}
sample *= Bloom_Sun*sunvis;
r11 += sample;
sunvis *= Decay;
}
}
r11 *= Exposure;
I'll be so glad if someone can help me!
Thanks in advance!!!