Object with texture as local light source

407 views
Skip to first unread message

stefan....@web.de

unread,
Apr 21, 2017, 1:55:33 PM4/21/17
to VPython-users
Hello,

I am really desperate looking for a way to create an object with a texture that is illuminated by itself
. I want to create a solar system with realistic textures, light and shadow. Everything works fine. However, as soon as I lay a texture over my sun, which is the only light source, the planets are still illuminated, but the sun itself becomes dark. Is there any way to illuminate the sun without distant light sources?
Example code with texture in appendix:

import visual as vs
import Image

scene
= vs.display( title   = "Sun",
                    lights  
= [],
                    ambient
= 0,
                 
)

sun
= vs.sphere( pos    = (0, 0, 0),
                 radius
= 1,
                 color  
= vs.color.white,
                 material
= vs.materials.emissive,
               
)

texture  
= 'sun.jpg'
width    
= 1024
height  
= 512
image    
= Image.open( texture )
image    
= image.resize( (width, height), Image.ANTIALIAS )
material
= vs.materials.texture( data=image, mapping="spherical" )

sun.material = material

lt1
= vs.local_light( pos = (0, 0, 0), color=vs.color.white )

Thanks for your answers!

Stef
sun.jpg

Bruce Sherwood

unread,
Apr 21, 2017, 7:38:04 PM4/21/17
to VPython-users
There isn't a way in Classic VPython to specify a material (texture) and also specify that the material be emissive. However, you might consider setting ambient to (1,1,1), in the absence of other lights, and delete your local light.

stefan....@web.de

unread,
Apr 22, 2017, 2:50:01 AM4/22/17
to VPython-users
Hi Brude,

thanks for your quick reply.

Too bad. Then I have to say goodbye to either the idea of ​​the realistic lighting and shadowing or the pretty pictures.

Well, so be it.
SolarSIM.PNG

stefan....@web.de

unread,
Apr 22, 2017, 2:51:35 AM4/22/17
to VPython-users
Sorry for the typo. I meant Bruce.

Bruce Sherwood

unread,
Apr 22, 2017, 8:51:26 AM4/22/17
to VPython-users
No version of VPython supports shadows, though it is likely that eventually shadows will be supported in the GPU-based GlowScript VPython (and therefore also Jupyter VPython, which uses the same WebGL library). The handling of opacity in the GlowScript library uses a "depth-peeling" GPU technique that is related to what one has to do to handle shadows.

Bruce

Paul Voytas

unread,
Sep 6, 2020, 11:14:58 AM9/6/20
to VPython-users
Hi Bruce,
two related questions then:
1) When lights illuminate an object, the surfaces are obviously lit in a directional way. What is this if not shadows?
2) I also am working on a solar system model and would like to make the sun the light source and turn off all the other light sources. When I tried:

scene.lights=[]
lamp = local_light(pos=vector(0,0,0),
                      color=color.yellow)
earthorb=1.0
moonorb=0.2
sun=sphere(pos=vec(0,0,0), radius=0.1, color=color.yellow, emissive=True)
earth=sphere(pos=vec(earthorb,0,0), radius=0.05, color=color.green)
moon=sphere(pos=vec(earthorb+moonorb,0,0), radius=0.01, color=color.white)

I still see ambient lighting and I don't obviously see light from the sun. I thought this was the proper syntax from: https://www.vpython.org/contents/docs/lights.html

Any guidance much appreciated!
-Paul

On Saturday, April 22, 2017 at 8:51:26 AM UTC-4

Bruce Sherwood

unread,
Sep 6, 2020, 12:37:41 PM9/6/20
to VPython-users
To turn off ambient light, just add scene.ambient = color.black. I don't understand "I don't obviously see light from the sun": the sides of your Earth and Moon facing the Sun are illuminated, and the other sides are not illuminated (once ambient light is turned off). The fact that VPython doesn't deal with shadows is seen by the fact that your Moon should be eclipsed by the Earth but isn't.

Bruce

Paul Voytas

unread,
Sep 6, 2020, 9:56:38 PM9/6/20
to VPython-users
My apologies: I didn't paste *exactly* what my code was. I left out a
canvas(width=700, height=700)
when this is included before the other code I showed earlier the ambient lights stay on. Full code where ambients stay on:

GlowScript 3.0 VPython
from vpython import *

canvas(width=700, height=700)

scene.lights=[]
lamp = local_light(pos=vector(0,0,0),
                      color=color.yellow)
earthorb=1.0
moonorb=0.2
sun=sphere(pos=vec(0,0,0), radius=0.1, color=color.yellow, emissive=True)
earth=sphere(pos=vec(earthorb,0,0), radius=0.05, color=color.green)
moon=sphere(pos=vec(earthorb+moonorb,0,0), radius=0.01, color=color.white)

If i comment out the canvas it works. I see now that was a leftover from my stumbles in updating to python3 and probably it defines a new (un-named?) scene with it's own ambients that were not affected by the scene.lights=[] setting.

Thanks--your comments helped me find my stupid error.
-Paul

Bruce Sherwood

unread,
Sep 7, 2020, 11:38:34 AM9/7/20
to VPython-users
For the record, at the start of a program VPython automatically executes "scene = canvas()" and creating a 3D object activates that canvas. If however you execute "canvas()", 3D objects will go into that (unnamed) canvas. By default, 3D objects go into the most recently executed canvas() statement.

Bruce

Reply all
Reply to author
Forward
0 new messages