[R] positioning a light source within a rgl-plot

Alexander Senger senger at physik.hu-berlin.de
Sun Feb 17 16:02:18 CET 2013


Am 27.01.2013 16:48, schrieb Duncan Murdoch:
> On 13-01-27 10:37 AM, Alexander Senger wrote:
>> Hello useRs,
>>
>>
>> I would like to draw a 3D-surface using rgl with a point-like
>> light-source within the scene, that is with finite distance of the
>> light-source to the surface to be lit.
> 
> The rgl package doesn't support that.
> 
>>
>>> From the help to the 'light3d' command I read:
>>
>> "They [the light-sources] are positioned either in world space or
>> relative to the camera using polar coordinates."
>>
>> which *could* be understood as if such a thing would be possible. But
>> probably this is wishful thinking as my naive approach:
>>
>> light3d(x = 0, y = 0, z = 1)
> 
> There are no x, y, z arguments to light3d.  Only directional sources at
> infinite distance are supported.
>>
>> gives an error about un-used arguments in the function call. Also
>> skimming the web does not produce any helpful examples.
>>
>> So please advise if there is a way to achieve my desired setting.
>> Alternatively any hint how and where to make (moderate) modifications to
>> the source code to get this functionality would be very welcome.
> 
> It's rather tedious to make the changes.  You need to change rgl.light,
> the rgl_light function in api.cpp that it calls, and the parts of
> light.hpp and light.cpp that are called by that.  For completeness you'd
> also want to fix writeWebGL and scene3d and the functions they call.
> 
> Duncan Murdoch


Hi Duncan,


thank you very much for your helpful advice.

At the moment I have everything working except writeWebGL. I had a fair
look into the matter and thought about implementing a slightly more
sophisticated per-fragment shading and including all 8 light sources
available in OpenGL.

However I wonder that you probably had very good reason to limit the
functionality to the simpler lighting model as is. Maybe you could share
some thoughts on why making the lighting more complex might not be such
a good idea, before I put too much effort into this topic.


Thanks again,

Alexander Senger



More information about the R-help mailing list