Jump to content

[WIP][1.9.x-1.12.x] Scatterer-atmospheric scattering (0.0838 - 14/08/2022) Scattering improvements, in-game atmo generation and multi-sun support


blackrack

Recommended Posts

Right, more stuff to work with and more stuff to cause you to pull your hair out from. Looking awesome though. Wish I wasn't on a non-gaming laptop computer, or I'd install this stuff in a heartbeat. As it is, if I tried to compress the process into a heartbeat, I'd be dead.

It could be a lot of fun actually, I think SQUAD could enable physically based rendering and HDR for everything.

Link to comment
Share on other sites

I was working on this but didn't release it.

My internship ends soon and I'm going to have loads and loads of free time while I figure out what to do next/obtain a new visa. Basically, expect daily updates in december and lots of the good stuff I've been promising for a while around christmas and in January.

Awesome! Thanks for your work!

Link to comment
Share on other sites

Thought of a way to get the moon to show clearly through the sky... My plan is to add another material on-top of the scaled space terrain material that will be a multiplicative shader to enhance the terminator and illuminate the body more. Then we just put the shader on the Transparent-1 queue. Should show up before the clouds, but after the atmosphere :)

Link to comment
Share on other sites

One question - why doesn't Scatterer effect show up on top of EVE clouds? CLouds all the way up to horison look weird, especially when there are some mountains on the horizon.

I use old .25 EVE. New one is too buggy for me.

Link to comment
Share on other sites

Thought of a way to get the moon to show clearly through the sky... My plan is to add another material on-top of the scaled space terrain material that will be a multiplicative shader to enhance the terminator and illuminate the body more. Then we just put the shader on the Transparent-1 queue. Should show up before the clouds, but after the atmosphere :)

So basically it's a multiplicative shader, would it cover all of the body or only the illuminated parts? Also, probably this would require HDR for correct rendering but no problem with that, HDR works fine in scaled space however I couldn't think of a way to make the terrain scaled space shaders render in higher intensities so HDR would really mask the dark areas of a body.

One question - why doesn't Scatterer effect show up on top of EVE clouds? CLouds all the way up to horison look weird, especially when there are some mountains on the horizon.

I use old .25 EVE. New one is too buggy for me.

Because the clouds don't write to the depth buffer. I actually thought clouds all the way to the horizon look weird also. I thought about this a bit a while ago and I think the easiest way to simulate this would be to modifiy the EVE clouds shader and make the clouds fade out towards the horizon/depending on viewing angle, distance to clouds and camera altitude.

Edited by blackrack
Link to comment
Share on other sites

So basically it's a multiplicative shader, would it cover all of the body or only the illuminated parts? Also, probably this would require HDR for correct rendering but no problem with that, HDR works fine in scaled space however I couldn't think of a way to make the terrain scaled space shaders render in higher intensities so HDR would really mask the dark areas of a body.

Exactly. It would cover everything basically, as it goes into the materials list. This is how I'm doing city lights now so I am not forced to replace the terrain shader. It wouldn't require HDR, but I think it would make it look better. I'm excited, this should work really well :)

Because the clouds don't write to the depth buffer. I actually thought clouds all the way to the horizon look weird also. I thought about this a bit a while ago and I think the easiest way to simulate this would be to modifiy the EVE clouds shader and make the clouds fade out towards the horizon/depending on viewing angle, distance to clouds and camera altitude.

EVE does some basic stuff around this (View.Normal), but I always wanted to go back and improve it.

Link to comment
Share on other sites

Thought of a way to get the moon to show clearly through the sky... My plan is to add another material on-top of the scaled space terrain material that will be a multiplicative shader to enhance the terminator and illuminate the body more. Then we just put the shader on the Transparent-1 queue. Should show up before the clouds, but after the atmosphere :)

I think if you enhance it too much it'd look weird, though. Look at the Moon in the daytime sky sometime- it's very low contrast with respect to the scattered background, and blends in fairly well if you're not looking for it. I would really like to see an enhanced, sharper terminator though- the current one on airless bodies is very diffuse and undefined, although this is kind of a side effect of how small Kerbal celestial bodies are.

Link to comment
Share on other sites

I think if you enhance it too much it'd look weird, though. Look at the Moon in the daytime sky sometime- it's very low contrast with respect to the scattered background, and blends in fairly well if you're not looking for it. I would really like to see an enhanced, sharper terminator though- the current one on airless bodies is very diffuse and undefined, although this is kind of a side effect of how small Kerbal celestial bodies are.
Exactly. It would cover everything basically, as it goes into the materials list. This is how I'm doing city lights now so I am not forced to replace the terrain shader. It wouldn't require HDR, but I think it would make it look better. I'm excited, this should work really well :)

I think in the end it's all about trial and error and playing with the settings until it looks right. What I'm concerned about is making the dark parts of the moon invisible from the atmosphere, I'm not sure if your method would help with this, even with HDR, as everything (dark and light areas) will get multiplied by the same amount. Though I can imagine making a quick approximation that lights the light areas and leaves the rest as is (based on direction of the sun), or does the opposite.

Link to comment
Share on other sites

I think if you enhance it too much it'd look weird, though. Look at the Moon in the daytime sky sometime- it's very low contrast with respect to the scattered background, and blends in fairly well if you're not looking for it. I would really like to see an enhanced, sharper terminator though- the current one on airless bodies is very diffuse and undefined, although this is kind of a side effect of how small Kerbal celestial bodies are.

No, current terminator is the effect of terrain not casting shadows.

Link to comment
Share on other sites

I think in the end it's all about trial and error and playing with the settings until it looks right. What I'm concerned about is making the dark parts of the moon invisible from the atmosphere, I'm not sure if your method would help with this, even with HDR, as everything (dark and light areas) will get multiplied by the same amount. Though I can imagine making a quick approximation that lights the light areas and leaves the rest as is (based on direction of the sun), or does the opposite.

That's the beauty of it though... we could do all sorts of funny things with it. I've been messing around with blending (I finally understand how it works now! ) One thought I had, was encoding an "Visibility" metric into the alpha channel of rendered stuff for Scatterer to use (This doesn't seem to affect rendering otherwise). Then scaterer could use the DestAlpha multiplier with blending instead of OneMinusSourceAlpha. BTW, the "OneMinusSourceAlpha" helps ensures lerp-like blending. If you want, you can use "One" there to allow more background through, thought it may overpower things to white.

Link to comment
Share on other sites

That's the beauty of it though... we could do all sorts of funny things with it. I've been messing around with blending (I finally understand how it works now! ) One thought I had, was encoding an "Visibility" metric into the alpha channel of rendered stuff for Scatterer to use (This doesn't seem to affect rendering otherwise). Then scaterer could use the DestAlpha multiplier with blending instead of OneMinusSourceAlpha. BTW, the "OneMinusSourceAlpha" helps ensures lerp-like blending. If you want, you can use "One" there to allow more background through, thought it may overpower things to white.

I'm not sure I understand all the blending modes well, but for the view from orbit scatterer uses additive blending (Blend One One) right now and for the ground view (haze/postprocessing) regular alpha blending (Blend SrcAlpha OneMinusSrcAlpha).

Not sure I understand how your idea works, so basically everything will have alpha values but won't use alpha blending itself? Then scatterer just uses these alpha values for itself? If I'm getting it right, I think this is a great idea, and would definitely work, let me just think about this a bit more.

My current idea was to just use HDR and use high brightness values for the scaledSpace objects and the atmosphere, and then finding a way to make the bright areas much brighter than the dark ones on the terrain, this would automatically produce all the desired effects, but also some glare/bloom can be simulated from high luminosity objects if needed simple postprocessing shaders. All other simulators use this approach too (Proland, Space engine, outerra). We could try with your multiplicative shader, or we could also contact SQUAD and ask them for their shader source code (not sure if they'd be open to this).

But yeah, your approach seems like a good idea. Also, what is lerp-like blending?

Link to comment
Share on other sites

Bingo. We would just adjust the ground view to be "Blend SrcAlpha DstAlpha" Everything should already be writing 1 if it is opaque ( should is the operative factor. I am not certain about things like water.) and we could adjust it for things like clouds (distance) and the luminosity of bodies.

- - - Updated - - -

Bingo. For the ground view we would use alpha additive "Blend SrcAlpha DstAlpha", and this should let us write in a value for alpha that would let us fade it out. Would work perfectly for celestial bodies, writing 1 with lots of light, 0 for none. Should work for clouds too if I encode a "distance" metric to the clouds... though I guess I could probably just make the clouds fade out...

Concerns:

1) Not sure if all shaders write to alpha (they should though) or if the values are as we would expect them to be.

2) Not sure for certain that cameras share a universal frame buffer (but I think this is how it works)

The HDR method might work, but I think you'd still have issues with the sky-body interaction.Either the body is above it (don't see blue) or below it(don't see Mun), and neither would exactly produce the results you'd like. Does Mun show through right now in scatterer or is it hidden? I would expect it to be hidden unless the proland stuff includes some mechanism to render moons.

EDIT: Realized that bodies are rendered in scaled space and therefor can't show above scatterer render.

Edited by rbray89
Link to comment
Share on other sites

Bingo. We would just adjust the ground view to be "Blend SrcAlpha DstAlpha" Everything should already be writing 1 if it is opaque ( should is the operative factor. I am not certain about things like water.) and we could adjust it for things like clouds (distance) and the luminosity of bodies.

- - - Updated - - -

Bingo. For the ground view we would use alpha additive "Blend SrcAlpha DstAlpha", and this should let us write in a value for alpha that would let us fade it out. Would work perfectly for celestial bodies, writing 1 with lots of light, 0 for none. Should work for clouds too if I encode a "distance" metric to the clouds... though I guess I could probably just make the clouds fade out...

Concerns:

1) Not sure if all shaders write to alpha (they should though) or if the values are as we would expect them to be.

2) Not sure for certain that cameras share a universal frame buffer (but I think this is how it works)

The HDR method might work, but I think you'd still have issues with the sky-body interaction.Either the body is above it (don't see blue) or below it(don't see Mun), and neither would exactly produce the results you'd like. Does Mun show through right now in scatterer or is it hidden? I would expect it to be hidden unless the proland stuff includes some mechanism to render moons.

EDIT: Realized that bodies are rendered in scaled space and therefor can't show above scatterer render.

The mun currently shows through the scatterer effects. What I call the "sky shader" uses additive blending, is rendered to scaled space, and renders on top of it's parent celestial object, also in top of other celestial bodies but I control on top of which one or under which one it renders using draw orders, so when the mun passes in front of kerbin it's not occluded. The same shader is also used for the planet's atmosphere when viewed from a high orbit. The postprocessing shader is only used on top of terrain and is rendered to the far camera, it uses alpha blending. So basically, the terrain itself renders on top of the sky, and the postprocessing shader renders on top of the terrain. An additional "extinction" layer is also used:

dTt3d7l.jpg

zB8SC7P.jpg

Edited: Also I know this is pretty random, but I felt like saying this here: Scatterer is one of the things I'm proudest of in my life, and I aim to see it through to the end.

Edited by blackrack
Link to comment
Share on other sites

Ah, I see... So if we had something that wrote the alpha value as an indicator of how visible through atmosphere it should be, the extinction and sky (and possibly haze) shader should be able to use that to blend. You may even be able to remove the extinction shader and just rely on the sky shader. You also wouldn't have to fiddle with queue order. I assume you do that with the material render queue?

Link to comment
Share on other sites

Ah, I see... So if we had something that wrote the alpha value as an indicator of how visible through atmosphere it should be, the extinction and sky (and possibly haze) shader should be able to use that to blend. You may even be able to remove the extinction shader and just rely on the sky shader. You also wouldn't have to fiddle with queue order. I assume you do that with the material render queue?

Probably but I'm not sure yet, I need to have the sky on additive blending, else the blending looks weird as hell near the edge of the atmosphere. Like this http://i.imgur.com/yA9XJGW.jpg.

Also, the extinction shader does tint the colors in a realistic manner (it uses the same calculations as those that give the sun it's reddish tint on sunsets/sunrise, though it may still need some tweaking), so probably I won't get rid of it.

Yes indeed, I do that with the material render queue, I check the nearby planets to see if they are between the camera and the parent planet or farther away and adjust accordingly.

Edited by blackrack
Link to comment
Share on other sites

Probably but I'm not sure yet, I need to have the sky on additive blending, else the blending looks weird as hell near the edge of the atmosphere. Like this http://i.imgur.com/yA9XJGW.jpg.

Also, the extinction shader does tint the colors in a realistic manner (it uses the same calculations as those that give the sun it's reddish tint on sunsets/sunrise, though it may still need some tweaking), so probably I won't get rid of it.

Yes indeed, I do that with the material render queue, I check the nearby planets to see if they are between the camera and the parent planet or farther away and adjust accordingly.

The sky can still be additive, it would just be additive based on the alpha value of whatever is behind it (more or less alpha would affect it in some way)

EDIT: Info on blend modes here: http://elringus.me/blend-modes-in-unity/

Basically, Blending can have multiple opps, and the first parameter is what to multiply the source color with (generated by shader) and the second parameter is what to multiply the destination color (frame buffer) with. These to resulting values are added (or other operation based on BlendOp) to produce the final value. You can also specify separate blending for alpha if that is what you want.

Edited by rbray89
Link to comment
Share on other sites

The sky can still be additive, it would just be additive based on the alpha value of whatever is behind it (more or less alpha would affect it in some way)

EDIT: Info on blend modes here: http://elringus.me/blend-modes-in-unity/

Basically, Blending can have multiple opps, and the first parameter is what to multiply the source color with (generated by shader) and the second parameter is what to multiply the destination color (frame buffer) with. These to resulting values are added (or other operation based on BlendOp) to produce the final value. You can also specify separate blending for alpha if that is what you want.

Cool, then in this case I could create some sort of additive alpha blending and it would work.

Link to comment
Share on other sites

Bingo. At least, that's the theory. I'm probably going to be trying this out soon...

Looking forward to it.

Also, up there you mentioned "2) Not sure for certain that cameras share a universal frame buffer (but I think this is how it works)", not sure what you mean here, but when I tried applying multiplicative blending effects to the far camera they also applied to what the scaledspace camera has already rendered so I think it may be the case.

Link to comment
Share on other sites

Looking forward to it.

Also, up there you mentioned "2) Not sure for certain that cameras share a universal frame buffer (but I think this is how it works)", not sure what you mean here, but when I tried applying multiplicative blending effects to the far camera they also applied to what the scaledspace camera has already rendered so I think it may be the case.

Ah, perfect! That's what I want to hear!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...