Skydome shader issue

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Tranquility
Posts: 3
Joined: Fri Jul 30, 2010 1:54 pm
Location: Belgium

Skydome shader issue

Post by Tranquility »

I'll keep it simple: I'm trying to make a more "realistic" skydome that doesn't require a texture or something like that. I create the sphere-mesh with some code I found in the source code from Irrlicht's createSkydome.

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);
If the time is between sunriseTime and zenithTime:

Code: Select all

sunPos = vector3df(cos(angle), sin(angle), 0);
If the time is between zenithTime and sunsetTime:

Code: Select all

sunPos = vector3df(-cos(angle), sin(angle), 0);
else:

Code: Select all

sunPos = vector3df(-cos(angle), -sin(angle), 0);
Nothing wrong with that (I know it's C++, I just post it to assure you the vectors I use are okay...)

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;
} 
and here's the fragment-shader:

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);
} 

What am I doing wrong? Everything is just black, sometimes(when I explicitly enter the vector of the sun), the sun just appears, in the wrong direction.[/code]

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:

Image
Last edited by Tranquility on Fri Jul 30, 2010 2:38 pm, edited 1 time in total.
Tranquility
Posts: 3
Joined: Fri Jul 30, 2010 1:54 pm
Location: Belgium

Update

Post by Tranquility »

FYI: The end-result is going to something like the skydome they use in FarCry2. I made a test-shader (which I lost :( ) and the result was pretty neat.
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Post by Auradrummer »

Hello Tranquility

I'm making a skydome too, but I'm not drawing the sun or the stars. Your glow effect is really nice! I'll send you mine today, just PM me.
Professional Software Developer and Amateur Game Designer ;-)
Post Reply