|
![](/i/fill.gif) |
> In summary, it appears that implementing reflection is mathematically
> impossible. I may perhaps still be able to realise my dream of rendering
> depth of field effects realistically. (Although without a nice detailed
> scene to look at, it might be rather disappointing...)
Obviously it's not, because there are plenty of shadertoy examples
showing it:
https://www.shadertoy.com/view/4ssGWX
Surfaces that reflect *OR* refract are trivial:
for(i=0;i<MAX_TRACE_DEPTH;i++)
{
intersect = Trace( ray );
if( REFLECT(intersect) ) ray = ReflectRay(ray , intersect);
if( REFRACT(intersect) ) ray = RefractRay(ray , intersect);
}
To do surfaces that do both you need to choose randomly at each
intersection which ray to follow (weighted appropriately depending on
the material) and then average over a larger number of samples. You can
either do many samples per frame (but obviously this gets slow for
complex scenes), or what is commonly done is to average over many frames
(and reset the average if the camera is moved). Or both.
Post a reply to this message
|
![](/i/fill.gif) |