View Issue Details

IDProjectCategoryView StatusLast Update
0000557Medieval EngineersEnhancementpublic2026-03-18 13:57
Reporterpeaceman Assigned To 
PrioritynormalSeveritytweakReproducibilityhave not tried
Status newResolutionopen 
PlatformWindows 
Summary0000557: Shader adjustments
Description

In Globals.hlsli change 200 to 2000 in float invZ = clamp(1 + linearZ / 200, 0.01, 1);
This is an important change as it fixes a problem where transparent materials like particles and billboards look very bright or dark when another transparent material is behind it further than 200m away and also changes the transparency of the material in the back.
Have not noticed any side effects of it being set to 2000.

Another shader adjustment that would be nice to have is in Clouds.hsls
These changes prevents the sun from shining through thick cloud layers when its low on the horizon and improves the interaction of the sun with the clouds when its going behind the horizon
The following 2 lines need to be replaced

float shadingMultiplier = clamp(pow(abs((1 - dot(input.normal, frame_.Light.directionalLightVec)) / 2), 2.0), 0.025, 1);
output = float4(colorSample, alphaSample) * shadingMultiplier * edgeFactor;

with:

// Planet-scale day/night from cloud shell position
float3 shellNormal = normalize(input.positionWorld.xyz - centerPosition);

// If this lights the wrong side, remove the minus sign.
float3 sunDir = -frame_.Light.directionalLightVec;

// Sun angle relative to the viewer-side horizon
float3 viewNormal = normalize(cameraPosition - centerPosition);
float viewSun = dot(viewNormal, sunDir);

// Manual smoothstep for broad global sunset fade
float globalSunFade = saturate((viewSun - (-0.45)) / (0.00 - (-0.45)));
globalSunFade = globalSunFade * globalSunFade * (3.0 - 2.0 * globalSunFade);

// Manual smoothstep for local day/night band
float localDay = saturate(dot(shellNormal, sunDir) + 0.6);
localDay = localDay * localDay * (3.0 - 2.0 * localDay);

// Local cloud detail lighting
float detailLight = saturate(dot(input.normal, sunDir));
detailLight = lerp(0.45, 1.0, detailLight * detailLight);

// Final lighting
float lighting = globalSunFade * localDay * detailLight;

float cloudAlpha = saturate(alphaSample * edgeFactor);

// Extra thickness where sunlit clouds would otherwise let the sun through
float occlusionBoost = lerp(1.5, 2.5, globalSunFade * localDay);
cloudAlpha = 1.0 - pow(1.0 - cloudAlpha, occlusionBoost);

output.rgb = colorSample * edgeFactor * lighting;
output.a = cloudAlpha;

TagsNo tags attached.

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2026-03-18 13:57 peaceman New Issue