POV-Ray : Newsgroups : povray.advanced-users : Phong BRDF pigment { function{} } : Phong BRDF pigment { function{} } Server Time
23 Feb 2024 18:04:32 EST (-0500)
  Phong BRDF pigment { function{} }  
From: Bald Eagle
Date: 11 Nov 2022 19:45:00
Message: <web.636eec0e210cb4a81f9dae3025979125@news.povray.org>
So, I have puzzled out the important parts of the importance sampling, and want
to move ahead to seeing how it affects a reflection model.

I had already worked out the fundamentals of the Phong model:


And so just needed to work out how to put all of that in vector component
separated and daisy-chained functions so I could texture a sphere.

It seems like I've got the basics down, however I'm needing to divide my angle
between the reflection vector and camera vector by 4, otherwise I get a HUGE
phong highlight.

My reflection vector calculation also seems to be sign inverted.


Also, even though I'm doing

function {min (max (Specular (x, y, z), 0), 1)}

I still seem to be veering out of the 0-1 range when my shininess factor  (the
phong exponent) goes below 2.  Weird.

I would love to get everything ironed out so as to not have to worry about weird
fudge factors, so that when I puzzle out and refine applying the importance
sampling part, I can focus on the real issues and not be chasing ghosts in the

#declare SFn_vdot = function (ax, ay, az, bx, by, bz) {ax*bx + ay*by + az*bz}

#declare RX = function {L_hatX - (2 * SFn_vdot (L_hatX, L_hatY, L_hatZ, x, y,
z)) * x}
#declare RY = function {L_hatY - (2 * SFn_vdot (L_hatX, L_hatY, L_hatZ, x, y,
z)) * y}
#declare RZ = function {L_hatZ - (2 * SFn_vdot (L_hatX, L_hatY, L_hatZ, x, y,
z)) * z}

#declare R_hatX = function {RX (x , y, z) / SFn_vlength (RX (x , y, z), RY (x ,
y, z), RY (x , y, z))}
#declare R_hatY = function {RY (x , y, z) / SFn_vlength (RX (x , y, z), RY (x ,
y, z), RY (x , y, z))}
#declare R_hatZ = function {RZ (x , y, z) / SFn_vlength (RX (x , y, z), RY (x ,
y, z), RY (x , y, z))}

#declare Specular = function {k_s * pow (SFn_vdot (-R_hatX (x, y, z), -R_hatY
(x, y, z), -R_hatZ (x, y, z), V_hatX, V_hatY, V_hatZ)/4, _alpha) * i_s}

The sphere on the left is a isosurface with finish {phong 1}, and the one on the
right is pigmented according to my Phong specular reflectance function.

Post a reply to this message

Download 'importancesampledphongbrdf.png' (68 KB)

Preview of image 'importancesampledphongbrdf.png'


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