# How to calculate lighting by point light with size of the lightsource like Sun?

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

## Recommended Posts

I calculate lightWeighting with that:
lightDirection = normalize(pointLightsPosition - vPosition.xyz);
normal = normalize(vTransformedNormal);
eyeDirection = normalize(-vPosition.xyz);
reflectionDirection = reflect(-lightDirection, normal);
specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), pointLightsParamsf[0]);
diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
lightWeighting = ambient + diffuse * diffuseLightWeighting + specular * specularLightWeighting;

It is point light source in pointLightsPosition, how to calculate lightWeighting if light source has a size like radius(Sun, lamp etc.)?
Thanks.

##### Share on other sites

You split it into smaller point light sources? I like analytical solutions to integrals, but somehow that is not the direction the development has taken (quality / render time).

##### Share on other sites
You can use the form factor of a disc pointing towards sample position:
qVec3 diff = ePos - rPos; //  emitter (disc) - receiving sample position
float dR = dot(rDir, diff); // rDir = receiver normal
if (dR > FP_EPSILON)
{
float dE = -dot(eDir, diff); // eDir = disc normal
if (dE > FP_EPSILON)
{
float sqD = dot(diff, diff);
float formFactor = (dR * dE) / (sqD * (PI * sqD + discArea)) * discArea;

qVec3 light = eLuminosity * eCol;
}
}
If that works for you, you could try to optimize for a sphere.
The code snippet below should help to understand the math.
It projects a sphere to the hemisphere and then to the normal plane of the sample (We want to know the area if the projected shape).
The disc is approximated then by a simple dot product (assuming orthonormal projection and ignoring perspective).
A disc intersecting the normal plane is also approximated only with a dot product -> some error when disc is large and close to sample.

inline void ProjectDisc (
qVec3 &ray, float &hemiSphereProjectedAreaByPI,
const qVec3 &relPos, const qVec3 &discDir, const qMat3 &local) // todo: remove matrix and give localRay instead
{
// Note: Disc direction is assumed to point towards the sample position!

float sqDist = relPos.SqL() + FP_TINY;
ray = local.Unrotate(relPos);
hemiSphereProjectedAreaByPI = -(ray[2] * discDir.Dot(relPos)) /
(sqDist * (PI * sqDist + discDir[3])) * discDir[3]; // discDir[3] = disc area

ray /= sqrt(sqDist);

//		unoptimized math:
//
//			planeArea = unitArea * ray[2];
//			planeArea *= fabs (discDir.Dot(ray));
//			planeAreaByPI = planeArea / PI;
//
//			float solidAngle = atan (radius * ooDist);
//			RenderCone (qVec3(0,0,0), (qVec3&)ray, solidAngle, 0,0.5,1, 1,0,0);
//			RenderCircle (sin(solidAngle), (qVec3&)(ray * cos(solidAngle)), (qVec3&)ray, 0,0.5,1);
}
Edited by JoeJ

##### Share on other sites
Just found another snippet for just a sphere:
float unitRad = rad / dist; // disk radius of sphere projected to hemisphere // == sin(solidAngle);
float planeArea = unitArea * ray[2]; // area on sample plane projection // ray[2] = sampleNormal.Dot(ray)
Those values are accurate as long as the sphere does not intersect the sample normal plane.
(For sun that case should go totally unnoticed)

Hope there's no bug (i've kept this in comments too because the math is confusing). Edited by JoeJ

##### Share on other sites

>> how to calculate lightWeighting if light source has a size like radius(Sun,

for something like a space flight sim, you'd probably want to use directional lights for nearby stars, with  lots of ambient, and very little diffuse.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013739
×