Jump to content
• Advertisement

# [Glsl] Spherical Area Light For Ggx Specular

This topic is 873 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

I have a GGX shader for specular highlights.

I have some point lights.

I already have attenuation calculation for spherical area lights.

I yet don't have area light calculation for specular. And I don't know how to calculate it correctly.

Would be nice to get some help! :)

Note. GGX specular is inside DisneyBRDF-like shader.

Edited by adriansnetlis

#### Share this post

##### Share on other sites
Advertisement

The easiest solution is the "representative direction" method, though it's not accurate when it comes to energy conservation (overall, it will be too bright, especially for large sphere), etc... but is still a good place to get started :)

* First calculate the reflection direction like you would for Phong specular (R = reflect(V,N)).

* Form a ray originating from the surface and traveling along this reflection direction.

* Find the closest point on the sphere to this ray (or: find closest point on the ray from the center of the sphere, then the closest point on the sphere to that first point).

*^ If the ray intersects the sphere, the answer is either of the intersection points between the ray and the sphere!

* Create a new "representative reflection direction", which is the direction from the surface to this point on the sphere.

* Run your specular code as usual (for a point light), but use this "representative reflection direction" as the lighting direction.

With a zero-sized sphere, the representative direction will always be equal to the original lighting direction, so you get the same results as a point light.

With larger spheres, the lighting direction gets shifted a little bit so that every surface is getting lit by a slightly different point light -- one that's placed somewhere on the surface of your sphere, to give the impression that there's actually a sphere-light in your scene :D

Edited by Hodgman

#### Share this post

##### Share on other sites

Uh... Not as easy as I thought. Appearantly the physics of a tire is a bit simplier topic:D

Well, what is the math for ray intersection test? I have never ever made raytracers or anything like that.

#### Share this post

##### Share on other sites

Well, what is the math for ray intersection test? I have never ever made raytracers or anything like that.

It's not that complex in this case.

Use this to compare the line (x1 = surface, x2 = surface + reflection) with the center of the sphere:

http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html

The resulting point will be inside the sphere in the case of an intersection.

e.g. bool is_inside = distance(sphere_center, closest_point_on_line) < radius

If that's true, use the reflection direction as the lighting direction.

Otherwise, find the closest point on the surface of the sphere to the above point:

http://math.stackexchange.com/questions/324268/how-do-i-find-the-nearest-point-on-a-sphere

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5
• Advertisement

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633674
• Total Posts
3013275
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!