Skip to content

RGL plot : lighting problem when triangle3d and persp3d are used in the same plot

4 messages · Stephane Chantepie, Duncan Murdoch

#
On 27/08/2012 1:47 PM, Stephane Chantepie wrote:
You need to set the normals at the vertices that are shared with the 
persp3d vertices.  rgl internally averages the normals to the pieces 
making up each facet; you don't have enough access to the internals to 
do that.  (You'd want to change the normal on the surface, as well, 
because your triangles should participate in the averaging.)

But you could set the normals to the new triangle to match the normal to 
the one it joins to, and get something that looks sort of okay.  It's 
not going to be a simple calculation:  you need to figure out the 
coordinates of the edges joining at those vertices, take a cross 
product, and use that.  See ?rgl.primitive for how to send the normals 
to points3d; I think the normals need to be length 1, but that may be 
forced internally.

If you were really ambitious, you could take a look at the C++ code that 
draws the surface, and contribute code to smooth the edge properly; I 
think it would be an improvement over the current behaviour, but it is 
tedious to write.

Duncan Murdoch
#
On 28/08/2012 7:49 AM, Stephane Chantepie wrote:
Thanks, I didn't know about those functions.

Duncan Murdoch