Tweaking the source code...

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
Evil Dr Ganymede
Posts: 1386
Joined: 06.06.2003
With us: 21 years

Tweaking the source code...

Post #1by Evil Dr Ganymede » 08.06.2003, 07:07

Has anyone tried tweaking the source code for Celestia?

I was wondering how straightforward it'd be to change it so that one could (a) have multiple light sources in a single system and (b) have proper stars (not fake ones) orbiting other stars.

So far I just found this one reference in the astro.cpp file:

// Compute the fraction of a sphere which is illuminated and visible
// to a viewer. The source of illumination is assumed to be at (0, 0, 0)
float astro::sphereIlluminationFraction(Point3d spherePos,
Point3d viewerPos)
{
return 1.0f;
}


I think the body.cpp file might have the stuff that tells you what goes in the stellar systems...

Has anyone tried changing the code? Or can anyone provide pointers to the files that contain this sort of information? Or am I just totally on my own here?

marc
Posts: 426
Joined: 13.03.2002
With us: 22 years 3 months
Location: Outback Australia

Re: Tweaking the source code...

Post #2by marc » 08.06.2003, 07:32

Both of these feature requests have come up before it might be worth doing a search of the forum.
Ive been fiddling with the Celestia code for about a year and i still dont know how half of it works. Im only a newbie at OpenGL but I think you would need to be pretty good at it to implement the multiple light sources. As for the orbiting stars issue I think that is a real tricky one because celestia treats stars as fixed points with respect to the galaxy.

If i were to have a go at it id have an invisible star then have the 'fake' stars orbiting the invisible point.

Topic author
Evil Dr Ganymede
Posts: 1386
Joined: 06.06.2003
With us: 21 years

Post #3by Evil Dr Ganymede » 08.06.2003, 07:53

Well, I don't pretend to be an expert in programming (other than in Fortran :D ) , so I'm just bumbling along looking through the source... I just thought/hoped it'd be a case of changing some little thing so that stars were treated like planets.

One thing that might be interesting to implement is light attenuation. Light drops off by an inverse square law, so (for example) the sun should be 25 times less bright as seen from Jupiter than it is from the Earth, since it's about 5 times further from the sun than the Earth. So I presume that when you look at Jupiter from jovian orbit, the illuminated half shouldn't be all that bright. I don't know if Celestia does this already, but it'd be interesting to see it in action - we're kinda spoilt by Voyager and Galileo images because they have longer exposures so everything looks brighter than it really is.

The system I'm trying to make in Celestia is a planet orbiting a Brown Dwarf, which in turn is orbiting Antares at a distance of 2000 AU. If I calculate the solar constants (the W/m2 of luminosity that arrives at the planet) from the Dwarf and Antares, I find that I get 476 W/m2 from the Dwarf and 3 W/m2 from Antares. Hrm. I suspect that means that the vast majority of the illumination on the planet actually comes from the Dwarf, and you'd barely see an 'illuminated hemisphere' caused by light from Antares? (solves one of the problems I had, anyway - I could just make the Dwarf the centre of the system and the sole light source, and have Antares as a 'fake star' with a big atmosphere, orbiting the Dwarf at 2000 AU perhaps?)

abiogenesis
Posts: 104
Joined: 07.06.2002
With us: 22 years
Location: Redmond, WA

Post #4by abiogenesis » 08.06.2003, 22:39

Multiple light sources are trivial to implement in OpenGL. The issue is with the way Celestia uses lights. I haven't looked at the code for a long time but, If I remember correctly, Celestia assumes a very simple lighting model.

Whenever the viewer is in the local coordinate space of a star, a single light is assumed to be at (0,0,0). There isn't, as far as I remember, any mechanism for specifying any other source of light. That part wouldn't be too hard to implement: just add another property to the existing body specifications. Then you could create more OpenGL lights.

I don't know to what extent OpenGL lighting is actually used by Celestia, though. Most of the pretty stuff comes from the Pixel and Vertex Shaders. Multiple light sources could exponentially increase the complexity of the math used in the shaders. And more complexity equals less speed.

- a b i o g e n e s i s -

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 5 months
Location: Seattle, Washington, USA

Post #5by chris » 08.06.2003, 23:50

Evil Dr Ganymede wrote:Well, I don't pretend to be an expert in programming (other than in Fortran :D ) , so I'm just bumbling along looking through the source... I just thought/hoped it'd be a case of changing some little thing so that stars were treated like planets.
If it was that easy, I'd have done it already :>

Basic two-source lighting is trivial . . . The difficult part is dealing with all of Celestia's vertex and pixel shaders, adding two light source versions of each one. Making shadows (eclipse and rings) work with two light sources will require a significant revision to Celestia's lighting, Unless you've spent some time writing 3D graphics code in the past, I don't think you'll have much luck modifying Celestia's renderer to add support for multiple light sources.

One thing that might be interesting to implement is light attenuation. Light drops off by an inverse square law, so (for example) the sun should be 25 times less bright as seen from Jupiter than it is from the Earth, since it's about 5 times further from the sun than the Earth. So I presume that when you look at Jupiter from jovian orbit, the illuminated half shouldn't be all that bright. I don't know if Celestia does this already, but it'd be interesting to see it in action - we're kinda spoilt by Voyager and Galileo images because they have longer exposures so everything looks brighter than it really is.
I deliberately avoided adding light source attentuation . . . The limited dynamic range of CRT and LCD monitors makes it rather less interesting than you'd think . . . Consider that Uranus's mean distance from the Sun is 19AU, so it should appear about 1/400 as bright as Earth. With 32-bit color, you only have 256 representable brightness level, so Uranus would be completely black! However, the human eye can adapt to remarkable range of light conditions, so if you were actually looking out the window of a spaceship passing by Uranus, it would be plainly visible . . . Linearly scaling the brightness is not the right thing to do; a logarithmic attenuation might be reasonable though. One final thing to consider: a full moon is 1/100,000th as bright as the Sun, yet it's very easy to see by its light--on a hypothetical planet 100AU from the Sun there would still be ten times as much light!

The system I'm trying to make in Celestia is a planet orbiting a Brown Dwarf, which in turn is orbiting Antares at a distance of 2000 AU. If I calculate the solar constants (the W/m2 of luminosity that arrives at the planet) from the Dwarf and Antares, I find that I get 476 W/m2 from the Dwarf and 3 W/m2 from Antares. Hrm. I suspect that means that the vast majority of the illumination on the planet actually comes from the Dwarf, and you'd barely see an 'illuminated hemisphere' caused by light from Antares? (solves one of the problems I had, anyway - I could just make the Dwarf the centre of the system and the sole light source, and have Antares as a 'fake star' with a big atmosphere, orbiting the Dwarf at 2000 AU perhaps?)


Is all of the 476 W/m2 of brown dwarf radiation in the visible spectrum? Even at 2000AU, I'd be very suprised if Antares didn't outshine the brown dwarf in the visible.

--Chris

Topic author
Evil Dr Ganymede
Posts: 1386
Joined: 06.06.2003
With us: 21 years

Post #6by Evil Dr Ganymede » 09.06.2003, 01:46

chris wrote:Basic two-source lighting is trivial . . . The difficult part is dealing with all of Celestia's vertex and pixel shaders, adding two light source versions of each one. Making shadows (eclipse and rings) work with two light sources will require a significant revision to Celestia's lighting, Unless you've spent some time writing 3D graphics code in the past, I don't think you'll have much luck modifying Celestia's renderer to add support for multiple light sources.

I probably wouldn't :). So having another light source isn't as simple as just letting the code run and seeing what comes out? You'd actually have to change things quite significantly?


chris wrote:I deliberately avoided adding light source attentuation . . . The limited dynamic range of CRT and LCD monitors makes it rather less interesting than you'd think . . . Consider that Uranus's mean distance from the Sun is 19AU, so it should appear about 1/400 as bright as Earth. With 32-bit color, you only have 256 representable brightness level, so Uranus would be completely black! However, the human eye can adapt to remarkable range of light conditions, so if you were actually looking out the window of a spaceship passing by Uranus, it would be plainly visible . . . Linearly scaling the brightness is not the right thing to do; a logarithmic attenuation might be reasonable though. One final thing to consider: a full moon is 1/100,000th as bright as the Sun, yet it's very easy to see by its light--on a hypothetical planet 100AU from the Sun there would still be ten times as much light!

That's a point, I hadn't thought of the pixel limitation of the screens... good point about the full moon though.


chris wrote:Is all of the 476 W/m2 of brown dwarf radiation in the visible spectrum? Even at 2000AU, I'd be very suprised if Antares didn't outshine the brown dwarf in the visible.


Dunno. I think that's the total luminosity over the whole spectrum, but I suspect most of it will be in the near IR/red end. Then again, so is Antares' luminosity, since that's a big M5 Ia-b supergiant (though it's at 3000K, rather than 1600K of the Dwarf). Hmm. I doubt if only 1% or so of the Dwarf's luminosity would be in the visible spectrum though, it'd probably be more than that.

I might as well post a piccie of it while I'm here. This is the best I've managed so far:

http://members.shaw.ca/evildrganymede/a ... tares2.jpg

The planet's the little purple ball in the lower-middle, and Antares is the big red glow in the top right (the Dwarf is the big thing in the left of the picture, obviously). I put a lightsource inside the Dwarf to illuminate the planet, and Antares is a 'fake star' (not emitting any light) that is 5 AU in radius orbiting the Dwarf at 2000 AU.

marc
Posts: 426
Joined: 13.03.2002
With us: 22 years 3 months
Location: Outback Australia

Post #7by marc » 09.06.2003, 03:45

I'm assuming you will make the zip available soon, id like to see that for real. :)

Topic author
Evil Dr Ganymede
Posts: 1386
Joined: 06.06.2003
With us: 21 years

Post #8by Evil Dr Ganymede » 09.06.2003, 06:07

marc wrote:I'm assuming you will make the zip available soon, id like to see that for real. :)


Zip? Of what, the stc/ssc files and textures? Well, I could do that I guess, it's not very big. Have to wait a week til after I get back from holiday though, and I need to tweak a few things anyway (I haven't got a texture for the planet sorted out yet, I'm just borrowing one from the Eta Carina system :) ).

This system is taken from one I designed for the Traveller tabletop RPG, BTW. The only bodies in the system are Antares, the Dwarf and the Planet so it's not all that exciting really :). But I would like to translate some other systems from that into Celestia, it would be a rather handy visualisation tool.

granthutchison
Developer
Posts: 1863
Joined: 21.11.2002
With us: 21 years 7 months

Post #9by granthutchison » 09.06.2003, 14:08

Evil Dr Ganymede wrote:Hmm. I doubt if only 1% or so of the Dwarf's luminosity would be in the visible spectrum though, it'd probably be more than that.

0.1% is actually nearer the mark - at 1600K, almost all the output is in the infrared. The fall-off in visible output is pretty steep below 3000K, which I think is what Chris was getting at.
What you need to quantify this is something called the luminous efficacy of an energy source - it takes into account what proportion of the energy output is in the visible band, as well as the human eye's differing sensitivities to different wavelengths. Taking the stars to be black-body radiators (to a first approximation) it's possible to come up with their luminous efficacy as a function of temperature. Here's a little table that can be useful when designing star systems:

Code: Select all

Temp(K)           Luminous efficacy (lm/W)
50000                     2.1
40000                     3.9
30000                     8.2
20000                     21
10000                     74
9000                       83
8000                       91
7000                       96
6000                       95
5000                       83
4000                       56
3000                       21
2000                       1.7
1500                       0.2
1000                       0.0002
800                         0.000001

Multiply the irradiance (the W/m?) by the luminous efficacy, and you'll get the illuminance, in lumens/m? or lux.
Typical illuminance values are:

Direct sunlight (Earth orbit) 130000 lx
Direct sunlight (Earth surface) 100000 lx
Indoor lighting 200-300 lx
Full moon 0.2 lx
Starlight .0003 lx


(Which illustrates Chris's point about the range of sensitivity of our eyes.)

So you're getting ~63 lx from Antares and ~95 lx from your brown dwarf.

Grant

Topic author
Evil Dr Ganymede
Posts: 1386
Joined: 06.06.2003
With us: 21 years

Post #10by Evil Dr Ganymede » 09.06.2003, 15:30

Interesting... thanks! So applying those numbers tells you how much luminosity is output in the visible spectrum? And where's the table taken from, is there a URL or book reference for that?

(1 lumen is apparently 0.00146 Watts, emitted in the middle of the visible spectrum).

That's going to be rather handy, I think :). Cheers. :D

granthutchison
Developer
Posts: 1863
Joined: 21.11.2002
With us: 21 years 7 months

Post #11by granthutchison » 09.06.2003, 17:16

Evil Dr Ganymede wrote:So applying those numbers tells you how much luminosity is output in the visible spectrum?
Yes. It's a conversion from electromagnetic energy to illumination - the eye and brain's perception of light.
Evil Dr Ganymede wrote:And where's the table taken from, is there a URL or book reference for that?
I worked it out - I have an old QuickBasic program that I wrote years ago to calculate stuff like this for me.
Basically, you integrate the energy per wavelength of the black-body spectrum across the visible range, but multiplying by the luminous efficacy at each wavelength. The function for black-body radiation is available in all sorts of physics textbooks. The luminous efficacy function you'll find in books on photometry. I'm afraid the book I used is ancient, out of print, and in a medical library several hundred kilometres from here. So I guess all I can suggest is a web search on various permutations of "photometry" "luminous efficacy" and "black body radiation".

Grant

julesstoop
Posts: 408
Joined: 27.03.2002
With us: 22 years 3 months
Location: Leiden, The Netherlands

Post #12by julesstoop » 10.06.2003, 18:12

Funny list, I never looked at things quite this way. I actually tells me that an O-type star needs to have an energy output about fifty times as large as our sun, to appear of the same brightness. The uv-output however, were this imaginary star in the sun's position, would probably burn away all life on earth in a few seconds.
Lapinism matters!
http://settuno.com/

granthutchison
Developer
Posts: 1863
Joined: 21.11.2002
With us: 21 years 7 months

Post #13by granthutchison » 10.06.2003, 19:21

Yes, there's a mismatch between energy and brightness that'd show up if you were on an Earth-like planet around a sufficiently hot star. To get an Earth-like temperature, you'd have to accept dimmer illumination, though nothing the human eye couldn't handle without you noticing.
But the surface brightness of the hot star would still be much higher - it'd just be so far away that it would be very small in the sky, and so would shed less light. So there would be a searingly bright pin-point up there, which would be a real danger to eyesight. Our reflexes are tuned to make us blink fast enough to prevent retinal damage if we glance towards the Sun, but with no more than a five-fold increase in surface brightness, you can't blink fast enough to prevent a spot on your retina burning - it'd be like glimpsing the first few milliseconds of an atomic bomb explosion. That happens at about 9000K, which translates to a spectral class somewhere around A2.

Grant

julesstoop
Posts: 408
Joined: 27.03.2002
With us: 22 years 3 months
Location: Leiden, The Netherlands

Post #14by julesstoop » 10.06.2003, 20:35

Yes, I've playing around with this effect through finding a distance near several sufficiently different stars where the central star has the same brightness as the sun at 1 AU. By then measuring the arcradius of the stardisc, one can sort of recalculate the spectral class. Amazing how small an O-class star appears.

From the lack of uv-sensitivity of our eyes one would also expect our eyes to respond much slower to this hotter sun-replacement, further slowing our blinking reflex. This reminds me of being able to stare straight at a blacklight tube or bulb in a dancing-club for an extended period of time, while staring directly at the 'normal' illumination actually causes a reflex.
Lapinism matters!
http://settuno.com/

granthutchison
Developer
Posts: 1863
Joined: 21.11.2002
With us: 21 years 7 months

Post #15by granthutchison » 23.06.2003, 15:03

Evil Doctor (or may I call you "Evil"? :wink:):
If you're still looking for some more information on photometry, I happened upon this forgotten link while clearing out my Favourites this afternoon:
http://home.tiscali.se/pausch/comp/radfaq.html
Full of handy information.

Grant

Avatar
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 3 months
Location: Hamburg, Germany

Post #16by t00fri » 23.06.2003, 17:48

granthutchison wrote:Evil Doctor (or may I call you "Evil"? :wink:):

Grant


Hi, hi...my thinking...
among colleagues we normally leave away titles and use first names;-)

Bye Fridger

Topic author
Evil Dr Ganymede
Posts: 1386
Joined: 06.06.2003
With us: 21 years

Post #17by Evil Dr Ganymede » 23.06.2003, 18:16

Well, you could just called me 'Consty', which is my actual name. :)
I just keep forgetting to sign off with it here ;)


Return to “Development”