• June 18, 2019, 08:10:38 PM
• Welcome, Guest

Pages: 1 ... 26 27 28 [29] 30 31 32 ... 34   Go Down

### AuthorTopic: Weekly progress report  (Read 42176 times)

0 Members and 1 Guest are viewing this topic.

#### slibenli

• member
• Offline
• Posts: 254
##### Re: Weekly progress report
« Reply #336 on: December 13, 2018, 03:32:08 AM »

Concerning atmospheric light scattering you might want to take a look at:
https://hal.inria.fr/inria-00288758
https://ebruneton.github.io/precomputed_atmospheric_scattering

I'm using some of the methods in il2ge (to compute the atmosphere thickness between viewer and object).
Logged

#### Stainless

• moderator
• member
• Offline
• Posts: 1240
##### Re: Weekly progress report
« Reply #337 on: December 13, 2018, 04:21:45 AM »

I calculate the scattering in my shader.

Here it is if it is useful

Code: [Select]
#include "ShaderVariables.inc"struct appdata { float3 Position : POSITION; float4 Normal : NORMAL; float2 UV0 : TEXCOORD0;  half4 Tangent : TANGENT0;  half4 Binormal : BINORMAL0;};struct vertexOutput { float4 HPosition : POSITION; float3 WorldLightVec : TEXCOORD0; float3 WorldNormal     : TEXCOORD1; float3 WorldEyeDirection : TEXCOORD2; half3  WorldTangent : TEXCOORD3; half3  WorldBinorm : TEXCOORD4;  float2 UV : TEXCOORD5;  half Fog : TEXCOORD6;  half2 Altitudes : TEXCOORD7; };float4 LightDirection = {100.0f, 100.0f, 100.0f, 1.0f};float4 LightColor = {1.0f, 1.0f, 1.0f, 1.0f};float4 LightColorAmbient = {0.0f, 0.0f, 0.0f, 1.0f};float4 FogColor = {1.0f, 1.0f, 1.0f, 1.0f};float fDensity ;bool isSkydome;float SunLightness = 0.2; float sunRadiusAttenuation = 256;float largeSunLightness = 0.2;float largeSunRadiusAttenuation = 3;float dayToSunsetSharpness = 1.5;float hazeTopAltitude = 20; texture DiffuseTexture;sampler SurfSamplerDiffuse = sampler_state{ Texture = <DiffuseTexture>; MinFilter = Linear; MipFilter = Linear; MagFilter = Linear;};texture SkyTextureNight;sampler SurfSamplerSkyTextureNight = sampler_state{ Texture = <SkyTextureNight>; MinFilter = Linear; MipFilter = Linear; MagFilter = Linear; AddressU = mirror; AddressV = mirror;};texture SkyTextureSunset;sampler SurfSamplerSkyTextureSunset = sampler_state{ Texture = <SkyTextureSunset>; MinFilter = Linear; MipFilter = Linear; MagFilter = Linear; AddressU = mirror; AddressV = mirror;};texture SkyTextureDay;sampler SurfSamplerSkyTextureDay = sampler_state{ Texture = <SkyTextureDay>; MinFilter = Linear; MipFilter = Linear; MagFilter = Linear; AddressU = mirror; AddressV = mirror;};vertexOutput mainVS (appdata IN){ vertexOutput OUT; float4 Po = float4(IN.Position.xyz,1); OUT.HPosition = mul( Po, WorldViewProjection); OUT.WorldNormal = mul( IN.Normal, WorldInverseTranspose).xyz; OUT.WorldTangent = mul(IN.Tangent, WorldInverseTranspose).xyz; OUT.WorldBinorm = mul(IN.Binormal, WorldInverseTranspose).xyz; OUT.WorldLightVec = -LightDirection.xyz; float3 Pw = mul( Po, World).xyz; OUT.WorldEyeDirection = ViewInverse[3].xyz - Pw; OUT.Altitudes.x = ViewInverse[3].y;   float4 pos = mul( IN.Position, World);    float dist = length(OUT.WorldEyeDirection); OUT.Fog = (1.f/exp(pow(dist * fDensity, 2))); OUT.Altitudes.y = Pw.y; OUT.UV = IN.UV0; return OUT;}float4 mainPS(vertexOutput IN) : COLOR0{ float4 colorOutput = float4(0,0,0,1); float4 DiffuseColor = tex2D( SurfSamplerDiffuse, float2( IN.UV.x, 1-IN.UV.y)); float4 colorAmbient = DiffuseColor; // Calculate light/eye/normal vectors float eyeAlt = IN.Altitudes.x; float3 eyeVec = normalize(IN.WorldEyeDirection); float3 normal = normalize(IN.WorldNormal); float3 lightVec = normalize(IN.WorldLightVec); // Calculate the amount of direct light float NdotL = max( dot( normal, -lightVec), 0); float4 colorDiffuse  = DiffuseColor * (NdotL * LightColor) + LightColorAmbient * DiffuseColor; colorOutput += colorDiffuse; colorOutput.a = 1.0f; // Calculate sun highlight... float sunHighlight = pow(max(0, dot(lightVec, -eyeVec)), sunRadiusAttenuation) * SunLightness; // Calculate a wider sun highlight float largeSunHighlight = pow(max(0, dot(lightVec, -eyeVec)), largeSunRadiusAttenuation) * largeSunLightness; // Calculate 2D angle between pixel to eye and sun to eye float3 flatLightVec = normalize(float3(lightVec.x, 0, lightVec.z)); float3 flatEyeVec = normalize(float3(eyeVec.x, 0, eyeVec.z)); float diff = dot(flatLightVec, -flatEyeVec); // Based on camera altitude, the haze will look different and will be lower on the horizon. // This is simulated by raising YAngle to a certain power based on the difference between the // haze top and camera altitude. // This modification of the angle will show more blue sky above the haze with a sharper separation. // Lerp between 0.25 and 1.25 float val = lerp(0.25, 1.25, min(1, hazeTopAltitude / max(0.0001, eyeAlt))); // Apply the power to sharpen the edge between haze and blue sky float YAngle = pow(max(0, -eyeVec.y), val); // Fetch the 3 colors we need based on YAngle and angle from eye vector to the sun float4 fogColorDay = tex2D( SurfSamplerSkyTextureDay, float2( 1 - (diff + 1) * 0.5, 1-YAngle)); float4 fogColorSunset = tex2D( SurfSamplerSkyTextureSunset, float2( 1 - (diff + 1) * 0.5, 1-YAngle)); float4 fogColorNight = tex2D( SurfSamplerSkyTextureNight, float2( 1 - (diff + 1) * 0.5, 1-YAngle)); float4 fogColor; // If the light is above the horizon, then interpolate between day and sunset // Otherwise between sunset and night if (lightVec.y > 0) { // Transition is sharpened with dayToSunsetSharpness to make a more realistic cut // between day and sunset instead of a linear transition fogColor = lerp(fogColorDay, fogColorSunset, min(1, pow(abs(1 - lightVec.y), dayToSunsetSharpness))); } else { // Slightly different scheme for sunset/night. fogColor = lerp(fogColorSunset, fogColorNight, min(1, -lightVec.y * 4)); } // Add sun highlights fogColor += sunHighlight + largeSunHighlight;    // Apply fog on output color colorOutput = lerp(fogColor, colorOutput, IN.Fog); // Make sun brighter for the skybox... //if (isSkydome) colorOutput = fogColor + sunHighlight; return colorOutput;}technique SkyDome { pass p0 { CullMode = None; VertexShader = compile VS_SHADERMODEL mainVS(); PixelShader = compile PS_SHADERMODEL mainPS(); }}
Logged

#### Stainless

• moderator
• member
• Offline
• Posts: 1240
##### Re: Weekly progress report
« Reply #338 on: December 14, 2018, 02:05:34 AM »

Thinking about it, I should put in a modified lighting equation for altitude. It is easy to do and will make a difference.

Currently I am using the horizontal plane as a filter, all I need to do is use the aircraft's altitude to rotate the plane till it is a tangent to the Earths surface at a point were the altitude intersects the Earth.

This image shows what I mean.

In the case described here, currently the aircraft would have no diffuse lighting. With the mod it would as the purple line would be the filter instead of the red.

It's only a rotation of a vector, but it would make a big difference.
Logged

#### slibenli

• member
• Offline
• Posts: 254
##### Re: Weekly progress report
« Reply #339 on: December 16, 2018, 06:53:49 AM »

I calculate the scattering in my shader.

Here it is if it is useful

Thanks, I'll look into it at some point.
Logged

#### Stainless

• moderator
• member
• Offline
• Posts: 1240
##### Re: Weekly progress report
« Reply #340 on: December 17, 2018, 05:13:42 AM »

Okay back to normal one step forward two steps back....

I dropped in the moon. I use the latitude and longitude as well as the date and time to calculate the position of the moon in the sky, and that seems correct. Needs more testing , but generally looks ok.

Then I calculate the Earths position in heliocentric coordinates and use that as the light direction so I get the correct moon phase. Except it's wrong.

Moon rise.

A few hours later

WTF!

Has the Earth moved massiveley around it's orbit in a few hours????

Any ideas?

What is wrong with this?

Code: [Select]
        public static Vector3 GetSunDirection(DateTime when)        {            //1. Days elapsed since J2000 (1st january 2000 at 12:00)            DateTime epoch = new DateTime(2000, 1, 1, 12, 0, 0);            TimeSpan j2000TS = when.ToUniversalTime() - epoch;            double j2000 = j2000TS.TotalDays;            //2. Centuries since J2000            double cJ2000 = j2000 / 36525.0f;            double inclinationE = (0.00005f - 46.94f * cJ2000 / 3600.0f) * rad;            double longNodeE = (-11.26064f - 18228.25f * cJ2000 / 3600.0f) *rad;            double longPeriE = (102.94719f + 1198.28f * cJ2000 / 3600.0f) * rad;            double meanDistE = 1.00000011f - 0.00000005f * cJ2000;            double eccenctricityE = 0.01671022f - 0.00003804f * cJ2000;            double meanLongE = Mod2Pi((100.46435f + 129597740.63f * cJ2000 / 3600.0f) * rad);            //Position of Earth in its orbit            double me = Mod2Pi(meanLongE - longPeriE);            double ve = TrueAnomaly(me, eccenctricityE);            double pEarthOrbit = meanDistE * (1 - eccenctricityE * eccenctricityE) / (1 + eccenctricityE * Math.Cos(ve));            //Heliocentric rectangular coordinates of Earth            double xe = pEarthOrbit * Math.Cos(ve + longPeriE);            double ye = pEarthOrbit * Math.Sin(ve + longPeriE);            double ze = 0.0f;            return new Vector3((float)xe, (float) ze, (float)ye);        }

Or am I just stupid and missing something obvious.

Logged

#### Pursuivant

• member
• Offline
• Posts: 668
##### Re: Weekly progress report
« Reply #341 on: December 18, 2018, 02:30:12 PM »

Assuming that the moon hasn't suddenly jumped to a new position in the sky (hard to tell because shifted PoV between the two pics), my guess is that you've got the shading effects on the "far side" of the moon a bit too dark, and you're not taking into account the fact that the portions of the moon which are illuminated by the sun are actually "emitting" (actually reflecting) light which better penetrates the Earth's atmosphere.

The fix might be just as simple as making the "moon by daylight" "texture" a bit lighter so that the brightest portions are visible against the morning sky, but the darker portions aren't so visible or shading the texture from white/yellow light on the illuminated portions to "sky color" on the unilluminated portions.
Logged

#### Stainless

• moderator
• member
• Offline
• Posts: 1240
##### Re: Weekly progress report
« Reply #342 on: December 19, 2018, 04:01:24 AM »

No , sadly it's far more serious than that.

It's the parallax problem.

I am trying to mimic a very large object a very long way away by drawing a much smaller object much closer.

However when I do that I can see around the back of the object as it moves around the sky.

The only solution I can see is to render the moon to a texture then draw a quad in the main game scene at the correct point in the sky. One step forward....
Logged

#### Stainless

• moderator
• member
• Offline
• Posts: 1240
##### Re: Weekly progress report
« Reply #343 on: December 20, 2018, 04:51:37 AM »

Anybody else noticed wobbly props on the He111?

Logged

#### Pursuivant

• member
• Offline
• Posts: 668
##### Re: Weekly progress report
« Reply #344 on: December 20, 2018, 01:18:01 PM »

The only solution I can see is to render the moon to a texture then draw a quad in the main game scene at the correct point in the sky. One step forward....

Or somehow rewrite the algorithm to "bend" light appropriately for a very large, distant object, but just for the moon.

But, no reason for the moon to be an actual physical object as opposed to just being a light source, and since you need a better texture anyway your solution is probably better.

The only sacrifice to realism is that the moon's surface will always be static relative to the Earth, which would only really make a difference if you were writing a space flight simulator!
Logged

#### Pursuivant

• member
• Offline
• Posts: 668
##### Re: Weekly progress report
« Reply #345 on: December 20, 2018, 01:24:50 PM »

Anybody else noticed wobbly props on the He111?

Yes, but I'd want to see it at a different angle and prop pitch/speed before I'm certain.

It might be a weirdness in the way your simulator renders models imported from IL2, but more likely, its some bug created many years ago by 1c and never noticed or fixed until now. The He-111 models are old to ancient.
Logged

#### Stainless

• moderator
• member
• Offline
• Posts: 1240
##### Re: Weekly progress report
« Reply #346 on: December 21, 2018, 02:15:34 AM »

What I am thinking of doing is keeping my current bump mapped moon, but render it to a texture using a calculated moon phase and angle based on latitude, longitude , and date.

This would then be added to the sky as a 2D axis aligned quad.

I would then render a second axis aligned quad over the top for moon glow based on a calculated "moonlight" value to give a glow and the same value could be used as a light source at night lighting objects in the world.

Well that is what I am planning anyway.
Logged

#### Stainless

• moderator
• member
• Offline
• Posts: 1240
##### Re: Weekly progress report
« Reply #347 on: January 23, 2019, 08:25:50 AM »

So now I render the moon into a texture using a  moon phase angle calculated from the current game date and time.

Then I calculate the moons position based on date, time, latitude, longitude and render the texture at the correct point in space.

I use a variable to position the moon in world space which I need to calculate based on date time, currently it is fixed but when I figure out the equation it will allow me to change the visible size of the moon so we can have super moons.

I also render with a colour which is currently white, when I figure out how to calculate partial lunar eclipses I can modify this colour to give us blood moons.

So far so good, now I just need to add a moon glow effect to the sky....  then add the stars ... sigh.

My TODO list is not a list , it's a fecking encyclopedia.

Logged
Pages: 1 ... 26 27 28 [29] 30 31 32 ... 34   Go Up

Page created in 0.012 seconds with 26 queries.