• Advertisement

Archived

This topic is now archived and is closed to further replies.

Practical Analytical Daylight Problems

This topic is 5058 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've cobbled together an attempt at implementing the imfamous "Practical Analytical Model for Daylight" paper from various sources on the boards (Illici's sky shader code I think), and surprise surprise, I'm having problems. When I render my skydome, I seem to have a jaggy seam that runs from the apex right down to the skirt of the dome. If I texture the dome, the texture has a nasty seam but it's nothing to do with clamping. When I try to color the dome, the jaggy seam breaks up the colors. I was able to fudge it so the jaggy seam went away, but then I lost the sun-bloom and instead the whole dome changed color at once based on time of day, rather than an arcing sun with halo etc. So my question is: What is the best way to generate skydome geometry that is compatible with the PAMfD method of shading? (In terms of being able to specify angles to the shading code) (I'd post screenshots but can't right now) [edited by - voodoo_john on April 14, 2004 11:59:43 AM]

Share this post


Link to post
Share on other sites
Advertisement
Here's the code


for (int j=startHeightSlice; j<heightSlices; j++)
{
float theta1 = j * HALFPI / float(heightSlices);
float theta2 = (j + 1) * HALFPI / float(heightSlices);

glBegin(GL_QUAD_STRIP);

for (int i=startRotationSlice;i<=rotationSlices;i++)
{
float theta3 = i * TWOPI / float(rotationSlices);
float c = theta3 / TWOPI * maxTexCoord;

CVector3 e1, p1;
e1.x = float(cos(theta1) * cos(theta3));
e1.y = float(sin(theta1));
e1.z = float(cos(theta1) * sin(theta3));
p1.x = radius * e1.x;
p1.y = radius2 * e1.y;
p1.z = radius * e1.z;

CVector3 e2, p2;
e2.x = float(cos(theta2) * cos(theta3));
e2.y = float(sin(theta2));
e2.z = float(cos(theta2) * sin(theta3));
p2.x = radius * e2.x;
p2.y = radius2 * e2.y;
p2.z = radius * e2.z;


CVector3 color;

color = skyColor.GetVertexColor(i*(3.14159/180),j*(3.14159/180));
//glTexCoord2f(c, float(j) / float(heightSlices));

glVertex3f(p1.x, p1.y, p1.z);
glColor3f( color.x, color.y, color.z );

//glTexCoord2f(c, float(j+1) / float(heightSlices));

//color = skyColor.GetVertexColor(theta1*(3.14159/180),theta2*(3.14159/180));

glVertex3f(p2.x, p2.y, p2.z);
glColor3f( color.x, color.y, color.z );

}


Anyone able to help at all?

[edited by - voodoo_john on April 14, 2004 6:10:18 PM]

Share this post


Link to post
Share on other sites
Acht come on guys! Surely somebody knows how to fix this!

When people say that there''s nothing left to write articles about, THIS kind of thing is exactly what is needing to be written about

Share this post


Link to post
Share on other sites
I can tell you it's probably an off-by-one error in either the loop condition or the texture-coordinate generation, but I doubt that helps much.

Why are you starting at startRotationSlice instead of at 0? If startRotationSlice != 0, then your theta3 should be (I think)

(i - startRotationSlice) * TWOPI / float(rotationSlices-startRotationSlice)

It's something like that anyway, if you're lucky someone will come along, tell me how wrong I am, and give you the correct answer.

[edit: darn line breaks never go where ya want them]

[edited by - fractoid on April 15, 2004 6:04:08 AM]

Share this post


Link to post
Share on other sites
Hey Fractoid,

Both the starting params in the loops start at 0, I just have them as variables for testing pruposes. Still no joy

The reason im going down this route is I want the dome geometry generation code separate from the sky shading code.

Thanks for replying :D

Share this post


Link to post
Share on other sites
From the screenshot it looks like there is z-fighting, perhaps you''re drawing 2 tris on top of each other or very close at that point? Drawing the dome in wireframe might give you a better view of any extra unwanted geometry.

Share this post


Link to post
Share on other sites
Didn''t look at the source yet but I was going to say the same thing, those jaggies are always a sign of z-buffer aliasing/fighting ...

Have you tried drawing the skybox first with glDisable(GL_DEPTH_TEST); and glDisable(GL_CULL_FACE); and then render the landscape ??

Share this post


Link to post
Share on other sites
Hi Paulc,

Yeah that thought had occured to me also, but the wireframe looks perfect. I will post a screenshot later.

Thing is when I texture it, there is a strange black seam like the traingles are not meeting..... Ag!

Edit: Also when you look at the dome, the left side is much darker than the right side... Why-oh-why?!

[edited by - voodoo_john on April 15, 2004 11:26:26 AM]

Share this post


Link to post
Share on other sites
Weyland,

Thanks for pointing that out, I'll test it when I get home.

Im getting old you see... too long in project management and you forget the obvious things :D

However, I have discoverd a kinds problem with the shading. I can get the sky color to change to what looks like appropriate colors, but the horizon is always lighter than the rest of the sky no matter what sun angle you use. Will post code later.

EDIT: Spelling

[edited by - voodoo_john on April 15, 2004 12:34:08 PM]

Share this post


Link to post
Share on other sites
Hi Guys,

Ok here are two new screenshots:


Clicky1


Clicky2

First picture is supposed to be 90 degree sun angle, turbidity=1
Second picture is supposed to be 45 degree sun angle, same T.

As you can see, something is clearly wrong

I wouldn't mind the colors, if there was the expeted sun bloom which there isnt. It seems perpetually confined to the horizon

Any ideas?



#include <cmath>
#include "CSkyColor.h"

#define PI 3.14159265
#define SQR(x) x*x

CSkyColor::CSkyColor()
{
suntheta = 0.0f;
T = 0.0f;
}

inline float CSkyColor::PerezFunction_x(float cosTheta, float cosGamma, float gamma)
{
float val1 = ( 1 + Ax * exp(Bx / cosTheta ) ) * ( 1 + Cx * exp(Dx * gamma) + Ex * SQR(cosGamma) );
float val2 = ( 1 + Ax * exp(Bx) ) * ( 1 + Cx * exp(Dx * suntheta) + Ex * SQR(cosSTheta) );

return val1 / val2;
}

inline float CSkyColor::PerezFunction_y(float cosTheta, float cosGamma, float gamma)
{
float val1 = ( 1 + Ay * exp(By / cosTheta) ) * ( 1 + Cy * exp(Dy * gamma ) + Ey * SQR(cosGamma ) );
float val2 = ( 1 + Ay * exp(By ) ) * ( 1 + Cy * exp(Dy * suntheta) + Ey * SQR(cosSTheta) );

return val1 / val2;
}

inline float CSkyColor::PerezFunction_Y(float cosTheta, float cosGamma, float gamma)
{
float val1 = ( 1 + AY * exp(BY / cosTheta) ) * ( 1 + CY * exp(DY * gamma ) + EY * SQR(cosGamma) );
float val2 = ( 1 + AY * exp(BY ) ) * ( 1 + CY * exp(DY * suntheta) + EY * SQR(cosSTheta) );

return val1 / val2;
}

void CSkyColor::SetInfo(float SunTheta, float Turbidity)
{
suntheta = SunTheta;
T = Turbidity;

T2 = T * T;
suntheta2 = suntheta * suntheta;
suntheta3 = suntheta * suntheta2;

Ax = -0.01925 * T - 0.25922;
Bx = -0.06651 * T + 0.00081;
Cx = -0.00041 * T + 0.21247;
Dx = -0.06409 * T - 0.89887;
Ex = -0.00325 * T + 0.04517;

Ay = -0.01669 * T - 0.26078;
By = -0.09495 * T + 0.00921;
Cy = -0.00792 * T + 0.21023;
Dy = -0.04405 * T - 1.65369;
Ey = -0.01092 * T + 0.05291;

AY = 0.17872 * T - 1.46303;
BY = -0.35540 * T + 0.42749;
CY = -0.02266 * T + 5.32505;
DY = 0.12064 * T - 2.57705;
EY = -0.06696 * T + 0.37027;

xz = ( 0.00165 * suntheta3 - 0.00375 * suntheta2 + 0.00209 * suntheta + 0.00000) * T2 +
(-0.02903 * suntheta3 + 0.06377 * suntheta2 - 0.03202 * suntheta + 0.00394) * T +
( 0.11693 * suntheta3 - 0.21196 * suntheta2 + 0.06052 * suntheta + 0.25886);

yz = ( 0.00275 * suntheta3 - 0.00610 * suntheta2 + 0.00317 * suntheta + 0.00000) * T2 +
(-0.04214 * suntheta3 + 0.08970 * suntheta2 - 0.04153 * suntheta + 0.00516) * T +
( 0.15346 * suntheta3 - 0.26756 * suntheta2 + 0.06670 * suntheta + 0.26688);

float X = (4.0f / 9.0f - T / 120.0f) * (PI - 2 * suntheta);

Yz = ((4.0453f * T - 4.9710) * tan(X) - 0.2155 * T + 2.4192) * 1000.0f;
}

CVector3 CSkyColor::ToRGB(float x, float y, float Y)
{
float fX, fY, fZ;

fY = Y;
fX = x / y * Y;
fZ = ((1.0f - x - y) / y) * Y;

float r, g, b;

r = 3.2404f * fX - 1.5371f * fY - 0.4985f * fZ;
g = -0.9692f * fX + 1.8759f * fY + 0.0415f * fZ;
b = 0.0556f * fX - 0.2040f * fY + 1.0573f * fZ;

float expo = -(1.0f / 10000.0f);
r = 1.0f - exp(expo * r);
g = 1.0f - exp(expo * g);
b = 1.0f - exp(expo * b);

if (r < 0.0f) r = 0.0f;
if (g < 0.0f) g = 0.0f;
if (b < 0.0f) b = 0.0f;
if (r > 1.0f) r = 1.0f;
if (g > 1.0f) g = 1.0f;
if (b > 1.0f) b = 1.0f;


CVector3 rgb;
rgb.x = r;
rgb.y = g;
rgb.z = b;

return rgb;
}


CVector3 CSkyColor::GetVertexColor(float th, float gm)
{
float x, y, Y;
float cosTheta, cosGamma;

if (th == PI / 2)
cosTheta = 0.0000001f;
else
cosTheta = cos(th);

cosGamma = cos(gm);
cosSTheta = cos(suntheta);

x = xz * PerezFunction_x(cosTheta, cosGamma, gm);
y = yz * PerezFunction_y(cosTheta, cosGamma, gm);
Y = Yz * PerezFunction_Y(cosTheta, cosGamma, gm);

CVector3 rgb = ToRGB(x, y, Y);

return rgb;

}


Thanks again!

EDIT: Forgot to mention TEH JAGGIES. The seem less prominent now, and if you look closely the remaining artifacts seem to be shading errors....

I promise if I nail this to write a tutorial, cause this topic needs hit on the head once and for all :D

[edited by - voodoo_john on April 15, 2004 12:42:55 PM]

[edited by - voodoo_john on April 16, 2004 10:21:05 AM]

Share this post


Link to post
Share on other sites
Ok I''m pulling my hair out with this, I''ve tried palying with the parameters and scaling this and that and it''s STILL wrong :''(

Is there anybody that can help me out here?

Share this post


Link to post
Share on other sites
Well, I can't directly help you, but maybe we can help each other. I've been working on coding this a while ago, but gave up due to incorrect results.

If you like, maybe we could compare our outputs, and see where it goes wrong, thereby hopefully fixing both our codes.

About the thing with the seam, it most probably is an off by one error or something like that. In my code I first generate the vertices, then the tris between them. Only then do I send each vert to be shaded according to the paper. I had similar problems first as well, but they seem to be gone now.

Mail me if you feel like teaming up (mail addresse is under my profile when you're logged in)

[edited by - rick_appleton on April 20, 2004 8:41:33 AM]

Share this post


Link to post
Share on other sites

  • Advertisement