Jump to content

Rogen's P3D v4


Recommended Posts

@dave2013

"Yes, his screenshots are quite nice, but realize that in some of them he is certainly using highly detailed payware scenery.  These are not pics of vanilla P3D.
His signature states: "Orbx Global, Vector and more".  I would add "lots more".
Dave"

From: Biggest differences and gains between v4 and v5? - The Prepar3d Forum - The AVSIM Community
----

That's the thing. We'll all be guessing unless Rogen himself create a version specific compilation of what he used and document his personal best-of P3D version.  A How To Guide or 'official' PDF guide of sorts which includes names and versions of software and hardware he used to create his personal best-of for a P3D version.

The community could use it as a baseline to compare other flightsim versions. Are newer versions really better? His pictures made me re-install P3D v4.5. As a result, I am now enjoying add-ons in P3D not available in other flightsim software.

Does anyone remember NickN and his guide to FSX? I wish NickN created a pdf file also of this post. We could use an update for version P3D v5 and v6 and other flightsims too:

https://forums.flightsimulator.com/t/anyone-remember-nickns-bible/372568/2

THE FSX COMPUTER SYSTEM: THE BIBLE - BY: NickN - SimForums.com Discussion

Nick Needham - In Memoriam - The AVSIM Community

  • Like 1
Link to comment

 

I don't actually use the preset, I kind of rolled my own.

And with regards to weather I mean clear skies (I stop ASN and choose clear skies), so that the weather is not influencing visibility and thus causing over or under adjustment of the Rayleigh scattering.

Some Info:

What I found was the author of Tomatoshade never updated to cater for 4.5 HF3 (that I'm aware of at least - v31 is the last I have).

As a result I noticed a ton of errors in the P3D logs.

At that point I found as long as you're not using the reflection options it is still a valuable tool in defining lighting and things like Rayleigh scattering.

So I rolled my own settings which I've been tweaking to my liking ever since, I've pasted the ini into a spoiler for your preview.

I also make two manual changes to 2 x shaders, one change to resolve a math issue and the other change for precipitation. Neither may apply to yourself as not all configs would have the same shader values but here they are based on my ini file.

Note if changing the values below they will be overwritten whenever the Tomatoshade config is applied, so the process would be to apply the Tomatoshade settings, then the edits, then trigger P3D to regenerate its shader cache, confirm the look and rinse and repeat until satisfied.

Cheers R

What I really like about P3D is there are a host of easily configurable settings able to be made with just a text editor.

e.g. slow down the road traffic, reset the sun/moon size, plus all the option avaialble in the P3D config file, great stuff to tune the look feel.

 

GPUTerrain.fx - wrap calc in an abs()

#pragma warning( disable : 3571 )
float2 atmoHeightDepth(float heightScale, float angle, float2 baseScale)
{
    return exp(-baseScale * heightScale) * (pow(abs(18.8125 * angle + 1.0), -1.28125) * 32.53323 + 0.29103) / baseScale;

}

 

PrecipParticle.fx - calcs for smaller looking rain/snow effects

void CreateStreakQuadVertices(float3 position, float3 velocity, float3 eyePosition, out float3 outQuadPosition[4], out float3 outQuadNormal)
{
    //Control how long streaks face and how big they are.
    // TBM 03/02/2019 change the calculated value for a smaller looking rain/snow effect
    float height = cb_fQuadSize * cb_fQuadSizeHeightScale / (2.4 - (cb_uPrecipType * 1.65));
    float width = cb_fQuadSize * cb_fQuadSizeWidthScale / (1.0 - (cb_uPrecipType * 0.25));
    
    //float height = cb_fQuadSize * cb_fQuadSizeHeightScale;
    //float width = cb_fQuadSize * cb_fQuadSizeWidthScale;

    velocity = normalize(velocity);
    float3 eyeVector = eyePosition - position;
    float3 eyeOnvelocityPlane = eyePosition - ((dot(eyeVector, velocity)) * velocity);
    float3 projectedeyeVector = eyeOnvelocityPlane - position;
    float3 sideVector = normalize(cross(projectedeyeVector, velocity));

    outQuadPosition[0] = position - (sideVector * 0.5 * width);
    outQuadPosition[1] = outQuadPosition[0] + (sideVector * width);
    outQuadPosition[2] = outQuadPosition[0] - (velocity * height);
    outQuadPosition[3] = outQuadPosition[2] + (sideVector * width);

    outQuadNormal = normalize(projectedeyeVector);
}

 

   Hide contents

[PTA VERSION]
Preset format=2

[PRESET COMMENTS]
Comment=

[HDR & POST-PROCESSING_HDRADAPTATION]
IsActive=0

[HDR & POST-PROCESSING_HDRTONE]
IsActive=0
Red=1.05
Green=1.00
Blue=1.05

[HDR & POST-PROCESSING_HDRTONEMAP]
IsActive=0
Uncharted2Tonemap=0

[WATER_WATER_SATURATION]
IsActive=1
SaturateRatio=0.65

[ATMOSPHERE & FOG_SKY_SATURATION]
IsActive=1
SaturateRatio=1.10

[ATMOSPHERE & FOG_SKY_FOG_TUNING]
IsActive=1
FogFactor=(saturate(0.15 - cb_Altitude/1438))

[HDR & POST-PROCESSING_HDRCONTRAST]
IsActive=0
Coeff=1.5

[WATER_WAVESPEED]
IsActive=0
SpeedRatio=1.0

[WATER_WAVESIZE]
IsActive=0
SizeRatio=1.0
SmoothRatio=2.0

[WATER_WATERSURFACE]
IsActive=0
ReflectionCoeff=(clamp(0.35 - 0.30 * cb_Altitude/700, 0.05, 0.35))
RefractionCoeff=(clamp(0.90 - 0.20 * cb_Altitude/304, 0.8, 0.9))
GranularityCoeff=3.00
SpecularBlend=1.5
FresnelAngle=4.0

[WATER_FSXREFLECTION]
IsActive=0

[ATMOSPHERE & FOG_RAYLEIGH_SCATTERING]
IsActive=1
DensityCorrection=1
ExcludeClouds=0
Power=3.42
Density=(saturate(0.00000000200 + (cb_Altitude-0)/(11000-0)*(0.00000000200-0.00000000280)))
Green=0.072
Blue=0.050
NoDensityAltitude=10000
VolumetricDensityHeight=10000
VolumetricDensityPower=2.0

[ATMOSPHERE & FOG_ATMO_HAZE]
IsActive=1
Power=1.21
Distance=(saturate(0.00000000015 + (cb_Altitude-0)/(11000-0)*(0.00000000015-0.00000000180)))
DensityCorrection=1
Red=1.00
Green=0.95
Blue=0.95
NoDensityAltitude=10000
VolumetricDensityHeight=10000

[ATMOSPHERE & FOG_CLOUDS_FOG_TUNING]
IsActive=1
FogFactor=0.5

[LIGHTING_BOOST_EMISSIVELANDCLASS]
IsActive=0
BoostRatio=1.0
SaturateRatio=2.0

[LIGHTING_TERRAIN_SATURATION]
IsActive=1
SaturateRatio=1.35

[LIGHTING_TERRAIN_LIGHTING]
IsActive=1
SunDiffuseCoeff=2.4
SunAmbientCoeff=0.8
MoonDiffuseCoeff=0.9
MoonAmbientCoeff=0.3
DiffuseGamma=1.05

[LIGHTING_SPECULAR_LIGHTING]
IsActive=1
SpecularRatio=1.4

[LIGHTING_AUTOGEN_LIGHTING]
IsActive=1
SunDiffuseCoeff=2.5
SunAmbientCoeff=1.0
MoonDiffuseCoeff=0.5
MoonAmbientCoeff=0.3
DiffuseGamma=1.0
Saturation=1.0

[CLOUDS_CLOUD_BRIGHTNESS_TWILIGHT]
IsActive=1

[CLOUDS_CIRRUS_BRIGHTNESS_TWILIGHT]
IsActive=0

[CLOUDS_CLOUD_SHADOWS_SIZE]
IsActive=1

[CLOUDS_CLOUD-SHADOW-DEPTH]
IsActive=1
Value=0.95

[CLOUDS_CLOUD_ALTERNATE_LIGHTING]
IsActive=0

[CLOUDS_CLOUD_SIZE]
IsActive=0
CloudSizeHCoeff=0.5
CloudSizeVCoeff=0.5

[CLOUDS_CLOUD_SATURATION]
IsActive=1
ShadeFactor=1.10

[CLOUDS_CLOUDS_LIGHTING_TUNING]
IsActive=0
CloudLightFactor=0.75
CloudSaturateFactor=0.33
DiffuseGamma=0.8

[CLOUDS_CIRRUS_LIGHTING]
IsActive=0
SaturateRatio=1.00
LightingRatio=1.00

[CLOUDS_CLOUD_VOLUME]
IsActive=1
ScatteringFactor=1.3
LightingFactor=0.5
NoPattern=1

[CLOUDS_POPCORN_MODIFICATOR]
IsActive=1
CloudDistanceFactor=0.00000000060
CloudOpacity=(clamp(0.10 + 0.20 * cb_Altitude/2000, 0.1, 0.3))

[LIGHTING_AIRCRAFT_LIGHTING]
IsActive=1
SunDiffuseCoeff=2.55
SunAmbientCoeff=0.89
MoonDiffuseCoeff=1.00
MoonAmbientCoeff=1.00
DiffuseGamma=1.05
SaturateRatio=1.05
VCOnly=0
VCSunDiffuseCoeff=
VCSunAmbientCoeff=
VCMoonDiffuseCoeff=
VCMoonAmbientCoeff=

[LIGHTING_AUTOGEN_EMISSIVE]
IsActive=1
LightsRatio=1.5
AutogenRatio=1.5
SmoothTransition=1

[TOMATO-MODE_OPTIMIZE REDUCE TRANSLUCENT SHADOW DISTANCE]
IsActive=1

[TOMATO-MODE_OPTIMIZE GPU TERRAIN RENDERING]
IsActive=1

[TOMATO-MODE_AUTOGEN DISTANCE SIZE]
IsActive=0
Factor=0.0025
FactorX=1.7777

[TOMATO-MODE_AUTOGEN POWER SMOOTHING]
IsActive=0
BasePowerFactor=0.7
MaxLightDistance=90000
FullPowerDistance=3000
DistanceCurvePower=4.0
Saturation=1.0
PowerLimit=0.0

[TOMATO-MODE_ADAPTIVE BLOOM]
IsActive=0
Power=3.0

[TOMATO-MODE_ALTERNATE TERRAIN LIGHTING]
IsActive=1
LightPower=0.4

[TOMATO-MODE_INCREASE PARTICLE SIZE WITH DIST]
IsActive=0
Factor=1.1

[TOMATO-MODE_DYNAMIC SPOT LIGHTS LIGHTING]
IsActive=1
AnglePower=1.0

[TOMATO-MODE_IMPROVE DYN LIGHT PERFORMANCE]
IsActive=1

[TOMATO-MODE_ADD MULTIPLE TEXTURE LOOKUPS]
IsActive=0

[TOMATO-MODE_SOFTEN SOLID SHADOWS]
IsActive=0

[TOMATO-MODE_ADVANCED ATMOSPHERE SCATTERING]
IsActive=1
PlanetRadius=6371e3
AtmosphereHeight=100000.0
AtmoBaseHeightOutScattering=0.00015
AtmoBaseHeightInScattering=0.00012
AbsorptionFactorRed=0.596e-5
AbsorptionFactorGreen=1.324e-5
AbsorptionFactorBlue=3.310e-5
AbsorptionScaleInRed=1.3
AbsorptionScaleInGreen=1.1
AbsorptionScaleInBlue=1.2
AbsorptionScaleGamma=2.5
InScatteringFactorAmbient=0.2
InScatteringFactorDiffuse=0.7
InScatteringDiffuseGamma=0.2
InScatteringStartFullDist=20000.0
TerrainOutputContrast=1.07875
ShadowsInflunceScattering=1

[TOMATO-MODE_ADVANCED FOG SCATTERING]
IsActive=1
ScatteringHeightPower=2.5
ScatteringHeightLimit=119716000000.0f
ScatteringDistanceBlue=82000
ScatteringDistanceGreen=145000
ScatteringDistanceRed=301000
ScatteringPowerBlue=0.85
ScatteringPowerGreen=0.65
ScatteringPowerRed=0.6
InScatteringSky=0.05
InScatteringSun=0.05

[TOMATO-MODE_FAST APPROXIMATION IMAGE BASED AIRCRAFT LIGHTING]
IsActive=0
DaylightAmbientIntensity=0.2
DaylightDiffuseIntensity=0.15
NightIntensity=0.2

[TOMATO-MODE_OPTIMIZE CLOUD MATRIX CALCULATION]
IsActive=1

[TOMATO_MODE_ALTERNATE SPECULAR LIGHTING]
IsActive=1

[TOMATO_MODE_PRECIPITATION OPACITY]
IsActive=0
OpacityRain=1.0
OpacitySnow=1.0

[TOMATO-MODE_IMPROVE GENERAL SHADOW RECEIVE]
IsActive=1

[TOMATO-MODE_IMPROVE TERRAIN SHADOW RECEIVE]
IsActive=1

[TOMATO_MODE_CHANGE CLOUD SHADOW RECEIVE CALCULATION]
IsActive=1

[TOMATO_MODE_CHANGE CLOUD SHADOW BUILD CALCULATION]
IsActive=1

[TOMATO_MODE_ADD CONDITIONAL DYNAMIC LIGHTING]
IsActive=1

[TOMATO_MODE_PER PIXEL CLOUD FOG]
IsActive=0

[TOMATO_MODE_BUMP MAP STRENGTH]
IsActive=1
IntensityScale=0.8

[TOMATO-MODE_OPTIMIZE PARTICLE DRAW]
IsActive=1

[TOMATO-MODE_OPTIMIZE PRECIPITATION DRAW]
IsActive=1

[TOMATO-REFLECTIONS_ADJUST STARS IN REFLECTION MAP]
IsActive=0
Intensity=0.0

[TOMATO-REFLECTIONS_ADJUST REFLECTION PARTICLE EMISSION]
IsActive=0
Size=64

[TOMATO-REFLECTIONS_ADJUST REFLECTION TERRAIN RENDERING]
IsActive=0
AddDetailTexture=1
MaxTextureLOD=14

[TOMATO-REFLECTIONS_ADJUST REFLECTION GENERAL RENDERING]
IsActive=0

[TOMATO-REFLECTIONS_OPTIMIZE CLOUD REFLECTIONS]
IsActive=0

[TOMATO-REFLECTIONS_TOMATO EXTENDED REFLECTION RENDERING]
IsActive=0

[TOMATO-REFLECTIONS_FIX GENERAL PROJECTION]
IsActive=0

[TOMATO-REFLECTIONS_FIX CLOUD PROJECTION]
IsActive=0

[TOMATO-REFLECTIONS_FIX TERRAIN PROJECTION]
IsActive=0

[TOMATO-REFLECTIONS_FIX PARTICLE PROJECTION]
IsActive=0

[POSTPROCESS_SHADER DPX]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A5265643D382E300D0A477265656E3D382E300D0A426C75653D382E300D0A526564433D302E33360D0A477265656E433D302E33360D0A426C7565433D302E33340D0A44505853617475726174696F6E3D332E300D0A436F6C6F7247616D6D613D322E350D0A426C656E643D302E320D0A

[POSTPROCESS_SHADER Tonemap]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A47616D6D613D312E300D0A4578706F737572653D302E300D0A53617475726174696F6E3D302E300D0A426C656163683D302E300D0A4465666F673D302E300D0A466F67436F6C6F72583D302E300D0A466F67436F6C6F72593D302E300D0A466F67436F6C6F725A3D322E35350D0A

[POSTPROCESS_SHADER LiftGammaGain]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A5247425F4C696674583D312E300D0A5247425F4C696674593D312E300D0A5247425F4C6966745A3D312E300D0A5247425F47616D6D61583D312E300D0A5247425F47616D6D61593D312E300D0A5247425F47616D6D615A3D312E300D0A5247425F4761696E583D312E300D0A5247425F4761696E593D312E300D0A5247425F4761696E5A3D312E300D0A

[POSTPROCESS_SHADER Vibrance]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A56696272616E63653D302E320D0A56696272616E63655F5247425F62616C616E6365583D312E300D0A56696272616E63655F5247425F62616C616E6365593D312E300D0A56696272616E63655F5247425F62616C616E63655A3D312E300D0A

[POSTPROCESS_SHADER Sepia]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A436F6C6F72546F6E65583D312E340D0A436F6C6F72546F6E65593D312E310D0A436F6C6F72546F6E655A3D302E390D0A47726579506F7765723D302E31310D0A5365706961506F7765723D302E35380D0A

[POSTPROCESS_SHADER Technicolor]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A546563686E69416D6F756E743D302E340D0A546563686E69506F7765723D342E300D0A7265644E65676174697665416D6F756E743D302E38380D0A677265656E4E65676174697665416D6F756E743D302E38380D0A626C75654E65676174697665416D6F756E743D302E38380D0A

 

Rogen sent me This a while back .

it would be great if anyone could break it down into an preset for us using RDSHADE

mike

 

 

 

  • Like 1
Link to comment

Hi Folks,

My presets are almost always in a state of flux being as I fly and maybe notice an item I'd like to change and therefore tweek a preset or setting.

So anything you see in my various previous forum post spoliers would relate to the date of the forum post only.

I'll give a bit of a dot point list of the items I use to achive the look-feel of the sim below.

  • P3D v4.5 HF3.
  • Tomatoshade with my own custom preset - no enhanced reflections.
  • Custom cloud shader (for dynamicaly lit clouds).
  • Custom mods to the GPUTerrain.fx (bugfix related to TomatoShade) & PrecipParticle.fx (look improvement).
  • ReShade (used to tweek colour, sharpness, banding and add faux ambient occlusion).
  • Freemesh (for the world).
  • REX 4 Texture Direct with Soft Clouds.
  • REX World Wide Airports.
  • Orbx Global Base.
  • Orbx Vector.
  • Orbx Regions.
  • Orbx HD Buildings.
  • Orbx Terraflora V2 (this I found was missing textures which Orbx have since corrected).
  • Global Orbx Wave Effects.
  • Drzewiecki Design HDGrass
  • A2A Accu-Feel.
  • The Orbx air traffic packs.
  • Alpha India Group (AIG) air traffic.
  • AI Lights Reborn (the free version).
  • AI Flow & AI Ground.
  • Global AI Ship Traffic V2.
  • Edit Voice Pack.
  • Banking Camera (to bank the view in line with the aircraft bank angle).
  • McCoy Effects (dirt and water fx).
  • PrecipitFX Effects (aircraft wash and braking fx).
  • Time Zone Fixer.
  • HD moon.
  • HD Milky way.
  • AutoStarsX.
  • Active Sky.
  • Real Turbulance (Hooks into Active Sky).
  • FFTF dynamic.
  • Landing Rate Monitor.
  • JoyToKey (for assigning key combos to joysticks that are not otherwise possible in P3D directly).

 

There is more than the above, these being more related to specific usage and non-defaults.

  • GPS 2020.
  • EasyFMC.
  • Reality XP GTN.
  • XMLTools64.
  • RealLight and True Glass.
  • ShockWave lighting.
  • Radar Contact.
  • Roland's Radar.
  • Rob Barendregt's Ground Handling.
  • AI Companion.
  • Little Nav Map.
  • P3D Addon Organiser
  • FSUIPC (registered).
  • SODE.

Then there are specific scenery addons and airports, mostly Orbx but there are a variety overall, I'm not going to list these are there are quite a few.

There are also many ajustments possible within the p3d config file where I've targeted configuration to better use the available resources i.e. ramped up values to max in some cases affecting things like shadows, texture requests, tree alignments to curves, the count of trees and autogen, lighting maximums, memory usage and memory clearing, noting p3d in default is typically configured for relatively lowly powered hardware.

Unfortuatelly LM's SDK cfg doco is quite sparse when it comes to information on values to use and how they are intended to function. Such is not uncommon in the software world as devs I've worked with in various software developments often don't know various settings themselves and need to delve into the code to discover the nitty gritty of the whats, whys and values for definintion. Painful and unfortunately not really an option with LM since they rarely answer questions on their forum where the info I've gathered has been from many different posts and forums etc.

It's important to note the prepar3d.cfg is just an ini file, there is no magic to it and best practices when editing are to make a regular backup, comment out the default setting and add the changed setting along with a comment on when and why you changed the value.

Of advantage is the multiple config profile option where several configs can be set for different flying conditions, e.g. I have one set to max everything, one for typicial use, one where vegetation shadows are off, one set to minimal for difficult areas and a couple of others, noting I adjust only in a text editor (notepad++) as otherwise p3d would reset many values I'd adjusted to defaults if changed from within P3D.

 

Also it's important to note the hardware I'm using as realisticaly the hardware you've got will play an important part in what can be achieved.

For example I never considered the use of Orbx's True Earth series until I'd updated my hardware to it's current.

Essentually the machine I'm running atm is a machine I originally built in 2017 and have updated as higher performance components became available (and affordable).

  • Motherboard is an Asus X370 Pro and still is and it's had many incremental BIOS updates to support newer functions and hardware.
  • CPU was originally a Ryzen 1700X and is now a 5800X
  • Ram is now 32 GB supporting a 3200 speed
  • CPU has SMT disabled (hyperthreading) and is base clocked to 4.7 GHz
  • Monitors are all Dell 30Hz capable 1080P where I use a DSR custom screen mode to achive 2560x1440 for the main screen which switches automatically when P3D is started or stopped.
  • The 30 Hz screen mode is used to vsync which is why my vids are pretty smooth. The 30 Hz vsync also reduces overall hardware usage which in turn allows a greater ramping up of options.

I do plan to build a completely new box in about a years time and will investigate newer monitor's/TV for the latested variable frame rate sync options given there are now three alternate variable types (NVIDIA, AMD, and VESA). VESA is looking like the best option atm.

To sum up, I'm happy overall with what I've managed to achieve and being P3D v4.5 means I also have access to a large number of quality aircraft to install and fly.

Really there is only one late release aircraft I have that doesn't run in v4.5, being the Piaggio P.180 Avanti by Milviz/Blackbird and that was free anyway.

On that note I'm happy to followup on any questions regarding the items I use in P3D and their configuration.

Cheers

  • Like 4
  • Upvote 1

Ryzen 5800X clocked to 4.7 Ghz (SMT off), 32 GB ram, Samsung 1 x 1 TB NVMe 970, 2 x 1 TB SSD 850 Pro raided, Asus Tuf 3080Ti

P3D 4.5.14, Orbx Global, Vector and more, lotsa planes too.

Catch my vids on Oz Sim Pilot, catch my screen pics @ Screenshots and Prepar3D

Link to comment

@Rogen Omg. So many add-ons. Definitely needs a detailed step-by-step write-up of how it's done exactly or a bible of some sort in a PDF file format.

I notice that you use REX 4 Texture Direct with Soft Clouds and Active Sky. Why use REX 4 and not Cloud Art since Cloud Art is also from the same developer of Active Sky?

In your list is Orbx Global Base and also tomato shade. Wouldn't those conflict with one another?

Is Reshade different from RDShade?  Why would you need those if you already use tomato shade?

Why use freemesh?  I thought Orbx airports and regions already have built-in mesh?

Thank you.





 

Hardware: i7-8700k, GTX 1070-ti, 32GB ram, NVMe/SSD drives with lots of free space.
Software: latest Windows 10 Pro, P3Dv4.5+, FSX Steam, and lots of addons (100+ mostly Orbx stuff).

 Pilotfly.gif?raw=1

Link to comment
2 hours ago, bofhlusr said:

@Rogen Omg. So many add-ons. Definitely needs a detailed step-by-step write-up of how it's done exactly or a bible of some sort in a PDF file format.

Yeah probably, at least for my own backup purposes should I need to reinstall, however I'm on the time poor side atm and some 6 weeks behind where I intended to be due to life's unforseen circumstances, in anycase my machines and NAS boxes backup at regular intervals which means should I loose the main box I can just restore a backup and be up and running again in next to no time.

 

2 hours ago, bofhlusr said:

I notice that you use REX 4 Texture Direct with Soft Clouds and Active Sky. Why use REX 4 and not Cloud Art since Cloud Art is also from the same developer of Active Sky?

I think I bought REX 4 Texture Direct back in FSX-SE days and the Soft Clouds Extended version was a cheap update at the time. At the time I was using the REX version of ActiveSky for Weather, which I ended up eventually dropping due to it's highly unorthidox GUI and replacing with Active Sky, (a breeze to understand and use compared to the REX option), all back in the FSX days anyway.

 

2 hours ago, bofhlusr said:

In your list is Orbx Global Base and also tomato shade. Wouldn't those conflict with one another?

Not at all as they are two completely different products. Orbx Global Base is the texture set replacing those defaults of FSX/P3D, whereas TomotoShade is a shader adjustment tool used to define colour & lighting for textures, TomotoShade updates the shader files located in the ShadersHLSL directory e.g. "~\Lockheed Martin\Prepar3D v[number]\ShadersHLSL".

Fun Fact #1:

Flight Sim World used Orbx Global Base as the default texture set, something P3D has never caught up with as P3D default still uses a slightly enhanced FSX default texture set.

 

2 hours ago, bofhlusr said:

Is Reshade different from RDShade?  Why would you need those if you already use tomato shade?

Reshade and RDShade are two different products, RDShade updates the shader files in the ShadersHLSL directory basically doing a similar job as TomotoShade, whereas Reshade has it's own shaders that can be appled to almost any game. I use it because it has some interesting functions and can be called and adjusted while P3D is running and your in the middle of flying.

With Reshade you can do things like adjust colour, sharpness, contrast, brightness, debanding, faux ambient occlusion, extra AA and all can be done on the fly so you can see the effects directly applied while in flight.

Here are a couple of pics where I've doen a before and after on the faux ambient occlusion, best to open each in a full screen and swap between them to view.

https://prepar3d.com/forum/viewtopic.php?f=6325&t=145416

Fun Fact #2: Flight Sim World used built in ambient occlusion.

P3D v6 has actual ambient occlusion, however the faux ambient occlusion of Reshade runs outside of the sim, uses almost no resources and is ideal for those P3D versions prior to v6.

 

2 hours ago, bofhlusr said:

Why use freemesh?  I thought Orbx airports and regions already have built-in mesh?

They do, but FreeMesh covers the world where as the Orbx Regions do not.

In any case P3D will load and use the most detailed mesh available for the area.

Cheers 🙂

 

Edited by Rogen
fixing
  • Like 1
  • Upvote 2

Ryzen 5800X clocked to 4.7 Ghz (SMT off), 32 GB ram, Samsung 1 x 1 TB NVMe 970, 2 x 1 TB SSD 850 Pro raided, Asus Tuf 3080Ti

P3D 4.5.14, Orbx Global, Vector and more, lotsa planes too.

Catch my vids on Oz Sim Pilot, catch my screen pics @ Screenshots and Prepar3D

Link to comment
4 minutes ago, newtie said:

Thanks for this Rogen. It’s amazing what you have done with the tools you have. I’m applying that same philosophy to my 5.3 setup with some successes already underway. Keep up the good work and appreciate your time in this.

Hey np 😁 it's all about the fun of it !

Cheers

  • Like 2

Ryzen 5800X clocked to 4.7 Ghz (SMT off), 32 GB ram, Samsung 1 x 1 TB NVMe 970, 2 x 1 TB SSD 850 Pro raided, Asus Tuf 3080Ti

P3D 4.5.14, Orbx Global, Vector and more, lotsa planes too.

Catch my vids on Oz Sim Pilot, catch my screen pics @ Screenshots and Prepar3D

Link to comment
On 8/15/2023 at 9:51 PM, Rogen said:

JoyToKey (for assigning key combos to joysticks that are not otherwise possible in P3D directly).

Thanks for listing this. It reminded me of similar apps I used in DCS which I've forgotten about and didn't realize I can now also use in P3D (Joystick Gremlin (whitemagic.github.io and vJoy download | SourceForge.net)

On 8/16/2023 at 4:05 AM, mikeymike said:

Global Orbx Wave Effects

I got this installed in the Documents, Add-ons folder and active in P3D v4, but the effect is not showing in an Orbx airport (KHAF) in Northern California. Do you know if the effects are available in sceneries other than in Orbx PNW and in non-Orbx airports? 

Thanks.

Edited by bofhlusr

Hardware: i7-8700k, GTX 1070-ti, 32GB ram, NVMe/SSD drives with lots of free space.
Software: latest Windows 10 Pro, P3Dv4.5+, FSX Steam, and lots of addons (100+ mostly Orbx stuff).

 Pilotfly.gif?raw=1

Link to comment
20 hours ago, bofhlusr said:
On 8/16/2023 at 9:05 PM, mikeymike said:

Global Orbx Wave Effects

I got this installed in the Documents, Add-ons folder and active in P3D v4, but the effect is not showing in an Orbx airport (KHAF) in Northern California. Do you know if the effects are available in sceneries other than in Orbx PNW and in non-Orbx airports? 

Waves are dependent on the scenery developer, if the dev has decided to add them to the coastline then they will be there.

I don't have Orbx's Half Moon Bay package but in the default there are waves, mostly around the breakwaters.

Cheers

Ryzen 5800X clocked to 4.7 Ghz (SMT off), 32 GB ram, Samsung 1 x 1 TB NVMe 970, 2 x 1 TB SSD 850 Pro raided, Asus Tuf 3080Ti

P3D 4.5.14, Orbx Global, Vector and more, lotsa planes too.

Catch my vids on Oz Sim Pilot, catch my screen pics @ Screenshots and Prepar3D

Link to comment
On 8/16/2023 at 9:05 PM, mikeymike said:

Can you please share your preset for tomatoshade?

And first 5 points in post regarding shaders ?

Hi @mikeymike,

As to the shader points.

On 8/16/2023 at 9:05 PM, mikeymike said:
  • Tomatoshade with my own custom preset - no enhanced reflections.
  • Custom cloud shader (for dynamicaly lit clouds).
  • Custom mods to the GPUTerrain.fx (bugfix related to TomatoShade) & PrecipParticle.fx (look improvement).
  • ReShade (used to tweek colour, sharpness, banding and add faux ambient occlusion).

You find the Tomotoshade preset and the custom cloud shader in the two spoilers attached to this post. Note the cloud shader is quite GPU intensive meaning a great GPU is needed, e.g. it's fine with my 3080Ti, note both are P3D v4.5 only.

And Reshade can be downloaded from https://reshade.me/ where the download you'll want for P3D will be the one with full addon support. Reshade supports DX12 so can be used with P3D v5+ as well as P3D v4.5.

There is a wiki on reshade.me with good info too.

The GPUTerrain.fx & PrecipParticle.fx shader changes are below, where I've quoted from the post you'd placed, which in turn was from a previous post of mine.

Note the GPUTerrain.fx chage is only applied if that line exists which it will if the attached Tomatoshade preset is appliedIf the preset is changed the line itself may change or not exist so check first and do not add the abs() wrap unless it is needed.

Note I use the very good Notepad++ text editor to edit these files, it's free and a Google search will find.

On 8/14/2023 at 5:41 PM, mikeymike said:

GPUTerrain.fx - wrap calc in an abs()

#pragma warning( disable : 3571 )
float2 atmoHeightDepth(float heightScale, float angle, float2 baseScale)
{
    return exp(-baseScale * heightScale) * (pow(abs(18.8125 * angle + 1.0), -1.28125) * 32.53323 + 0.29103) / baseScale;

}

 

PrecipParticle.fx - calcs for smaller looking rain/snow effects

void CreateStreakQuadVertices(float3 position, float3 velocity, float3 eyePosition, out float3 outQuadPosition[4], out float3 outQuadNormal)
{
    //Control how long streaks face and how big they are.
    // TBM 03/02/2019 change the calculated value for a smaller looking rain/snow effect
    float height = cb_fQuadSize * cb_fQuadSizeHeightScale / (2.4 - (cb_uPrecipType * 1.65));
    float width = cb_fQuadSize * cb_fQuadSizeWidthScale / (1.0 - (cb_uPrecipType * 0.25));
    
    //float height = cb_fQuadSize * cb_fQuadSizeHeightScale;
    //float width = cb_fQuadSize * cb_fQuadSizeWidthScale;

    velocity = normalize(velocity);
    float3 eyeVector = eyePosition - position;
    float3 eyeOnvelocityPlane = eyePosition - ((dot(eyeVector, velocity)) * velocity);
    float3 projectedeyeVector = eyeOnvelocityPlane - position;
    float3 sideVector = normalize(cross(projectedeyeVector, velocity));

    outQuadPosition[0] = position - (sideVector * 0.5 * width);
    outQuadPosition[1] = outQuadPosition[0] + (sideVector * width);
    outQuadPosition[2] = outQuadPosition[0] - (velocity * height);
    outQuadPosition[3] = outQuadPosition[2] + (sideVector * width);

    outQuadNormal = normalize(projectedeyeVector);
}

 

Tomatoshade preset.

Spoiler

[PTA VERSION]
Preset format=2

[PRESET COMMENTS]
Comment=TBM 28/06/2023 1.2.5 In Testing ATM~^#================================~^#[LIGHTING_TERRAIN_LIGHTING]~^#From:~^#SunDiffuseCoeff=2.7~^#SunAmbientCoeff=1.35~^#To:~^#SunDiffuseCoeff=3.2~^#SunAmbientCoeff=2.55~^#~^#~^#TBM 21/06/2023 1.2.5 In Testing ATM~^#================================~^#[LIGHTING_TERRAIN_LIGHTING]~^#From:~^#SunDiffuseCoeff=2.4~^#SunAmbientCoeff=1.35~^#To:~^#SunDiffuseCoeff=2.7~^#SunAmbientCoeff=1.55~^#~^#[LIGHTING_AUTOGEN_LIGHTING]~^#From:~^#SunAmbientCoeff=1.0~^#To:~^#SunAmbientCoeff=1.35~^#~^#To brighten up the terrain in the sunshine a little further.~^#~^#Also disabled as I apply an Uncharted2 tone map directly in \PostProcess\HDR.hlsl~^#[HDR & POST-PROCESSING_HDRTONEMAP]~^#(IsActive=0)~^#Which will now enable the option of,~^#~^#[HDR & POST-PROCESSING_HDRCONTRAST]~^#IsActive=1~^#Coeff=0.65~^#~^#~^#TBM 05/05/2023 1.2.4~^#================================~^#Testing some changes to see if they affect the moon, sun and stars.~^#Changes are based on those of the RDPreset_v1.8~^#TBM - all seems Ok (no big difference).~^#~^#TBM 18/03/2023 1.2.3~^#================================~^#Enabled water surface for review.~^#Increased Granularity to 6.50 to reduce reflection flicker~^#~^#Water Saturation=0.98~^#~^#Disabled ADVANCED REFLECTIONS / ADJUST TERRAIN RENDERING ~^#where I've been attempting a few fixes for the fEyeDistance invalid ~^#subscript error (to no avail).~^#~^#I think this is about as far as I can take TomatoShade...~^#~^#~^#TBM 07/01/2023 1.2.2~^#================================~^#Disabled Advanced Reflections since testing shows ~^#it's a lot of work to build custom modeling for both ~^#external and internal aircraft models and the results ~^#tend to be not that great with unintended fx like paint ~^#being very dull or being replaced with bare metal types ~^#of shine.~^#~^#Enabled the following:~^#Soften Solid Shadows~^#Adjust Terrain Rendering~^#Aircaft Image Based Lighting~^#    DaylightAmbientIntensity=0.3 (up from 0.2)~^#    DaylightDiffuseIntensity=(0.15 + (1.0 - saturate(colorDiffuseSun.g)) * 1.0) (up from 0.15)~^#~^#~^#TBM 28/12/2022 1.2.1~^#================================~^#Enabled Advanced Reflection options consisting of,~^#Adjust Terrain Rendering and Extended ~^#Reflections, disabling Aircaft Image Based Lighting~^#is required. ~^#~^#TBM 06/01/2022~^#=================================~^#Custom Tomato shade configuration - version 1.2.0~^#Enable alternate lighting on clouds.~^#~^#TBM 21/12/2021~^#=================================~^#Custom Tomato shade configuration - version 1.1.9~^#Set Bump Mapping to zero (P3D default, as the A/Craft looks too craggy).~^#Enable AutoGen Lighting Adjustements (so as not too bright in the distance).~^#Enable Aircraft Image Based Lighting (We'll see what it does)~^#~^#=================================~^#Custom Tomato shade configuration - version 1.1.8~^#[ATMOSPHERE & FOG_RAYLEIGH_SCATTERING]~^#Density=0.0000000298~^#~^#[WATER_WATER_SATURATION] (from 0.65 to 0.45 as it just looks too blue)~^#SaturateRatio=0.45~^#~^#=================================~^#Custom Tomato shade configuration - version 1.1.7~^#~^#[ATMOSPHERE & FOG_SKY_SATURATION]~^#SaturateRatio=(saturate((1 + cb_Altitude/1219 * 0.5) - (cb_fPrecipitationLevel * 0.5)))~^#~^#[ATMOSPHERE & FOG_SKY_FOG_TUNING]~^#FogFactor=(saturate(0.15 - cb_Altitude/1438))~^#~^#[ATMOSPHERE & FOG_RAYLEIGH_SCATTERING]~^#Density=0.0000000198~^#~^#Green=0.050~^#Blue=0.072~^#~^#Colour values were previously reversed making the distance too green.~^#~^#=================================~^#Custom Tomato shade configuration - version 1.1.6~^#[TOMATO-MODE_ALTERNATE TERRAIN LIGHTING]~^#0.4 to 0.3 (defaut is 0.2)~^#~^#[CLOUDS_CLOUD_VOLUME]~^#IsActive=1~^#ScatteringFactor=2.3~^#LightingFactor=0.85~^#NoPattern=1~^#~^#[CLOUDS_CLOUD_BRIGHTNESS_TWILIGHT]~^#IsActive=1~^#~^#[CLOUDS_CLOUDS_LIGHTING_TUNING]~^#IsActive=1~^#CloudLightFactor=0.75~^#CloudSaturateFactor=0.35~^#DiffuseGamma=0.95~^#=================================~^#Tomato-Mode/Bump map strength reduced from 0.8 to 0.3 (P3D default is zero)~^#~^#Does not use advanced reflections due to errors in the shader additions.~^#That said it is very useful for shader configuration otherwise.~^#~^#=================================~^#Items not used in this preset due to errors occuring in P3D v4.5 HF3:~^#    error X3018: invalid subscript 'fEyeDistance' Shader cache failed to compile or create shader. source-file: GPUTerrain.fx~^#~^#    Occurs when ADVANCED REFLECTIONS / ADJUST TERRAIN RENDERING is enabled, which is a requirement for using advanced reflections.~^#    Thusly Advanced Reflections and Adjust Terrain Rendering are disabled in this preset.~^#~^#    Also disabled are all four ADVANCED REFLECTIONS / Fix Projections as they do not apply to P3D v4.5 HF3~^#    e.g. Clouds, General, Particles, Terrain~^#~^#=================================~^#Manual shader corrections:~^#GPUTerrain.fx~^#    warning X3571: pow(f, e) will not work for negative f~^#    Added abs wrapper on line 282.~^#    "return exp(-baseScale * heightScale) * (pow(abs(18.8125 * angle + 1.0), -1.28125) * 32.53323 + 0.29103) / baseScale;"~^#~^#~^#PrecipParticle.fx~^#    // Control how long streaks face and how big they are.~^#    // TBM 03/02/2019 change the calculated value for a smaller looking rain/snow effect.~^#    float height = cb_fQuadSize * cb_fQuadSizeHeightScale / (2.4 - (cb_uPrecipType * 1.65));~^#    float width = cb_fQuadSize * cb_fQuadSizeWidthScale / (1.0 - (cb_uPrecipType * 0.25));~^#~^#    //float height = cb_fQuadSize * cb_fQuadSizeHeightScale;~^#    //float width = cb_fQuadSize * cb_fQuadSizeWidthScale;~^#~^#=================================~^#P3D values: Adjust to suit taste.~^#HDR_BRIGHTNESS=1.250000~^#HDR_BLOOM_MAGNITUDE=0.350000~^#HDR_SATURATION=0.9500000~^#=================================~^#

[HDR & POST-PROCESSING_HDRADAPTATION]
IsActive=0

[HDR & POST-PROCESSING_HDRTONE]
IsActive=0
Red=1.05
Green=1.00
Blue=1.05

[HDR & POST-PROCESSING_HDRTONEMAP]
IsActive=1
Uncharted2Tonemap=1

[WATER_WATER_SATURATION]
IsActive=1
SaturateRatio=0.98

[ATMOSPHERE & FOG_SKY_SATURATION]
IsActive=1
SaturateRatio=(saturate((1 + cb_Altitude/1219 * 0.5) - (cb_fPrecipitationLevel * 0.5)))

[ATMOSPHERE & FOG_SKY_FOG_TUNING]
IsActive=1
FogFactor=(saturate(0.15 - cb_Altitude/1438))

[HDR & POST-PROCESSING_HDRCONTRAST]
IsActive=1
Coeff=0.65

[WATER_WAVESPEED]
IsActive=0
SpeedRatio=1.0

[WATER_WAVESIZE]
IsActive=0
SizeRatio=1.0
SmoothRatio=2.0

[WATER_WATERSURFACE]
IsActive=1
ReflectionCoeff=0.45
RefractionCoeff=0.30
GranularityCoeff=6.50
SpecularBlend=1.5
FresnelAngle=2.5

[WATER_FSXREFLECTION]
IsActive=0

[ATMOSPHERE & FOG_RAYLEIGH_SCATTERING]
IsActive=1
DensityCorrection=1
ExcludeClouds=1
Power=3.42
Density=(saturate(0.00000000100 + (cb_Altitude-0)/(11000-0)*(0.00000000100-0.00000000180)))
Green=0.050
Blue=0.072
NoDensityAltitude=15000
VolumetricDensityHeight=10000
VolumetricDensityPower=2.0

[ATMOSPHERE & FOG_ATMO_HAZE]
IsActive=1
Power=1.21
Distance=(saturate(0.00000000100 + (cb_Altitude-0)/(11000-0)*(0.00000000100-0.00000000180)))
DensityCorrection=1
Red=1.00
Green=0.95
Blue=0.95
NoDensityAltitude=10000
VolumetricDensityHeight=10000

[ATMOSPHERE & FOG_CLOUDS_FOG_TUNING]
IsActive=1
FogFactor=0.5

[LIGHTING_BOOST_EMISSIVELANDCLASS]
IsActive=0
BoostRatio=1.0
SaturateRatio=2.0

[LIGHTING_TERRAIN_SATURATION]
IsActive=1
SaturateRatio=1.25

[LIGHTING_TERRAIN_LIGHTING]
IsActive=1
SunDiffuseCoeff=2.75
SunAmbientCoeff=0.89
MoonDiffuseCoeff=0.9
MoonAmbientCoeff=0.3
DiffuseGamma=0.95

[LIGHTING_SPECULAR_LIGHTING]
IsActive=1
SpecularRatio=3.5

[LIGHTING_AUTOGEN_LIGHTING]
IsActive=1
SunDiffuseCoeff=2.75
SunAmbientCoeff=1.35
MoonDiffuseCoeff=0.5
MoonAmbientCoeff=0.3
DiffuseGamma=0.95
Saturation=1.0

[CLOUDS_CLOUD_BRIGHTNESS_TWILIGHT]
IsActive=1

[CLOUDS_CIRRUS_BRIGHTNESS_TWILIGHT]
IsActive=1

[CLOUDS_CLOUD_SHADOWS_SIZE]
IsActive=1

[CLOUDS_CLOUD-SHADOW-DEPTH]
IsActive=1
Value=1.10

[CLOUDS_CLOUD_ALTERNATE_LIGHTING]
IsActive=1

[CLOUDS_CLOUD_SIZE]
IsActive=1
CloudSizeHCoeff=0.5
CloudSizeVCoeff=0.5

[CLOUDS_CLOUD_SATURATION]
IsActive=1
ShadeFactor=1.35

[CLOUDS_CLOUDS_LIGHTING_TUNING]
IsActive=1
CloudLightFactor=((0.68-(0.0*cb_mDayNightInterpolant)))
CloudSaturateFactor=0.35
DiffuseGamma=0.95

[CLOUDS_CIRRUS_LIGHTING]
IsActive=1
SaturateRatio=0.855
LightingRatio=0.80

[CLOUDS_CLOUD_VOLUME]
IsActive=1
ScatteringFactor=2.3
LightingFactor=0.85
NoPattern=1

[CLOUDS_POPCORN_MODIFICATOR]
IsActive=1
CloudDistanceFactor=0.00000000060
CloudOpacity=(clamp(0.10 + 0.20 * cb_Altitude/2000, 0.1, 0.3))

[LIGHTING_AIRCRAFT_LIGHTING]
IsActive=1
SunDiffuseCoeff=2.55
SunAmbientCoeff=0.89
MoonDiffuseCoeff=1.00
MoonAmbientCoeff=1.00
DiffuseGamma=0.75
SaturateRatio=1.05
VCOnly=0
VCSunDiffuseCoeff=
VCSunAmbientCoeff=
VCMoonDiffuseCoeff=
VCMoonAmbientCoeff=

[LIGHTING_AUTOGEN_EMISSIVE]
IsActive=1
LightsRatio=1.5
AutogenRatio=1.5
SmoothTransition=1

[TOMATO-MODE_OPTIMIZE REDUCE TRANSLUCENT SHADOW DISTANCE]
IsActive=1

[TOMATO-MODE_OPTIMIZE GPU TERRAIN RENDERING]
IsActive=1

[TOMATO-MODE_AUTOGEN DISTANCE SIZE]
IsActive=0
Factor=0.0025
FactorX=1.7777

[TOMATO-MODE_AUTOGEN POWER SMOOTHING]
IsActive=1
BasePowerFactor=0.7
MaxLightDistance=90000
FullPowerDistance=3000
DistanceCurvePower=4.0
Saturation=1.0
PowerLimit=0.0

[TOMATO-MODE_ADAPTIVE BLOOM]
IsActive=0
Power=3.0

[TOMATO-MODE_ALTERNATE TERRAIN LIGHTING]
IsActive=1
LightPower=0.3

[TOMATO-MODE_INCREASE PARTICLE SIZE WITH DIST]
IsActive=0
Factor=1.1

[TOMATO-MODE_DYNAMIC SPOT LIGHTS LIGHTING]
IsActive=1
AnglePower=1.0

[TOMATO-MODE_IMPROVE DYN LIGHT PERFORMANCE]
IsActive=1

[TOMATO-MODE_ADD MULTIPLE TEXTURE LOOKUPS]
IsActive=0

[TOMATO-MODE_SOFTEN SOLID SHADOWS]
IsActive=1

[TOMATO-MODE_ADVANCED ATMOSPHERE SCATTERING]
IsActive=1
PlanetRadius=6371e3
AtmosphereHeight=100000.0
AtmoBaseHeightOutScattering=0.00015
AtmoBaseHeightInScattering=0.00012
AbsorptionFactorRed=0.596e-5
AbsorptionFactorGreen=1.324e-5
AbsorptionFactorBlue=3.310e-5
AbsorptionScaleInRed=1.3
AbsorptionScaleInGreen=1.1
AbsorptionScaleInBlue=1.2
AbsorptionScaleGamma=2.5
InScatteringFactorAmbient=0.2
InScatteringFactorDiffuse=0.7
InScatteringDiffuseGamma=0.2
InScatteringStartFullDist=20000.0
TerrainOutputContrast=1.07875
ShadowsInflunceScattering=1

[TOMATO-MODE_ADVANCED FOG SCATTERING]
IsActive=1
ScatteringHeightPower=2.5
ScatteringHeightLimit=119716000000.0f
ScatteringDistanceBlue=82000
ScatteringDistanceGreen=145000
ScatteringDistanceRed=301000
ScatteringPowerBlue=0.85
ScatteringPowerGreen=0.65
ScatteringPowerRed=0.6
InScatteringSky=0.05
InScatteringSun=0.05

[TOMATO-MODE_FAST APPROXIMATION IMAGE BASED AIRCRAFT LIGHTING]
IsActive=1
DaylightAmbientIntensity=0.3
DaylightDiffuseIntensity=(0.15 + (1.0 - saturate(colorDiffuseSun.g)) * 1.0)
NightIntensity=0.2

[TOMATO-MODE_OPTIMIZE CLOUD MATRIX CALCULATION]
IsActive=1

[TOMATO_MODE_ALTERNATE SPECULAR LIGHTING]
IsActive=1

[TOMATO_MODE_PRECIPITATION OPACITY]
IsActive=0
OpacityRain=0.7
OpacitySnow=1.0

[TOMATO-MODE_IMPROVE GENERAL SHADOW RECEIVE]
IsActive=1

[TOMATO-MODE_IMPROVE TERRAIN SHADOW RECEIVE]
IsActive=1

[TOMATO_MODE_CHANGE CLOUD SHADOW RECEIVE CALCULATION]
IsActive=1

[TOMATO_MODE_CHANGE CLOUD SHADOW BUILD CALCULATION]
IsActive=1

[TOMATO_MODE_ADD CONDITIONAL DYNAMIC LIGHTING]
IsActive=1

[TOMATO_MODE_PER PIXEL CLOUD FOG]
IsActive=1

[TOMATO_MODE_BUMP MAP STRENGTH]
IsActive=1
IntensityScale=0.2

[TOMATO-MODE_OPTIMIZE PARTICLE DRAW]
IsActive=1

[TOMATO-MODE_OPTIMIZE PRECIPITATION DRAW]
IsActive=1

[TOMATO-REFLECTIONS_ADJUST STARS IN REFLECTION MAP]
IsActive=0
Intensity=1.5

[TOMATO-REFLECTIONS_ADJUST REFLECTION PARTICLE EMISSION]
IsActive=1
Size=64

[TOMATO-REFLECTIONS_ADJUST REFLECTION TERRAIN RENDERING]
IsActive=1
AddDetailTexture=1
MaxTextureLOD=12

[TOMATO-REFLECTIONS_ADJUST REFLECTION GENERAL RENDERING]
IsActive=1

[TOMATO-REFLECTIONS_OPTIMIZE CLOUD REFLECTIONS]
IsActive=1

[TOMATO-REFLECTIONS_TOMATO EXTENDED REFLECTION RENDERING]
IsActive=0

[TOMATO-REFLECTIONS_FIX GENERAL PROJECTION]
IsActive=0

[TOMATO-REFLECTIONS_FIX CLOUD PROJECTION]
IsActive=0

[TOMATO-REFLECTIONS_FIX TERRAIN PROJECTION]
IsActive=0

[TOMATO-REFLECTIONS_FIX PARTICLE PROJECTION]
IsActive=0

[POSTPROCESS_SHADER DPX]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A5265643D382E300D0A477265656E3D382E300D0A426C75653D382E300D0A526564433D302E33360D0A477265656E433D302E33360D0A426C7565433D302E33340D0A44505853617475726174696F6E3D332E300D0A436F6C6F7247616D6D613D312E350D0A426C656E643D302E320D0A

[POSTPROCESS_SHADER Tonemap]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A47616D6D613D312E300D0A4578706F737572653D302E300D0A53617475726174696F6E3D302E300D0A426C656163683D302E300D0A4465666F673D302E300D0A466F67436F6C6F72583D302E300D0A466F67436F6C6F72593D302E300D0A466F67436F6C6F725A3D322E35350D0A

[POSTPROCESS_SHADER LiftGammaGain]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A5247425F4C696674583D312E300D0A5247425F4C696674593D312E300D0A5247425F4C6966745A3D312E300D0A5247425F47616D6D61583D312E300D0A5247425F47616D6D61593D312E300D0A5247425F47616D6D615A3D312E300D0A5247425F4761696E583D312E300D0A5247425F4761696E593D312E300D0A5247425F4761696E5A3D312E300D0A

[POSTPROCESS_SHADER Vibrance]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A56696272616E63653D302E320D0A56696272616E63655F5247425F62616C616E6365583D312E300D0A56696272616E63655F5247425F62616C616E6365593D312E300D0A56696272616E63655F5247425F62616C616E63655A3D312E300D0A

[POSTPROCESS_SHADER Sepia]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A436F6C6F72546F6E65583D312E340D0A436F6C6F72546F6E65593D312E310D0A436F6C6F72546F6E655A3D302E390D0A47726579506F7765723D302E31310D0A5365706961506F7765723D302E35380D0A

[POSTPROCESS_SHADER Technicolor]
IsActive=0
Index=-10000
Params=4461794E696768745573653D300D0A546563686E69416D6F756E743D302E340D0A546563686E69506F7765723D342E300D0A7265644E65676174697665416D6F756E743D302E38380D0A677265656E4E65676174697665416D6F756E743D302E38380D0A626C75654E65676174697665416D6F756E743D302E38380D0A

 

Cloud.fx shader

Spoiler

//---------------------------------------------------------------------------
// Prepar3d - Shader Effect Files
// Copyright (c) 2014, Lockheed Martin Corporation
//---------------------------------------------------------------------------

//===========================================================================
// TBM have adjusted the following items
// static const float SetPSS1 = 0.99   ; // TBM default = 0.75      (Cloud Shadows darkness) 0.99 is max and is good noting values > 0.99 seem to be ignored, TomatoShade value was 1.10.
// static const float SetPS90 = 1.42   ; // TBM Default = 1.20*1.35 (calcs to 1.62). This value does have an overall effect on the general cloud brightness - lower value = darker clouds, trialed 1.32 originally.
// static const float SetGSS1 = 1.45   ; // TBM default = 0.65      (Size of shadow textures, a larger value reduces the shadow size and allows more light shining through)
// static const float SetPS79 = 0.65   ; // TBM Default = 1.00      (The total saturation of the clouds towards bluing, have reduced the value to minimise the quite green looking clouds that sometimes appear).
// static const float SetPS80 = 0.35   ; // TBM Default = 0.65      (Level of overall bluing of the final color, have reduced the value to minimise the quite green looking clouds that sometimes appear).
// static const float SetPS97 = 1.25   ; // TBM Default = 1.00      (Alpha channel setting for the transparency of clouds at short distances, higher is less transparent).
//===========================================================================

#include "ShaderMacros.h"
#include "ConstantBuffers.fxh"
#include <FuncLibrary.fxh>
#include <IRSim.fxh>
#include <InstanceIndexing.fxh>
#define MAX_COLOR_LEVELS 5

shared Texture2D txBase : REGISTER(t, 0);
shared Texture2D txSceneDepth : REGISTER(t,SCENE_DEPTH_TEXTURE_REGISTER);

    static float FA1 = frac((25+cb_Altitude)/1000) ; static float FA0 = frac((25+cb_Altitude)/100) ; // Variables for test settings.
    static float fT0 = abs( frac(  (  cb_mFog[0].cb_mFogTop + cb_Altitude  ) /1000) ) ; static float fB0 = abs( frac(  (  cb_mFog[0].cb_mFogBase + cb_Altitude  ) /1000) ) ; //
    static float fT1 = abs( frac(  (  cb_mFog[1].cb_mFogTop + cb_Altitude  ) /1000) ) ; static float fB1 = abs( frac(  (  cb_mFog[1].cb_mFogBase + cb_Altitude  ) /1000) ) ; //
    static float fT2 = abs( frac(  (  cb_mFog[2].cb_mFogTop + cb_Altitude  ) /1000) ) ; static float fB2 = abs( frac(  (  cb_mFog[2].cb_mFogBase + cb_Altitude  ) /1000) ) ; //

//    static float FFz =  abs(cb_mViewFacingVector.z) ; static float FF1z =  1-abs(cb_mViewFacingVector.z) ; //
//    static float FFx =  1-abs(cb_mViewFacingVector.x) ; static float FF1x =  1-abs(cb_mViewFacingVector.x) ; //

// (VS)
//****************************************************************************************************************************************

// cloud texture size 0.1 ~ 1
 static const float SetVS1 = 0.65 ; // 0.75

// The spatial size of the clouds along the X, Y, and Z axes.
 static const float SetVS2x = 1.3 ;  static const float SetVS2y = 0.85 ;  static const float SetVS2z = 1.3 ; //

// Moving clouds to the horizon at the limit of visibility.
 static const float SetVS3 = 1 ; // switch - turn off the tweak. 1 - enabled. 0 - disabled

// lift height. m   //  Distance of thrust ~ = visibility range*0.9. m   //  routine of lowering.
 static const float SetVS3H = 3000 ;    static const float SetVS3D = 170000 ;                    static const float SetVS3S = 0.00008 ; //

//===================================================================================================================================================

// (VGB)
//===================================================================================================================================================
// Minimum gradient steepness (for clouds of maximum thickness)
 static const float SetVS10 = 1.5 ;

// Maximum steepness of the gradient (for clouds of minimum thickness)
 static const float SetVS11 = 35 ;

// Cloud vertical gradient pattern
 static const float SetVS12 = 8 ;

// General offset correction of cloud vertical gradient
 static const float SetVS13 = -0.0 ;

// "General" correction of the steepness of the vertical gradient of clouds
 static const float SetVS14 = 1.0 ;

// Additional enhancement of the detail of the base vertical cloud gradient
 static const float SetVS15 = 0.22 ;

// "Initial minimum coefficient of solar brightness at low altitudes" clouds ( ~< 1.5 km )
 static const float SetVS20 = 0.55 ;

// "Initial minimum coefficient of solar brightness at high altitudes" clouds ( ~> 5.5 km )
 static const float SetVS21 = 0.77 ;

// Initial maximum vertex brightness
 static const float SetVS22 = 1.45 ;

// The initial maximum brightness factor of the vertices at a low position - the sun at the solar opposition
 static const float SetVS22o = 1.80 ;

// Minimum base detail level based on fIntensity
 static const float SetVS23 = 0.25 ;

// (EG)
// The initial minimum brightness coefficient of the shadow areas of the cloud.
 static const float SetVS30 = 0.00 ;

// Minimum base shadow detail level based on fIntensity
 static const float SetVS31 = 0.35 ;

//  Brightness level of the illuminated areas at the maximum position - the sun at its zenith.
 static const float SetVS32 = 1.50 ;

// Brightness level of illuminated areas at a very low position - the sun. (side lighting)
 static const float SetVS33 = 2.00 ;

// Level of brightness of the illuminated areas at a low position - the sun at the solar opposition.
 static const float SetVS33o = 2.30 ;

// Coefficient of additional brightness of the illuminated areas on the direction - the sun at a very low position - the sun.
 static const float SetVS340 = 0.80 ; static const float SetVS34A = 0.65 ; // at low altitudes // at high altitudes

// Additional gain level of side lighting at a low position - the sun.
 static const float SetVS35 = 0.00 ;

// √gamma coefficient of the difference between the illuminated-shadow areas of the ScatterDueToNormal function when the sun is at its zenith.
 static const float SetVS36 = 1.0 ;

// √gamma coefficient of the difference between the illuminated-shadow areas of the ScatterDueToNormal function at a very low position - the sun.
 static const float SetVS37 = 1.45 ;

// Additional gamma coefficient of the ScatterDueToNormal function at a very low position - the sun.
 static const float SetVS38 = 1.3 ;

// Additional (negative) coefficient of fall of the brightness of illuminated areas after sunset - the sun.
 static const float SetVS39 = -0.30 ;

// "Position" of the center of the tangentoid at which the change in the incidence of the "brightness" of the illuminated areas is 50%
 static const float SetVS40t = -0.040 ; // TBM Default = -0.040

// Rhythm of the tangent of incidence brightness of the illuminated areas.
 static const float SetVS41t = 53 ;

// Final Gradient Contrast Settings
// "The level of contrast changes" by changing the brightness of the vertices that have the maximum brightness at some fixed level of dark tones.
// Pre-processing (colorVGB)
// contrast depending on the position of the sun.

// -The sun is at its zenith // -The sun is not very low above the horizon // -The sun is on the horizon (sunset/sunrise)
 static const float SetVS51a = 1.0 ; static const float SetVS51e = 1.0 ; static const float SetVS51s = 1.0 ; // TBM Default = 1.0 ; 1.0 ; 1.0

// Minimum Convergence Convergence Level.
 static const float SetVS51M = 0.50 ; // TBM Default = 0.50

// "Pre-processing" (ColorE)
// Contrast depending on the position of the sun

// -Sun at zenith // -Sun not very low above the horizon // -Sun on the horizon (sunset/sunrise)
 static const float SetVS52a = 1.05 ; static const float SetVS52e = 1.15 ; static const float SetVS52s = 1.10 ;

// Minimum Convergence Convergence Level.
 static const float SetVS52M = 0.50 ;

// Final color processing (BcolorFinal)
// Contrast depending on the position of the sun at low altitudes ~< 1000 m

// -Sun at zenith // -Sun not very low above the horizon // -Sun on the horizon (sunset/sunrise)
 static const float SetVS53a = 1.0 ; static const float SetVS53e = 1.0 ; static const float SetVS53s = 1.15   ;

// Contrast depending on the position of the sun at high altitudes ~> 5000 m
 static const float SetVS80a = 1.0 ; static const float SetVS80e = 1.0 ; static const float SetVS80s = 1.15   ;

// Minimum Convergence Convergence Level.
 static const float SetVS53M = 0.50 ;

// The level of shadow detail at the maximum position - the sun at its zenith.
 static const float SetVS55 = 0.45 ; //  0.35*0

// Level of overall shadow detail at very low position - the sun. (side lighting)
 static const float SetVS56 = 0.65 ;

// Enables the function to transition from shadow detail to additional vertical detail at a very low position - the sun.
// "Additional enhancement level" of the basic vertical cloud gradient detail when the sun is on the horizon.
 static const float SetVS57 = 0.0 ;

// Routineness of transition characteristics to additional vertical detailing.
 static const float SetVS58 = 0.9 ;

// Correction of brightness (additional coefficient) on the solar opposition at a low position - the sun.
 static const float SetVS60 = 0.25 ;

// Correction brightness (correction factor) on the solar opposition at the position of the sun on the horizon.
 static const float SetVS60s = -0.1 ;

// Interpolation between standard and alternative cloud illumination calculation model based on puff groups. 0 - alternative model. 1 - standard.

// -Sun at zenith // -Sun not very low above the horizon // -Sun on the horizon (sunset/sunrise)
 static const float SetVS61a = 1.00 ; static const float SetVS61e = 0.8 ; static const float SetVS61s = 0.90 ;

// In the solar sector at low altitudes ~< 1000 m
 static const float SetVS62a = 1.00 ; static const float SetVS62e = 0.09 ; static const float SetVS62s = 0.09 ;

// In the solar sector at high altitudes ~> 5000 m
 static const float SetVS63a = 1.00 ; static const float SetVS63e = 0.09 ; static const float SetVS63s = 0.09 ;

// The general highlighting factor on the directional is the sun by the RedDueToN function.
 static const float SetVS65 = 0.50 ;

// Actor of rotation to the observer of illuminated textures (in immediate proximity to the -sun) of the RedDueToN function
 static const float SetVS66 = 1.0 ;


//-------------------------------------------------------------------------------------------------------------------------------
// The effect of additional highlighting of the tops and soles on the sun direction (fcolorGSs).

// Overall coefficient of lightness and thickness
 static const float SetVS71 = 1.55 ; // TBM default 1.55

// Center Brightness Compensation
 static const float SetVS73 = 0.0 ; // TBM default 0.0

// ћmaximum displacement range of the gradient
// under the sun // above the sun (lower backlight)
 static const float SetVS74 = -0.55 ;  static const float SetVS75 = -0.25 ; // TBM default -0.55 ; -0.25

// Edge width and contrast actor
// At the middle position - the sun // At the low position - the sun
 static const float SetVS76 = 1.15 ;  static const float SetVS77 = 1.20 ;

// Routine delimitation of the backlight vector
 static const float SetVS78 = 25 ; // TBM default 25

// Final brightness correction (diffuse)
 static const float SetVS99 = 1.20 ; // TBM default 1.20

//-------------------------------------------------------------------------------------------------------------------------------

// Size of shadow textures
 static const float SetGSS1 = 1.45 ; // TBM default 0.65

// Shadow intensity
 static const float SetPSS1 = 0.99 ; // TBM default 0.75 (Cloud Shadows darkness)

// Haze Toning Adjustment
 static const float SetFog  = 0.90 ; // TBM default 0.90
 
// (PS)
//*******************************************************************************************************************************

// Level of texture detail per RGB channel
 static const float SetPS00 = 0.55 ;

// "Pre-adjustment" of "brightness" and "gamma" before the fabric filter
//-------------------------------------------------------------------------------------------------------------------------------

// Auxiliary Color Preliminary Gamma (M1)
 static const float SetPS01 = 1.00 ; // TBM default 1.00

// Secondary Color Pre-Luminance (M1)
 static const float SetPS02 = 0.75 ; // TBM default 0.75

// Preliminary gamut of the main color (M2)
 static const float SetPS03 = 0.90 ; // TBM default 0.80 Testing 0.90

// Color synthesis settings
//-------------------------------------------------------------------------------------------------------------------------------

// Initial level (-the sun at its zenith) of the general color interpolation of clouds (coloring)
 static const float SetPS14 = 0.10 ; // TBM default 0.10

// End base points of color interpolation
// Components g, b for vertices
 static const float SetPS15g = 0.57 ; // initial g-factor
 static const float SetPS16g = 0.22 ; // additional g-factor for middle position -sun
 static const float SetPS15b = 0.08 ; // initial b-factor

// Components g, b for the lower part
 static const float SetPS17g = 0.55 ; static const float SetPS17b = 0.08 ; // TBM Defaults 0.55 ; TBM default 0.08

// Correction GB-component of the color filter to vertices.
// Initial correction factor
 static const float SetPS18 = 1 ;

// Correction factor at a low position - the sun.
 static const float SetPS19 = 0.7 ;

// Additional final correction factor after sunset.
 static const float SetPS20 = 1.1 ;

// Remote settings
// "General level of reddening" of clouds at long distances
 static const float SetPS21 = 0.35 ; // TBM default 0.3

// Overall color index at long distances
 static const float SetPS22 = 0.2 ;

// Maximum color corrective interpolators for long distances
 static const float SetPS22r = 1.2 ; static const float SetPS22g = 0.6 ; static const float SetPS22b = 0.6 ;

// "Saturation of illuminated areas at different heights" of the cloud.
// Saturation factor at high altitudes of cloud location ( ~> 5.5 km )
 static const float SetPS40 = 1 ;

// Saturation factor at high cloud heights ( ~> 5.5 km ) at low sun position
 static const float SetPS41 = 0.75 ;

// Saturation coefficient at low cloud heights ( ~< 1.5 km )
 static const float SetPS42 = 1.15 ; // TBM Defaults SetPS42 = 1.15

// Coefficient of additional saturation of the brightest areas
// -sun at zenith // -sun not very low above the horizon // -sun on the horizon (sunset/sunrise)
 static const float SetPS47a = 0.1 ; static const float SetPS47e = 0.2 ; static const float SetPS47s = 0.2 ; // TBM Defaults SetPS47a = 0.1, SetPS47e = 0.2, SetPS47s = 0.2

// Saturation level of the final color of the synthesis before the fabric filter
// -sun at zenith // -sun not very low above the horizon // -sun on the horizon (sunset/sunrise)
 static const float SetPS48a = 0.80 ; static const float SetPS48e = 0.65 ; static const float SetPS48s = 0.75 ;

// "functions" to remove red halos along the contour of clouds
 static const float SetPS49 = 0.5 ;

//----------------------------------------------------------------------------------------------------------------------------------------------
// Smoothing shadow filter settings
// Shadow Filter Total Level Correction Factor
 static const float SetPS54 = 1.38*0.7 ;

// Shadow filter level in days
// -the sun is at its zenith // -the sun is not very low above the horizon // -the sun is on the horizon (sunset/sunrise)
 static const float SetPS55a = 1.00 ; static const float SetPS55e = 0.70 ; static const float SetPS55s = 0.55 ;

// Early twilight // Late twilight and night
 static const float SetPS55d = 0.70 ; static const float SetPS55n = 1.00 ;
 
// Shadow filter brightness compensation factor in days
// -the sun is at its zenith // -the sun is not very low above the horizon // -the sun is on the horizon (sunset/sunrise)
 static const float SetPS56a = 1 ; static const float SetPS56e = 1 ; static const float SetPS56s = 1 ;

// Early twilight // Late twilight and night
 static const float SetPS56d = 1 ; static const float SetPS56n = 1 ;

// Color gamma of the filter. Basic levels of color components.
// red // green // blue
 static const float SetPS57r = 0.20 ; static const float SetPS57g = 0.28 ; static const float SetPS57b = 0.30 ; // TBM Defaults SetPS57r = 0.20, SetPS57g = 0.28, SetPS57b = 0.30

// Saturation level of the filter.
 static const float SetPS58 = 0.30 ;
 static const float SetPS59 = 2.50 ;
 
// Filter Threshold Offset Setting
//----------------------------------------------------------------------------------------------------------------------------------------------
// Composite offset correction of filter thresholds
// red // green // blue
 static const float SetPS61r = 1.90 ; static const float SetPS61g = 1.50 ; static const float SetPS61b = 1.50 ;

// The total saturation of the clouds to bluing
 static const float SetPS79 = 0.65 ; // TBM Defaults SetPS79 = 1.00

// Level of overall bluing of the final color
 static const float SetPS80 = 0.35 ; // TBM Defaults SetPS80 = 0.65
 
// The level of bluing at close range as a fraction of the total level
 static const float SetPS81 = 0.00 ; // TBM Defaults SetPS81 = 0.00
 
// Setting the bluing color. (Setting the rgb components by multiplying factors)
// red // green // blue
 static const float SetPS82r = 0.65 ; static const float SetPS82g = 0.85 ; static const float SetPS82b = 1.00 ; // TBM Defaults SetPS82r = 0.65, SetPS82g = 0.85, SetPS82b = 1.00

// The level of the effect of additional highlighting of texture contours.(size effect makes more pronounced granulation along the silhouette of the cloud)
 static const float SetPS10 = 0.00 ; // This effect is designed for use with special textures, in the case of ordinary textures, the effect should be = 0.


// Uncompensated adjustment of the preliminary brightness for the shadow filter
// -the sun is at its zenith // -the sun is not very low on the horizon // -sun on the horizon (sunset/sunrise)
 static const float SetPS04a = 1.00 ; static const float SetPS04e = 0.50 ; static const float SetPS04s = 0.40 ;

// Early twilight // Late twilight and night
 static const float SetPS04d = 0.35 ; static const float SetPS04n = 0.40*1.5 ;

// General setting of pre-brightness for shadow filter
 static const float SetPS05 = 0.65 ; // TBM Default 0.65

// Setting the brightness drop compensation for the output of the shadow and color filter for general stabilization of the brightness at the output
// Normalization of the compensating coefficient of brightness
 static const float SetPS06 = 0.35 ; // TBM Defaults SetPS06 = 0.35

// Brightness drop compensation level at the filter output // =0 - brightness compensation is completely absent. =1 - full compensation.
 static const float SetPS07 = 0.0 ;

// Steepness of change of brightness compensation at the filter output
 static const float SetPS08 = 0.5 ; // TBM Defaults SetPS08 = 0.5

// Lower threshold for limiting compensation for brightness at the filter output
 static const float SetPS09 = 0.1 ; // TBM Defaults SetPS09 = 0.1

// Gamma correction in the solar sector at sunset and after sunset (additional factor)
 static const float SetPS85 = 0.3 ; // TBM Defaults SetPS85 = 0.3

// Correction brightness in the solar sector at sunset and after sunset (additional factor)
 static const float SetPS86 = 0.00 ;

// Total daytime output cloud brightness
 static const float SetPS90 = 1.56 ; // TBM Default = 1.20*1.35 (calcs to 1.62) This value does have an overall effect on the general cloud brightness. Testing 1.56

// General night cloud brightness at output
 static const float SetPS91 = 0.025 ;

// Correction of the brightness of the clouds at the output in days
// -sun at zenith // -sun not very low above the horizon // -sun on the horizon (sunset/sunrise)
 static const float SetPS93a = 0.80 ; static const float SetPS93e = 1.10 ; static const float SetPS93s = 1.37 ;

// Early twilight // Late twilight and night
 static const float SetPS93d = 1.50 ; static const float SetPS93n = 0.70 ;

// "General" cloud saturation at the output
 static const float SetPS94 = 0.99 ; // TBM Default = 0.99

// Alpha channel settings
// Transparency of clouds at short distances
 static const float SetPS97 = 1.25 ; // TBM Defaults SetPS97 = 1.00

// Cloud Transparency at Long Distances (Junty Popcorn)
 static const float SetPS98 = 0.55 ; // TBM Defaults SetPS98 = 0.55

// anti-aliasing routine alpha channel
 static const float SetPS99 = 1.70 ; //  

// –Reserve =================================================================================================================
// -displacement of darkening height of the base and lower part of the clouds
 static const float SetC11 = 200 ; // TBM Default = 200

// Minimum brightness of the outsole and clipping strength of the minimum brightness of the lower parts.
 static const float SetC12 = 0.480 ; // TBM Default = 0.480

//***************************************************************************************************************************************
//***************************************************************************************************************************************

 static const float Sundy  = cb_mSun.mDirection.y ;
 static const float Sundx  = cb_mSun.mDirection.x ;
 static const float Sundz  = cb_mSun.mDirection.z ;
 static const float Moondy = cb_mMoon.mDirection.y ;
 static const float Moondx = cb_mMoon.mDirection.x ;
 static const float Moondz = cb_mMoon.mDirection.z ;

 static const float ALtit1 = cb_Altitude/10000 ;
 float FAcorrP( float xAltHmax, float Sc )
  { return saturate(1-step(0, -(ALtit1-xAltHmax))*pow(abs((ALtit1-xAltHmax)/xAltHmax), Sc)) ; }
 float FAexpP( float xWa, float Sc )
    { return 1-exp(-pow(abs( xWa *ALtit1 ), Sc )) ; }
 static const float HAoffset = step( 0, ALtit1)*(0.051*exp(log(abs(ALtit1))/1.77)-0.0022*exp(log(abs(ALtit1))/1.1)) ;
 static const float VisSunOn = saturate((Sundy+HAoffset+0.04 )*15 ) ;

 static const float fAcorr22 = FAcorrP( 2.0, 2.0 );  static const float fAcorr_22 = 1-fAcorr22 ;
 static const float fAcorr23 = FAcorrP( 2.0, 3.0 );  static const float fAcorr_23 = 1-fAcorr23 ;
 static const float fAcorr24 = FAcorrP( 2.0, 4.0 );  static const float fAcorr_24 = 1-fAcorr24 ;
 static const float fAcorr26 = FAcorrP( 2.0, 6.0 );  static const float fAcorr_26 = 1-fAcorr26 ;
 static const float fAcorr28 = FAcorrP( 2.0, 8.0 );  static const float fAcorr_28 = 1-fAcorr28 ;

 static const float fAexp23 = FAexpP( 2, 3 ) ;   static const float fAexp24 = FAexpP( 2, 4 ) ;
 static const float fAexp33 = FAexpP( 3, 3 ) ;   static const float fAexp34 = FAexpP( 3, 4 ) ;
 static const float fAexp43 = FAexpP( 4, 3 ) ;   static const float fAexp44 = FAexpP( 4, 4 ) ;
 static const float fAexp53 = FAexpP( 5, 3 ) ;   static const float fAexp84 = FAexpP( 8, 4 ) ;
 static const float fAexp83 = FAexpP( 8, 3 ) ;

 static const float FACorE1 = fAexp53*fAexp53 ;

 static const float FACorR4 = saturate( tanh(2.8*ALtit1) )  ;  static const float FACorR_4 = 1-FACorR4 ;
 static const float FACorR1 = saturate(1-exp(-3.0*ALtit1))  ;  static const float FACorR_1 = 1-FACorR1 ;

 static const float ProcessDE0 = saturate(0.5+0.5*tanh(5*(Sundy-0.50 ))) ;  static const float Process_DE0 = 1-ProcessDE0 ;
 static const float ProcessDE1 = saturate(0.5+0.5*tanh(7*(Sundy-0.50 ))) ;  static const float Process_DE1 = 1-ProcessDE1 ;
 static const float ProcessDE2 = saturate(0.5+0.5*tanh(8*(Sundy-0.33 ))) ;  static const float Process_DE2 = 1-ProcessDE2 ;
 static const float ProcessDE5 = saturate(0.5+0.5*tanh(35*(Sundy-0.15 ))) ;  static const float Process_DE5 = 1-ProcessDE5 ;
 static const float ProcessD_E5 = saturate((0.5+0.5*tanh(-12*(Sundy-0.65 )))*1.03) ;  static const float Process_D_E5 = 1-ProcessD_E5 ;
 static const float ProcessDT1 = saturate( tanh(11*Sundy )) ;  static const float ProcessDT_1 = 1-ProcessDT1 ;
 static const float ProcessSF1 = ProcessDE5*ProcessD_E5 ;
 static const float ProcessSn1 = saturate(1- (1- pow(abs( (Sundy- 1 )/(1-0.35)), 2 ))*(1-exp(-pow(abs( 5.5 *(Sundy-0.35)), 2)))) ;

 static const float ProcessDES = saturate(1.021*(0.5+0.5*tanh( 35*( Sundy - 0.06 )))-0.02) ; static const float Process_DES = 1-ProcessDES ;
 static const float PReProcessE  = saturate(1.025*(0.5+0.5*tanh(20*(Sundy-0.11 )))-0.02) ; //  
 static const float PReProcess_E = 1-PReProcessE ;
 static const float PReProcessE2  = saturate( 1.01* ( 1-exp(-pow(abs( 8 *Sundy ), 2.5  )) )*tanh( 4*Sundy)) ; static const float PReProcess_E2 = 1-PReProcessE2 ;//  
 static const float PReProcessEDES  = lerp(ProcessDE2, ProcessDES, SetVS58 ) ; static const float PReProcess_EDES = 1-PReProcessEDES ;
 static const float PReProcessEE  = saturate(tanh( 11 * Sundy)*((0.5+0.5*tanh( -7 *(Sundy- 0.50 )))*1.05-0.02) ) ;
 static const float PReProcessES1  = saturate(1-pow(abs((Sundy-0.1)/0.1), 3)*step(0, -(Sundy-0.1)) ) ;
 static const float PReProcessEt   = saturate(1.025*(0.5+0.5*tanh(20*(Sundy-0.11 )))-0.02) ;
 static const float PReProcess_Et = 1-PReProcessEt ;
 static const float PReProcessEGt =  saturate( 1.003*(1-exp(-pow(abs( 18 *(Sundy+0.03)), 3 )))*exp(-pow(abs( (5-2)*(Sundy+0.03)), 3 )))*step(0, (Sundy+0.03)) ;

 static const float PReProcessEG =  saturate( 1.003*(1-exp(-pow(abs( 18 *(Sundy+0.03)), 3 )))*exp(-pow(abs( (5-2)*(Sundy+0.03)), 3 )))*step(0, (Sundy+0.03)) ;
 static const float PReProcessEG1 =   saturate(tanh( 11 * Sundy)* exp(-pow(abs( 8 *(Sundy - 0.35)), 2.5 ))) ;
 static const float Sxoffs1 = 0.10 ;  static const float SfDy = Sundy-Sxoffs1 ;
 static const float ScEs = 4 ;
 static const float ScWea = 2.3 ;
 static const float PReProcessEG2 = step(0, -SfDy)*saturate(1-pow(abs(SfDy/Sxoffs1), ScEs)) + step(0, SfDy)* exp(-pow(abs(ScWea *SfDy), 3 )) ;

 static const float POstProcessD0 = saturate(0.5+0.5*tanh(28*(Sundy+0.08 ))) ;        static const float POstProcess_D0 = 1-POstProcessD0 ;
 static const float POstProcessD1 = saturate(1.0* (0.5+0.5*tanh(35*(Sundy+0.085)))) ; static const float POstProcess_D1 = 1-POstProcessD1 ;

 static const float POstProcessB0 = saturate(0.5+0.5*tanh(35*(Sundy+0.095 ))) ;       static const float POstProcess_B0 = 1-POstProcessB0 ;
 static const float POstProcessB1 = saturate(0.5+0.5*tanh(33*(Sundy+0.15  ))) ;       static const float POstProcess_B1 = 1-POstProcessB1 ;
 static const float POstProcessS1 = saturate(1*(0.5+0.5*tanh(50*(Sundy+0.050)))) ;    static const float POstProcess_S1 = 1-POstProcessS1 ;
 static const float POstProcessS2 = saturate(0.5+0.5*tanh(55*(Sundy-0.05  ))) ;       static const float POstProcess_S2 = 1-POstProcessS2 ;
 static const float POstProcessS3 = saturate(0.5+0.5*tanh(53*(Sundy-SetVS40t ))) ;    static const float POstProcess_S3 = 1-POstProcessS3 ;

 float FProcessF(in float xDA, in float xEG, in float xSU )
               { return lerp(lerp( xSU, xDA, PReProcessE ), xEG, PReProcessEG) ; }

 static const float aSetC9H =   lerp(SetVS3H, 0, FACorE1 ) ;
 static const float cSetVS61 =  lerp(FProcessF( SetVS61a, SetVS61e, SetVS61s ), 1, POstProcess_S3 ) ;
 static const float cSetVS620 = lerp(FProcessF( SetVS62a, SetVS62e, SetVS62s ), 1, POstProcess_S3 ) ;
 static const float cSetVS63A = lerp(FProcessF( SetVS63a, SetVS63e, SetVS63s ), 1, POstProcess_S3 ) ;
 static const float cSetVS62 =  lerp(cSetVS620, cSetVS63A, fAcorr28  ) ;
 static const float cSetPS55 =  lerp(lerp(FProcessF( SetPS55a, SetPS55e, SetPS55s ), SetPS55d,  POstProcess_S1), SetPS55n, POstProcess_B1) ;
 static const float cSetPS56 =  lerp(lerp(FProcessF( SetPS56a, SetPS56e, SetPS56s ), SetPS56d,  POstProcess_S1), SetPS56n, POstProcess_B1) ;
 static const float cSetPS04 =  lerp(lerp(FProcessF( SetPS04a, SetPS04e, SetPS04s ), SetPS04d,  POstProcess_S1), SetPS04n, POstProcess_B1) ;
 static const float cSetPS93 =  lerp(lerp(FProcessF( SetPS93a, SetPS93e, SetPS93s ), SetPS93d,  POstProcess_S1), SetPS93n, POstProcess_B1) ;

    float RIntGc( float fIntGB )
     {  const float Sud = 4 ;
        const float IntSud = 0.0 ;
        const float IntLc  = 0.5 ;
        const float IntTn0 = 3 ;
        float UpScf = saturate(1-pow(abs(fIntGB-1), Sud) ) ;  float DwScf = saturate( pow(abs(fIntGB), 1/Sud) ) ;
        return fIntGB - IntLc*(saturate(tanh(IntTn0*fIntGB)) *(lerp(UpScf, DwScf, IntSud)-fIntGB)) ;
     }

//perObject
shared cbuffer cbPerObjectCloudData : REGISTER(b,PER_MATERIAL_CB_REGISTER)
{
    float   fAlpha :                                packoffset(c0.x);
    float   fAlphaEdges :                           packoffset(c0.y);
    float   fRadius :                               packoffset(c0.z);
    float   fCloudExpandScale :                     packoffset(c0.w);

    float   fCloudExpandDistance :                  packoffset(c1.x);
    float   fCloudFadeDistanceInverse :             packoffset(c1.y);
    float   fCloudFadeDistance :                    packoffset(c1.z);
    float   ColorLevelHeightLow :                   packoffset(c1.w);

    float   ColorLevelHeightMediumLow :             packoffset(c2.x);
    float   ColorLevelHeightMedium :                packoffset(c2.y);
    float   ColorLevelHeightMediumHigh :            packoffset(c2.z);
    float   ColorLevelHeightHigh :                  packoffset(c2.w);

    float   fCloudEndFadeDistance :                 packoffset(c3.x);
    float   fCloudExpandSizeScale :                 packoffset(c3.y);
    float   fFiller0 :                              packoffset(c3.z);
    float   fFiller1 :                              packoffset(c3.w);

    float4  ColorLevelColors[MAX_COLOR_LEVELS] :    packoffset(c4);
    
};

struct VS_OUTPUT
{
    float4x4 position : POSITION;
    float4x4 diffuse : COLORS;
    float4 uv : TEXCOORD;
    float fFogDistance : FOG;
    float4 mAlt : ALTITUDE;
};

struct GS_OUTPUT
{
    float4 position : SV_POSITION;
    float2 uv : TEXCOORD;
    float2 localUV : TEXCOORD2;
    
    #if defined(SHD_VIEW_SHADOW)
        float z : SHADOWZ;
    #else
        float mAlt : ALTITUDE;
        float4 diffuse : COLOR;
        float fFogDistance : FOG;
    #endif

    #if defined(SHD_GS_INSTANCING)
        uint RTIndex : SV_RenderTargetArrayIndex;
    #endif
};

struct PS_INPUT
{
    float4 position : SV_POSITION;

    float2 uv : TEXCOORD;
    float2 localUV : TEXCOORD2;
   
    float mAlt : ALTITUDE;
    float4 diffuse : COLOR;
    float fFogDistance : FOG;
};

void GetScreenQuadPositions( out float4x3 output, in float width, in float height )
{
    float halfWidth = width;
    float halfHeight = height;
    /// VALUE // Quadrant
    output[0].x = -halfWidth;   //-1
    output[0].y = -halfHeight;  //-1
    output[0].z = 0;

    output[1].x =  halfWidth;   // 1
    output[1].y = -halfHeight;  //-1
    output[1].z = 0;

    output[2].x = -halfWidth;   // -1
    output[2].y =  halfHeight;  //  1
    output[2].z = 0;

    output[3].x = halfWidth;    // 1
    output[3].y = halfHeight;   // 1
    output[3].z = 0;
}

float ComputeScatterFactor(float3 vNormal, float3 cameraDir, float3 lightDirection, float fViewDependency)
{
    //vNormal = -vNormal;

    // how much is the camera looking into the light source?
    float fBackContribution = (dot(-cameraDir, lightDirection) + 1.0) * 0.5;

    // compute the result to get the right falloff
    fBackContribution *= fBackContribution;
    fBackContribution *= fBackContribution;

    // use the reverse normal to compute scatter
    float fScatterDueToNormal = (dot(-lightDirection, -vNormal) + 1.0) * 0.5;

    // choose between scatter and back contribution based on artist-controlled parameter
    float fScatterFactor = lerp(fScatterDueToNormal, fBackContribution, fViewDependency);

    // back it off based on how much cloud is in the way
    float fReductionDueToNormal = (dot(-cameraDir, vNormal) + 1.0) * 0.5;
    fScatterFactor *= fReductionDueToNormal;

    return fScatterFactor;
}

void ComputeFarAndNearFade(in out float4 position, in out float4 diffuse)
{
    // Calculate fade distance and alpha
    float fFadeDistance = position.w;
    fFadeDistance = min(fFadeDistance, fCloudFadeDistance);
    fFadeDistance -= fCloudEndFadeDistance;

    float fOneOverRange = rcp(fCloudFadeDistance - fCloudEndFadeDistance);
    float fAlphaFade = fFadeDistance * fOneOverRange;

    // Apply fading at the far clip. This prevents clouds popping in/out at the far clip
#if defined(SHD_FADE_AT_FAR_CLIP)
    fAlphaFade = FarClipAlphaFade(position.w, fAlphaFade);
#endif

    // Apply a distance fade relative to the camera
    diffuse.w *= fAlphaFade;

    bool bOverrideZ = (position.w < cb_NearClip);
    bOverrideZ = bOverrideZ && (position.w > fCloudEndFadeDistance);

    position.z *= !bOverrideZ;

    float fUseNear = cb_NearClip * bOverrideZ;
    position.w = position.w * !bOverrideZ + fUseNear;
}

void GetPointDiffuse( out float4 diffuse, in float3 corner, in float3 fvNormal, in float3 fvPosition, in float cloudDistance, in float3 facingDir,
                      in float3 nPosition1, in float3 nPosition2,  in float3 nPosition3,  in float3 VecEx , in matrix matWorld2 )
{
 // float3 nPosition1 = normalize(Position1) ;  float3 nPosition2 = normalize(Position2) ;  float3 nPosition3 = normalize(Position3) ;
    const float fExp32 = saturate(exp(  SetVS3S* (cloudDistance - SetVS3D*0.9 ))) ;
    const float MdistFac = 0.5*1.5*cloudDistance/200000 ;
    const float fExp_P =  saturate(1-exp(-pow(abs(0.7*1.8*( MdistFac-1)), 5)))*step(0, -( MdistFac-1)) ; //  saturate(1-pow(abs(MdistFac), 1 ) )
    const float fExpP = 1-fExp_P ;

  float4 RotAzProj = mul( float4(VecEx,1.0), matWorld2 ) ;
  float3 AngPosVec = normalize( RotAzProj.xyz ) ;
  float3 AngWSAVec = normalize( float3(RotAzProj.x, RotAzProj.y+ cb_Altitude, RotAzProj.z ) ) ;
 
 const float fAngY1 = saturate(pow(abs(AngPosVec.y), 0.5 ) ) ; const float fAng_Y1 = 1 - fAngY1 ;
  const float P_i = 3.1415926536 ; const float PiU2 = 6.2831853072 ; const float Pi_2 = 1.5707963268 ;
  float AzRDx = (step(0,  AngPosVec.z)*step(0,  AngPosVec.x)* 0.25* atan(abs(( AngPosVec.x )/( AngPosVec.z )) )/Pi_2
               + step(0, -AngPosVec.z)*step(0,  AngPosVec.x)*( 0.25*atan(abs(( AngPosVec.z )/( AngPosVec.x )) )/Pi_2+0.25 )
               + step(0, -AngPosVec.z)*step(0, -AngPosVec.x)*( 0.25*atan(abs(( AngPosVec.x )/( AngPosVec.z )) )/Pi_2+0.5  )
               + step(0,  AngPosVec.z)*step(0, -AngPosVec.x)*( 0.25*atan(abs(( AngPosVec.z )/( AngPosVec.x )) )/Pi_2+0.75 )) ;

  float SundirX = (round(Sundx*100000)+0.1)/100000 ;
  float MoondirX = (round(Moondx*100000)+0.1)/100000 ;
  float AangleSUN =  1-(step(0, Sundz)*step(0, -Sundx) +0.5*step(0, Sundx) +atan(Sundz/SundirX )/PiU2)-0.25   ;
  float AangleMoon = 1-(step(0, Moondz)*step(0, -Moondx) +0.5*step(0, Moondx) +atan(Moondz/MoondirX )/PiU2)-0.25 ;
  float AngleSC = (AangleSUN+0.5)*2*P_i ;  float ASsin = sin(AngleSC) ;  float AScos = cos(AngleSC) ;
  const float asun = AzRDx - AangleSUN   ; const float amoon = AzRDx - AangleMoon ;
  const float asun1 = asun+1 ; const float asun_1 = asun-1 ; const float asunO1 = asun+0.5 ; const float asun_O1 = asun-0.5 ;
  const float angsunY =  AngPosVec.y - cb_mSun.mDirection.y ;

  float TempSUNYZ = 1-exp(-pow(abs( 2.5*(AngPosVec.y -1)), 2.5 )) ;
  float TempSUNY1 = exp(-pow(abs( 3.5*angsunY), 2 )) ;
  float TempSUNYm = exp(-pow(abs( 11*angsunY), 1.5 )) ;
  float TempSUNR1 = (1-(1-exp(-pow(abs( 11*asun), 3)) )*(1-exp(-pow(abs( 11*asun1), 3)) )*(1-exp(-pow(abs( 11*asun_1), 3) ) )) ;
  float TempSUNR2 = (1-(1-exp(-pow(abs( 8*asun), 3)) )*(1-exp(-pow(abs( 8*asun1), 3)) )*(1-exp(-pow(abs( 8*asun_1), 3) ) )) ;
  float TempSUNR3 = (1-(1-exp(-pow(abs( 3*asun), 3)) )*(1-exp(-pow(abs( 3*asun1), 3)) )*(1-exp(-pow(abs( 3*asun_1), 3) ) )) ;
  float TempSUNR4 = (1-(1-exp(-pow(abs( 5*asun), 4)) )*(1-exp(-pow(abs( 5*asun1), 4)) )*(1-exp(-pow(abs( 5*asun_1), 4) ) )) ;

  float TempSUNRm = (1-(1-exp(-pow(abs( 17*asun), 1.7)) )*(1-exp(-pow(abs( 17*asun1), 1.7)) )*(1-exp(-pow(abs( 17*asun_1), 1.7) ) )) ;
  float TempSUNR_O1 = (1-exp(-pow(abs( 3*asunO1), 3)) )*(1-exp(-pow(abs( 3*asun_O1), 3)) ) ;
  float TempSUNRO1 = 1-saturate(TempSUNR_O1) ;
  float TempSUNR_O2 = (1-exp(-pow(abs( 7*asunO1), 2)) )*(1-exp(-pow(abs( 7*asun_O1), 2)) ) ;
  float TempSUNRO2 = 1-saturate(TempSUNR_O2) ;

  float TempFullS1 = TempSUNY1*TempSUNR1 ;
  float TempFullSm = TempSUNYm*TempSUNRm ;

  float TempAngHY1 =  saturate( exp(-11*AngWSAVec.y)) ;
  float Roxz1 =   nPosition1.x*ASsin + nPosition1.z*AScos ;
  float Roxz2 =   nPosition2.x*ASsin + nPosition2.z*AScos ;
  float Roxz3 =   nPosition3.x*ASsin + nPosition3.z*AScos ;

  float kSoff1 = lerp( 0.4, 0.2, fAcorr28 ) ;
  float kSoff2 = lerp( 0.45, 0.25, fAcorr28 ) ;

  float fSoffset = kSoff1-kSoff2*TempSUNRO1 -0.25*TempSUNR3*(1-exp(-5*abs(AngPosVec.y-saturate(Sundy)))) ;
  float TempXZ1 = saturate(0.5+0.5*tanh( -5* (Roxz1  +  fSoffset  )))  ;  // saturate(  saturate(1- nPosition1.y)-fA0 ) *

  float TempXZ2 = saturate(0.5+0.5*tanh(2* (Roxz2  + 1   ))) ;   //  saturate(pow(abs(0.5+0.5*Roxz2), 2 ))

  float HAcompY = RotAzProj.y+ cb_Altitude +3100*pow(abs(cloudDistance/200000), 2 ) +1.1*aSetC9H*SetVS3*fExp32 ;
  float hCAltitudeY1 = HAcompY/10000 ;
  float fIntAltCorr1 = (1-exp(-pow(abs( 4 * hCAltitudeY1), 3.5)))*saturate(tanh( 2.2 *hCAltitudeY1))  ;
  float3 groupCenter = lerp(  fvNormal, fvPosition, lerp(cSetVS61, cSetVS62, 0.2*TempSUNR2 ) ) ;

//-----------------------------------------------------------------------------------------------------------------------------------------------
    // Sun lighting
    // See bglfp.cpp, g2d_LightCloudFromNormal() - KEEP SHADER IN SYNC!

    float3 ActiveLightDirectionSM = lerp(cb_mSun.mDirection, cb_mMoon.mDirection, POstProcess_B1) ;
    float3 cloudGroupNormal = normalize( corner.xyz - groupCenter + float3(0, fExp32*0.9*aSetC9H, 0) );
    float3 facingDirection = cross( cloudGroupNormal, float3( 0, 1, 0 ) );
    float3 lightDirection = float3(ActiveLightDirectionSM.x,  saturate(ActiveLightDirectionSM.y),  ActiveLightDirectionSM.z)  ;
    float  fIntensity = -1.0f * max(dot(lightDirection, cloudGroupNormal), dot(lightDirection, facingDirection));

    if (fIntensity < -cb_mMedianLine)
    {
        // The "1.0001" in the line above is a hack to fix a bug
        // observed on some hardware. Even though the else branch
        // of this if/else was taken a divide by zero in this
        // branch (when cb_mMedianLine is 1.0) caused the whole
        // shader to go crazy.
        fIntensity = cb_mMinIntensity + ((cb_mMedianIntensity - cb_mMinIntensity) *    ((1 + fIntensity) / (1.0001 - cb_mMedianLine)));
    }
    else
    { fIntensity = cb_mMedianIntensity +(1 - cb_mMedianIntensity) *(fIntensity + cb_mMedianLine) / (1 + cb_mMedianLine); }

    // Height band lighting/coloring
    // See SwarmCloud.cpp, GetColor() - KEEP SHADER IN SYNC!
    float height =  corner.y ;
    float4 baseColor ;
    float4 topColor ;
    float  baseHeight ;
    float  topHeight ;
    float  height2 = height ; // - fofss2  + ShDizx*100 + 1.2*aSetC9H*SetVS3*fExp32
    
    if (height2 <= ColorLevelHeightLow)
    {   baseColor  = ColorLevelColors[0]; topColor   = ColorLevelColors[0];
        baseHeight = ColorLevelHeightLow; topHeight  = ColorLevelHeightLow + 1 ; } // +1 to avoid division by zero below
    else if (height2 <= ColorLevelHeightMediumLow)
    {   baseColor  = ColorLevelColors[0]; topColor   = ColorLevelColors[1];
        baseHeight = ColorLevelHeightLow; topHeight  = ColorLevelHeightMediumLow; }
    else if (height2 <= ColorLevelHeightMedium)
    {   baseColor  = ColorLevelColors[1]; topColor   = ColorLevelColors[2];
        baseHeight = ColorLevelHeightMediumLow; topHeight  = ColorLevelHeightMedium; }
    else if (height2 <= ColorLevelHeightMediumHigh)
    {   baseColor  = ColorLevelColors[2]; topColor   = ColorLevelColors[3];
        baseHeight = ColorLevelHeightMedium; topHeight  = ColorLevelHeightMediumHigh; }
    else if (height2 <= ColorLevelHeightHigh)
    {   baseColor  = 1.0*ColorLevelColors[3]; topColor   = ColorLevelColors[4];
        baseHeight = ColorLevelHeightMediumHigh; topHeight  = ColorLevelHeightHigh; }
    else
    {   baseColor  = ColorLevelColors[4];  topColor   = ColorLevelColors[4];
        baseHeight = ColorLevelHeightHigh; topHeight  = ColorLevelHeightHigh + 1 ; } // +1 to avoid division by zero below

    float heightE = nPosition2.y;
    float  baseHeightE;
    float  topHeightE;
    if (heightE <= ColorLevelHeightLow)
    { baseHeightE = ColorLevelHeightLow ; topHeightE = ColorLevelHeightLow + 100 ; } // +1 to avoid division by zero below
    else if (heightE <= ColorLevelHeightMediumLow)
    { baseHeightE = ColorLevelHeightLow ; topHeightE = ColorLevelHeightMediumLow; }
    else if (heightE <= ColorLevelHeightMedium)
    { baseHeightE = ColorLevelHeightMediumLow ; topHeightE = ColorLevelHeightMedium; }
    else if (heightE <= ColorLevelHeightMediumHigh)
    { baseHeightE = ColorLevelHeightMedium ; topHeightE = ColorLevelHeightMediumHigh; }
    else if (heightE <= ColorLevelHeightHigh)
    { baseHeightE = ColorLevelHeightMediumHigh ; topHeightE = ColorLevelHeightHigh; }
    else
    { baseHeightE = ColorLevelHeightHigh; topHeightE = ColorLevelHeightHigh + 1000 ; } // +1 to avoid division by zero below

    float VthicknessE = (topHeightE - baseHeightE ) ;
    float Vthickness = (topHeight - baseHeight ) ;

    float ofsBasTop = 0.5 ;
    float st = saturate( (height2 - baseHeight) / Vthickness - ofsBasTop ) ;

    float s = saturate( (height2 - baseHeight) / Vthickness ) ;
    float colorA = lerp( baseColor.a, topColor.a, s ) ; // 1.002*

//---------------------------------------------------------------------------------------------------------------------------------------------
    const float fCcolorBase = 1*lerp(1, 1, fAngY1 );
    const float fCcolorTop  = 4;
    const float fcolorC     = 1.8;

    baseColor.rgb = fCcolorBase*pow(abs(baseColor.rgb), 1.0 ) ; // *float3(1, 1, 1 )
    topColor.rgb  = fCcolorTop *pow(abs(topColor.rgb), 1.0 ) ; // *float3(1, 1, 1 )
    float colorB  = lerp( baseColor.r, topColor.r, pow(abs(st), 2 ) );
          colorB  = pow(abs(colorB), 2);
    float TrA     = step(0, 0.1*baseHeight+1000*0.28) ; // TBM Default step(0, 0.1*baseHeight+1000*0.28) // calculation of the darkening limit of the sole, and the textures below the sole (additionally on the alpha channel : colorA = colorA*TrA ; )
    colorB        = fcolorC*clamp(colorB , SetC12, 5) ; // TBM Default fcolorC*clamp(colorB , SetC12, 5) // limited darkening of the sole, and textures below the sole
//----------------------------------------------------------------------------------------------------------------------------------------

    // Fade in/out alpha
    float distance_from_center = length(corner);
    float alpha = 1.0f;

    if (fAlpha > 0)
    {  // Fading in from or out to the edges
        float fMagnitude = 1.3f * fRadius - distance_from_center;
        fMagnitude = max(0, fMagnitude);
        alpha = fAlpha - fAlphaEdges * (fMagnitude / fRadius);
    }
    else
    {   // Fading out to the core
        alpha = -fAlpha - fAlphaEdges * (distance_from_center / fRadius);
    }
    const float fExp = saturate(exp(-cloudDistance * cloudDistance * 0.00000000077));

    float tempHYc =  1-saturate(exp(-44* abs(  AngWSAVec.y   ))) ; // AngPosVec.y
    float AngRCs = SetVS66*TempFullSm ;
    float3 facingDirE = float3(facingDir.z, facingDir.y, facingDir.x )  ;
    float RedDueToNs = saturate((dot(-facingDir, cloudGroupNormal) + 1) * 0.5 -0.1) ;
    float RedDueToNr = lerp( RedDueToNs, saturate((dot(-facingDirE, cloudGroupNormal) + 1) * 0.5 -0.2),  AngRCs ) ;
    float RedDueToNp = lerp( RedDueToNs, saturate((dot( facingDirE, cloudGroupNormal) + 1) * 0.5 -0.2),  AngRCs ) ;
    float RedDueToN = RedDueToNr*step(0, -facingDir.z ) + RedDueToNp*step(0, facingDir.z ) ;
    RedDueToN = pow(abs(RedDueToN), 2 ) ; RedDueToNs = pow(abs(RedDueToNs), 3 ) ;
    RedDueToN = SetVS65*( 0.8* RedDueToN*TempFullSm + 0.2* RedDueToNs*TempFullS1 )*lerp(1, saturate(nPosition2.y), 0.2 ) *POstProcessS2*tempHYc ;

    float ScatterDueToNormal =  saturate( (dot(-lightDirection, -cloudGroupNormal ) + 1.0 )*0.50 ) ; // use the reverse normal to compute scatter
    ScatterDueToNormal = pow(abs(ScatterDueToNormal), lerp( SetVS36, SetVS37, TempSUNRO1*Process_DE0)+TempSUNR3*SetVS38*Process_DE0 ) ; // saturate

    float ctBrL =   SetVS14*lerp( SetVS10, SetVS11, saturate(exp( -SetVS12* (VthicknessE-80)/1000  ))) ; // коэффициент крутизны градиента от толщины облачности
    float corrDistH = saturate(0.7*SetVS3H/5000) ;

    float fIntHVint1 = saturate(tanh( ctBrL *(nPosition1.y + corrDistH*fExp32  ) )) ;
    float fIntHVint2 = saturate(tanh( ctBrL *(nPosition2.y + corrDistH*fExp32  ) )) ;
    float fIntHVint =  lerp( fIntHVint2, fIntHVint1, lerp(SetVS15, SetVS57, SetVS57*PReProcess_EDES ) ) ;
    fIntHVint = pow( abs(fIntHVint), 1+11*TempFullS1 )+ SetVS13 + 0.3*fIntAltCorr1 -0.2*SetVS57*POstProcess_S3-0.2*PReProcess_E   ;

    float vecSune =  saturate(0.5+0.5*tanh(SetVS78 *(AngPosVec.y - Sundy ))) ;
    float fIntHVint3 =  saturate(tanh( ctBrL *( (nPosition2.y + nPosition1.y) + corrDistH*fExp32  ) ))+lerp( SetVS75, SetVS74, vecSune ) ; // pow(abs( 1*ctBrL *( nPosition1.y+nPosition2.y + corrDistH*fExp32 +1-2*fA0  ) ), 2.0 )
    float fcolorGSs = fIntHVint3*2*SetVS71 ;

    float LBcolor = lerp(SetVS20, SetVS21, fIntAltCorr1) ; float HTcolor = lerp(SetVS22, SetVS22o, TempSUNRO2*Process_DE2*ProcessDES ) ; float cIntcolor = SetVS23 ;

    float fCTcolor = 1.3 *saturate(HTcolor - LBcolor ) ;
    float colorVGB =  LBcolor +  fCTcolor* fIntHVint2*lerp(1, saturate(1 *fIntensity), cIntcolor ) ; // (1 - fA0* (1-saturate(fIntensity)))

    float corrMsp = 1+ 0.5*cSetVS61 ;
    float ColorE =  SetVS30 + (1+SetVS39* POstProcess_S3)*ScatterDueToNormal*corrMsp
                    *lerp(lerp(SetVS33, SetVS33o, TempSUNRO2*Process_DE2*ProcessDES ), SetVS32, ProcessDE0)
                    *(1+  lerp(SetVS340, SetVS34A, fAexp83)* TempSUNR2*Process_DE0 ) + SetVS31*saturate(fIntensity) ; // *TempXZ1*1.5  lerp( 1.3, 0.4,  TempXZ1 ) ScatterDueToNormal colorVGB *ScatterDueToNormal*1.0
    float ColorSD =  SetVS35 *PReProcessEG2*TempXZ1 ;

    float  ContrD = FProcessF( SetVS51a, SetVS51e, SetVS51s ) ;
    float  minLevD = SetVS51M ;
    colorVGB = 1*(saturate(minLevD)+saturate(1-(minLevD))*pow(abs(ContrD), 3))*(1-ContrD*(1-colorVGB)) ;
    float  ContrE = FProcessF( SetVS52a, SetVS52e, SetVS52s ) ;
    float  minLevE = SetVS52M ;
    ColorE = 1*(saturate(minLevE)+saturate(1-(minLevE))*pow(abs(ContrE), 3))*(1-ContrE*(1-ColorE)) ;

    float fIntEDDu = lerp(lerp( 1-lerp(saturate(SetVS56), 0, PReProcess_EDES*SetVS57 ), 1-saturate(SetVS55), ProcessDE0 ), 1, 0.2*TempSUNRO2*Process_DE0 ) ;

    float ContrSv = lerp( SetVS77, SetVS76, pow(abs(saturate(Sundy)), 0.5 )) ;
    fcolorGSs = (saturate(0.35)+saturate(1-0.35)*pow(abs(ContrSv), 3))*(1-ContrSv*(1-fcolorGSs)) ;

    float BcolorFinal = lerp(  ColorE,  colorVGB,  lerp(fIntEDDu, 1, PReProcess_EDES*SetVS57) )+ RedDueToN + ColorSD ;

    float  ContrF0 = FProcessF( SetVS53a, SetVS53e, SetVS53s ) ;
    float  ContrFA = FProcessF( SetVS80a, SetVS80e, SetVS80s ) ;
    float  ContrF = lerp( ContrF0, ContrFA, fAcorr28 ) ;
    float  minLevF = SetVS53M ;
    float AddVCSn2 = fcolorGSs*TempSUNR2*TempSUNYZ*(1+SetVS73*TempSUNR1)*(1+0.0 *TempFullSm )*POstProcessS1*ProcessSn1*(1-0.1*Process_DES) ;
    BcolorFinal = (1- (0.5*TempFullSm + 0.50*TempSUNR2*TempSUNYZ* Process_DE1 )*POstProcessB1 )
                 *(saturate(minLevF)+saturate(1-minLevF)*pow(abs(ContrF), 3))*(1-ContrF*(1-BcolorFinal)) + 1.0*AddVCSn2 ;

    diffuse.r = SetVS99 *BcolorFinal*(1+TempSUNRO2*Process_DE2*fIntAltCorr1*lerp( SetVS60, SetVS60s, Process_DES) ) ;
    diffuse.g = TempSUNR2 ; // TempSUNR2 colorVGB fcolorGSs PReProcessEG2
    diffuse.b = TempFullSm ;
    diffuse.a =  colorA*saturate(alpha) ;

}  //  void GetPointDiffuse

// Generate a rotation matrix based on the bank, with 0 pitch and heading
float3x3 GenerateBankMatrix(in float b)
{
    float sin_b = sin(b);
    float cos_b = cos(b);

    float3x3 matRot;

    matRot[0].x = cos_b;
    matRot[1].x = -sin_b;
    matRot[2].x = 0;

    matRot[0].y = sin_b;
    matRot[1].y = cos_b;
    matRot[2].y = 0;

    matRot[0].z = 0;
    matRot[1].z = 0;
    matRot[2].z = 1;

    return matRot;
}

VS_OUTPUT VS(VS_INPUT In)
{
    VS_OUTPUT Out = (VS_OUTPUT)0;

    float4 spriteCenter = In.vPosition;
    float3 groupCenter = In.vNormal.xyz;
    float4 packedUV = In.cColor;
    float2 packedCorner = In.Tex;
    float  bankRadian = In.fRBias[0];
    float  puffRadius = In.fRBias[1];

    GeoidTranform geoTrans = GetGeoidTranform(In.mInstanceIndex);

    // Get round world matrix
    matrix matWorld = ComputeRoundWorldMatrix(geoTrans, cb_ViewOrigin);

    // Set UV
    Out.uv = packedUV;

    // Offset the spritecenter with cluster offset. The cluster is a group of sprites to make upa cloud. This is needed because sometimes we draw one cluster at a time to do sorting
    float4 clusterOffset = GetCloudClusterOffset(In.mInstanceIndex);

    float3x3 rotationMatrix;

#if defined(SHD_VIEW_SHADOW)
    float3 shadowFacingVector = normalize(cb_mShadowLightDirection);

    rotationMatrix[2] = shadowFacingVector;
    rotationMatrix[0] = normalize(cross(rotationMatrix[2], float3(0, 1.0f, 0)));
    rotationMatrix[1] = normalize(-cross(rotationMatrix[2], rotationMatrix[0]));
#elif defined(SHD_VIEW_CUBEMAP) || defined(SHD_CLOUD_ALWAYS_CAMERA_FACE)
    // We baked a value [0 or 1] into the w component to tell us if this draw call is per puff
    int IsPuffDraw = saturate(clusterOffset.w);
    clusterOffset.w = 0.0;

//-----------------------------------------------------------------------------------------------------------------------------------
//    float3 positionVector = -mul(spriteCenter - clusterOffset, matWorld).xyz;
//    float3 cameraFacingVector = normalize(positionVector);

    float3 positionVector = -mul(spriteCenter - clusterOffset, matWorld).xyz;

    float cvcCFVi = 1 ;

//    float3 cameraFacingVector = normalize(positionVector) ;
    float cloudDistance = length(positionVector) ;
    float cloudDistanceR = length(positionVector.xz) ;
    float3 cameraFacingVector1 = normalize(positionVector) ;
    float3 cameraFacingVector = positionVector / cloudDistance ;
    float3 PosOVec1 ;
//------------------------------------------------------------------------------------------------------------------------------------

    rotationMatrix[2] = normalize(cameraFacingVector) ;
    rotationMatrix[0] = normalize(cross(rotationMatrix[2], float3(0, 1, 0))) ;
    rotationMatrix[1] = normalize(-cross(rotationMatrix[2], rotationMatrix[0])) ;
#else
    // We baked a value [0 or 1] into the w component to tell us if this draw call is per puff
    int IsPuffDraw = saturate(clusterOffset.w);
    clusterOffset.w = 0.0;

//------------------------------------------------------------------------------------------------------------------------------------
    float3 positionVector = -mul(spriteCenter - clusterOffset, matWorld).xyz ;
//    float3 cameraFacingVector = normalize(positionVector) ;

    float3 screenFacingVector = normalize(-cb_mInverseView[2].xyz) ;
    float cloudDistance = length(positionVector) ;
    float cloudDistanceR = length(positionVector.xz) ;
    float3 cameraFacingVector1 = normalize(positionVector) ;
    float3 cameraFacingVector = positionVector / cloudDistance;
    float3 PosOVec1 ;
//-------------------------------------------------------------------------------------------------------------------------------------

    float blendDistance = 3000; // Clouds will be fully volumize from 3000 meters, reducing to 0 at 6000

    float facingBlend = saturate(((blendDistance - cloudDistance) / blendDistance) * IsPuffDraw) ;

    rotationMatrix[2] = normalize(lerp(cameraFacingVector, screenFacingVector, facingBlend)) ;
    rotationMatrix[0] = normalize(cross(rotationMatrix[2], float3(0, 1, 0))) ;
    rotationMatrix[1] = normalize(-cross(rotationMatrix[2], rotationMatrix[0])) ;
#endif

#if !defined(SHD_GS_INSTANCING)
    matrix worldView = mul(matWorld, cb_mViewToDevice) ;
#if defined(SHD_NO_NEAR_CLIP)
    matrix worldViewProj = mul(worldView, cb_mNoNearProj) ;
#elif defined(SHD_NO_FAR_CLIP)
    matrix worldViewProj = mul(worldView, cb_mNoFarProj) ;
#else
    matrix worldViewProj = mul(worldView, cb_mProjToDevice) ;
#endif
#endif

//--------------------------------------------------------------------------------------------------------
    float3 positionVector2 = -mul(spriteCenter - clusterOffset, matWorld).xyz ;
    float cloudDistance2 = length(positionVector2) ;
    float cloudDistance2R = length(positionVector2.xz) ;
    const float fExp2 = saturate(exp(-cloudDistance2 * cloudDistance2 * 0.00000000077 )) ;
    const float fExp3 = saturate(exp(SetVS3S* (cloudDistance2 - SetVS3D*0.9 ))) ;
    const float kSizeC = saturate(SetVS1) ;
//----------------------------------------------------------------------------------------------------------

    //Apply the sprite bank rotation.
    rotationMatrix = mul(GenerateBankMatrix(bankRadian), rotationMatrix);

    Out.diffuse = (float4x4)0;

    float4x3 quad = (float4x3)0;
    float height = packedCorner.y;
    float width = packedCorner.x;
    GetScreenQuadPositions(quad, width*kSizeC, height*kSizeC  );

    const float fExpR = exp(-pow(abs( 0.1*50*cloudDistance2R/200000), 2)) ;
//    float iSetC8x = lerp(0.8*SetVS2x, 2, fExpR) ; float iSetC8z = lerp(2*SetVS2z, 1, fExpR) ;
    float iSetC8x = lerp(1*SetVS2x, 1, fExpR) ; float iSetC8z = lerp(1*SetVS2z, 1, fExpR) ;

    [unroll]for(int i = 0; i < 4; i++)
    {
        // Perform rotation
        float3 position = mul(quad.xyz, rotationMatrix )*float3( iSetC8x, SetVS2y, iSetC8z  )+float3( 0, -aSetC9H*SetVS3*fExp3, 0 ) ;
        // Add the sprite center without scale to keep the diffuse color calculation identicle
        float3 position1 = normalize(position) ;
        position = (spriteCenter.xyz + position) ;
        float3 position2 = normalize(position) ;
        float3 position3 = normalize(spriteCenter.xyz) ;

#if defined(SHD_VIEW_SHADOW)
        position = -clusterOffset.xyz + position;
        Out.position = mul(float4(position, saturate(SetGSS1) ), matWorld);
    }

#elif defined(SHD_GS_INSTANCING)
// Calculate the lighting of the clouds based on position of each corner
//        GetPointDiffuse(Out.diffuse, position, spriteCenter.xyz, rotationMatrix[2]);
        PosOVec1 = 0 ; // position - clusterOffset.xyz
        GetPointDiffuse(Out.diffuse, position, In.vNormal.xyz, In.vPosition.xyz, cloudDistance, rotationMatrix[2],
                             position1, position2, position3, PosOVec1, matWorld );
        position -= clusterOffset.xyz;
        Out.position = mul(float4(position, 1.0), matWorld);
    }
#else
 
// Calculate the lighting of the clouds based on position of each corner
//        GetPointDiffuse( Out.diffuse, position, spriteCenter.xyz, rotationMatrix[2]) ;

          PosOVec1 = position - clusterOffset.xyz ;

        GetPointDiffuse(Out.diffuse, position, In.vNormal.xyz, In.vPosition.xyz, cloudDistance, rotationMatrix[2],
                             position1, position2, position3, PosOVec1, matWorld ) ;

        // Apply cluster offset and scale factor
        position -= clusterOffset.xyz;
        float4 worldPos = mul( float4(position,1.0), matWorld ) ;
        Out.mAlt = worldPos.y ;
        Out.position = mul( float4(position,1.0), worldViewProj ) ;

        //Compute far and near fade for the position and diffuse.
        ComputeFarAndNearFade(Out.position, Out.diffuse) ;
    }
#endif

    #if !defined(SHD_VIEW_SHADOW)
        // Compute fog
        float3 vSpriteCenter = spriteCenter.xyz - clusterOffset.xyz;
        Out.fFogDistance = FogVS(float4(vSpriteCenter, 1), matWorld, float4(cb_mEyePoint.xyz, 1));
    #endif
    return Out;
}

#if defined(SHD_GS_INSTANCING)
[instance(SHD_GS_INSTANCE_COUNT)]
#endif
[maxvertexcount(4)]
void GS(point VS_OUTPUT input[1], inout TriangleStream<GS_OUTPUT> SpriteStream,
    uint InstanceID : SV_GSInstanceID)
{
    GS_OUTPUT output;

    float2 lowerleft = input[0].uv.xy;
    float2 upperright = input[0].uv.zw;

    #if defined(SHD_VIEW_SHADOW)
        output.RTIndex = InstanceID;

        // Bottom left
        output.position = mul(input[0].position[0], cb_mTranslucentViewProjection[InstanceID]);
        output.z = output.position.z ; // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = lowerleft.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Bottom right
        output.position = mul(input[0].position[2], cb_mTranslucentViewProjection[InstanceID]);
        output.z = output.position.z; // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = lowerleft.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Top Left
        output.position = mul(input[0].position[1], cb_mTranslucentViewProjection[InstanceID]);
        output.z = output.position.z; // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = upperright.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        // Top right
        output.position = mul(input[0].position[3], cb_mTranslucentViewProjection[InstanceID]);
        output.z = output.position.z; // pass down real z to PS
        output.position.z *= saturate(output.position.z); // pancake just in case
        output.uv.x = upperright.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        SpriteStream.RestartStrip();
    #elif defined(SHD_GS_INSTANCING)

        output.RTIndex = InstanceID;

#if defined(SHD_VIEW_CUBEMAP)
#if defined(SHD_NO_NEAR_CLIP)
        matrix viewProj = mul(cb_mViewCubemap[InstanceID], cb_mNoNearProj);
#elif defined(SHD_NO_FAR_CLIP)
        matrix viewProj = mul(cb_mViewCubemap[InstanceID], cb_mNoFarProj);
#else
        matrix viewProj = mul(cb_mViewCubemap[InstanceID], cb_mProjToDevice);
#endif
#else
#if defined(SHD_NO_NEAR_CLIP)
        matrix viewProj = mul(cb_mViewInstance[InstanceID], cb_mNoNearProj);
#elif defined(SHD_NO_FAR_CLIP)
        matrix viewProj = mul(cb_mViewInstance[InstanceID], cb_mNoFarProj);
#else
        matrix viewProj = mul(cb_mViewInstance[InstanceID], cb_mProjToDevice);
#endif
#endif

        output.fFogDistance = input[0].fFogDistance;
        output.mAlt = input[0].position[0].y;

        // Bottom left
        output.position = mul(input[0].position[0], viewProj);
        output.diffuse = input[0].diffuse[0];
        #if !defined(SHD_VIEW_CUBEMAP)
        ComputeFarAndNearFade(output.position, output.diffuse);
        #endif
        output.uv.x = lowerleft.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Bottom right
        output.position = mul(input[0].position[2], viewProj);
        output.diffuse = input[0].diffuse[2];
        #if !defined(SHD_VIEW_CUBEMAP)
        ComputeFarAndNearFade(output.position, output.diffuse);
        #endif
        output.uv.x = lowerleft.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = 1;
        SpriteStream.Append(output);

        // Top Left
        output.position = mul(input[0].position[1], viewProj);
        output.diffuse = input[0].diffuse[1];
        #if !defined(SHD_VIEW_CUBEMAP)
        ComputeFarAndNearFade(output.position, output.diffuse);
        #endif
        output.uv.x = upperright.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        // Top right
        output.position = mul(input[0].position[3], viewProj);
        output.diffuse = input[0].diffuse[3];
        #if !defined(SHD_VIEW_CUBEMAP)
        ComputeFarAndNearFade(output.position, output.diffuse);
        #endif
        output.uv.x = upperright.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = -1;
        SpriteStream.Append(output);

        SpriteStream.RestartStrip();

    #else
        output.fFogDistance = input[0].fFogDistance;
        output.mAlt = input[0].mAlt.y;

        // Bottom left
        output.position = input[0].position[0];
        output.diffuse = input[0].diffuse[0];
        output.uv.x = lowerleft.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = 1;

        SpriteStream.Append(output);

        // Bottom right
        output.position = input[0].position[2];
        output.diffuse = input[0].diffuse[2];
        output.uv.x = lowerleft.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = 1;

        SpriteStream.Append(output);

        // Top Left
        output.position = input[0].position[1];
        output.diffuse = input[0].diffuse[1];
        output.uv.x = upperright.x;
        output.uv.y = lowerleft.y;
        output.localUV.x = -1;
        output.localUV.y = -1;

        SpriteStream.Append(output);

        // Top right
        output.position = input[0].position[3];
        output.diffuse = input[0].diffuse[3];
        output.uv.x = upperright.x;
        output.uv.y = upperright.y;
        output.localUV.x = 1;
        output.localUV.y = -1;

        SpriteStream.Append(output);

        SpriteStream.RestartStrip();
    #endif
}

// TBM 29/04/2022 Original code, increase SetPSS1 value from the default of 0.75 to increase shadow darkness.
#if defined(SHD_VIEW_SHADOW)
float2 PS(GS_OUTPUT In): SV_TARGET
{
    float4 cColor = txBase.Sample( samWrap, In.uv );
    return float2( 1.0f-cColor.a*saturate(SetPSS1), In.z);
//    return float2(1.0f-cColor.a * SetPSS1,In.z);
}

#else

float4 PS(
#if defined(SHD_GS_INSTANCING)
    GS_OUTPUT In
#else
    PS_INPUT In
#endif
) : SV_TARGET
{
 float fAngY =  In.mAlt/(In.fFogDistance+1) ;
  float fAngYh =  (In.mAlt + 2*cb_Altitude )/(In.fFogDistance+1) ;
  float TempAngY1 = exp(-pow(abs( 4*fAngY), 3 )) * (1-exp(-pow(abs( 3*In.fFogDistance/10000 ), 2 )))  ;
  float TempExH1  = saturate( exp( -11*fAngYh )) ;
  float tempHYc =  1-saturate(exp(-11* abs( fAngYh   ))) ;
  float tempZv =  1-saturate(exp(-pow( abs(8* ( fAngYh-1  ) ),  3))) ;
  float fExp32 = saturate(exp(  SetVS3S* (In.fFogDistance - SetVS3D*0.9 )));
  float HAcompY = In.mAlt+ cb_Altitude +3100*pow(abs(In.fFogDistance/200000), 2 ) +1.1*aSetC9H*SetVS3*fExp32 ;
  float hCAltitudeY1 = HAcompY/10000 ;
  float fIntAltCorr1 = (1-exp(-pow(abs( 4 * hCAltitudeY1), 3.5)))*saturate(tanh( 2.2 *hCAltitudeY1)) ;
  float cfIntAltTR =  lerp(lerp(0.55, 1, fIntAltCorr1), 0.0, FACorE1) ;
//  float fIntAlt = pow(abs(saturate( 1*((In.mAlt + cb_Altitude )/10000) )), 1.2 ) ; // 1-exp( -pow(abs( 3*((In.mAlt + cb_Altitude )/10000)), 2.8 ))
  float fIntAlt = saturate( tanh(1*((In.mAlt + cb_Altitude )/10000)) ) ;
  float fIntAlt2 = saturate( (In.mAlt + cb_Altitude )/10000 ) ;

  const float BLSu1  = 0.900 ; // brightness level at sunrise/sunset
  const float BposD1 = -0.27 ; // positions of the minimum before sunrise/after sunset. (beginning of the non-linear process of the lower branch)
  const float BscD1  = 4.0   ; // the steepness of the rise / fall of brightness before sunrise / after sunset. (lower branch)
  const float BposL1 = -0.40 ; // positions of the minimum of the linear process before sunrise/after sunset
  const float BLdSu1 = 0.12  ; // level of the linear process at sunrise/sunset
  const float BFIw1  = -22   ; // branch interpolation width centered at sunrise/sunset

    float FGBrSkyD1 =  saturate(  -(BLdSu1/BposL1)*(Sundy-BposL1) // linear directional
  +(BLSu1-BLdSu1)*pow( abs((Sundy-BposD1)/BposD1), BscD1 )*step(0, (Sundy-BposD1))) ; // lower branch
    float GBrSky1 = saturate( FGBrSkyD1) ;
    float GBrSky_1 = saturate(1-GBrSky1) ;
    float GBrSkyd = saturate(1.2*(cb_mCloudDirectional.r+cb_mCloudDirectional.g +cb_mCloudDirectional.b)/3) ;

    float4  Rdiffuse = float4(In.diffuse.r, In.diffuse.r, In.diffuse.r, In.diffuse.a ) ;
    float4 RCcColor = txBase.Sample(samWrap, In.uv);
    float CanallsRGB = 1 - SetPS00*saturate(1-RCcColor.r) ; // RCcColor.r
    float4 ColorM0 = Rdiffuse*float4(CanallsRGB, CanallsRGB, CanallsRGB, RCcColor.a ) ; // RCcColor.r

    const float fExp = saturate(exp(-In.fFogDistance * In.fFogDistance * 0.00000000077)) ;
    float fDistP1 =  pow(abs(1-1*saturate(In.fFogDistance/(1000000* 0.1) )), 5 ) ;
    float fDistP1_1 = 1-fDistP1  ;  float fDistP1_2 = 1-fDistP1*POstProcessS2*(1-fAexp83) ;
    float fDistP1_3 = 1-fDistP1*POstProcessS2* fAexp83  ;

    float LbSc  = 0.7 ;  float Scfdb  = 2 ;  
    float offsSdy = 0.3 ;  float Scfd = 5 ;  float fxoffsSdy = Sundy-offsSdy ;
    float ProcessRGBc =  saturate( LbSc*pow(abs(Sundy-1), Scfdb) +(1-LbSc)* step(0, -fxoffsSdy )*pow(abs(fxoffsSdy/offsSdy), Scfd ) ) ;
    float Process_RGBc =  1-ProcessRGBc ;
    float addSunGc =  SetPS10*In.diffuse.b*RCcColor.b*tempHYc*VisSunOn ;
    float3 ColorM1  = SetPS02*pow(abs(ColorM0.rgb), SetPS01 ) + addSunGc ;
    float colorFErgb = (ColorM1.r+ColorM1.g+ColorM1.b)/3 ;
    float alfaFG1 = saturate(pow(abs(1.0* ( 1-ColorM0.a)), 3 )) ;
    float colorInv = saturate(1-2*RCcColor.b) ;

// Pre-adjustment of brightness and gamma before surge protector //  lerp(SetPS04s, SetPS04z, (0.7*ProcessDE1 + 0.3*saturate(Sundy)) )
    float FPBrC    = cSetPS04*SetPS05 ; // Uncompensated adjustment of the preliminary brightness for the shadow filter

// Shadow and color filter output dimming compensation setting for overall output brightness stabilization
    float blBrC    = clamp(FPBrC/SetPS06, 0.0001, 100000) ; // Resulting luminance factor under the shadow filter
    float LCompFBr = SetPS07 ; // Brightness drop compensation level at the filter output //=0 - brightness compensation is completely absent. =1 - full compensation.
    float LSpFBr   = SetPS08 ; // The steepness of the change in brightness compensation at the filter output
    float TLBrmin  = SetPS09 ; // Lower threshold for limiting brightness compensation at the filter output

    float K_blBrCFin = pow(abs(lerp( 1,  pow(abs(blBrC), LSpFBr )+TLBrmin, LCompFBr )), 3 ) ;
    float3 ColorM2   =  FPBrC*pow(abs(ColorM0.rgb), SetPS03 ) + addSunGc ; // 0*clamp(pow(abs( 1*(colorFErgb-fA0)), 3) , 0, 10 )   +

    float3 ColorMcf   =   ColorM2*(1+ 0*In.diffuse.g ) ;

    float fCFint1 = 0.99*exp(-pow(abs( 0.70 *colorFErgb), 3  )) ; // Interpolator of the brightness gradient of the body region.
    float fCFint2_1 =    clamp((colorFErgb- 0.5 )* 1,  0, 10  ) ; //1 - exp(-pow(abs( 3 *colorFErgb), 3  )) + step(0, colorFErgb-0.4 )*pow(abs((colorFErgb- 0.4 )* 1 ), 2 )
    float fCFintR = exp(-pow(abs( 0.8 *colorFErgb), 3  )) ; // Luminance gradient interpolator R.

 

    float fCGint1 =    0*PReProcessEG1*clamp((colorFErgb- 2*0.50 )* (0.5+1), 0, 10 ) ; // Interpolator of the brightness gradient of the body region.
    float fDistP1eff = fDistP1_1*SetPS21 ;

    float infIntGB = lerp(lerp(lerp( 0,  SetPS22,  fDistP1eff ), 1, ProcessRGBc ), 1, SetPS14 ) ;
    float infIntGB_A = infIntGB*lerp(SetPS18, SetPS19, PReProcessEG2 )*lerp(SetPS20, 1, POstProcessS3) ;
    float infIntGB_B = infIntGB ;

    // End color points of color interpolation
    float FintCAg = SetPS15g+SetPS16g*PReProcess_E2*PReProcessEG2 ; // g - vertex component.
    float FintCAb = SetPS15b ; // b - vertex component.
    float FintCBg = SetPS17g ; // g - component for the bottom.
    float FintCBb = SetPS17b ; // b - component for the bottom.
    float SatGnC =   POstProcessB0 ; // reversal of interpolation after entering

    float fIntAbovG = lerp( 1, lerp(1, FintCAg, RIntGc(infIntGB_A) ),  SatGnC  ) ; // RIntGc(infIntGB_A)
    float fIntAbovB = lerp( 1, lerp(1, FintCAb,        infIntGB_A  ),  SatGnC  ) ;
    float fIntButtG = lerp( 1, lerp(1, FintCBg, RIntGc(infIntGB_B) ),  SatGnC  ) ; // RIntGc(infIntGB_B)
    float fIntButtB = lerp( 1, lerp(1, FintCBb,        infIntGB_B  ),  SatGnC  ) ;
    float CorrGc = 1- 0.15*POstProcessD1*ProcessDT_1 ;
     ColorMcf.r *= lerp(1, 1, fIntAlt )*lerp( 1,  SetPS22r,  fDistP1eff )/(1+ 0.3*fCGint1) ;
     ColorMcf.g *= lerp(fIntButtG, fIntAbovG, fIntAlt )*lerp(1, SetPS22g, fDistP1eff )*CorrGc/(1+ 0.35*fCGint1) ;
     ColorMcf.b *= lerp(1, 1, fIntAlt )*lerp(fIntButtB, 1*fIntAbovB, fIntAlt )*lerp(1, SetPS22b, fDistP1eff )/(1+ 0.65*fCGint1) ;

    float GsatBr = lerp( SetPS42, lerp(SetPS40, SetPS41,  POstProcessS3*PReProcess_E2), fIntAlt)  ;
    float addsatBr = FProcessF( SetPS47a, SetPS47e, SetPS47s ) ; // coefficient of additional saturation of the brightest areas
    ColorMcf  = lerp(dot(ColorMcf, float3(0.299f, 0.587f, 0.114f )), ColorMcf, GsatBr*(1+ addsatBr*fCFint2_1) ) ; // tempZv* lerp(1, 0.5*pow(abs(colorFErgb ), 0.8 ), 0.9 )
    ColorMcf  = lerp(dot(ColorMcf, float3(0.299f, 0.587f, 0.114f )), ColorMcf, POstProcessS1*FProcessF( SetPS48a, SetPS48e, SetPS48s ) ) ;
    ColorMcf  = lerp(ColorMcf,  ColorMcf*float3((1- 0.8*alfaFG1), (1+ 0.3*alfaFG1), (1+ 0.8*alfaFG1) ), SetPS49 ) *(1+0.0*fIntAlt2)   ; // *lerp( 1, float3( 1, 0.50 , 0.50 ), 0.7*(1-fExp)*PReProcessE2 )

    float CompBrRGB = ((ColorM2.r-ColorMcf.r)+(ColorM2.g-ColorMcf.g)+(ColorM2.b-ColorMcf.b))/3 ;
    float3 ColorMF   = ColorMcf*(1 + 0.0*CompBrRGB+ 0.0* (1-fExp)*PReProcessE2)*(1+ 0.2*POstProcess_S1) ; // ColorM2 ;

    float fLevL = cSetPS55*SetPS54  ; // Main absolute filter level

//  Brightness compensation to stabilize the brightness of shadow areas when adjusting the shadow filter level
    float CompBrF = cSetPS56 ; // Output color brightness compensation level when adjusting the fabric filter
    float sFlev = SetPS59 ; // Main filter slope
    float andSunLft0 = 1+ 0.5*ProcessSn1*lerp(1, ProcessDE5, 1 )*In.diffuse.g ;
    float andSunLft1 = lerp(andSunLft0, 1, 0 ) ;

//  Overall threshold factor of the lower (shadow) clipping level. (smoothing and clipping details) Final component.
    float gLovTrDet = fLevL*1.7*(1+0.1*TempExH1)*andSunLft0*lerp(0.9, 1-0.5*POstProcess_D1*POstProcessB1, TempAngY1) ;

//  Component-by-component shadow clipping thresholds.
    float CLovTrR = SetPS57r ; float CLovTrG = SetPS57g ; float CLovTrB = SetPS57b  ; float3 CLovTrRGB = float3(CLovTrR, CLovTrG, CLovTrB) ;
    CLovTrRGB = lerp(dot(CLovTrRGB, float3(0.2126f, 0.7152f, 0.0722f)), CLovTrRGB, SetPS58 ) ;

//  Component-by-component coefficients of the final correction of transitional thresholds
    float corrTrR = SetPS61r  ; float corrTrG = SetPS61g  ; float corrTrB = SetPS61b  ;
    float LovTrDetR = CLovTrRGB.r*gLovTrDet ; float LovTrDetG = CLovTrRGB.g*gLovTrDet ; float LovTrDetB = CLovTrRGB.b*gLovTrDet ;
    ColorMF.r = lerp( ColorMF.r, LovTrDetR, saturate(0.5+0.5*tanh( -sFlev* ( ColorMF.r-LovTrDetR*corrTrR ) )) ) ; // 1+0.*0.5
    ColorMF.g = lerp( ColorMF.g, LovTrDetG, saturate(0.5+0.5*tanh( -sFlev* ( ColorMF.g-LovTrDetG*corrTrG ) )) ) ; // 1+0.5*0.1
    ColorMF.b = lerp( ColorMF.b, LovTrDetB, saturate(0.5+0.5*tanh( -sFlev* ( ColorMF.b-LovTrDetB*corrTrB ) )) ) ;

    ColorMF  = 1*lerp(dot(ColorMF, float3(0.2126f, 0.7152f, 0.0722f)), ColorMF, SetPS79 ) ;

//    float3 ColorM3 =   1.0*(1+ 0*In.diffuse.g)*lerp( ColorM1 , ColorM2, 0 ) ;

    float4  cColor ; cColor.a = ColorM0.a ;
    cColor.rgb = ColorMF*lerp(1,  CompBrF,   fLevL)/K_blBrCFin ;
    cColor.rgb = lerp(cColor.rgb, 0.07*float3(0.65, 0.85, 1), 0.0 )*(1+ 0.10*In.diffuse.g*PReProcessEG  )/andSunLft1 ; // ProcessSn1*ProcessDE5*

    cColor.rgb *= lerp(float3(SetPS82r, SetPS82g, SetPS82b), float3(1, 1, 1), lerp(1, lerp( 0,saturate(1-SetPS81), fDistP1), SetPS80) ) ; // bluing

    cColor.rgb = pow(abs(cColor.rgb), 1+SetPS85*In.diffuse.b )*(1+SetPS86*POstProcessS2*In.diffuse.b)
                *lerp(SetPS91, SetPS90, GBrSky1) *lerp(1.0, 0.38, TempAngY1*(1-In.diffuse.b)*POstProcess_D1*POstProcessB1) ;
    cColor.rgb  = 1.1*cSetPS93*lerp(dot(cColor.rgb, float3(0.2126f, 0.7152f, 0.0722f)), cColor.rgb, SetPS94 ) ;

    cColor.a *= lerp( 1.05, 0.80, fIntAlt) ; // *float3(1.3, 0.83, 1 )
    cColor.a = lerp( SetPS98, SetPS97, fDistP1 )*pow(abs(cColor.a), SetPS99 ) ;

    // Apply IR if active
    #if defined(SHD_IR_ACTIVE)
        cColor = ApplyIr(cColor);
        cColor = FogIR(cColor, In.fFogDistance);

#if defined(SHD_IR_BLACK_HOT)
        cColor.rgb = 1.0f - cColor.rgb;
#endif

    return cColor;
    #endif //SHD_IR_ACTIVE

    // Soft edges.
    #if defined(SHD_CLOUD_FADE_AT_Z)
    #endif

    #if !defined(SHD_NO_FOG) && !defined(SHD_VIEW_CUBEMAP)
        //Compute fog contribution.
        #if defined(SHD_VOLUMETRIC_FOG)
            cColor = VolumetricFogPS( In.mAlt, cColor, In.fFogDistance / 2.0, cb_mFogDensity, cb_mFogColor.xyz);
        #else
            cColor = float4( FogPS( cColor.xyz, In.fFogDistance / 2.0, cb_mFogDensity, cb_mFogColor.xyz ), cColor.a );
        #endif //SHD_VOLUMETRIC_FOG
    #endif //!SHD_NO_FOG

    DEBUG_MARK(cColor)

    return cColor;
}
#endif

 

And finally here are a few pics of the cloud shader in use where the cloud textures are Rex high resolution 32bit images.

The rendering effect would be similar should alternate cloud textures be used.

spacer.png

?imw=5000&imh=5000&ima=fit&impolicy=Lett

?imw=5000&imh=5000&ima=fit&impolicy=Lett

 

spacer.png

 

?imw=5000&imh=5000&ima=fit&impolicy=Lett

  • Like 3

Ryzen 5800X clocked to 4.7 Ghz (SMT off), 32 GB ram, Samsung 1 x 1 TB NVMe 970, 2 x 1 TB SSD 850 Pro raided, Asus Tuf 3080Ti

P3D 4.5.14, Orbx Global, Vector and more, lotsa planes too.

Catch my vids on Oz Sim Pilot, catch my screen pics @ Screenshots and Prepar3D

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...