POV-Ray : Newsgroups : povray.general : Specular Lens Flares? Server Time
19 Nov 2024 13:39:32 EST (-0500)
  Specular Lens Flares? (Message 1 to 6 of 6)  
From: Andrew Cocker
Subject: Specular Lens Flares?
Date: 11 Mar 2002 09:07:39
Message: <3c8cba2b@news.povray.org>
Hi,

Assuming we have a sphere and one point light source, is it possible to work
out the point on the sphere where the specular highlight is, *and then* pass
that vector to Chris Colefax's Lens Effects include file? I *could* place
the flare by trial and error, but would like to animate the scene.

Andy


Post a reply to this message

From: Hugo
Subject: Re: Specular Lens Flares?
Date: 11 Mar 2002 09:59:27
Message: <3c8cc64f$1@news.povray.org>
Hi Andrew,

Yes, that is possible with a sphere. Not sure about more complex objects. I
suggest you take a look at the documentation for Pov3.5 :

4.2  POV-Ray SDL tutorial: A raytracer

- And the sub texts, I think they will give you exactly what you're looking
for.

Regards,
Hugo


Post a reply to this message

From: Micha Riser
Subject: Re: Specular Lens Flares?
Date: 20 Mar 2002 12:15:00
Message: <3c98c394@news.povray.org>
Andrew Cocker wrote:
> Assuming we have a sphere and one point light source, is it possible to
> work out the point on the sphere where the specular highlight is, *and
> then* pass that vector to Chris Colefax's Lens Effects include file? I
> *could* place the flare by trial and error, but would like to animate the
> scene.

Are you still looking for a solution to the problem? I think I just have 
seen the solution for an equivalent problem.


Post a reply to this message

From: Andrew Cocker
Subject: Re: Specular Lens Flares?
Date: 20 Mar 2002 14:52:07
Message: <3c98e867@news.povray.org>
"Micha Riser" <mri### [at] gmxnet> wrote in message
news:3c98c394@news.povray.org...

> Are you still looking for a solution to the problem? I think I just have
> seen the solution for an equivalent problem.

I haven't had time to act upon the previous suggestion made to me, so 'Yes',
I'm still interested in any other suggestions you may have.

Ideally, what I'd like to be able to do, is this:

Wherever a specular highlight on an object occurs, if that highlight is
above a certain brightness threshold, then place a lens flare there, with an
equivalent brightness, size etc. Obviously this wouldn't work (or would be
impractical) for objects with many specular highlights - where a surface
normal is used for example, but on simpler objects it should work ok I
think.

Dunno if your solution will help me get anywhere close to achieving this,
but please let me know what you have found.

All the best,

Andy Cocker


Post a reply to this message

From: Micha Riser
Subject: Re: Specular Lens Flares?
Date: 21 Mar 2002 13:33:05
Message: <3c9a2755@news.povray.org>
Andrew Cocker wrote:
> Ideally, what I'd like to be able to do, is this:
> 
> Wherever a specular highlight on an object occurs, if that highlight is
> above a certain brightness threshold, then place a lens flare there, with
> an equivalent brightness, size etc. Obviously this wouldn't work (or would
> be impractical) for objects with many specular highlights - where a
> surface normal is used for example, but on simpler objects it should work
> ok I think.

You can calculate the exact point of the highlight with planes and spheres 
(and objects constructed of only these two things like meshs for example) 
when there is no normal pertubation. With all other objects and pertubated 
normals the highlights can be of any shape and you may have difficulty 
where to place the lens flare even when doing by hand.

A highlight occurs where the light rays from the light source are directly 
reflected into the camera (and the surface supports this). If you put some 
objects at the place where the light source is and make the highlighting 
object reflective you will see the reflection of that object where 
previously the highlight was. Equivalently if you shoot a ball from the 
camera to the point of hightlight it will hit the light source.

Calculating the highlight on a plane is easy: Just mirror the lightsource L 
at the plane (-> L') and intersect the line camera-L' with the plane. Of 
course there is only a highlight visible at the intersection point P if 
nothing is between the camera and P and nothing between P and the 
lightsource.

Following I will provide a solution for calculating the mid-point of 
specular highlights on a sphere. First you can reduce the problem from 3D 
to 2D: the camera, the light source, the sphere's midpoint and the 
highlighting point lie all in the same plane. Therefore you can restrict 
all calculations to this plane.

To make calculation easier I place the camera at position <a,0,0>, the 
light source at position <px,py,0> and the sphere at the origin with radius 
1. If you want a general solution you can always rotate, translate and 
scale things so that they come to lie in that way.

Let n be the vector pointing from the origin to the highlighting point R,
q the vector <a,0,0> and p the vector <px,py,0>. Now we mirror q at the 
tangent in R and get q'. 

If n is the solution then the vectors n-q' and p-n have to be collinear:

        l(n-q')=p-n

where l is a factor and l>=0.

I do not provide more mathematics of the solution here. If you know a bit 
German you might have a look at
        http://www.wr.inf.ethz.ch/education/nsr/exercises/ex12/ex.ps and
        http://www.wr.inf.ethz.ch/education/nsr/exercises/ex12/sol.ps
where two ways of solving an equivilent problem are presented.

You can reduce the problem to a 4th-order polynom equation only having 'l' 
as unknown:

a^2*(a^2-1) * l^4  +  2a(a-px) * l^3  +  
(4a*px-a^2-(px^2-py^2)*(1+2a^2)) * l^2 + 2(px^2+py^2-a*px) * l +
(px^4+py^4+2px^2*py^2-px^2-py^2) == 0

Now one needs to find the roots of this polynom and with that you can 
calculate n:

            l-1
n =  ------------------- * <a*l+px,py,0>
      a^2*l^2-px^2-py^2

With that you find all possible points of highlights. However some of them 
can be hidden by the sphere itself. For example if both camera and 
lightsource are outside the sphere you will see at most one highlight. But 
when the sphere is partly open or transparent you can see highlights in the 
inner. You can use the trace() function to check if highlights are hidden 
or not.

If both camera and lightsource are inside the sphere you will have up to 4 
highligths. All of them are found as roots of the polynom above.

Calculation of n fails when |a|=||p|| (division zero by zero) but this 
happens to be a special case where it is easy to calculate the highlights 
differently.

I have written a macro which calculates the position of highlights in the 
way mentioned above. However it uses a clumsy implementation of Newton's 
algorithm to calculate the roots and does not always find the relevant ones.
(Shouldn't there be a standard macro for doing that?).

Macro is in p.t.s-f.


An alternative way to find the highlights is to do it the way a ray-tracer 
does: It does not find the midpoints of them but can calculate how bright 
the highlight is at some point. So you could for example use povray to 
trace a picture of your scene where you have all textures replaced so that 
everything is black except the highlights. Then you would have to find the 
centers of the highlights showing up in the resulting picture and could 
trace() at those points to find where to place the light flare.

- Micha


Post a reply to this message

From: Andrew Cocker
Subject: Re: Specular Lens Flares?
Date: 22 Mar 2002 11:50:47
Message: <3c9b60e7@news.povray.org>
Micha,

Thankyou very much for this.. I will go and play with it now...

All the best,

Andy Cocker


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.