// English Lane by Jerome Liard, April 2021
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
//
https://www.shadertoy.com/view/fsXXzX//
// You are walking and flying through an infinite English countryside.
// Chill out and use the mouse to look around.
// A single walk->fly cycle is about 50s.
//
// Shadertoy compilation time seems to be about 15s, thanks for your patience.
// This is the start lane index. At each walk-flight cycle we switch to the next lane midair.
// You can set any reasonable integer value (negative ok too) to walk along other paths.
#define FIRST_LANE_INDEX 10.0
//#define FIRST_LANE_INDEX (-80.0+mod(iDate.x*365.+iDate.y*31.+iDate.z,160.)) // one different lane every day (no fade when day changes)
// If the reprojection is janky please press the button that resets time to zero.
//
// I wanted to make a navigable countryside with paths inspired by paintings from Richard Thorn (see his book "Down an English Lane"),
// and a little bit by Hiroshi Nagai and Tezuka Osamu's Jumping short anime (both life long inspirations).
//
// Creation of the initial patchwork and parameterized paths network:
//
// - 2 perpendicular sets of regularly spaced parallel 1d lanes are used.
// - Each 1d lane has an id. The amplitude of each 1d lane must be such that they don't cross the previous or next 1d lane.
// - The horizonal set of parallel lanes have constant vertical center spacing.
// - The twist: the vertical set of parallel lanes can have their spacing set more freely based on which stab we are in the horizontal set.
// This helps generating complex branching patterns.
// - For each set of parallel lanes we simply use its local x coordinate as a parameter (used for garden brick wall and camera).
// - The intersections of lane stabs give us a cellular base for country patches, and for each patch we get an id, a distance to boundary, and parameterized borders.
//
// Trees and houses placement:
//
// - Patches ids is used to decide what combination of things goes on the patch (trees, bushes, farms, walls, lawn...)
// - There are 3 layers of cellular placement for trees, bushes, and farms.
// - Bushes are too close to each other and must be soft blended, but 3x3 search is no-no so we do a "4 or 5" neighbours search (we only consider checkboard black cells).
// - For farms and trees we use randomly decimated jittered grid and actually only consider the current cell we are in, and hack marching to death to compensate.
// - Modeling:
// - Trees leaves volume have a base shape done with 2 spheres soft blended, then distored by 2 layers of packed 3d spheres tiling to blobify the leaves volume, and then some fine noise distortion on the surface.
// The use of densely packed sphere tiling is inspired by @Shane's Cellular Tiling
https://www.shadertoy.com/view/4scXz2// - Farms are randomized with gable and hipped roof, chimneys and colors very vaguely inspired by pictures of Devon.
//
// Marching:
//
// - For patches, marching uses ghost steps nearby patch boundaries so that we don't check neighbour patches objects, only the patch we are in.
// - For trees and farms too, we force the raymarch to take ghost steps along their cell borders for x1 sdf eval.
// - This ghost point machinery is hacky and not perfect (esp on patches boundary where we don't have clean intersections) but still helps.
// - Because of all the cellular evals going on, to save height evals we use taylor expansion of the heightfield on local neiborhood.
// - Despite above efforts I had to resort to reprojection and still perf isn't great.
// Blurring the noise with reprojection also helps hide the general noisy lameness and gives better colors.
//
// Clouds are volumetric but baked in a spheremap at first frame and assumed distant.
// Also had to turn view trace/shadow trace/scene gradient/cellular evals into loops to help compile time on the website, sometimes at the expense of runtime perfs.
// As always some code, techniques, ideas from @iq, @Dave_Hoskins, @Shane, @FabriceNeyret2 are used in various places,
// this shader also uses some spherical gaussian code from Matt Pettineo
// (see comment for links to references).