Jump to content

WIP - Environmental Visual Enhancements Development


rbray89

Recommended Posts

This is one of the most glorious things I've seen in a while.

May I ask for technical details on how you did this? Whatever it is you're planning to do to make it work with the clouds I'm stealing to make it work with the scatterer atmosphere.

Projectors. It's actually a really simple shader:


Shader "EVE/PlanetShadow" {
Properties {
_PlanetOrigin ("Sphere Center", Vector) = (0,0,0,1)
_SunDir ("Sunlight direction", Vector) = (0,0,0,1)
_PlanetRadius ("Planet Radius", Float) = 1
}
SubShader {
Pass {
Blend DstColor Zero
ZWrite Off
CGPROGRAM
#include "EVEUtils.cginc"
#pragma target 3.0
#pragma glsl
#pragma vertex vert
#pragma fragment frag

uniform sampler2D _MainTex;
float4 _MainOffset;
uniform sampler2D _DetailTex;
fixed4 _DetailOffset;
float _DetailScale;
float _DetailDist;
float4 _SunDir;
float _PlanetRadius;

float3 _PlanetOrigin;
uniform float4x4 _Projector;

struct appdata_t {
float4 vertex : POSITION;
float3 normal : NORMAL;
};

struct v2f {
float4 pos : SV_POSITION;
float4 posProj : TEXCOORD0;
float dotcoeff : TEXCOORD1;
float originDist : TEXCOORD2;
float nDotL : TEXCOORD3;
float4 worldPos : TEXCOORD4;
float3 L : TEXCOORD5;

};

v2f vert (appdata_t v)
{
v2f o;
o.posProj = mul(_Projector, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float3 normView = normalize(float3(_Projector[2][0],_Projector[2][1], _Projector[2][2]));

float4 vertexPos = mul(_Object2World, v.vertex);
o.worldPos = vertexPos;

float3 worldOrigin = _PlanetOrigin;
o.L = worldOrigin - vertexPos;
o.originDist = length(o.L);
o.nDotL = -dot(_SunDir, mul(_Object2World, float4(v.normal,0)).xyz);
return o;
}

fixed4 frag (v2f IN) : COLOR
{
//Eliminate vertexes facing the "wrong" way. Either behind the projector, or facing away from it.
half shadowCheck = step(0, IN.posProj.w)*step(0, IN.nDotL);
//Get the component of L facing the Sun.
float tc = dot(IN.L,- _SunDir);
//Find the distance from the sphere center to the tangent.
float d = sqrt(dot(IN.L,IN.L)-(tc*tc));
//Chceck for occlusion. d should be smaller than radius, and tc should be >0 (facing the sphere)
half sphereCheck = step(d, _PlanetRadius)*step(0.0, tc);

fixed4 color = half4(1,1,1,sphereCheck);

color.a = 1.2*(1.2-color.a);
color = saturate(color);


return lerp(1, color.a, shadowCheck);
}

ENDCG
}
}
}

The issue right now of course is that projectors don't work well with transparent objects. I think what I'm going to do is keep the projectors for world-space, and for scaled space, create another material that can do several body shadows in a single pass. I'll then add those passes to my cloud shader.

I'm not certain it will translate well to atmospheric use, then again, I don't really understand how Scatterer calculates all the math in the first place. You'd probably have to add some math to determine what percentage of light is now occluded from the region of air you are looking into.

Edited by rbray89
Link to comment
Share on other sites

cool stuff

I was thinking about the orbital view first, I thought it should be easy to adapt from what you have now for scaledSpace or what you plan to make for the shadows. Ground view is gona be complicated though... I was thinking of something simpler like space engine does it and reducing exposure for the unaffected areas of the sky: http://voksenlia.net/spaceengine/eclipse.jpg

Anyway, I don't understand projectors that well, does this assume perfect spheres for both planets? So it's just rendered on top of the planet? Do you have to create instances of this for every moon and planet combo?

Link to comment
Share on other sites

Awesome. The shadow shouldn't be as sharp tho, like it can be seen here. Also, shadows from planes that have atmosphere should be strongly colored - have you seen Moon eclipse? Because atmosphere allows lots of red light to pass through it and refracts it at the same time the moon is not black but red.

sims_schneider_eclipse_mar202015.jpg.CROP.original-original.jpg

Edited by sashan
Link to comment
Share on other sites

So the way projectors work is that they have a FOV (In this case orthogonal and with a size of the planet that casts the shadow), Layer masks, and Clip planes, much like cameras do. Every material in the frustum of the projector in the layer mask and without the shader tag "IgnoreProjector=True", will be re-rendered with the new shader.

In our case, the shader is placed on the surface of the shadow casting body facing away from the sun, projecting the shadow shader on anything in it's path. The shadow is calculated using the vertex of the mesh, along with the sun direction and center of the casting body. IT assumes a perfect sphere, so unfortunately oblate bodies won't be handled properly.

Luckily when using projectors, the implementation is simplified, but imperfect. We only have to use one projector per body, and swap the layer masks and variables to go from scaled space to macro, but this means if you have a craft in space past PQS, the shadows won't render properly on BOTH the craft and body (has to be one unless you have multiple projectors). It also means clouds can't receive them either.

What I plan to do is move to a (much more complicated) solution where the projectors are kept for PQS and ship-in-space situations, and the scaled space situations will use additional material(s) that implement shadows. If I want the clouds to properly receive them, I'll have to add all the shadows to the cloud shader. I think I have a way to do this in a single pass, but it may result in BAD performance. If I do this, I'll end up re-using this implementation with the shader for bodies and there will just be a single material for the body shadows. With this, I think I will be able to do up to 4 celestial shadows casting on a single body (matrix of 4 value sets: body position [xyz] and radius [w]) but it will require choosing a select set of bodies and managing their positions to plug into the materials. Much more involvement, but should be a more complete solution.

- - - Updated - - -

Awesome. The shadow shouldn't be as sharp tho, like it can be seen here. Also, shadows from planes that have atmosphere should be strongly covered - have you seen Moon eclipse? Because atmosphere allows lots of red light to pass through it and refracts it at the same time the moon is not black but red.

http://www.slate.com/content/dam/slate/blogs/bad_astronomy/2015/03/23/sims_schneider_eclipse_mar202015.jpg.CROP.original-original.jpg

Yeah, I still need to alter the penumbra to be more accurate.

Link to comment
Share on other sites

So the way projectors work is that they have a FOV (In this case orthogonal and with a size of the planet that casts the shadow), Layer masks, and Clip planes, much like cameras do. Every material in the frustum of the projector in the layer mask and without the shader tag "IgnoreProjector=True", will be re-rendered with the new shader.

In our case, the shader is placed on the surface of the shadow casting body facing away from the sun, projecting the shadow shader on anything in it's path. The shadow is calculated using the vertex of the mesh, along with the sun direction and center of the casting body. IT assumes a perfect sphere, so unfortunately oblate bodies won't be handled properly.

Luckily when using projectors, the implementation is simplified, but imperfect. We only have to use one projector per body, and swap the layer masks and variables to go from scaled space to macro, but this means if you have a craft in space past PQS, the shadows won't render properly on BOTH the craft and body (has to be one unless you have multiple projectors). It also means clouds can't receive them either.

What I plan to do is move to a (much more complicated) solution where the projectors are kept for PQS and ship-in-space situations, and the scaled space situations will use additional material(s) that implement shadows. If I want the clouds to properly receive them, I'll have to add all the shadows to the cloud shader. I think I have a way to do this in a single pass, but it may result in BAD performance. If I do this, I'll end up re-using this implementation with the shader for bodies and there will just be a single material for the body shadows. With this, I think I will be able to do up to 4 celestial shadows casting on a single body (matrix of 4 value sets: body position [xyz] and radius [w]) but it will require choosing a select set of bodies and managing their positions to plug into the materials. Much more involvement, but should be a more complete solution.

I get it, this is awesome. But why not just do it for the PQS/ships and scaledspace at the same time? Is there a big performance hit for two projectors at the same time?

Also, is it possible to get smoother/blurrier edge?

Link to comment
Share on other sites

I get it, this is awesome. But why not just do it for the PQS/ships and scaledspace at the same time? Is there a big performance hit for two projectors at the same time?

Keeping projector count down is better :) I could try with multiple projectors to check it out though.

Also, is it possible to get smoother/blurrier edge?

Very possible. We would just use the "d" value and compare it against the planet radius to do a linear smoothing.

Link to comment
Share on other sites

Keeping projector count down is better :) I could try with multiple projectors to check it out though.

Very possible. We would just use the "d" value and compare it against the planet radius to do a linear smoothing.

Very nice! Yeah please try with multiple projectors if you can, maybe the performance impact is negligible.

Link to comment
Share on other sites

Very nice! Yeah please try with multiple projectors if you can, maybe the performance impact is negligible.

At any rate though, projectors won't work for clouds or atmo, so we'll have to do something different for them anyways.

EDIT:

Now that I think about it though, we could use the same mechanism planned for clouds in the shader for projectors, reducing the draw call significantly, use only one projector per active PQS, and fix the ocean issue (both ground and ocean receive projectors, and should have a filter mechanism like cloud shadows do.

Edited by rbray89
Link to comment
Share on other sites

At any rate though, projectors won't work for clouds or atmo, so we'll have to do something different for them anyways.

EDIT:

Now that I think about it though, we could use the same mechanism planned for clouds in the shader for projectors, reducing the draw call significantly, use only one projector per active PQS, and fix the ocean issue (both ground and ocean receive projectors, and should have a filter mechanism like cloud shadows do.

Just a quick question that crossed my mind: Changing the render queue of a projector shouldn't do anything right?

Link to comment
Share on other sites

Just a quick question that crossed my mind: Changing the render queue of a projector shouldn't do anything right?

Nope. Projectors should be rendered Somewhere after geometry, but before transparency. Don't know the exact queue number though.

Link to comment
Share on other sites

Thanks :) sorry I couldn't find it anywhere :P

On another note, I found that the original x86Release.zip from the overhaul branch doesn't work only the one in the release tags?

Thanks again for your awesome work!

We are now on mainline :) Overhaul branch is now depricated. I may create new branches for additional features and whatnot though. If that's the case, I'll update here.

Link to comment
Share on other sites

Condensed question, what settings would I change to make the atmosphere change from looking like this:

PKQPejp.png

To this:

L5wXghT.png

I'm unsure if you answered this yet or not, but I was noticing while creating my own configs I couldn't make the atmosphere fade quicker. I could change it's height and density, but not the edge fade distance like you could in old EVE. Is this a planned feature that hasn't been added yet? So far all the atmosphere configs I've seen from new EVE look as though the atmosphere is ablating high into orbit (Like, 400k up).

Edited by Avera9eJoe
Link to comment
Share on other sites

I'm unsure if you answered this yet or not, but I was noticing while creating my own configs I couldn't make the atmosphere fade quicker. I could change it's height and density, but not the edge fade distance like you could in old EVE. Is this a planned feature that hasn't been added yet? So far all the atmosphere configs I've seen from new EVE look as though the atmosphere is ablating high into orbit (Like, 400k up).

Atmosphere is currently not truly supported. Given there is already scatterer, I figured I'd work on other things so that we don't have two direct competitors. Right now I'm focused on bug squashing, and shadows.

Link to comment
Share on other sites

Atmosphere is currently not truly supported. Given there is already scatterer, I figured I'd work on other things so that we don't have two direct competitors. Right now I'm focused on bug squashing, and shadows.

Aahhh that makes perfect sense!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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...