Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3733,7 +3733,7 @@ add_tslang_example(golden_line core/golden_line_world.ts core/golden_line_trees.
core/golden_line_tunnel.ts core/golden_line_portal.ts core/golden_line_houses.ts core/golden_line_station.ts
core/golden_line_signs.ts
core/golden_line_shadowfit.ts core/golden_line_shadows.ts core/golden_line_puffs.ts
core/golden_line_plume.ts core/golden_line_steam.ts core/golden_line_birds.ts core/golden_line_motes.ts core/golden_line_bloom.ts)
core/golden_line_plume.ts core/golden_line_steam.ts core/golden_line_birds.ts core/golden_line_motes.ts core/golden_line_bloom.ts core/golden_line_shots.ts)
add_tslang_example_test(golden_line)
add_tslang_example_test(golden_line SUFFIX cab ARGS -shot cab)
add_tslang_example_test(golden_line SUFFIX seat ARGS -shot seat)
Expand Down
6 changes: 3 additions & 3 deletions core/golden_line_plume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// ground shadow reads). Computes in doubles as the JavaScript does (the Float32Array maps rounded where it
// stores them), so the same frames give the same puffs (checked against the original's dumps).
//
// The original's drone and inspect shots (frame.shotId) are not ported: frame.aerialShot stands for "the shot
// is the drone or the inspect camera", which our app never sets, so `aerial` stays 0.
// frame.aerialShot: the shot is the drone chase or a still (-eye) camera (the original's shotId 'drone' or
// 'inspect'), from which the swollen tail of the plume is seen.
//
// Imported with `import { Plume, PlumeFrame } from "../core/golden_line_plume";` (from examples/).

Expand Down Expand Up @@ -422,7 +422,7 @@ export class PlumeFrame {
forwardY = 0.0;
forwardZ = 1.0;
cut: int = 0; // counts the camera's cuts
aerialShot = false; // the drone or inspect shot (never, in our app)
aerialShot = false; // the drone chase or a still camera
interior = false; // the camera rides inside the train
tunnelFactor = 0.0; // how deep the camera is in a bore
originZ = 0.0; // the floating origin
Expand Down
1,216 changes: 1,216 additions & 0 deletions core/golden_line_shots.ts

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions core/golden_line_steam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// line, splatted on the CPU every frame; and before them the plume's soft shadow on the land, a box
// multiplying the finished colour, looked up in the plume's map toward the sun.
//
// Not ported: the original's dazzle (the extra exposure of the shot breaking out of a bore, which our
// camera never takes) and the drone's swollen plume (golden_line_plume.ts leaves `aerial` at 0).
// As the engine breaks out of a bore the tunnel take opens the eye wide (SteamLight.dazzle, its extra
// exposure): the steam then takes back about half of it, so that it glows and still shows its billows.
//
// Imported with `import { Steam, SteamLight } from "../core/golden_line_steam";` (from examples/).

Expand Down Expand Up @@ -71,6 +71,8 @@ export class SteamLight {
lightX = 0.0;
lightY = 1.0;
lightZ = 0.0;
// the tunnel take's extra exposure (main.js's frame.dazzle), 0 elsewhere
dazzle = 0.0;
}

function smWrap(v: number): number {
Expand Down Expand Up @@ -278,6 +280,16 @@ export class Steam {
this.set4(SC_DRIFT, smWrap(-t * 0.045), smWrap(-t * 0.062), smWrap(t * 0.036), this.depthA);
this.set4(SC_DRIFT_BROAD, smWrap(-t * 0.0255), smWrap(-t * 0.034), smWrap(t * 0.021), this.depthB);
this.lightSmoke(light);
// Steam is the brightest thing in a dazzled frame and would burn out to a flat white shape.
if (light.dazzle != 0.0) {
const held = 1.0 / (1.0 + light.dazzle * 0.55);
const slots: int[] = [SC_SUN, SC_SKY, SC_SIDE, SC_GROUND, SC_RIM];
for (const slot of slots) {
for (let k = 0; k < 3; k++) {
c[slot + k] = <f32>(c[slot + k] * held);
}
}
}
this.placeSun(light, width, height);
const mouth = frame.tunnelFactor * (1.0 - 0.8 * light.lamps);
this.set4(SC_PORTAL, 1.0 * 0.6 * mouth, 0.82 * 0.6 * mouth, 0.58 * 0.6 * mouth, 0.0);
Expand Down
33 changes: 32 additions & 1 deletion core/golden_line_structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ export class StructuresRenderer {
private packX = 1e9;
private packZ = 1e9;
private dirty = true;
// a stretch of the pole line a camera take leaves out (setClearPoles)
private clearOn = false;
// the tunnel take's extra exposure (main.js's frame.dazzle): the dark of a mouth stays dark under it
dazzle = 0.0;
private clearZ0 = 0.0;
private clearZ1 = 0.0;
private anchorZ = 0.0;
private wireCount: int = 0;
private wireAnchor = 0.0;
Expand Down Expand Up @@ -1203,7 +1209,7 @@ export class StructuresRenderer {
gl[1] = <f32>(this.tunnelOut - originZ);
gl[2] = <f32>this.inside;
// seen from daylight the dark inside a mouth goes down with the day outside
gl[3] = <f32>(1.2 * (1.0 - 0.86 * this.lamps));
gl[3] = <f32>(1.2 * (1.0 - 0.86 * this.lamps) / (1.0 + this.dazzle));
gl[4] = <f32>this.cabX;
gl[5] = <f32>this.cabY;
gl[6] = <f32>(this.cabZ - originZ);
Expand Down Expand Up @@ -1329,6 +1335,25 @@ export class StructuresRenderer {
}
}

/**
* A composed camera take can ask for a stretch of the pole line [z0, z1] to be left out of its frame
* (an empty list: none). A change re-packs the pools on the spot, where the cut hides it.
*/
setClearPoles(range: number[]): void {
const on = range.length == 2;
const z0 = on ? range[0] : 0.0, z1 = on ? range[1] : 0.0;
if (on != this.clearOn || z0 != this.clearZ0 || z1 != this.clearZ1) {
this.clearOn = on;
this.clearZ0 = z0;
this.clearZ1 = z1;
this.dirty = true;
}
}

private cleared(z: number): boolean {
return this.clearOn && z > this.clearZ0 && z < this.clearZ1;
}

/** lineside.js's packRing: the items within reach, nearest first, into the ring's near and far pools. */
private packRing(commandList: CommandList, r: StRing): void {
const cx = this.cameraX, cz = this.cameraZ;
Expand All @@ -1344,6 +1369,9 @@ export class StructuresRenderer {
}
const list = this.chunks[c].items.list(r.kind);
for (let i = 0; i < list.length; i++) {
if (r.kind == LS_POLES && this.cleared(list[i].z)) {
continue;
}
const dx = list[i].x - cx, ddz = list[i].z - cz;
const dist = dx * dx + ddz * ddz;
if (dist < reach * reach) {
Expand Down Expand Up @@ -1409,6 +1437,9 @@ export class StructuresRenderer {
for (let c = 0; c < this.chunks.length; c++) {
const wires = this.chunks[c].items.wires;
for (let i = 0; i < wires.length; i++) {
if (this.cleared(wires[i].az) || this.cleared(wires[i].bz)) {
continue;
}
const dx = wires[i].ax - cx, dz = wires[i].az - cz;
const dist = dx * dx + dz * dz;
if (dist < 420.0 * 420.0) {
Expand Down
78 changes: 76 additions & 2 deletions core/golden_line_vegetation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Imported with `import { TreeRenderer } from "../core/golden_line_vegetation";` (from examples/).

import { App, BindingLayoutDesc, BindingSet, BindingSetDesc, CommandList, Frame, GraphicsPipelineDesc, InputLayoutDesc } from "./donut";
import { World, TerrainMesh, terrainColumns, deg, SEG_VIADUCT, SEG_RIVER, SEG_TUNNEL, SUN_DIR_X, SUN_DIR_Z } from "./golden_line_world";
import { World, TerrainMesh, terrainColumns, deg, hypot2, SEG_VIADUCT, SEG_RIVER, SEG_TUNNEL, SUN_DIR_X, SUN_DIR_Z } from "./golden_line_world";
import { buildTrees, TREE_TYPES, TREE_STRIDE, TREE_BUSH } from "./golden_line_trees";
import { LsFarmSite, lsSiteFarm } from "./golden_line_lineside";
import { Geo, Prototype, buildPrototype, PROTO_COUNT } from "./golden_line_treegen";
Expand Down Expand Up @@ -88,7 +88,12 @@ const VEG_SLICES: number[] = [0.0, 19.0, 15.0, 68.0, 56.0, 218.0, 180.0, 660.0];
const VEG_VERTEX_FLOATS: int = 15;

// struct TreeGlobals: six planes, the camera and level-of-detail scale, the wind, the cascades' slices, the sun.
const VEG_GLOBAL_FLOATS: int = 52;
// The viewpoints trees are kept out of (trees.js's CLEARANCE): none, the viaduct, beside the rails, the drone.
export const VEG_CLEAR_NONE: int = 0;
export const VEG_CLEAR_BRIDGE: int = 1;
export const VEG_CLEAR_TRACKSIDE: int = 2;
export const VEG_CLEAR_DRONE: int = 3;
const VEG_GLOBAL_FLOATS: int = 60; // TreeGlobals (shaders/golden_line_trees.hlsl)

const MODE_BARK: int = 0;
const MODE_NEAR: int = 1;
Expand Down Expand Up @@ -354,6 +359,14 @@ export class TreeRenderer {

private app: App;
private world: Shared<World>;
// keepViewOpen's latch: where the rule was set up, and for which cut
private latchCut: int = -1;
private latchX = 0.0;
private latchY = 0.0;
private latchZ = 0.0;
private latchSlope = 0.0;
private latchOffset = 1.0;
private latchHeight = 0.0;
// the last chunk's farm, sited on its trees before any were cleared (for the lineside planner)
private farm = new LsFarmSite();
private protos: Prototype[] = [];
Expand Down Expand Up @@ -429,6 +442,7 @@ export class TreeRenderer {
for (let i = 0; i < VEG_GLOBAL_FLOATS; i++) {
this.globals.push(<f32>0.0);
}
this.globals[58] = <f32>1.0; // clearB: no rule (0, 0, 1, 0)
this.quad = new MeshRange(0, 0);
}

Expand Down Expand Up @@ -1032,6 +1046,66 @@ export class TreeRenderer {
}
}

/**
* The rule that keeps a viewpoint open (trees.js's CLEARANCE and keepViewOpen): a tree that would wall
* off the view grows only as high as the sight line allows. rule: VEG_CLEAR_NONE, _BRIDGE, _TRACKSIDE
* or _DRONE; the camera in true world, which way it looks (its forward's y), its vertical field of
* view (degrees), its render-space x and z; cut: the shots so far, jumped: the train was sent on.
*/
keepViewOpen(rule: int, cut: int, jumped: boolean, eyeX: number, eyeY: number, eyeZ: number, forwardY: number,
fovDeg: number, originZ: number, camX: number, camZ: number) {
const g = this.globals;
if (rule == VEG_CLEAR_NONE) {
g[56] = <f32>0.0;
g[57] = <f32>0.0;
g[58] = <f32>1.0;
g[59] = <f32>0.0;
this.latchCut = -1;
return;
}
const track = this.world.value.track;
const radial = rule != VEG_CLEAR_DRONE;
const reach = rule == VEG_CLEAR_BRIDGE ? 190.0 : rule == VEG_CLEAR_TRACKSIDE ? 8.5 : 520.0;
const below = rule == VEG_CLEAR_BRIDGE ? 0.22 : -0.1;
const lift = rule == VEG_CLEAR_TRACKSIDE ? 0.6 : 0.0;
const rail = track.Y(eyeZ);
// A new shot, or a trackside camera that has set itself up again further down the line.
const moved = radial && hypot2(eyeX - this.latchX, eyeZ - this.latchZ) > 60.0;
if (this.latchCut != cut || jumped || moved) {
this.latchCut = cut;
this.latchX = eyeX;
this.latchZ = eyeZ;
this.latchY = eyeY + lift;
if (radial) {
const pitch = Math.asin(Math.max(-1.0, Math.min(1.0, forwardY)));
this.latchSlope = Math.tan(pitch - deg(fovDeg) * below);
}
const offset = eyeX - track.X(eyeZ);
this.latchOffset = Math.abs(offset) < 8.0 ? (offset < 0.0 ? -8.0 : 8.0) : offset;
this.latchHeight = eyeY - rail;
}
if (radial) {
g[52] = <f32>this.latchX;
g[53] = <f32>(this.latchZ - originZ);
g[54] = <f32>this.latchSlope;
g[55] = <f32>this.latchY;
g[56] = <f32>1.0;
g[57] = <f32>reach;
g[58] = <f32>1.0;
g[59] = <f32>0.0;
} else {
// Distance is measured from the flying camera, but only far out, where it cannot be seen to matter.
g[52] = <f32>camX;
g[53] = <f32>camZ;
g[54] = <f32>0.0;
g[55] = <f32>(rail + this.latchHeight);
g[56] = <f32>2.0;
g[57] = <f32>reach;
g[58] = <f32>this.latchOffset;
g[59] = <f32>rail;
}
}

// Sorts the trees into the frame's draw lists. worldToClip is golden_line.hlsl's (by rows, render
// space); camera in render space; fovY in radians; time in seconds.
cull(commandList: CommandList, originZ: number, worldToClip: f32[], cx: number, cy: number, cz: number, fovY: number, time: number) {
Expand Down
15 changes: 15 additions & 0 deletions core/golden_line_world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,21 @@ export class Layout {
return this.segments[this.indexAt(z)];
}

// The index of the first segment of `type` whose centre lies beyond z (layout.js's nextOfType).
nextOfType(type: int, z: number): int {
let i = this.indexAt(z);
for (;;) {
while (i >= this.segments.length) {
this.generateNext();
}
const seg = this.segments[i];
if (seg.type == type && seg.zc > z) {
return i;
}
i++;
}
}

// The indices in segments of all segments overlapping [a, b].
inRange(a: number, b: number): int[] {
this.ensure(b + 1.0);
Expand Down
Loading
Loading