Practical Analytical Daylight Problems

Started by
15 comments, last by voodoo_john 20 years ago
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*xCSkyColor::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]
Advertisement
*bump*
So is this one of these topics that everybody talks about but don''t really know it?
help!
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?
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]
Hi Rick,

I''ve emailed you. Thanks for your help.

This topic is closed to new replies.

Advertisement