Skip to content

PQS Main Shader

Shader: Terrain/PQS/PQS Main Shader  ·  materialType = Main

The PQS Material { } drives the shader that paints a body's near-surface terrain — the real, subdivided quad-sphere you see from low orbit down to the ground. This is the counterpart to the ScaledVersion materials, which paint only the distant low-LOD sphere; the PQS material takes over as the camera descends and the two are cross-faded across the fadeStart / fadeEnd altitudes. Terrain/PQS/PQS Main Shader is the canonical, full-featured member of the "PQS Main" family.

Unlike the scaled-space shaders, which sample a single pre-baked colour map, the PQS Main shader builds the surface procedurally from a small set of tiling textures. It is world-space triplanar — it projects each texture down the three world axes and blends them by the surface normal, so there are no UV seams and a handful of textures can clothe an entire planet. On top of that it blends three textures by elevation, layers a separate texture on steep slopes, crossfades between a fine and a coarse tiling by camera distance, and (on bodies with an atmosphere) folds in aerial-perspective haze and underwater fog.

Main is one of the pre-1.8 terrain shaders. It is the richest of the height-blend variants — every elevation band carries its own normal map with independent near/far tiling. If you want the same look with a lighter texture/normal budget, see the Optimized variant; for the 1.8-era blend used by stock Kerbin's terrain, see MainFastBlend; for the PBR zoom-rotation variant, see MainTriplanarZoomRotation.

We shall first see how to enable the material, then how the shader assembles the surface, and finally discuss each group of properties in turn.

Enabling

Select the material by setting materialType = Main in the PQS { } node. The Material { } node then accepts the properties listed below.

cfg
PQS
{
    materialType = Main
    Material
    {
        // Colour grading of the per-vertex colour map
        saturation = 1
        contrast   = 1
        tintColor  = 1, 1, 1, 0

        // How strongly the textures show, and the near/far crossfade distance
        powerNear      = 0.5
        powerFar       = 0.5
        groundTexStart = 2000
        groundTexEnd   = 10000

        // Low elevation band
        lowTex          = MyMod/PluginData/sand_color.dds
        lowBumpMap      = MyMod/PluginData/sand_normal.dds
        lowNearTiling   = 1000
        lowMultiFactor  = 10

        // Mid elevation band
        midTex          = MyMod/PluginData/rock_color.dds
        midBumpMap      = MyMod/PluginData/rock_normal.dds
        midNearTiling   = 1000
        midMultiFactor  = 10

        // High elevation band
        highTex         = MyMod/PluginData/snow_color.dds
        highBumpMap     = MyMod/PluginData/snow_normal.dds
        highNearTiling  = 1000
        highMultiFactor = 10

        // Where each band fades to the next (on normalised vertex elevation)
        lowStart  = 0
        lowEnd    = 0.3
        highStart = 0.8
        highEnd   = 1

        // Steep-slope overlay
        steepTex      = MyMod/PluginData/cliff_color.dds
        steepBumpMap  = MyMod/PluginData/cliff_normal.dds
        steepPower    = 1

        // Atmospheric haze (only visible on bodies with an atmosphere)
        globalDensity = 1
        fogColorRamp  = MyMod/PluginData/fog_ramp.dds
    }
}

How the surface is built

The shader is a triplanar terrain surface assembled per pixel. There is no single colour map; instead a base colour, three elevation textures, a steep overlay, and fog are combined in the following order:

  1. Per-vertex colour grading — the PQS supplies a colour per vertex (COLOR.rgb, usually from a colour map or LandControl). The shader desaturates that colour toward its luma by saturation, mixes in tintColor (whose alpha is the mix amount), and scales it by contrast. The result is the base colour that the band textures then tint.
  2. Three elevation bandslowTex, midTex and highTex are blended by the vertex's normalised elevation (written into COLOR.w by the PQS height build). lowStart/lowEnd set the elevation window where the low band fades up into the mid band, and highStart/highEnd the window where the mid band fades into the high band — so low covers the bottom of the height range, mid the middle, high the top.
  3. Near/far tiling crossfade — each band is sampled at two tiling scales and crossfaded by camera distance: a fine near tiling (*NearTiling) for close-up detail and a coarse far tiling (*MultiFactor) for the distance, blended between the groundTexStart and groundTexEnd view distances. powerNear and powerFar set how strongly the near and far textures show. Because the triplanar coordinates are world position scaled by 10⁻⁵, the tiling numbers are large (the defaults are 1000 near, 10 far).
  4. Texture vs. flat colour — the blended band texture does not replace the base colour, it modulates it: the final albedo is lerp(baseColour, baseColour × bandTexture, texMix), where texMix is driven by powerNear/powerFar and the near/far mix. Where it falls to zero — far away, or with both powers at 0 — you see the flat graded colour map; where it is high you see fully textured terrain.
  5. Steep-slope overlaysteepTex and steepBumpMap are blended over the result on steep terrain. The per-vertex steepness is multiplied by steepPower and clamped, so higher steepPower makes the cliff texture reach onto gentler slopes. The overlay has its own distance fade between steepTexStart and steepTexEnd, and its own steepNearTiling / steepTiling.
  6. Normal mapping — each band and the steep overlay carry a matching DXT5nm normal map, accumulated at the same band/near/far weights and transformed into world space through the mesh's tangent frame. The surface is then lit with a plain diffuse (Lambert) term plus spherical-harmonic ambient — there is no specular highlight.
  7. Aerial-perspective & ocean fog — on a body with an atmosphere, a distance haze is mixed in last. Its colour is read from fogColorRamp indexed by the sun angle, and its strength grows with distance and globalDensity. A second, underwater ocean fog term reads the same ramp at a different row. On an airless body the whole fog stage is compiled out and these properties do nothing. (Main does not expose oceanFogDistance; the variants that do — such as Extra — let you tune the underwater falloff distance.)

The triplanar projection means the band textures need no UV mapping on the mesh, but the normal mapping still needs mesh tangents, which the PQS quad-sphere provides. Because the colour, elevation and slope all come from the PQS build, the final look depends as much on your PQSMods (height, colour, LandControl) as on the textures set here.

Properties

The properties fall into five groups, which we shall take in turn:

  1. Colour grading — how the per-vertex colour map is processed before texturing.
  2. Texture blend & distance — the near/far strengths and the crossfade distances.
  3. Elevation bands — the three height textures, their normal maps, tiling and transition windows.
  4. Steep-slope overlay — the cliff texture for steep terrain.
  5. Fog & opacity — the atmospheric haze ramp and the PQS fade scalar.

Colour grading

PropertyFormatDescription
saturationDecimalSaturation of the per-vertex colour map: 0 collapses it to greyscale (luma), 1 leaves it unchanged, higher oversaturates. Default 1.
contrastDecimalContrast multiplier applied to the graded colour. Default 1.
tintColorColorA tint mixed into the base colour; the alpha is the mix amount (0 = no tint). Default (1, 1, 1, 0) — i.e. no tint.

Texture blend & distance

PropertyFormatDescription
powerNearDecimalStrength of the fine near texture tier. Drops the textures out toward the flat colour map as it approaches 0. Default 0.5.
powerFarDecimalStrength of the coarse far texture tier. Default 0.5.
groundTexStartDecimalView distance (m) at which the near→far tiling crossfade begins. Default 2000.
groundTexEndDecimalView distance (m) at which only the far tiling remains. Default 10000.

Elevation bands

Each band has an albedo texture, a normal map, and near/far tiling for both. The band weights come from the vertex elevation and the four transition values at the end of the table.

PropertyFormatDescription
lowTexFile PathAlbedo for the low elevation band. Triplanar, world-tiled. Default "white".
lowTexScale / lowTexOffsetVector2Tiling and offset of lowTex.
lowBumpMapFile PathDXT5nm normal map for the low band. Default "bump" (flat).
lowBumpMapScale / lowBumpMapOffsetVector2Tiling and offset of lowBumpMap.
lowNearTilingDecimalWorld tiling of the low albedo at the near tier. Default 1000.
lowMultiFactorDecimalWorld tiling of the low albedo at the far tier. Default 10.
lowBumpNearTilingDecimalWorld tiling of the low normal map at the near tier. Default 1.
lowBumpFarTilingDecimalWorld tiling of the low normal map at the far tier. Default 1.
midTexFile PathAlbedo for the mid elevation band. Default "white".
midTexScale / midTexOffsetVector2Tiling and offset of midTex.
midBumpMapFile PathDXT5nm normal map for the mid band. Default "bump".
midBumpMapScale / midBumpMapOffsetVector2Tiling and offset of midBumpMap.
midNearTilingDecimalWorld tiling of the mid albedo at the near tier. Default 1000.
midMultiFactorDecimalWorld tiling of the mid albedo at the far tier. Default 10.
midBumpNearTilingDecimalWorld tiling of the mid normal map at the near tier. Default 1.
midBumpFarTilingDecimalWorld tiling of the mid normal map at the far tier. Default 1.
highTexFile PathAlbedo for the high elevation band. Default "white".
highTexScale / highTexOffsetVector2Tiling and offset of highTex.
highBumpMapFile PathDXT5nm normal map for the high band. Default "bump".
highBumpMapScale / highBumpMapOffsetVector2Tiling and offset of highBumpMap.
highNearTilingDecimalWorld tiling of the high albedo at the near tier. Default 1000.
highMultiFactorDecimalWorld tiling of the high albedo at the far tier. Default 10.
highBumpNearTilingDecimalWorld tiling of the high normal map at the near tier. Default 1.
highBumpFarTilingDecimalWorld tiling of the high normal map at the far tier. Default 1.
lowStartDecimalElevation (normalised 0–1) at which the low band begins fading into the mid band. Default 0.
lowEndDecimalElevation at which the low band has fully given way to the mid band. Default 0.3.
highStartDecimalElevation at which the mid band begins fading into the high band. Default 0.8.
highEndDecimalElevation at which the high band fully takes over. Default 1.

Steep-slope overlay

PropertyFormatDescription
steepTexFile PathAlbedo blended over steep slopes (cliffs). Default "white".
steepTexScale / steepTexOffsetVector2Tiling and offset of steepTex.
steepBumpMapFile PathDXT5nm normal map for the steep overlay. Default "bump".
steepBumpMapScale / steepBumpMapOffsetVector2Tiling and offset of steepBumpMap.
steepPowerDecimalMultiplier on the vertex steepness before it is clamped to the overlay weight. Higher values push the steep texture onto gentler slopes; 0 disables it. Default 1.
steepTexStartDecimalView distance (m) at which the steep overlay's near→far tiling fade begins. Default 20000.
steepTexEndDecimalView distance (m) at which the steep overlay reaches its far tiling. Default 30000.
steepNearTilingDecimalWorld tiling of the steep overlay at the near tier. Default 1.
steepTilingDecimalWorld tiling of the steep overlay at the far tier. Default 1.

Fog & opacity

PropertyFormatDescription
globalDensityDecimalDensity multiplier for the aerial-perspective haze. Only has an effect on bodies with an atmosphere; higher values thicken the distance fog. Default 1.
fogColorRampFile Path1-D colour ramp for the fog. The aerial haze is read from it indexed by the sun angle (so the fog can be tinted differently toward and away from the sun); a second row supplies the underwater ocean-fog colour. Default "white".
fogColorRampScale / fogColorRampOffsetVector2Tiling and offset of the fog ramp.
FogColorRampGradientThe fogColorRamp, defined inline as a gradient instead of as a texture.
planetOpacityDecimalOpacity of the PQS material, used by KSP to fade the terrain against the scaled-space sphere across the fadeStart/fadeEnd transition. Normally left at 1. Default 1.

Notes

  • These are the body's near-surface terrain materials. The body simultaneously has a ScaledVersion material for the distant sphere; KSP cross-fades between the two across the fadeStart / fadeEnd altitudes, so the two should be tuned to match where they meet.
  • The textures are world-space triplanar, so they need no UVs and the tiling values are in world units scaled by 10⁻⁵ (hence the large defaults). The shader still requires mesh tangents for its normal mapping, which the PQS quad-sphere provides.
  • The band colour, the per-vertex elevation that drives the band blend, and the slope that drives the steep overlay all come from the PQS build — your height, colour and LandControl mods shape the input this shader paints.
  • The fog stage (globalDensity, fogColorRamp) is only compiled in for bodies with an atmosphere; on an airless body it is removed entirely and those properties have no effect.
  • Several shader inputs are driven by KSP at runtime and are not config properties: a floating-origin offset that keeps the world-space triplanar coordinates stable as the game shifts the origin around the craft, and the sun direction, camera altitude and viewer air density used by the fog.
  • The surface is lit with a diffuse (Lambert) term only — there is no specular response on this shader. The PBR MainTriplanarZoomRotation variant is the one that adds a specular term.
  • materialType = Main is also accepted under its older alias AtmosphericMain, which you may see in existing configs; the two select the same shader.