[R] rgl and lighting

james.foadi at diamond.ac.uk james.foadi at diamond.ac.uk
Fri Sep 10 11:45:05 CEST 2010


Yes. A white cube and all lights off to start with give me what I want.

Many thanks!

J

Dr James Foadi PhD
Membrane Protein Laboratory (MPL)
Diamond Light Source Ltd
Diamond House
Harewell Science and Innovation Campus
Chilton, Didcot
Oxfordshire OX11 0DE

Email    :  james.foadi at diamond.ac.uk
Alt Email:  j.foadi at imperial.ac.uk



-----Original Message-----
From: Duncan Murdoch [mailto:murdoch.duncan at gmail.com]
Sent: Thu 09/09/2010 18:00
To: Foadi, James (Imperial Coll.,RAL,DIA)
Cc: r-help at r-project.org
Subject: Re: [R] rgl and lighting
 

  On 09/09/2010 12:02 PM, james.foadi at diamond.ac.uk wrote:
> Dear R community (and Duncan more specifically),
> I can't work out how to make additional light sources work in rgl.
> Here is the example.
>
> First I create a cube and visualize it:
>
> >  cubo<- cube3d(col="black")
> >  shade3d(cubo)
>
> Next I position the viewpoint at theta=0 and phi=30:
>
> >  view3d(theta=0,phi=30)
>
> Next, I want to create a 2nd light source which diffuses red light from the front face. I thought I could do:
>
> >light3d(diffuse="red",theta=0,phi=0)
>
> but...the front side doesn't show any red-iness. Same goes for specular and ambient.
> What am I doing wrong here? How should the fron side show in red colour?

Black doesn't reflect anything, so that's why you're not seeing the 
red.  Colour the cube white, and you'll see it turn pink when you turn 
the red light on, or red if you turn off the default light first (using 
rgl.pop("lights")).

Be aware that OpenGL (underlying rgl) has a fairly complicated lighting 
model.  When you say col="black", you're only setting the "ambient" 
colour, i.e. the colour that appears the same in all directions. (It 
won't be the same on all faces of the cube, because the intensity 
depends on the incoming light.) There is also a "specular" component, 
which makes things appear shiny, because it's brighter from some 
viewpoints than others.  It is normally white.  Finally there's an 
"emission" component, which doesn't care about lighting, but is normally 
turned off.

Lights also have 3 components, "ambient" (non-directional), "diffuse" 
(somewhat directional), and "specular" (highly directional).

Duncan Murdoch

> J
>
> Dr James Foadi PhD
> Membrane Protein Laboratory (MPL)
> Diamond Light Source Ltd
> Diamond House
> Harewell Science and Innovation Campus
> Chilton, Didcot
> Oxfordshire OX11 0DE
>
> Email    :  james.foadi at diamond.ac.uk
> Alt Email:  j.foadi at imperial.ac.uk
>
>



-- 
This e-mail and any attachments may contain confidential...{{dropped:8}}



More information about the R-help mailing list