TerrainSplatFragmentShader

Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Game.Graphics.Shaders.Shader, Libraries.Language.Object

TerrainSplatFragmentShader colors the ground with up to four textures, blended by a splat map: each point of the ground says how much of each texture to show there. It is the default 3D fragment shader with one more case. Models whose material has a negative metallic value are terrain, and are splatted. Every other model is drawn exactly as the default shader draws it, so this shader can stand in for the default one. For a terrain model, the shader reads three things: 1. The splat weights, from the model's texture override, which holds the region's splat map. Its texture coordinates are the vertex's place in that map. The four weights are made to add up to 1. 2. The four ground layers, from the model's color override, in one of two ways: - Plain textures: its red, green, blue and alpha bytes are the places of the red, green, blue and alpha textures in the global texture array. - Texture sets, marked by an alpha byte of 255: its red byte is the place of the layer table, a 4 by 1 texture with one pixel per layer (see WorldTerrain's CheckLayerTableReady), and its green byte is how softly layers blend by height. Each layer then has a color and height texture, a normal, roughness and ambient occlusion texture, and its own tile size. A layer without a normal texture (255 in the table) is a plain texture: flat, with the material's roughness and a middle height. Until a model has a color override, it is drawn a plain green. 3. The pixel's world position, which gives the ground textures' coordinates, so they tile evenly and line up across regions. The layer repeat is how many world units one tile covers. The outputs are the same five the default shader writes for the deferred lighting pass: position, color, normal, ambient occlusion, roughness and metallic, and emissive light (none, for terrain), so lighting and shadows work as they do for any model. Height blending is Terrain3D's idea: where layers meet, each point shows the layer that stands highest there, its height map plus its weight, so stones poke through grass instead of the two fading into each other. The softness sets how far below the highest layer another can be and still show.

Example Code

use Libraries.Game.Graphics.Worlds.TerrainSplatFragmentShader

TerrainSplatFragmentShader shader
shader:SetLayerRepeat(4)

Actions

GetLayerRepeat()

This action returns how many world units one tile of each ground texture covers.

Returns

number: The size of one tile, in world units.

SetLayerRepeat(number tileSize)

This action sets how many world units one tile of each ground texture covers. It must be set before the shader is compiled.

Parameters

  • tileSize number: The size of one tile, in world units. It must be more than 0.

Inherited Actions

14 actions from Libraries.Game.Graphics.Shaders.Shader
3 actions from Libraries.Language.Object