Then the problems start: I'm not good with shaders.
The theory is this:
I enter a number between 0 and (24*3600) (exclusive).
That number will act as the "skyTime" and I use it calculate a vector that points towards the sun with this:
First I try to find the quadrant the sun is in and use the appropiate formula:
If the time is between 0 and sunriseTime:
Code: Select all
sunPos = vector3df(cos(angle), -sin(angle), 0);
Code: Select all
sunPos = vector3df(cos(angle), sin(angle), 0);
Code: Select all
sunPos = vector3df(-cos(angle), sin(angle), 0);
Code: Select all
sunPos = vector3df(-cos(angle), -sin(angle), 0);
I pass it the shaders with setVertexConstant and try to get the dotproduct of it and the normal.
if the dotproduct is larger the 0.96, draw a sun, or else just black-sky...
here is the vertex shader: (glsl)
Code: Select all
uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform vec3 mLightPos; // Sunpos
uniform vec3 mCamPos;
varying float dotP;
void main()
{
gl_Position = mWorldViewProj * gl_Vertex;
vec4 normal = vec4(gl_Normal, 0.0);
normal *= mInvWorld;
normal = normalize(normal);
vec4 worldpos = gl_Vertex * mTransWorld;
vec4 lightVector = worldpos - vec4(mLightPos,1.0);
lightVector = normalize(lightVector);
dotP = dot(lightVector, normal);
gl_TexCoord[0] = gl_MultiTexCoord0;
}
Code: Select all
varying float dotP;
void main()
{
if(dotP > 0.96) gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
else gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
Edit: Sorry for the double post, didn't found the edit button but here's a screenshot of the working skydome shader, I just can't find the source: