As some of you know, I have been working on an update for the System Features Rings OXP and there were some discussion about it in the Screenshots thread starting with this post
. Because the discussion was out of topic over there (sorry again!), I thought of continuing it here. I currently have three issues that I would like to solve/improve and I would greatly appreciate some advice:
- drawing distance seems to be set at 2.7 OU, at which points the rings pop out of existance. Apparently this would have to be modified in the core code of the game.
- applying opacity < 1.0 to rings: no matter what value I use as the last argument of gl_FragColor. Some people told me that I can't have transparency in Oolite. Others told me to look at the atmosphere fragment shader, but I can't understand why the transparency works there and not with the rings shader. I have also read online that one must enable blending in order to work with opacity, but I am an utter complete GLSL noob and I don't know what that means nor how to accomplish it.
- a minor thing, but would someone here perhaps know how to improve the Moire patterns that the rings display?
Hi, I'm new here, and I am reviving a topic that's more than a year old, but perhaps it will be interesting anyway. I have spent some time working on rings in my own open source space game, and I can describe what I did for that. Perhaps some of it will be useful in Oolite as well. I was largely inspired by this amazing video: https://www.youtube.com/watch?v=UgxWkOXcdZU
which is supposedly made from photographs of Saturn taken by the Cassini probe, which is to say, it's not CGI.
There are a couple interesting things I noticed about this video.
1) The rings tend to be either fully opaque, or have fully transparent gaps (opacity tends to be either 1.0 or 0.0, with little in the way of translucent sections.)
2) The two sides of the rings are not the same. One side is in shadow, and is darker (but not fully dark) and one side is in sun, and is brighter.
As for the opacity, I was a little reluctant to discard translucency entirely, since while it may be the case that Saturn has little in the way of translucent rings, other imaginary planets might be different. Nevertheless, I did make the rings tend a bit towards opacity. What I really did was link the opacity to the brightness, more or less, of the underlying texture, so that lighter areas of the rings were more opaque, and darker areas more transparent (this alpha manipulation is baked into the texture).
As for the two sides, in my ring shader (I have a shader specifically for rings), I determine the plane of the ring, and determine which side of this plane the camera is on, and which side of this plane the light source resides. If the camera and the light source are on the same side, then we are looking at the bright side of the ring. If the camera and the light source are on opposite sides of the plane, then we are looking at the dark side, and the brightness is attenuated.
As for the moire effect, what I did is use essentially a 1 dimensional texture, which defines a cross section of the ring. Actually, I used a 2 dimensional texture, but each ring uses only a single texel wide slice of this texture. That way I can cram 512 different ring textures into a single 512x512 image, and it's high enough resolution that I don't seem to have too much problems with moire, or rather, the way the texture is sampled, the moire doesn't seem to happen. In the fragment shader, I compute the distance from the center of the ring, and use this to index into one axis of the texture (the other axis is held constant -- but a different constant for each planet's ring.) And also in the ring fragment shader, I shoot a ray back towards the light source to see if it intersects the planet, and thus get the planet's shadow onto the ring. And in the planet fragment shader, I find the intersection of a ray from the planet surface to the light source with the ring, and sample the ring texture to allow casting the shadow of the ring onto the planet in a way that matches the rings. I also put a little bit of specular reflection on the ring.
Results look like the links below. The first two show the same planet from different angles, showing the light and dark side of the ring, the 3rd shows some specular reflection.
Ring shader: https://github.com/smcameron/space-nerd ... xel.shader
Planet shader: https://github.com/smcameron/space-nerd ... xel.shader
Perhaps some of these ideas will find their way into Oolite in some form or another.