# New ReleaseD3D9Client Development

#### Felix24

##### Member
Dude, this is awesome!

I was able to make it visible away from the terminator. Try this code in Surface.fx, starting at line 1079:
PHP:
		float dCS = dot(nrm, vSunDir);			// Cloud normal sun angle
//float dMN = dot(frg.nrmW, vSunDir);	// Planet mean normal sun angle

// increase brightness of sun illumination with low sun angle, twice is nicer
// Lambertian looks dull, this looks better
dCS = saturate((dCS * (1.0f -dCS)) + dCS); // new
dCS = saturate((dCS * (1.0f -dCS)) + dCS); // new

// Effect of normal/sun angle to color
// Add some brightness (borrowing red channel from sunset attenuation)
// Adding it to the sun illumination factor, taking care to keep from saturating
cTex.rgb *= (0.2f * frg.atten.r) + (0.8f * dCS); // new
}
#endif

#if defined(_CLOUDMICRO)
float f = cTex.a;
float g = lerp(1, cMic.a, frg.fade.y);
float h = (g + 4.0f)*0.2f;
cTex.a = saturate(lerp(g, h, f) * f);
#endif

// make the light falloff to be grayscale; to me, cloud tops look better this way than colored
// borrow the red channel because it penetrates farther through atmosphere
// multiply it by 3 to keep it brighter closer to the terminator
float3 color = cTex.rgb*saturate(frg.atten.r*3)*fCloudInts + frg.insca.rgb*vHazeMax; // new

return float4(saturate(color + a), cTex.a*saturate(fCloudInts*fCloudInts));
}

#### DaveS

##### Space Shuttle Ultra Project co-developer
Donator
Beta Tester
Dude, this is awesome!

I was able to make it visible away from the terminator. Try this code in Surface.fx, starting at line 1079:
PHP:
        float dCS = dot(nrm, vSunDir);            // Cloud normal sun angle        //float dMN = dot(frg.nrmW, vSunDir);    // Planet mean normal sun angle                // increase brightness of sun illumination with low sun angle, twice is nicer        // Lambertian looks dull, this looks better        dCS = saturate((dCS * (1.0f -dCS)) + dCS); // new        dCS = saturate((dCS * (1.0f -dCS)) + dCS); // new        // Effect of normal/sun angle to color        // Add some brightness (borrowing red channel from sunset attenuation)        // Adding it to the sun illumination factor, taking care to keep from saturating        cTex.rgb *= (0.2f * frg.atten.r) + (0.8f * dCS); // new    }#endif#if defined(_CLOUDMICRO)        float f = cTex.a;        float g = lerp(1, cMic.a, frg.fade.y);        float h = (g + 4.0f)*0.2f;        cTex.a = saturate(lerp(g, h, f) * f);#endif    // make the light falloff to be grayscale; to me, cloud tops look better this way than colored    // borrow the red channel because it penetrates farther through atmosphere    // multiply it by 3 to keep it brighter closer to the terminator    float3 color = cTex.rgb*saturate(frg.atten.r*3)*fCloudInts + frg.insca.rgb*vHazeMax; // new    return float4(saturate(color + a), cTex.a*saturate(fCloudInts*fCloudInts));    //return float4(saturate(color + a), cTex.a*saturate(frg.fade.x*fCloudInts*fCloudInts)); }
</div>I've applied this code Surface.fx and I'm not getting anything like in your screenshots. Still only visible near the terminator. Have I done something wrong? I replaced all the existing code from 1079 to 1100. Did I miss something?

#### Felix24

##### Member
</div>I've applied this code Surface.fx and I'm not getting anything like in your screenshots. Still only visible near the terminator. Have I done something wrong? I replaced all the existing code from 1079 to 1100. Did I miss something?

Sorry, I must have missed something. Here's the whole code section in case I forgot something. Replacing lines 1034 through 1102:

PHP:
float4 CloudTechPS(CloudVS frg) : COLOR
{
float2 vUVMic = frg.texUV.xy * vMicroOff.zw + vMicroOff.xy;
float2 vUVTex = frg.texUV.xy;

float a = (tex2Dlod(NoiseTexS, float4(vUVTex,0,0)).r - 0.5f) * ATMNOISE;

float4 cTex = tex2D(DiffTexS, vUVTex);
float4 cMic = tex2D(CloudMicroS, vUVMic);

#if defined(_CLOUDNORMALS)

if (bCloudNorm) {

/*#if defined(_CLOUDMICRO)
float4 cMicNorm = tex2D(CloudMicroNormS, vUVMic);  // Filename "cloud1_norm.dds" (does not exists in distribution)
#endif*/

// Filter width
float d = 2.0 / 512.0;
float3 nrm = 0;

float x1 = tex2D(DiffTexS, vUVTex + float2(-d, 0)).a;
float x2 = tex2D(DiffTexS, vUVTex + float2(+d, 0)).a;
nrm.x = (x1*x1 - x2*x2);

float y1 = tex2D(DiffTexS, vUVTex + float2(0, -d)).a;
float y2 = tex2D(DiffTexS, vUVTex + float2(0, +d)).a;
nrm.y = (y1*y1 - y2*y2);

float m = max(abs(nrm.x), abs(nrm.y));

// Bump magnitude/contrast function
float contrast = m * 1.0f;

/*#if defined(_CLOUDMICRO)
nrm.xy = nrm.xy * cMicNorm.rg * 4.0f; // Blend Normals
#endif*/

nrm = normalize(nrm) * contrast;
nrm.z = sqrt(1.0f - nrm.x*nrm.x - nrm.y*nrm.y);

// Approximate world space normal from local tangent space
nrm = normalize((vTangent * nrm.x) + (vBiTangent * nrm.y) + (frg.nrmW * nrm.z));

float dCS = dot(nrm, vSunDir);			// Cloud normal sun angle
//float dMN = dot(frg.nrmW, vSunDir);	// Planet mean normal sun angle

dCS = saturate((dCS * (1.0f -dCS)) + dCS);
dCS = saturate((dCS * (1.0f -dCS)) + dCS);

// Effect of normal/sun angle to color
cTex.rgb *= (0.2f * frg.atten.r) + (0.8f * dCS);
//cTex.rgb *= dCS + ((1.0f - dCS) * 0.2f * frg.atten.r);
}
#endif

#if defined(_CLOUDMICRO)
float f = cTex.a;
float g = lerp(1, cMic.a, frg.fade.y);
float h = (g + 4.0f)*0.2f;
cTex.a = saturate(lerp(g, h, f) * f);
#endif

float3 color = cTex.rgb*saturate(frg.atten.r*3)*fCloudInts + frg.insca.rgb*vHazeMax;

return float4(saturate(color + a), cTex.a*saturate(fCloudInts*fCloudInts));
}

Edit: One more idea: I didn't change my atmospheric parameters at all, so if you did, you should try restoring the default settings and try again.

Last edited:

#### DaveS

##### Space Shuttle Ultra Project co-developer
Donator
Beta Tester
Restoring the original atmospheric parameters worked and some tweaking later it is very impressive, especially at higher altitudes, in this case some 555 km up.

#### Attachments

• D3D9Client_impressive_sunrise.jpg
111.4 KB · Views: 32

#### DaveS

##### Space Shuttle Ultra Project co-developer
Donator
Beta Tester
Felix24: Could you confirm that there's not supposed to be any cloud normal mapping at the solar angle shown in the attached screenshot? If so, then more work remains as clouds still look very flat.

#### Attachments

• No_cloud_normal_maps.jpg
73.8 KB · Views: 29

#### Felix24

##### Member
Felix24: Could you confirm that there's not supposed to be any cloud normal mapping at the solar angle shown in the attached screenshot? If so, then more work remains as clouds still look very flat.

My feeling is that you should be seeing the effect more than that.

The clouds in your screenshot look very blurry at that angle. That could be the cause, but I'm not sure. What is your altitude and FOV? Also, can you enable planetarium mode so that I have more visual cues?

I might be able to figure out how to increase the depth of the normal map, enhancing the cloud surface texture. I also want the microtexture to affect the normal map too.

#### DaveS

##### Space Shuttle Ultra Project co-developer
Donator
Beta Tester
My feeling is that you should be seeing the effect more than that.

The clouds in your screenshot look very blurry at that angle. That could be the cause, but I'm not sure. What is your altitude and FOV? Also, can you enable planetarium mode so that I have more visual cues.
FoV: 60°
Altitude: 76.2 km

#### Attachments

• No_cloud_normal_maps2.jpg
144 KB · Views: 25

#### jarmonik

Beta Tester
Dude, this is awesome!

Yes, this is really awesome !
:thumbup:

---------- Post added at 02:53 ---------- Previous post was at 02:42 ----------

My question is : Do we need manually edit elevation tiles (hard work) or does exist a fix trough parameters (d3d9 client or nvidia driver...) ?

We are aware of some caps appearing between the tiles. Some places are more sensitive to caps than others, there are no known fix for that right now. Manually editing something is unlikely going to work. Since it's a minor cosmetic issue, I'll look into it when doing some other upgrades to the elevation, there are some other issues too with the elevation that would need to be solved.

#### Felix24

##### Member
FoV: 60°
Altitude: 76.2 km

I think the clouds look flat in that situation because the cloud bumps become really visible only when the sun is less than ~20 degrees above the horizon, and in the screenshot, the sun is closer to 45 degrees.

That, coupled with the relatively low altitude and the resolution of the cloud textures, I think this is a situation where microtextures are the only real solution. I'm experimenting with microtextures right now.

#### Wolf

##### Donator
Donator
Dude, this is awesome!

I was able to make it visible away from the terminator. Try this code in Surface.fx, starting at line 1079:
PHP:
        float dCS = dot(nrm, vSunDir);            // Cloud normal sun angle        //float dMN = dot(frg.nrmW, vSunDir);    // Planet mean normal sun angle                // increase brightness of sun illumination with low sun angle, twice is nicer        // Lambertian looks dull, this looks better        dCS = saturate((dCS * (1.0f -dCS)) + dCS); // new        dCS = saturate((dCS * (1.0f -dCS)) + dCS); // new        // Effect of normal/sun angle to color        // Add some brightness (borrowing red channel from sunset attenuation)        // Adding it to the sun illumination factor, taking care to keep from saturating        cTex.rgb *= (0.2f * frg.atten.r) + (0.8f * dCS); // new    }#endif#if defined(_CLOUDMICRO)        float f = cTex.a;        float g = lerp(1, cMic.a, frg.fade.y);        float h = (g + 4.0f)*0.2f;        cTex.a = saturate(lerp(g, h, f) * f);#endif    // make the light falloff to be grayscale; to me, cloud tops look better this way than colored    // borrow the red channel because it penetrates farther through atmosphere    // multiply it by 3 to keep it brighter closer to the terminator    float3 color = cTex.rgb*saturate(frg.atten.r*3)*fCloudInts + frg.insca.rgb*vHazeMax; // new    return float4(saturate(color + a), cTex.a*saturate(fCloudInts*fCloudInts));    //return float4(saturate(color + a), cTex.a*saturate(frg.fade.x*fCloudInts*fCloudInts));}

How do you get that beautiful 3D clouds effect?

#### kuddel

##### Donator
Donator
@Jarmonik: We should make Felix' CloudTechPS the default one shouldn't we?

#### Felix24

##### Member
@Jarmonik: We should make Felix' CloudTechPS the default one shouldn't we?

I'm not done with it, still working on improving it.

#### jarmonik

Beta Tester
@Jarmonik: We should make Felix' CloudTechPS the default one shouldn't we?

Yes, when it's ready, we will include it.

#### DaveS

##### Space Shuttle Ultra Project co-developer
Donator
Beta Tester
Would it be possible to implement a random cloud generator? That would eliminate these ugly things(the seams in the cloud layer texture):

#### Attachments

• cloud_layer_seam.jpg
112.9 KB · Views: 25

#### jedidia

##### shoemaker without legs
Would it be possible to implement a random cloud generator?

That would be non-trivial, and I think that's quite an understatement... It would take quite some effort to make them look half as good as high-resolution satelite imagery. Maybe Artlav still has some code lying about...?
In any case, I'm not familiar with the clients architecture. It might take some major rearranging to stream the data in there. If it's getting the data from orbiter itself (which I assume it does, no point in forcing graphics clients to re-implement the whole file-streaming mess), it might even get pretty hacky...

#### kuddel

##### Donator
Donator
[...]still working on improving it.
Whaaat? It can be improved? :thumbup:

#### DaveS

##### Space Shuttle Ultra Project co-developer
Donator
Beta Tester
That would be non-trivial, and I think that's quite an understatement... It would take quite some effort to make them look half as good as high-resolution satelite imagery. Maybe Artlav still has some code lying about...?
In any case, I'm not familiar with the clients architecture. It might take some major rearranging to stream the data in there. If it's getting the data from orbiter itself (which I assume it does, no point in forcing graphics clients to re-implement the whole file-streaming mess), it might even get pretty hacky...
kuddel did link to this earlier when clouds were being discussed: https://www.orbiter-forum.com/showthread.php?p=605539&postcount=5172

#### jarmonik

Beta Tester
kuddel did link to this earlier when clouds were being discussed: https://www.orbiter-forum.com/showthread.php?p=605539&postcount=5172

I did look into that but I don't remember the details nothing that would really solve anything. What kind of cloud rendering policy should we have ? There are three main conditions:
1) How the clouds looks when standing at sea level.
2) How the clouds looks when flying near them (slightly above/below)
3) And how do they look when viewed from Orbit.

Should we focus on orbital rendering and forget the rest. Most computer games only deal with cases 1 & 2. And most topics/publications regarding cloud rendering are about those two cases.

When comparing Orbiter clouds to many photographs they are pretty good when the sun angle is high.

Combined cloud visual image and altimeter data (in pixel basis) would be useful but I highly doubt that any exists.

#### DaveS

##### Space Shuttle Ultra Project co-developer
Donator
Beta Tester
Wouldn't cases 1 and 2 take care of case 3 given their 3D nature? Clouds are never flat like we have them right now, they always have a thickness to them as they're measured by their bases and tops.

#### Felix24

##### Member
Try this updated CloudTechPS (goes in Surface.fx, replacing lines 1034-1102 of the original), and don't forget to download the updated cloud microtextures zip file below the screenshots.

This is not perfect- see the artifacts in the last screenshot.

Reset your atmospheric parameters or else it won't look like the other screenshots.

Thanks to Jarmonik for adding this capability and for pointing out the section of code to play with.

PHP:
float4 CloudTechPS(CloudVS frg) : COLOR
{
float2 vUVMic = frg.texUV.xy * vMicroOff.zw + vMicroOff.xy;
float2 vUVTex = frg.texUV.xy;

float a = (tex2Dlod(NoiseTexS, float4(vUVTex,0,0)).r - 0.5f) * ATMNOISE;

float4 cTex = tex2D(DiffTexS, vUVTex);
float4 cMic = tex2D(CloudMicroS, vUVMic);

#if defined(_CLOUDNORMALS)

if (bCloudNorm) {

#if defined(_CLOUDMICRO)
float4 cMicNorm = tex2D(CloudMicroNormS, vUVMic);  // Filename "cloud1_norm.dds" (does not exists in distribution)
#endif

// Filter width
float d = 2.0 / 512.0;
float3 nrm = 0;
float3 nrmMicro = 0;

float x1 = tex2D(DiffTexS, vUVTex + float2(-d, 0)).a;
float x2 = tex2D(DiffTexS, vUVTex + float2(+d, 0)).a;
nrm.x = (x1*x1 - x2*x2);

float y1 = tex2D(DiffTexS, vUVTex + float2(0, -d)).a;
float y2 = tex2D(DiffTexS, vUVTex + float2(0, +d)).a;
nrm.y = (y1*y1 - y2*y2);

float m = max(abs(nrm.x), abs(nrm.y));

float dMN = dot(frg.nrmW, vSunDir);	// Planet mean normal sun angle
// Bump magnitude/contrast function
// Increase normals contrast based on sun-earth angle.
float contrast = (m * (1.0f + (dMN*2.0f)));

#if defined(_CLOUDMICRO)
// Blend in cloud normals only on thick clouds.
nrm.xy = (nrm.xy + saturate((cTex.a * 4.0f) - 1.5f) * (cMicNorm.rg - 0.5f));
#endif

nrm = normalize(nrm) * contrast;
nrm.z = sqrt(1.0f - nrm.x*nrm.x - nrm.y*nrm.y);

// Approximate world space normal from local tangent space
nrm = normalize((vTangent * nrm.x) + (vBiTangent * nrm.y) + (frg.nrmW * nrm.z));

float dCS = dot(nrm, vSunDir);			// Cloud normal sun angle

// Brighten the lighting model for clouds, based on sun-earth angle.
// Low sun angles = greater effect. No modulation leads to washed out normals at high sun angles.
dCS = saturate((1.0f - dMN) * (dCS * (1.0f - dCS)) + dCS);
dCS = saturate((1.0f - dMN) * (dCS * (1.0f - dCS)) + dCS);

// Effect of normal/sun angle to color
// Add some brightness (borrowing red channel from sunset attenuation)
// Adding it to the sun illumination factor, taking care to keep from saturating
cTex.rgb *= dCS + ((1.0f - dCS) * 0.2f);
}
#endif

#if defined(_CLOUDMICRO)
float f = cTex.a;
float g = lerp(1.0f, cMic.a, frg.fade.y);
float h = (g + 4.0f)*0.2f;
cTex.a = saturate(lerp(g, h, f) * f);
#endif

// Reduce attenuation near terminator (multiply by 3)
// Change attenuation to be grayscale, not colored (.r not .rgb)
// Ensure illumination goes as far as possible by borrowing red channel (.r)
float3 color = cTex.rgb*saturate(frg.atten.r*3)*fCloudInts + frg.insca.rgb*vHazeMax;

return float4(saturate(color + a), cTex.a*saturate(fCloudInts*fCloudInts));
}

Microtextures disabled:

Microtextures enabled:

Not sure why Antarctica is pink/orange:

Microtextures enabled:

Microtextures disabled:

In the next image, the shadows turn into some ugly artifacts when the sun is directly overhead.

#### Attachments

• 2020-08-07 cloud microtextures.zip
2.8 MB · Views: 6