Agent Harness
Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
Принят владельцем вручную — без оценки ИИ. Очки за вклад не начислены. Оценка восстановлена по объёму правки.
| +добавлено | import type { User } from '../domain/User'; |
| +добавлено | import type { UserRepository } from '../domain/UserRepository'; |
| +добавлено | |
| +добавлено | export class MemoryUserRepository implements UserRepository { |
| +добавлено | private readonly users = new Map<string, User>(); |
| +добавлено | |
| +добавлено | find(id: string): User | null { |
| +добавлено | return this.users.get(id) ?? null; |
| +добавлено | } |
| +добавлено | |
| +добавлено | save(user: User): void { |
| +добавлено | this.users.set(user.id, user); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | import { registerUser } from '../application/RegisterUser'; |
| +добавлено | import type { UserRepository } from '../domain/UserRepository'; |
| +добавлено | |
| +добавлено | export function renderRegistration(repo: UserRepository): string { |
| +добавлено | const user = registerUser(repo, 'u-1', 'Ada'); |
| +добавлено | return `user: ${user.name}`; |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-22-40-245Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 5, |
| +добавлено | "edges": 2, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts imports \"../infrastructure/MemoryUserRepository\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts imports \"../ui/App\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:22:40.246Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-23-06-771Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:23:06.772Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-23-12-073Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:23:12.074Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-24-25-274Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:24:25.274Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-24-26-221Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:24:26.222Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-24-32-702Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:24:32.703Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-24-33-598Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:24:33.598Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-25-15-520Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:25:15.521Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-25-16-461Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:25:16.462Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-27-39-353Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:27:39.354Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-27-40-572Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:27:40.573Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-27-40-572Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "config": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty\\architecture.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "stats": { |
| +добавлено | "files": 7, |
| +добавлено | "edges": 4, |
| +добавлено | "external": 0 |
| +добавлено | }, |
| +добавлено | "byRule": { |
| +добавлено | "forbidden-import": 2, |
| +добавлено | "cycle": 1 |
| +добавлено | }, |
| +добавлено | "errors": [ |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/ui/Panel.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/Panel.ts -> src/infrastructure/MemoryUserRepository.ts — UI must not reach persistence directly" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "forbidden-import", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/domain/Policy.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/domain/Policy.ts -> src/ui/App.ts — domain must not know about UI" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "cycle", |
| +добавлено | "severity": "error", |
| +добавлено | "file": "src/application/A.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "import cycle (2): src/application/A.ts -> src/application/B.ts -> src/application/A.ts" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "warnings": [ |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/ui/App.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/ui/App.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "unresolved-import", |
| +добавлено | "severity": "warning", |
| +добавлено | "file": "src/infrastructure/MemoryUserRepository.ts", |
| +добавлено | "line": 0, |
| +добавлено | "message": "src/infrastructure/MemoryUserRepository.ts imports \"../domain/User\" which does not resolve to a project file" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "function-too-long", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything is 48 lines (budget 30)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "too-many-params", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything takes 6 parameters (budget 4)", |
| +добавлено | "severity": "warning" |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "rule": "deep-nesting", |
| +добавлено | "file": "src/application/Big.ts", |
| +добавлено | "line": 1, |
| +добавлено | "message": "src/application/Big.ts:1 processEverything nests 4 levels (budget 3)", |
| +добавлено | "severity": "warning" |
| +добавлено | } |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:27:40.573Z" |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-23-11-978Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "packageManager": null, |
| +добавлено | "frontend": false, |
| +добавлено | "architecture": true, |
| +добавлено | "config": "<HOME>\\.agent-harness\\.agent-gates.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "missingRequired": [], |
| +добавлено | "unverifiedRequired": [ |
| +добавлено | "scope" |
| +добавлено | ], |
| +добавлено | "finishedAt": "2026-11-05T05:23:12.198Z", |
| +добавлено | "results": [ |
| +добавлено | { |
| +добавлено | "name": "architecture", |
| +добавлено | "command": "node \"<HOME>\\.agent-harness/tools/arch.mjs\" check", |
| +добавлено | "required": true, |
| +добавлено | "log": ".agent-state\\artifacts\\gates-2026-11-05T05-23-11-978Z\\architecture.log", |
| +добавлено | "status": "failed", |
| +добавлено | "exitCode": 1, |
| +добавлено | "durationMs": 116 |
| +добавлено | }, |
| +добавлено | { |
| +добавлено | "name": "scope", |
| +добавлено | "command": "node \"<HOME>\\.agent-harness/tools/scope.mjs\"", |
| +добавлено | "required": true, |
| +добавлено | "log": ".agent-state\\artifacts\\gates-2026-11-05T05-23-11-978Z\\scope.log", |
| +добавлено | "status": "unverified", |
| +добавлено | "exitCode": 2, |
| +добавлено | "durationMs": 100 |
| +добавлено | } |
| +добавлено | ] |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-24-26-126Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "packageManager": null, |
| +добавлено | "frontend": false, |
| +добавлено | "architecture": true, |
| +добавлено | "config": "<HOME>\\.agent-harness\\.agent-gates.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "missingRequired": [], |
| +добавлено | "unverifiedRequired": [], |
| +добавлено | "finishedAt": "2026-11-05T05:24:26.248Z", |
| +добавлено | "results": [ |
| +добавлено | { |
| +добавлено | "name": "architecture", |
| +добавлено | "command": "node \"<HOME>\\.agent-harness/tools/arch.mjs\" check", |
| +добавлено | "required": true, |
| +добавлено | "log": ".agent-state\\artifacts\\gates-2026-11-05T05-24-26-126Z\\architecture.log", |
| +добавлено | "status": "failed", |
| +добавлено | "exitCode": 1, |
| +добавлено | "durationMs": 119 |
| +добавлено | } |
| +добавлено | ] |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-24-33-514Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "packageManager": null, |
| +добавлено | "frontend": false, |
| +добавлено | "architecture": true, |
| +добавлено | "config": "<HOME>\\.agent-harness\\.agent-gates.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "missingRequired": [], |
| +добавлено | "unverifiedRequired": [], |
| +добавлено | "finishedAt": "2026-11-05T05:24:33.621Z", |
| +добавлено | "results": [ |
| +добавлено | { |
| +добавлено | "name": "architecture", |
| +добавлено | "command": "node \"<HOME>\\.agent-harness/tools/arch.mjs\" check", |
| +добавлено | "required": true, |
| +добавлено | "log": ".agent-state\\artifacts\\gates-2026-11-05T05-24-33-514Z\\architecture.log", |
| +добавлено | "status": "failed", |
| +добавлено | "exitCode": 1, |
| +добавлено | "durationMs": 103 |
| +добавлено | } |
| +добавлено | ] |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-25-16-357Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "packageManager": null, |
| +добавлено | "frontend": false, |
| +добавлено | "architecture": true, |
| +добавлено | "config": "<HOME>\\.agent-harness\\.agent-gates.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "missingRequired": [], |
| +добавлено | "unverifiedRequired": [], |
| +добавлено | "finishedAt": "2026-11-05T05:25:16.492Z", |
| +добавлено | "results": [ |
| +добавлено | { |
| +добавлено | "name": "architecture", |
| +добавлено | "command": "node \"<HOME>\\.agent-harness/tools/arch.mjs\" check", |
| +добавлено | "required": true, |
| +добавлено | "log": ".agent-state\\artifacts\\gates-2026-11-05T05-25-16-357Z\\architecture.log", |
| +добавлено | "status": "failed", |
| +добавлено | "exitCode": 1, |
| +добавлено | "durationMs": 130 |
| +добавлено | } |
| +добавлено | ] |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-27-40-482Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "packageManager": null, |
| +добавлено | "frontend": false, |
| +добавлено | "architecture": true, |
| +добавлено | "config": "<HOME>\\.agent-harness\\.agent-gates.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "missingRequired": [], |
| +добавлено | "unverifiedRequired": [], |
| +добавлено | "finishedAt": "2026-11-05T05:27:40.593Z", |
| +добавлено | "results": [ |
| +добавлено | { |
| +добавлено | "name": "architecture", |
| +добавлено | "command": "node \"<HOME>\\.agent-harness/tools/arch.mjs\" check", |
| +добавлено | "required": true, |
| +добавлено | "log": ".agent-state\\artifacts\\gates-2026-11-05T05-27-40-482Z\\architecture.log", |
| +добавлено | "status": "failed", |
| +добавлено | "exitCode": 1, |
| +добавлено | "durationMs": 108 |
| +добавлено | } |
| +добавлено | ] |
| +добавлено | } |
| +добавлено | { |
| +добавлено | "runId": "2026-11-05T05-27-40-482Z", |
| +добавлено | "cwd": "<HOME>\\.agent-harness\\tools\\fixtures\\arch\\dirty", |
| +добавлено | "packageManager": null, |
| +добавлено | "frontend": false, |
| +добавлено | "architecture": true, |
| +добавлено | "config": "<HOME>\\.agent-harness\\.agent-gates.json", |
| +добавлено | "verdict": "failed", |
| +добавлено | "missingRequired": [], |
| +добавлено | "unverifiedRequired": [], |
| +добавлено | "finishedAt": "2026-11-05T05:27:40.593Z", |
| +добавлено | "results": [ |
| +добавлено | { |
| +добавлено | "name": "architecture", |
| +добавлено | "command": "node \"<HOME>\\.agent-harness/tools/arch.mjs\" check", |
| +добавлено | "required": true, |
| +добавлено | "log": ".agent-state\\artifacts\\gates-2026-11-05T05-27-40-482Z\\architecture.log", |
| +добавлено | "status": "failed", |
| +добавлено | "exitCode": 1, |
| +добавлено | "durationMs": 108 |
| +добавлено | } |
| +добавлено | ] |
| +добавлено | } |
| +добавлено | {"at":"2026-11-05T05:22:40.250Z","type":"arch.checked","runId":"2026-11-05T05-22-40-245Z","verdict":"failed","errors":1} |
| +добавлено | {"at":"2026-11-05T05:23:06.777Z","type":"arch.checked","runId":"2026-11-05T05-23-06-771Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:23:12.077Z","type":"arch.checked","runId":"2026-11-05T05-23-12-073Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:23:12.202Z","type":"gates.finished","runId":"2026-11-05T05-23-11-978Z","verdict":"failed"} |
| +добавлено | {"at":"2026-11-05T05:24:25.276Z","type":"arch.checked","runId":"2026-11-05T05-24-25-274Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:24:26.225Z","type":"arch.checked","runId":"2026-11-05T05-24-26-221Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:24:26.251Z","type":"gates.finished","runId":"2026-11-05T05-24-26-126Z","verdict":"failed"} |
| +добавлено | {"at":"2026-11-05T05:24:32.706Z","type":"arch.checked","runId":"2026-11-05T05-24-32-702Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:24:33.601Z","type":"arch.checked","runId":"2026-11-05T05-24-33-598Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:24:33.623Z","type":"gates.finished","runId":"2026-11-05T05-24-33-514Z","verdict":"failed"} |
| +добавлено | {"at":"2026-11-05T05:25:15.524Z","type":"arch.checked","runId":"2026-11-05T05-25-15-520Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:25:16.467Z","type":"arch.checked","runId":"2026-11-05T05-25-16-461Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:25:16.494Z","type":"gates.finished","runId":"2026-11-05T05-25-16-357Z","verdict":"failed"} |
| +добавлено | {"at":"2026-11-05T05:27:39.357Z","type":"arch.checked","runId":"2026-11-05T05-27-39-353Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:27:40.576Z","type":"arch.checked","runId":"2026-11-05T05-27-40-572Z","verdict":"failed","errors":3} |
| +добавлено | {"at":"2026-11-05T05:27:40.596Z","type":"gates.finished","runId":"2026-11-05T05-27-40-482Z","verdict":"failed"} |
| +добавлено | { |
| +добавлено | "layers": [ |
| +добавлено | { "name": "domain", "path": "src/domain", "mayImport": ["domain"] }, |
| +добавлено | { "name": "application", "path": "src/application", "mayImport": ["domain", "application"] }, |
| +добавлено | { "name": "infrastructure", "path": "src/infrastructure", "mayImport": ["domain", "application", "infrastructure"] }, |
| +добавлено | { "name": "ui", "path": "src/ui", "mayImport": ["application", "domain", "ui"] } |
| +добавлено | ], |
| +добавлено | "forbidden": [ |
| +добавлено | { "from": "src/ui/**", "to": "src/infrastructure/**", "reason": "UI must not reach persistence directly" }, |
| +добавлено | { "from": "src/domain/**", "to": "src/ui/**", "reason": "domain must not know about UI" } |
| +добавлено | ], |
| +добавлено | "budgets": { "maxFileLines": 120, "maxFunctionLines": 30, "maxParams": 4, "maxNesting": 3 }, |
| +добавлено | "cycles": true, |
| +добавлено | "failOn": ["layer-violation", "forbidden-import", "cycle"] |
| +добавлено | } |
| +добавлено | import { stepB } from './B'; |
| +добавлено | |
| +добавлено | export function stepA(value: number): number { |
| +добавлено | return value === 0 ? 0 : stepB(value - 1) + 1; |
| +добавлено | } |
| +добавлено | import { stepA } from './A'; |
| +добавлено | |
| +добавлено | export function stepB(value: number): number { |
| +добавлено | return value === 0 ? 0 : stepA(value - 1) + 1; |
| +добавлено | } |
| +добавлено | export function processEverything(a: string, b: string, c: string, d: string, e: string, f: string): string { |
| +добавлено | let result = ''; |
| +добавлено | for (let i = 0; i < 3; i += 1) { |
| +добавлено | if (i === 0) { |
| +добавлено | if (a) { |
| +добавлено | if (b) { |
| +добавлено | result += a; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | } |
| +добавлено | result += b; |
| +добавлено | result += c; |
| +добавлено | result += d; |
| +добавлено | result += e; |
| +добавлено | result += f; |
| +добавлено | result += a; |
| +добавлено | result += b; |
| +добавлено | result += c; |
| +добавлено | result += d; |
| +добавлено | result += e; |
| +добавлено | result += f; |
| +добавлено | result += a; |
| +добавлено | result += b; |
| +добавлено | result += c; |
| +добавлено | result += d; |
| +добавлено | result += e; |
| +добавлено | result += f; |
| +добавлено | result += a; |
| +добавлено | result += b; |
| +добавлено | result += c; |
| +добавлено | result += d; |
| +добавлено | result += e; |
| +добавлено | result += f; |
| +добавлено | result += a; |
| +добавлено | result += b; |
| +добавлено | result += c; |
| +добавлено | result += d; |
| +добавлено | result += e; |
| +добавлено | result += f; |
| +добавлено | result += a; |
| +добавлено | result += b; |
| +добавлено | result += c; |
| +добавлено | result += d; |
| +добавлено | result += e; |
| +добавлено | result += f; |
| +добавлено | } |
| +добавлено | return result; |
| +добавлено | } |
| +добавлено | import { renderRegistration } from '../ui/App'; |
| +добавлено | |
| +добавлено | export function policyShowsUi(): string { |
| +добавлено | return renderRegistration({ find: () => null, save: () => {} }); |
| +добавлено | } |
| +добавлено | import type { User } from '../domain/User'; |
| +добавлено | |
| +добавлено | export class MemoryUserRepository { |
| +добавлено | private readonly users = new Map<string, User>(); |
| +добавлено | |
| +добавлено | find(id: string): User | null { |
| +добавлено | return this.users.get(id) ?? null; |
| +добавлено | } |
| +добавлено | |
| +добавлено | save(user: User): void { |
| +добавлено | this.users.set(user.id, user); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | import type { User } from '../domain/User'; |
| +добавлено | |
| +добавлено | export function renderRegistration(user: User | null): string { |
| +добавлено | return user ? `user: ${user.name}` : 'nobody'; |
| +добавлено | } |
| +добавлено | import { MemoryUserRepository } from '../infrastructure/MemoryUserRepository'; |
| +добавлено | |
| +добавлено | export function panel(): string { |
| +добавлено | const repo = new MemoryUserRepository(); |
| +добавлено | return repo.find('u-1')?.name ?? 'nobody'; |
| +добавлено | } |
| +добавлено | import * as THREE from 'three'; |
| +добавлено | |
| +добавлено | import { |
| +добавлено | ARENA, |
| +добавлено | U, |
| +добавлено | forces, |
| +добавлено | lights, |
| +добавлено | impacts, |
| +добавлено | occluders, |
| +добавлено | packWorld, |
| +добавлено | } from '../ue/vfx/common.js'; |
| +добавлено | import { Q, TIERS } from '../ue/engine/quality.js'; |
| +добавлено | import { CameraRig } from '../ue/engine/camera.js'; |
| +добавлено | import { bakeNoise } from '../ue/vfx/noise.js'; |
| +добавлено | import { GroundField } from '../ue/vfx/GroundField.js'; |
| +добавлено | import { Particles } from '../ue/vfx/Particles.js'; |
| +добавлено | import { TrailRibbons, AnalyticRibbons } from '../ue/vfx/Ribbons.js'; |
| +добавлено | import { Bolts } from '../ue/vfx/Bolts.js'; |
| +добавлено | import { Volumes } from '../ue/vfx/Volumes.js'; |
| +добавлено | import { Shockwaves } from '../ue/vfx/Shockwaves.js'; |
| +добавлено | import { Spikes } from '../ue/vfx/Spikes.js'; |
| +добавлено | import { Sigils } from '../ue/vfx/Sigils.js'; |
| +добавлено | import { Metaballs } from '../ue/vfx/Metaballs.js'; |
| +добавлено | import { FxTarget } from '../ue/vfx/FxTarget.js'; |
| +добавлено | import { Lens } from '../ue/vfx/Lens.js'; |
| +добавлено | import { Casts } from '../ue/spells/cast.js'; |
| +добавлено | import { SPELLS, ELEMENTS } from '../ue/spells/index.js'; |
| +добавлено | |
| +добавлено | /** |
| +добавлено | * Хост заклинаний Ultra-Elements (Humpalumps, MIT). |
| +добавлено | * |
| +добавлено | * Собирает ровно тот объект `fx`, который ждут заклинания, и гоняет их |
| +добавлено | * симуляцию. Арена автора заменена нашим миром: земля — `islandHeight`, |
| +добавлено | * цели — наши враги (объекты вида { x, z, pos, status.frozen, hit() }). |
| +добавлено | */ |
| +добавлено | |
| +добавлено | export interface SpellTarget { |
| +добавлено | x: number; |
| +добавлено | z: number; |
| +добавлено | pos: THREE.Vector3; |
| +добавлено | status: { frozen: number }; |
| +добавлено | hit: (dir: THREE.Vector3, strength?: number) => void; |
| +добавлено | } |
| +добавлено | |
| +добавлено | export interface SpellHostDeps { |
| +добавлено | renderer: THREE.WebGLRenderer; |
| +добавлено | camera: THREE.PerspectiveCamera; |
| +добавлено | /** Куб неба (для отражений в ледяных шейдерах). */ |
| +добавлено | skyCube: THREE.Texture; |
| +добавлено | /** Направление и цвет солнца. */ |
| +добавлено | sunDir: THREE.Vector3; |
| +добавлено | sunColor: THREE.Vector3; |
| +добавлено | /** Центр площадки, где работают декали (иней и лёд на земле). */ |
| +добавлено | groundCenter: THREE.Vector3; |
| +добавлено | /** Размер площадки в метрах. */ |
| +добавлено | groundSize?: number; |
| +добавлено | /** Уровень качества для их профиля: low | medium | high | ultra. */ |
| +добавлено | tier?: string; |
| +добавлено | /** Высота рельефа — тот же islandHeight, что у мира. */ |
| +добавлено | groundHeight: (x: number, z: number) => number; |
| +добавлено | } |
| +добавлено | |
| +добавлено | const GROUND_EXTENT = 260; |
| +добавлено | |
| +добавлено | export class SpellHost { |
| +добавлено | readonly fx: any; |
| +добавлено | readonly casts: any; |
| +добавлено | /** Сцены эффектов: их надо отрисовать в тот же HDR-буфер, что и воду. */ |
| +добавлено | readonly refract = new THREE.Scene(); |
| +добавлено | readonly lines = new THREE.Scene(); |
| +добавлено | readonly fxScene = new THREE.Scene(); |
| +добавлено | /** Меши, которым нужна глубина сцены (шипы) — кладём в наш мир. */ |
| +добавлено | readonly opaque = new THREE.Scene(); |
| +добавлено | |
| +добавлено | private ground: any; |
| +добавлено | private particles: any; |
| +добавлено | private spikes: any; |
| +добавлено | private sigils: any; |
| +добавлено | private trails: any; |
| +добавлено | private bolts: any; |
| +добавлено | private volumes: any; |
| +добавлено | private shocks: any; |
| +добавлено | private metaballs: any; |
| +добавлено | private fxTarget: any; |
| +добавлено | private lens: any; |
| +добавлено | private rig: any; |
| +добавлено | private probePts = Array.from({ length: 16 }, () => [0, 0]); |
| +добавлено | private probeXZ = Array.from({ length: 16 }, () => new THREE.Vector2()); |
| +добавлено | private probeN = 0; |
| +добавлено | private probeReadN = 0; |
| +добавлено | private probeOut = new Float32Array(8); |
| +добавлено | private probeList: number[][] = []; |
| +добавлено | private seed = 1; |
| +добавлено | private warmQueue: any[] = []; |
| +добавлено | private warming = false; |
| +добавлено | private warmAt = 0; |
| +добавлено | private simTime = 0; |
| +добавлено | targets: SpellTarget[] = []; |
| +добавлено | /** Шаги конструктора, отключённые через ?skip= (для бисекции). */ |
| +добавлено | readonly skipped: string[] = []; |
| +добавлено | |
| +добавлено | constructor(private deps: SpellHostDeps) { |
| +добавлено | const { renderer, camera, skyCube, sunDir, sunColor, groundCenter } = deps; |
| +добавлено | // ── ФЛАГ БИСЕКЦИИ: ?skip=bake,ground,particles,fx,lens ───────────────── |
| +добавлено | // Отключает шаги конструктора по одному, чтобы найти, какой из них ломает |
| +добавлено | // кадр. Пустой список = всё включено (обычный режим). |
| +добавлено | this.skipped = (new URLSearchParams(location.search).get('skip') ?? '') |
| +добавлено | .split(',') |
| +добавлено | .map((x) => x.trim()) |
| +добавлено | .filter(Boolean); |
| +добавлено | const off = (name: string): boolean => this.skipped.includes(name); |
| +добавлено | if (deps.tier) { |
| +добавлено | // ВАЖНО: Q собран из TIERS на импорте, поэтому одной смены tier мало — |
| +добавлено | // надо пересчитать производные поля (размер поля земли, пул частиц, шум), |
| +добавлено | // иначе движок аллоцирует ресурсы чужого тира. |
| +добавлено | (Q as any).tier = deps.tier; |
| +добавлено | Object.assign(Q, (TIERS as any)[deps.tier] ?? {}); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // ── конфигурация арены под наш мир ───────────────────────────────────── |
| +добавлено | // Площадка для декалей (иней, лёд, грязь) — вокруг стартовой точки героя. |
| +добавлено | ARENA.ground.min.set(groundCenter.x - GROUND_EXTENT / 2, groundCenter.z - GROUND_EXTENT / 2); |
| +добавлено | ARENA.ground.size = GROUND_EXTENT; |
| +добавлено | U.uGroundRect.value.set(ARENA.ground.min.x, ARENA.ground.min.y, GROUND_EXTENT, 1 / GROUND_EXTENT); |
| +добавлено | // Лужи в нашем мире нет: ровняем «воду бассейна» с землёй, чтобы рельеф не дырявился. |
| +добавлено | // Бассейн арены (4.5×9 м) у воды — якорь для водных заклинаний. В нашем |
| +добавлено | // мире ставим его на мелководье рядом со спавном, чтобы цунами и брызги |
| +добавлено | // взаимодействовали с настоящим морем, а не с центром острова. |
| +добавлено | ARENA.pool.water = 0; |
| +добавлено | { |
| +добавлено | const found = this.findShallowNear(groundCenter, 90); |
| +добавлено | if (found) { |
| +добавлено | ARENA.pool.center.set(found.x, found.z); |
| +добавлено | ARENA.pool.half.set(6, 11); |
| +добавлено | U.uGroundRect.value.set(ARENA.ground.min.x, ARENA.ground.min.y, GROUND_EXTENT, 1 / GROUND_EXTENT); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | ARENA.focus.copy(groundCenter).setY(groundCenter.y + 1.6); |
| +добавлено | |
| +добавлено | (U as any).uSkyCube.value = skyCube; |
| +добавлено | U.uSunDir.value.copy(sunDir); |
| +добавлено | U.uSunColor.value.copy(sunColor); |
| +добавлено | |
| +добавлено | this.rig = new CameraRig(); |
| +добавлено | |
| +добавлено | if (!off('bake')) bakeNoise(renderer, Q); |
| +добавлено | this.ground = off('ground') |
| +добавлено | ? { update() {}, setProbes() {}, splat() {}, probes: new Float32Array(8), probeCount: 0 } |
| +добавлено | : new GroundField(renderer, Q.groundSize); |
| +добавлено | |
| +добавлено | const post = { |
| +добавлено | // заглушка: настоящая постобработка у нас от Ultra-Water, а заклинаниям |
| +добавлено | // нужен только этот интерфейс (вспышка кадра) |
| +добавлено | params: { flash: 0, bloomLevels: Q.bloomLevels, anamorphic: 0, maxExposure: 20 }, |
| +добавлено | viewCamera: camera, |
| +добавлено | setSize: () => {}, |
| +добавлено | render: () => {}, |
| +добавлено | }; |
| +добавлено | const sky = { cube: skyCube, sunDir, sunColor, update: () => {} }; |
| +добавлено | // Заглушка арены. Заклинания читают конкретные поля: pool.swirl/ripple, |
| +добавлено | // arena.focus.color, arena.setFocus(), arena.orb — без них каст падает |
| +добавлено | // («Cannot read properties of undefined (reading 'color')»). |
| +добавлено | const pool = { |
| +добавлено | center: new THREE.Vector2(ARENA.pool.center.x, ARENA.pool.center.y), |
| +добавлено | half: new THREE.Vector2(ARENA.pool.half.x, ARENA.pool.half.y), |
| +добавлено | swirl: () => {}, |
| +добавлено | ripple: () => {}, |
| +добавлено | }; |
| +добавлено | const arena = { |
| +добавлено | group: new THREE.Group(), |
| +добавлено | refractGroup: new THREE.Group(), |
| +добавлено | dummies: [], |
| +добавлено | pool, |
| +добавлено | uniforms: {}, |
| +добавлено | focus: { color: new THREE.Color(0.42, 0.8, 1.0) }, |
| +добавлено | orb: { visible: false }, |
| +добавлено | setFocus: () => {}, |
| +добавлено | update: () => {}, |
| +добавлено | updateSun: () => {}, |
| +добавлено | }; |
| +добавлено | |
| +добавлено | this.particles = off('particles') |
| +добавлено | ? { addKind() {}, build() {}, update() {}, glow: null, media: null, debris: [] } |
| +добавлено | : new Particles(renderer, { ground: this.ground }); |
| +добавлено | this.trails = new TrailRibbons({ max: 64, points: 48 }); |
| +добавлено | this.bolts = new Bolts(); |
| +добавлено | this.volumes = new Volumes(); |
| +добавлено | this.shocks = new Shockwaves(); |
| +добавлено | this.spikes = new Spikes({ max: 48 }); |
| +добавлено | this.sigils = new Sigils({ max: 8 }); |
| +добавлено | this.metaballs = new Metaballs({ max: 4 }); |
| +добавлено | // FxTarget (полуразрешённый MRT с float-глубиной) ломает кадр: с ним |
| +добавлено | // измеренная яркость падает с 115 до 36 (84 % кадра в чёрном). Пока не |
| +добавлено | // разобрано, создаём его только по явному запросу ?fx=on — для проверки |
| +добавлено | // на GPU. Без него композит просто отдаёт сцену как есть, а ледяные |
| +добавлено | // заклинания рисуются проходом преломления и видны. |
| +добавлено | const wantFx = new URLSearchParams(location.search).get('fx') !== 'off'; // слой эффектов включён по умолчанию (?fx=off — отладка) |
| +добавлено | this.fxTarget = !off('fx') && wantFx ? new FxTarget(renderer) : null; |
| +добавлено | this.lens = off('lens') ? null : new Lens(renderer); |
| +добавлено | |
| +добавлено | const self = this; |
| +добавлено | this.fx = { |
| +добавлено | renderer, |
| +добавлено | camera, |
| +добавлено | scenes: { opaque: this.opaque, refract: this.refract, lines: this.lines, fx: this.fxScene }, |
| +добавлено | U, |
| +добавлено | Q, |
| +добавлено | ARENA, |
| +добавлено | sky, |
| +добавлено | arena, |
| +добавлено | ground: this.ground, |
| +добавлено | particles: this.particles, |
| +добавлено | trails: this.trails, |
| +добавлено | bolts: this.bolts, |
| +добавлено | volumes: this.volumes, |
| +добавлено | shocks: this.shocks, |
| +добавлено | spikes: this.spikes, |
| +добавлено | sigils: this.sigils, |
| +добавлено | metaballs: this.metaballs, |
| +добавлено | lights, |
| +добавлено | forces, |
| +добавлено | impacts, |
| +добавлено | occluders, |
| +добавлено | rig: this.rig, |
| +добавлено | post, |
| +добавлено | lens: this.lens, |
| +добавлено | fxTarget: this.fxTarget, |
| +добавлено | AnalyticRibbons, |
| +добавлено | dummies: [] as SpellTarget[], |
| +добавлено | pool, |
| +добавлено | spells: {} as Record<string, unknown>, |
| +добавлено | reduced: matchMedia('(prefers-reduced-motion: reduce)').matches, |
| +добавлено | systems: [] as { update(dt: number, camera: THREE.Camera): void }[], |
| +добавлено | rand() { |
| +добавлено | self.seed = (Math.imul(self.seed, 1664525) + 1013904223) >>> 0; |
| +добавлено | return self.seed / 4294967296; |
| +добавлено | }, |
| +добавлено | flash(amount: number) { |
| +добавлено | post.params.flash = Math.min(2, Math.max(post.params.flash, amount)); |
| +добавлено | }, |
| +добавлено | groundAt: (x: number, z: number) => this.groundAt(x, z), |
| +добавлено | }; |
| +добавлено | this.fx.dummies = this.targets; |
| +добавлено | |
| +добавлено | // ── общие меши и регистрация умений (порядок как у автора) ───────────── |
| +добавлено | this.lines.add(this.bolts.cores, this.trails.lines, this.sigils.mesh); |
| +добавлено | this.opaque.add(this.spikes.opaque); |
| +добавлено | this.refract.add(this.spikes.refract, this.metaballs.group); |
| +добавлено | this.fxScene.add(this.bolts.glows, this.trails.fx, this.shocks.mesh, this.volumes.group); |
| +добавлено | |
| +добавлено | for (const s of SPELLS as any[]) { |
| +добавлено | s.defaults = { ...s.params }; |
| +добавлено | s.params = { ...s.params }; |
| +добавлено | for (const [k, def] of Object.entries(s.kinds ?? {})) { |
| +добавлено | this.particles.addKind(`${s.id}.${k}`, def as never); |
| +добавлено | } |
| +добавлено | this.fx.spells[s.id] = s; |
| +добавлено | } |
| +добавлено | // Заклинания создаются ЛЕНИВО: create() компилирует свои программы, и делать |
| +добавлено | // это для всех 39 сразу — значит заморозить первые кадры. Материализуем то, |
| +добавлено | // которое реально кастуют (ensureInst). |
| +добавлено | this.particles.build(); this.particles.build(); |
| +добавлено | if (this.particles.glow) this.lines.add(this.particles.glow); |
| +добавлено | if (this.particles.media) this.fxScene.add(this.particles.media); |
| +добавлено | if (this.particles.debris?.length) this.opaque.add(...this.particles.debris); |
| +добавлено | this.refract.add(this.lines); |
| +добавлено | |
| +добавлено | this.casts = new Casts(this.fx); |
| +добавлено | this.fx.casts = this.casts; |
| +добавлено | |
| +добавлено | // Фоновый прогрев (приём автора): первый каст каждого заклинания компилирует |
| +добавлено | // его программы, и без прогрева это фриз на кадр. Греем по одному в секунду. |
| +добавлено | this.warmQueue = [...(SPELLS as any[])]; |
| +добавлено | |
| +добавлено | // постоянный ветер: нулевой слот сил |
| +добавлено | const wind = forces.acquire(); |
| +добавлено | Object.assign(wind, { type: 0, p: [0, 0.35, 0.25, 0] }); |
| +добавлено | wind.dir.set(1, 0, 0.3).normalize(); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Мелководье рядом с точкой — для «бассейна» водных заклинаний. */ |
| +добавлено | private findShallowNear(center: THREE.Vector3, reach: number): { x: number; z: number } | null { |
| +добавлено | for (let r = 12; r < reach; r += 6) { |
| +добавлено | for (let a = 0; a < Math.PI * 2; a += 0.35) { |
| +добавлено | const x = center.x + Math.cos(a) * r; |
| +добавлено | const z = center.z + Math.sin(a) * r; |
| +добавлено | const h = this.deps.groundHeight(x, z); |
| +добавлено | if (h > -3 && h < -0.4) return { x, z }; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | return null; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // ── цели: наши враги в виде манекенов автора ──────────────────────────── |
| +добавлено | |
| +добавлено | setTargets(list: SpellTarget[]): void { |
| +добавлено | this.targets = list; |
| +добавлено | this.fx.dummies = list; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // ── кадр ──────────────────────────────────────────────────────────────── |
| +добавлено | |
| +добавлено | setSun(dir: THREE.Vector3, color: THREE.Vector3, ambient: THREE.Vector3): void { |
| +добавлено | U.uSunDir.value.copy(dir); |
| +добавлено | U.uSunColor.value.copy(color); |
| +добавлено | U.uAmbient.value.copy(ambient); |
| +добавлено | } |
| +добавлено | |
| +добавлено | setTargets2(w: number, h: number, depth: THREE.Texture, color: THREE.Texture, near: number, far: number): void { |
| +добавлено | (U as any).uSceneDepth.value = depth; |
| +добавлено | (U as any).uSceneColor.value = color; |
| +добавлено | U.uResolution.value.set(w, h); |
| +добавлено | U.uNearFar.value.set(near, far); |
| +добавлено | this.fxTarget?.setSize(w, h, Q.fxScale); |
| +добавлено | this.lens?.setSize?.(w, h); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Прогреть одно заклинание: создать и скомпилировать его программы. */ |
| +добавлено | private warmNext(): void { |
| +добавлено | if (this.warming) return; |
| +добавлено | const s = this.warmQueue.shift(); |
| +добавлено | if (!s) return; |
| +добавлено | this.warming = true; |
| +добавлено | try { |
| +добавлено | this.ensureInst(s); |
| +добавлено | const r = this.deps.renderer as unknown as { |
| +добавлено | compileAsync?: (o: THREE.Object3D, c: THREE.Camera, sc: THREE.Scene) => Promise<unknown>; |
| +добавлено | }; |
| +добавлено | const jobs: Promise<unknown>[] = []; |
| +добавлено | if (r.compileAsync) { |
| +добавлено | for (const sc of [this.opaque, this.refract, this.lines, this.fxScene]) { |
| +добавлено | jobs.push(r.compileAsync(sc, this.deps.camera, sc).catch(() => undefined)); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | Promise.all(jobs).finally(() => { |
| +добавлено | this.warming = false; |
| +добавлено | }); |
| +добавлено | } catch { |
| +добавлено | this.warming = false; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Поставить стихию в начало очереди прогрева (её кастуют сейчас). */ |
| +добавлено | prioritize(spells: unknown[]): void { |
| +добавлено | const set = new Set(spells); |
| +добавлено | this.warmQueue.sort((a, b) => Number(set.has(b)) - Number(set.has(a))); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Симуляция эффектов — до отрисовки. Порядок как в их renderFrame. */ |
| +добавлено | update(dt: number, camera: THREE.Camera): void { |
| +добавлено | this.simTime += dt; |
| +добавлено | // прогрев: не чаще одного заклинания в секунду, чтобы не отбирать кадр |
| +добавлено | this.warmAt += dt; |
| +добавлено | if (this.warmAt > 1 && this.warmQueue.length) { |
| +добавлено | this.warmAt = 0; |
| +добавлено | this.warmNext(); |
| +добавлено | } |
| +добавлено | U.uTime.value = this.simTime; |
| +добавлено | U.uDt.value = dt; |
| +добавлено | U.uFrame.value = (U.uFrame.value as number) + 1; |
| +добавлено | |
| +добавлено | this.casts.update(dt); |
| +добавлено | for (const s of SPELLS as any[]) s.inst?.tick?.(dt); |
| +добавлено | this.spikes.update(dt); // пишет капсулы-окклюдеры, поэтому до packWorld |
| +добавлено | this.sigils.update(); |
| +добавлено | packWorld(dt, { maxLights: Q.maxLights, maxShadowed: Q.shadowLights }); |
| +добавлено | |
| +добавлено | this.particles.update(dt, this.simTime); |
| +добавлено | this.updateProbes(); |
| +добавлено | this.ground.update(dt); |
| +добавлено | this.trails.update(dt); |
| +добавлено | this.bolts.update(); |
| +добавлено | this.volumes.update(camera); |
| +добавлено | this.shocks.update(dt); |
| +добавлено | this.metaballs.update(); |
| +добавлено | for (const sys of this.fx.systems) sys.update(dt, camera); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** |
| +добавлено | * Композит эффектов поверх уже отрисованной сцены. |
| +добавлено | * Возвращает HDR-текстуру, которую дальше берёт постобработка. |
| +добавлено | */ |
| +добавлено | composite(sceneTex: THREE.Texture): THREE.Texture { |
| +добавлено | return this.fxTarget ? this.fxTarget.render(this.fxScene, this.deps.camera, sceneTex, null, null) : sceneTex; |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** |
| +добавлено | * Камера-риг автора: затухание тряски и hitstop + наложение на камеру. |
| +добавлено | * Вызывать после того, как контроллер игрока выставил камеру, и до отрисовки — |
| +добавлено | * тогда тряска живёт один кадр и не накапливается (следующий кадр её сбросит). |
| +добавлено | */ |
| +добавлено | applyRig(camera: THREE.Camera, dt: number): void { |
| +добавлено | this.rig.apply(camera, dt); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // ── прицеливание по земле (как в их probes) ───────────────────────────── |
| +добавлено | |
| +добавлено | private groundAt(x: number, z: number): Float32Array | null { |
| +добавлено | let best = -1; |
| +добавлено | let bd = 1; |
| +добавлено | for (let i = 0; i < Math.min(this.probeReadN, this.ground.probeCount); i++) { |
| +добавлено | const d = Math.hypot(this.probeXZ[i].x - x, this.probeXZ[i].y - z); |
| +добавлено | if (d < bd) { |
| +добавлено | bd = d; |
| +добавлено | best = i; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | if (best < 0) return null; |
| +добавлено | for (let k = 0; k < 8; k++) this.probeOut[k] = this.ground.probes[best * 8 + k]; |
| +добавлено | return this.probeOut; |
| +добавлено | } |
| +добавлено | |
| +добавлено | private updateProbes(): void { |
| +добавлено | this.probeReadN = this.probeN; |
| +добавлено | for (let i = 0; i < this.probeN; i++) { |
| +добавлено | this.probeXZ[i].set(this.probePts[i][0], this.probePts[i][1]); |
| +добавлено | } |
| +добавлено | this.probeN = 0; |
| +добавлено | for (const d of this.targets) { |
| +добавлено | if (this.probeN >= 16) break; |
| +добавлено | this.probePts[this.probeN][0] = d.x; |
| +добавлено | this.probePts[this.probeN][1] = d.z; |
| +добавлено | this.probeN++; |
| +добавлено | } |
| +добавлено | for (const c of this.casts.list) { |
| +добавлено | if (!c.alive || this.probeN >= 16) continue; |
| +добавлено | this.probePts[this.probeN][0] = c.to.x; |
| +добавлено | this.probePts[this.probeN][1] = c.to.z; |
| +добавлено | this.probeN++; |
| +добавлено | } |
| +добавлено | this.probeList.length = 0; |
| +добавлено | for (let i = 0; i < this.probeN; i++) this.probeList.push(this.probePts[i]); |
| +добавлено | this.ground.setProbes(this.probeList); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // ── каст ──────────────────────────────────────────────────────────────── |
| +добавлено | |
| +добавлено | /** Стихии автора в их порядке (с клавишами 1…0, H). */ |
| +добавлено | get elements(): { id: string; name: string; hue: string; key: string }[] { |
| +добавлено | return ELEMENTS as { id: string; name: string; hue: string; key: string }[]; |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Сколько всего форм у автора. */ |
| +добавлено | get totalForms(): number { |
| +добавлено | return (SPELLS as any[]).reduce((n, s) => n + Math.max(1, s.forms?.length ?? 0), 0); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Список доступных форм умений выбранного элемента. */ |
| +добавлено | formsOf(element: string): { key: string; name: string; hue: string; spell: any; form: string }[] { |
| +добавлено | return (SPELLS as any[]) |
| +добавлено | .filter((s) => s.element === element) |
| +добавлено | .flatMap((s) => |
| +добавлено | (s.forms?.length ? s.forms : [s.name]).map((form: string) => ({ |
| +добавлено | key: `${s.id}:${form}`, |
| +добавлено | name: s.forms?.length ? form : s.name, |
| +добавлено | hue: s.hue, |
| +добавлено | spell: s, |
| +добавлено | form: s.forms?.length ? form : '', |
| +добавлено | })), |
| +добавлено | ); |
| +добавлено | } |
| +добавлено | |
| +добавлено | cast(spell: any, to: THREE.Vector3, form = '', target = -1, held = true): void { |
| +добавлено | this.ensureInst(spell); |
| +добавлено | // held: у автора каст каналируется удержанием («hold for channelled |
| +добавлено | // spells»). Без этого лучи и щиты обрывались сразу после начала. |
| +добавлено | this.casts.cast(spell, to, { form, target, held, from: this.deps.camera.position.clone() }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Самый свежий живой каст — для строки отладки в интерфейсе. */ |
| +добавлено | activeCast(): { spell: unknown; phase: string; t: number } | null { |
| +добавлено | return this.casts.active(); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Отпустить удержание: каналируемое заклинание доводится до конца. */ |
| +добавлено | releaseHeld(): void { |
| +добавлено | this.casts.releaseHeld(); |
| +добавлено | } |
| +добавлено | |
| +добавлено | /** Создать заклинание при первом касте и сразу спрятать его холостые меши. */ |
| +добавлено | private ensureInst(s: any): void { |
| +добавлено | if (s.inst) return; |
| +добавлено | const before = new Set<unknown>(); |
| +добавлено | for (const sc of [this.opaque, this.refract, this.lines, this.fxScene]) { |
| +добавлено | sc.traverse((o: THREE.Object3D) => before.add(o)); |
| +добавлено | } |
| +добавлено | s.inst = s.create(this.fx); |
| +добавлено | for (const sc of [this.opaque, this.refract, this.lines, this.fxScene]) { |
| +добавлено | sc.traverse((o: THREE.Object3D) => { |
| +добавлено | if (!before.has(o)) (o as THREE.Object3D).visible = false; |
| +добавлено | }); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | } |
| +добавлено | MIT License |
| +добавлено | |
| +добавлено | Copyright (c) 2026 Humpalumps |
| +добавлено | |
| +добавлено | Permission is hereby granted, free of charge, to any person obtaining a copy |
| +добавлено | of this software and associated documentation files (the "Software"), to deal |
| +добавлено | in the Software without restriction, including without limitation the rights |
| +добавлено | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| +добавлено | copies of the Software, and to permit persons to whom the Software is |
| +добавлено | furnished to do so, subject to the following conditions: |
| +добавлено | |
| +добавлено | The above copyright notice and this permission notice shall be included in all |
| +добавлено | copies or substantial portions of the Software. |
| +добавлено | |
| +добавлено | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| +добавлено | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| +добавлено | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| +добавлено | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| +добавлено | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| +добавлено | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| +добавлено | SOFTWARE. |
| +добавлено | # Third-party notices |
| +добавлено | |
| +добавлено | Ultra Elements is MIT-licensed (see `LICENSE`). It adapts code from the projects below, all under the MIT License. Their copyright lines are listed here, and the full MIT text is at the end of this file. The papers and talks credited in source comments, such as Hillaire, Bruneton, Karis, Lagarde, Wyman–Sloan–Shirley, Bridson, Schneider, Jimenez, Eiserloh and James–von Tunzelmann–Franklin–Thorne, are references for techniques that were implemented from scratch. They are not copied code. |
| +добавлено | |
| +добавлено | ## three.js |
| +добавлено | https://github.com/mrdoob/three.js. Copyright © 2010–2026 three.js authors. |
| +добавлено | |
| +добавлено | A runtime dependency. Also adapted: |
| +добавлено | - `src/engine/PostFX.js` reproduces the math of three's `AgXToneMapping` shader chunk so it can bake it into a LUT, and its `NeutralToneMapping` chunk (Khronos PBR Neutral) |
| +добавлено | - the cloud layer of three's `Sky.js` (`src/scene/sky.js`) |
| +добавлено | - the mirrored-camera and oblique-clip-plane math of three's `Reflector` (`src/engine/PlanarReflection.js`, `src/spells/void/portal.js`) |
| +добавлено | |
| +добавлено | ## lil-gui |
| +добавлено | https://github.com/georgealways/lil-gui. Copyright (c) 2019 George Michael Brower. |
| +добавлено | |
| +добавлено | A runtime dependency (the settings panel), bundled into the built site. |
| +добавлено | |
| +добавлено | ## Ultra Water |
| +добавлено | https://github.com/Humpalumps/Ultra-Water. Copyright (c) 2026 Humpalumps. |
| +добавлено | |
| +добавлено | Adapted: |
| +добавлено | - the sky and atmosphere (`src/scene/sky.js`, `src/scene/atmosphere.js`) |
| +добавлено | - scene-colour refraction with depth validation (`src/vfx/Refraction.js`, `src/scene/pool.js`, `src/vfx/Spikes.js`) |
| +добавлено | - the water presets and optics in `src/vfx/Metaballs.js` and `src/spells/water.js` |
| +добавлено | - the water surface shading and the baked foam texture used by the particle fluid (`src/vfx/ParticleFluid.js`, `src/vfx/ParticleFluid.glsl.js`) |
| +добавлено | - the ocean surface model, deep-water colour, shore foam and spray puffs on Tsunami's wave (`src/spells/water/tsunami.js`, `src/spells/water/tsunami.glsl.js`) |
| +добавлено | - the async probe readback (`src/vfx/GroundField.js`) |
| +добавлено | - the fence-synced benchmark and the uncapped frame loop (`src/main.js`) |
| +добавлено | |
| +добавлено | ## WebGL Water (Evan Wallace) |
| +добавлено | https://madebyevan.com/webgl-water. Copyright (c) 2011 Evan Wallace. |
| +добавлено | |
| +добавлено | The pool's ripple height field: the height-plus-velocity update, the four-neighbour Laplacian and the cosine drops, in `src/scene/pool.js`. |
| +добавлено | |
| +добавлено | ## Hash without Sine (Dave Hoskins) |
| +добавлено | https://www.shadertoy.com/view/4djSRW. Copyright (c) 2014 David Hoskins. |
| +добавлено | |
| +добавлено | The `hash11`, `hash12`, `hash21`, `hash31` and `hash33` functions in `src/vfx/common.js` and `src/engine/PostFX.js`. |
| +добавлено | |
| +добавлено | ## Inigo Quilez |
| +добавлено | https://iquilezles.org. Copyright (c) Inigo Quilez. |
| +добавлено | |
| +добавлено | - The ray–capsule intersection in `src/vfx/Volumes.js`. |
| +добавлено | - The polynomial smooth minimum in `src/vfx/Metaballs.js`. |
| +добавлено | - The Voronoi edge distance in `src/vfx/GroundField.js`. |
| +добавлено | |
| +добавлено | --- |
| +добавлено | |
| +добавлено | ## MIT License (applies to each project above) |
| +добавлено | |
| +добавлено | ``` |
| +добавлено | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
| +добавлено | associated documentation files (the "Software"), to deal in the Software without restriction, |
| +добавлено | including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| +добавлено | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| +добавлено | furnished to do so, subject to the following conditions: |
| +добавлено | |
| +добавлено | The above copyright notice and this permission notice shall be included in all copies or |
| +добавлено | substantial portions of the Software. |
| +добавлено | |
| +добавлено | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
| +добавлено | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| +добавлено | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES |
| +добавлено | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| +добавлено | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| +добавлено | ``` |
| +добавлено | import * as THREE from 'three'; |
| +добавлено | |
| +добавлено | // Camera game feel, all of it on the camera rather than in post: |
| +добавлено | // - trauma shake (Eiserloh, "Juicing Your Cameras With Math", GDC 2016): offsets = trauma^2 x Perlin |
| +добавлено | // noise, so small hits barely move it and big ones slam. Each source keeps its own frequency |
| +добавлено | // (earth rumbles at ~8 Hz, lightning cracks at ~30 Hz) and they mix weighted by trauma. |
| +добавлено | // - FOV punch and hitstop (Nijman, "The Art of Screenshake", 2013). |
| +добавлено | // apply() goes right after OrbitControls.update() and restore() right before the next one, so the |
| +добавлено | // controls never see the offsets and can't accumulate them. No allocations per frame. |
| +добавлено | |
| +добавлено | const DEG = Math.PI / 180; |
| +добавлено | const YAW = 2 * DEG, PITCH = 2 * DEG, ROLL = 3 * DEG, MOVE = 0.06; // at trauma 1 |
| +добавлено | const SOURCES = 4, QUEUE = 8; |
| +добавлено | |
| +добавлено | // 1D gradient noise in [-1, 1] (hashed gradients on the integer lattice, quintic fade) |
| +добавлено | function grad(i) { |
| +добавлено | i = Math.imul(i ^ (i >>> 16), 0x45d9f3b); |
| +добавлено | i = Math.imul(i ^ (i >>> 16), 0x45d9f3b); |
| +добавлено | return (((i ^ (i >>> 16)) >>> 0) / 2147483648) - 1; |
| +добавлено | } |
| +добавлено | function perlin(x, seed) { |
| +добавлено | const i = Math.floor(x), f = x - i, s = seed * 1013; |
| +добавлено | const a = grad(i + s) * f, b = grad(i + 1 + s) * (f - 1); |
| +добавлено | return 2 * (a + (b - a) * f * f * f * (f * (f * 6 - 15) + 10)); |
| +добавлено | } |
| +добавлено | |
| +добавлено | const _q = new THREE.Quaternion(), _e = new THREE.Euler(), _v = new THREE.Vector3(); |
| +добавлено | |
| +добавлено | export class CameraRig { |
| +добавлено | reduced = false; // "Reduce flashes & shake": shake x0.25, no hitstop, no punch |
| +добавлено | amount = 1; // shake multiplier (GUI) |
| +добавлено | decay = 1.5; // trauma lost per second |
| +добавлено | |
| +добавлено | constructor() { |
| +добавлено | this._src = Array.from({ length: SOURCES }, (_, i) => ({ trauma: 0, freq: 15, phase: 0, seed: i * 6 + 1 })); |
| +добавлено | this._queue = Array.from({ length: QUEUE }, () => ({ t: 0, trauma: 0, freq: 15 })); |
| +добавлено | this._stop = 0; // hitstop seconds left |
| +добавлено | this._punch = { deg: 0, t: 1, dur: 1 }; |
| +добавлено | this._off = new THREE.Vector3(); // what apply() added, for restore() |
| +добавлено | this._rot = new THREE.Quaternion(); |
| +добавлено | this._fov = 0; |
| +добавлено | this._applied = false; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // trauma 0..1 (it adds up and clamps); delay in seconds (thunder: distance / 343) |
| +добавлено | shake(trauma, freqHz = 15, delay = 0) { |
| +добавлено | if (!(trauma > 0)) return; |
| +добавлено | if (delay > 0) { |
| +добавлено | let slot = this._queue[0]; |
| +добавлено | for (const q of this._queue) if (q.t <= 0) { slot = q; break; } else if (q.t > slot.t) slot = q; // full: drop the latest |
| +добавлено | slot.t = delay; slot.trauma = trauma; slot.freq = freqHz; |
| +добавлено | return; |
| +добавлено | } |
| +добавлено | // same-ish frequency: same source, trauma adds; else a free slot, else the weakest one |
| +добавлено | let slot = null, weakest = this._src[0]; |
| +добавлено | for (const s of this._src) { |
| +добавлено | if (s.trauma > 0 && Math.abs(s.freq - freqHz) < 0.2 * freqHz) { slot = s; break; } |
| +добавлено | if (s.trauma < weakest.trauma) weakest = s; |
| +добавлено | } |
| +добавлено | if (!slot) { slot = weakest; slot.trauma = 0; slot.freq = freqHz; } |
| +добавлено | slot.trauma = Math.min(1, slot.trauma + trauma); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // FOV kick: +deg over a frame, then eases back over the rest of `duration` |
| +добавлено | punch(deg = 3, duration = 0.08) { |
| +добавлено | if (this.reduced) return; |
| +добавлено | const p = this._punch; |
| +добавлено | if (p.t < p.dur && Math.abs(p.deg) * (1 - p.t / p.dur) > Math.abs(deg)) return; // a bigger one is still running |
| +добавлено | p.deg = deg; p.t = 0; p.dur = Math.max(duration, 1e-3); |
| +добавлено | } |
| +добавлено | |
| +добавлено | hitstop(seconds) { |
| +добавлено | if (!this.reduced) this._stop = Math.max(this._stop, seconds); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // main multiplies the simulation dt by this |
| +добавлено | get timeScale() { return this._stop > 0 && !this.reduced ? 0.05 : 1; } |
| +добавлено | |
| +добавлено | // dt: real (unscaled) seconds; the shake keeps going through hitstop |
| +добавлено | apply(camera, dt) { |
| +добавлено | this.restore(camera); // in case restore() was skipped |
| +добавлено | dt = dt > 0 ? Math.min(dt, 0.1) : 0; |
| +добавлено | for (const q of this._queue) if (q.t > 0 && (q.t -= dt) <= 0) this.shake(q.trauma, q.freq); |
| +добавлено | this._stop = Math.max(0, this._stop - dt); |
| +добавлено | |
| +добавлено | let total = 0, yaw = 0, pitch = 0, roll = 0, x = 0, y = 0, z = 0; |
| +добавлено | for (const s of this._src) { |
| +добавлено | if (s.trauma <= 0) continue; |
| +добавлено | s.phase = (s.phase + s.freq * dt) % 65536; |
| +добавлено | const w = s.trauma, t = s.phase; |
| +добавлено | total += w; |
| +добавлено | yaw += w * perlin(t, s.seed); pitch += w * perlin(t, s.seed + 1); roll += w * perlin(t, s.seed + 2); |
| +добавлено | x += w * perlin(t, s.seed + 3); y += w * perlin(t, s.seed + 4); z += w * perlin(t, s.seed + 5); |
| +добавлено | s.trauma = Math.max(0, s.trauma - this.decay * dt); |
| +добавлено | } |
| +добавлено | |
| +добавлено | this._off.set(0, 0, 0); |
| +добавлено | this._rot.identity(); |
| +добавлено | if (total > 0) { |
| +добавлено | const tr = Math.min(total, 1), k = tr * tr * this.amount * (this.reduced ? 0.25 : 1) / total; |
| +добавлено | this._rot.setFromEuler(_e.set(pitch * k * PITCH, yaw * k * YAW, roll * k * ROLL, 'YXZ')); |
| +добавлено | camera.quaternion.multiply(this._rot); |
| +добавлено | this._off.set(x, y, z).multiplyScalar(k * MOVE).applyQuaternion(camera.quaternion); |
| +добавлено | camera.position.add(this._off); |
| +добавлено | } |
| +добавлено | |
| +добавлено | const p = this._punch; |
| +добавлено | this._fov = 0; |
| +добавлено | if (p.t < p.dur && !this.reduced) { |
| +добавлено | const u = p.t / p.dur; |
| +добавлено | this._fov = p.deg * (u < 0.2 ? u / 0.2 : ((1 - u) / 0.8) ** 2); |
| +добавлено | p.t += dt; |
| +добавлено | } |
| +добавлено | if (this._fov !== 0) { camera.fov += this._fov; camera.updateProjectionMatrix(); } |
| +добавлено | this._applied = true; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // takes back exactly what apply() added (subtracting, so camera jumps made in between survive) |
| +добавлено | restore(camera) { |
| +добавлено | if (!this._applied) return; |
| +добавлено | this._applied = false; |
| +добавлено | camera.position.sub(this._off); |
| +добавлено | camera.quaternion.multiply(_q.copy(this._rot).invert()); |
| +добавлено | if (this._fov !== 0) { camera.fov -= this._fov; camera.updateProjectionMatrix(); } |
| +добавлено | } |
| +добавлено | } |
| +добавлено | import * as THREE from 'three'; |
| +добавлено | |
| +добавлено | // One big triangle covering the viewport; shared by every fullscreen pass. |
| +добавлено | const geometry = new THREE.BufferGeometry(); |
| +добавлено | geometry.setAttribute('position', new THREE.Float32BufferAttribute([-1, -1, 0, 3, -1, 0, -1, 3, 0], 3)); |
| +добавлено | const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1); |
| +добавлено | |
| +добавлено | export const FULLSCREEN_VERT = /* glsl */` |
| +добавлено | in vec3 position; |
| +добавлено | out vec2 vUv; |
| +добавлено | void main() { |
| +добавлено | vUv = position.xy * 0.5 + 0.5; |
| +добавлено | gl_Position = vec4(position.xy, 0.0, 1.0); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | export function rawPass(fragmentShader, uniforms = {}, extra = {}) { |
| +добавлено | return new THREE.RawShaderMaterial({ |
| +добавлено | glslVersion: THREE.GLSL3, |
| +добавлено | vertexShader: FULLSCREEN_VERT, |
| +добавлено | fragmentShader, |
| +добавлено | uniforms, |
| +добавлено | depthTest: false, |
| +добавлено | depthWrite: false, |
| +добавлено | ...extra, |
| +добавлено | }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | export class FullscreenQuad { |
| +добавлено | constructor(material) { |
| +добавлено | this.mesh = new THREE.Mesh(geometry, material); |
| +добавлено | this.mesh.frustumCulled = false; |
| +добавлено | } |
| +добавлено | get material() { return this.mesh.material; } |
| +добавлено | set material(m) { this.mesh.material = m; } |
| +добавлено | render(renderer, target) { |
| +добавлено | renderer.setRenderTarget(target); |
| +добавлено | renderer.render(this.mesh, camera); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // GPU timings via EXT_disjoint_timer_query_webgl2. Queries can't nest, so each |
| +добавлено | // labelled section is begun/ended back-to-back; results arrive a few frames late. |
| +добавлено | export class GpuTimer { |
| +добавлено | constructor(gl) { |
| +добавлено | this.gl = gl; |
| +добавлено | this.ext = gl.getExtension('EXT_disjoint_timer_query_webgl2'); |
| +добавлено | this.pending = []; |
| +добавлено | this.current = null; |
| +добавлено | this.frame = null; |
| +добавлено | this.ms = {}; // smoothed ms per label |
| +добавлено | this.total = 0; // smoothed sum of all labels |
| +добавлено | } |
| +добавлено | |
| +добавлено | get available() { return !!this.ext; } |
| +добавлено | |
| +добавлено | beginFrame() { if (this.ext) this.frame = []; } |
| +добавлено | |
| +добавлено | begin(label) { |
| +добавлено | if (!this.ext || !this.frame) return; |
| +добавлено | this.end(); |
| +добавлено | const q = this.gl.createQuery(); |
| +добавлено | this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT, q); |
| +добавлено | this.current = { label, q }; |
| +добавлено | } |
| +добавлено | |
| +добавлено | end() { |
| +добавлено | if (!this.current) return; |
| +добавлено | this.gl.endQuery(this.ext.TIME_ELAPSED_EXT); |
| +добавлено | this.frame.push(this.current); |
| +добавлено | this.current = null; |
| +добавлено | } |
| +добавлено | |
| +добавлено | endFrame() { |
| +добавлено | if (!this.ext || !this.frame) return; |
| +добавлено | this.end(); |
| +добавлено | this.pending.push(this.frame); |
| +добавлено | this.frame = null; |
| +добавлено | if (this.keep) return; // benchmark: keep everything for drain() |
| +добавлено | const gl = this.gl; |
| +добавлено | const disjoint = gl.getParameter(this.ext.GPU_DISJOINT_EXT); |
| +добавлено | while (this.pending.length) { |
| +добавлено | const f = this.pending[0]; |
| +добавлено | if (!gl.getQueryParameter(f[f.length - 1].q, gl.QUERY_RESULT_AVAILABLE)) break; |
| +добавлено | this.pending.shift(); |
| +добавлено | let sum = 0; |
| +добавлено | for (const { label, q } of f) { |
| +добавлено | const ms = gl.getQueryParameter(q, gl.QUERY_RESULT) / 1e6; |
| +добавлено | gl.deleteQuery(q); |
| +добавлено | if (disjoint) continue; |
| +добавлено | this.ms[label] = this.ms[label] === undefined ? ms : this.ms[label] * 0.95 + ms * 0.05; |
| +добавлено | sum += ms; |
| +добавлено | } |
| +добавлено | if (disjoint) continue; |
| +добавлено | this.total = this.total ? this.total * 0.95 + sum * 0.05 : sum; |
| +добавлено | for (const k in this.ms) if (!f.some((x) => x.label === k)) delete this.ms[k]; // a pass that stopped running (lens) leaves the HUD |
| +добавлено | } |
| +добавлено | // ponytail: drop backlog if the GPU never reports (tab hidden etc.) |
| +добавлено | if (this.pending.length > 8) this.pending.splice(0, this.pending.length - 8).flat().forEach(({ q }) => gl.deleteQuery(q)); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // read every pending query (call after a GPU fence) -> mean ms per label per frame; peak |
| +добавлено | // holds each label's worst frame and peak.total the worst whole frame |
| +добавлено | drain() { |
| +добавлено | const gl = this.gl, sums = {}, peak = { total: 0 }; |
| +добавлено | const frames = this.pending.length; |
| +добавлено | for (const f of this.pending) { |
| +добавлено | let frameSum = 0; |
| +добавлено | for (const { label, q } of f) { |
| +добавлено | if (gl.getQueryParameter(q, gl.QUERY_RESULT_AVAILABLE)) { |
| +добавлено | const ms = gl.getQueryParameter(q, gl.QUERY_RESULT) / 1e6; |
| +добавлено | sums[label] = (sums[label] || 0) + ms; |
| +добавлено | peak[label] = Math.max(peak[label] || 0, ms); |
| +добавлено | frameSum += ms; |
| +добавлено | } |
| +добавлено | gl.deleteQuery(q); |
| +добавлено | } |
| +добавлено | peak.total = Math.max(peak.total, frameSum); |
| +добавлено | } |
| +добавлено | this.pending = []; |
| +добавлено | for (const k in sums) sums[k] /= frames; |
| +добавлено | this.peak = peak; |
| +добавлено | return sums; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // Quality tiers. Spells author counts at High; emission is multiplied by Q.emission (tier x auto). |
| +добавлено | // Anything here that changes a shader define or a target size only changes on an explicit tier |
| +добавлено | // switch (main.js shows "Recompiling…"); the auto ladder only touches uniforms and sizes. |
| +добавлено | export const TIERS = { |
| +добавлено | low: { resolution: 0.6, msaa: 2, fxScale: 0.5, particles: [256, 128], debris: 512, volumeSteps: 12, noiseSize: 64, groundSize: 512, reflections: false, reflectionScale: 0.35, reflectFx: false, maxLights: 8, shadowLights: 0, bloomLevels: 3, emission: 0.35, fluidIterations: 6 }, |
| +добавлено | medium: { resolution: 0.85, msaa: 4, fxScale: 0.5, particles: [512, 256], debris: 2048, volumeSteps: 16, noiseSize: 128, groundSize: 1024, reflections: false, reflectionScale: 0.35, reflectFx: false, maxLights: 16, shadowLights: 1, bloomLevels: 6, emission: 0.7 }, |
| +добавлено | high: { resolution: 1, msaa: 4, fxScale: 0.5, particles: [512, 512], debris: 4096, volumeSteps: 24, noiseSize: 128, groundSize: 1024, reflections: false, reflectionScale: 0.35, reflectFx: true, maxLights: 16, shadowLights: 4, bloomLevels: 6, emission: 1 }, |
| +добавлено | ultra: { resolution: 1, msaa: 4, fxScale: 1, particles: [1024, 1024], debris: 8192, volumeSteps: 32, noiseSize: 128, groundSize: 2048, reflections: false, reflectionScale: 0.5, reflectFx: true, maxLights: 16, shadowLights: 4, bloomLevels: 6, emission: 1.6, fluid: true, anamorphic: true }, |
| +добавлено | }; |
| +добавлено | |
| +добавлено | const args = new URLSearchParams(location.search); |
| +добавлено | export const mobile = args.has('mobile') || (!args.has('desktop') && matchMedia('(pointer: coarse)').matches); |
| +добавлено | const asked = args.get('q'); |
| +добавлено | export const tierName = TIERS[asked] ? asked : mobile ? 'low' : 'high'; |
| +добавлено | |
| +добавлено | // live values; auto scales multiply on top (auto.emission, auto.steps) |
| +добавлено | export const Q = { tier: tierName, mobile, ...TIERS[tierName], autoResolution: mobile, auto: { emission: 1, steps: 1 } }; |
| +добавлено | import * as THREE from 'three'; |
| +добавлено | import { ARENA, U, WORLD_W, MAX_LIGHTS, MAX_IMPACTS, MAX_OCCLUDERS, COMMON_GLSL, NOISE_GLSL, WORLD_GLSL, LIGHTS_GLSL, GROUND_GLSL } from '../vfx/common.js'; |
| +добавлено | import { CRACK_SOURCES, FISSURE_A, FISSURE_B } from '../vfx/GroundField.js'; |
| +добавлено | |
| +добавлено | // Every lit arena surface (floor, stone, dummies) is one lean ShaderMaterial pipeline, so they all |
| +добавлено | // react to spells the same way and the idle arena stays cheap (the spells are the product): |
| +добавлено | // 1. state: impacts (spherical volume decals) + the ground field (full strength on the floor, |
| +добавлено | // creeping up the foot of stone) |
| +добавлено | // 2. the surface itself (slabs, stone, wood...): one or two noise taps |
| +добавлено | // 3. responses: char, wet, frost, heat glow, crack, acid foam, corruption veins, holy glow, |
| +добавлено | // electric crackle, all behind one branch on "anything there?" (most pixels skip it) |
| +добавлено | // 4. lighting: sun/moon GGX + Lambert with one hardware-PCF shadow tap, the sky cube for |
| +добавлено | // ambient and (roughness-blurred) reflections, spell lights with capsule shadows |
| +добавлено | // Nothing here changes a define after load: every variation is a uniform. |
| +добавлено | |
| +добавлено | // --- baked noise: 256^2 RGBA8, tileable, mipmapped --------------------------------------- |
| +добавлено | // r, g: value-noise fbm (two seeds), b: voronoi F2-F1 (0 on cell edges, 12 cells per tile; |
| +добавлено | // cracks, veins), a: fine fbm (grain, specks). Generated once in JS (~30 ms), no assets. |
| +добавлено | function hashi(x, y, s) { |
| +добавлено | let h = Math.imul(x, 374761393) + Math.imul(y, 668265263) + Math.imul(s, 1274126177) | 0; |
| +добавлено | h = Math.imul(h ^ (h >>> 13), 1274126177); |
| +добавлено | return ((h ^ (h >>> 16)) >>> 0) / 4294967296; |
| +добавлено | } |
| +добавлено | function bakeStoneNoise(N = 256) { |
| +добавлено | const data = new Uint8Array(N * N * 4); |
| +добавлено | const vnoise = (x, y, P, s) => { |
| +добавлено | const xi = Math.floor(x), yi = Math.floor(y), fx = x - xi, fy = y - yi; |
| +добавлено | const ux = fx * fx * (3 - 2 * fx), uy = fy * fy * (3 - 2 * fy); |
| +добавлено | const x0 = ((xi % P) + P) % P, y0 = ((yi % P) + P) % P, x1 = (x0 + 1) % P, y1 = (y0 + 1) % P; |
| +добавлено | const a = hashi(x0, y0, s), b = hashi(x1, y0, s), c = hashi(x0, y1, s), d = hashi(x1, y1, s); |
| +добавлено | return a + (b - a) * ux + (c - a) * uy + (a - b - c + d) * ux * uy; |
| +добавлено | }; |
| +добавлено | const fbm = (u, v, base, oct, s) => { |
| +добавлено | let sum = 0, amp = 0.5, norm = 0; |
| +добавлено | for (let o = 0; o < oct; o++) { const f = base << o; sum += amp * vnoise(u * f, v * f, f, s + o * 31); norm += amp; amp *= 0.5; } |
| +добавлено | return sum / norm; |
| +добавлено | }; |
| +добавлено | const C = 12, pts = []; |
| +добавлено | for (let j = 0; j < C; j++) for (let i = 0; i < C; i++) pts.push(i + 0.1 + 0.8 * hashi(i, j, 91), j + 0.1 + 0.8 * hashi(i, j, 92)); |
| +добавлено | for (let y = 0; y < N; y++) for (let x = 0; x < N; x++) { |
| +добавлено | const u = x / N, v = y / N, o = (y * N + x) * 4; |
| +добавлено | const cx = u * C, cy = v * C, ix = Math.floor(cx), iy = Math.floor(cy); |
| +добавлено | let f1 = 9, f2 = 9; |
| +добавлено | for (let dj = -1; dj <= 1; dj++) for (let di = -1; di <= 1; di++) { |
| +добавлено | const gi = ix + di, gj = iy + dj, wi = ((gi % C) + C) % C, wj = ((gj % C) + C) % C; |
| +добавлено | const px = pts[(wj * C + wi) * 2] + (gi - wi), py = pts[(wj * C + wi) * 2 + 1] + (gj - wj); |
| +добавлено | const d = Math.hypot(px - cx, py - cy); |
| +добавлено | if (d < f1) { f2 = f1; f1 = d; } else if (d < f2) f2 = d; |
| +добавлено | } |
| +добавлено | data[o] = fbm(u, v, 4, 5, 1) * 255; |
| +добавлено | data[o + 1] = fbm(u, v, 4, 5, 7) * 255; |
| +добавлено | data[o + 2] = Math.min(f2 - f1, 1) * 255; |
| +добавлено | data[o + 3] = fbm(u, v, 32, 2, 13) * 255; |
| +добавлено | } |
| +добавлено | const t = new THREE.DataTexture(data, N, N, THREE.RGBAFormat); |
| +добавлено | t.wrapS = t.wrapT = THREE.RepeatWrapping; |
| +добавлено | t.minFilter = THREE.LinearMipmapLinearFilter; |
| +добавлено | t.magFilter = THREE.LinearFilter; |
| +добавлено | t.generateMipmaps = true; |
| +добавлено | t.anisotropy = 2; // low-frequency taps: 8x bought ~0.02 ms of nothing at 3.3 MP |
| +добавлено | t.needsUpdate = true; |
| +добавлено | return t; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // Shared by every arena material (and the pool). uReflection / uReflMatrix / uReflDistort stay |
| +добавлено | // for main.js's API (planar reflections are off: the sky cube does the reflections). |
| +добавлено | export const arenaUniforms = { |
| +добавлено | uStoneNoise: { value: bakeStoneNoise() }, |
| +добавлено | uReflection: { value: null }, |
| +добавлено | uReflMatrix: { value: new THREE.Matrix4() }, |
| +добавлено | uReflDistort: { value: 0.35 }, |
| +добавлено | uRuneColor: { value: new THREE.Color(0.25, 0.85, 1.0).multiplyScalar(1.6) }, |
| +добавлено | uFocusColor: { value: new THREE.Color(1, 0.6, 0.25) }, // orb colour x intensity (pedestal runes) |
| +добавлено | // the sun's static shadow map (arena.js points these at sunLight.shadow) |
| +добавлено | uShadowMap: { value: null }, |
| +добавлено | uShadowMatrix: { value: new THREE.Matrix4() }, |
| +добавлено | uShadowOn: { value: 0 }, |
| +добавлено | // sky-cube reflections x this: a spell that hides the sky (a storm deck) dims what the floor mirrors. |
| +добавлено | // ponytail: one writer at a time (the last spell to tick wins); a per-spell min if two decks ever overlap |
| +добавлено | uEnvScale: { value: 1 }, |
| +добавлено | uCrackSrc: { value: CRACK_SOURCES }, // craters the floor's fractures radiate from (GroundField) |
| +добавлено | uFissA: { value: FISSURE_A }, uFissB: { value: FISSURE_B }, // hot fissure lines (GroundField) |
| +добавлено | }; |
| +добавлено | { // 1x1 transparent fallback |
| +добавлено | const t = new THREE.DataTexture(new Uint8Array(4), 1, 1); |
| +добавлено | t.needsUpdate = true; |
| +добавлено | arenaUniforms.uReflection.value = t; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // The world texture is RGBA32F, and a 32-bit-float RGBA fetch runs at a fraction of the normal |
| +добавлено | // rate: 16 lights x 2-3 texels per pixel cost more than the lighting maths. The same Float32Array |
| +добавлено | // rows are bound as uniform arrays instead (views of U.uWorld's data, so packWorld fills them |
| +добавлено | // with no copy); the loop index is the same for the whole warp, so each read is a constant-cache |
| +добавлено | // broadcast. Needs 192 fragment uniform vectors; on smaller GPUs it falls back to texel fetches. |
| +добавлено | const worldData = U.uWorld.value.image.data, ROW = WORLD_W * 4; |
| +добавлено | export const worldUniforms = { |
| +добавлено | uWL: { value: worldData.subarray(0, ROW) }, // lights |
| +добавлено | uWI: { value: worldData.subarray(2 * ROW, 3 * ROW) }, // impacts |
| +добавлено | uWO: { value: worldData.subarray(3 * ROW, 4 * ROW) }, // occluders |
| +добавлено | }; |
| +добавлено | let worldInUniforms = true; |
| +добавлено | export function configureWorldFetch(renderer) { worldInUniforms = renderer.capabilities.maxFragmentUniforms >= 448; } |
| +добавлено | export const worldDefines = () => (worldInUniforms ? { ARENA_WORLD_UNIFORMS: '' } : {}); |
| +добавлено | |
| +добавлено | const f = (x) => x.toFixed(4); |
| +добавлено | const P = ARENA.pool; |
| +добавлено | |
| +добавлено | // --- GLSL --------------------------------------------------------------------------------- |
| +добавлено | // needs COMMON_GLSL + WORLD_GLSL + LIGHTS_GLSL (the dummy ice shell and the pool use it too) |
| +добавлено | export const LIGHT_FN_GLSL = /* glsl */` |
| +добавлено | #ifdef ARENA_WORLD_UNIFORMS |
| +добавлено | uniform vec4 uWL[${WORLD_W}]; |
| +добавлено | uniform vec4 uWI[${WORLD_W}]; |
| +добавлено | uniform vec4 uWO[${WORLD_W}]; |
| +добавлено | #define WL(i) uWL[i] |
| +добавлено | #define WI(i) uWI[i] |
| +добавлено | #define WO(i) uWO[i] |
| +добавлено | #else |
| +добавлено | #define WL(i) worldTexel(0, i) |
| +добавлено | #define WI(i) worldTexel(2, i) |
| +добавлено | #define WO(i) worldTexel(3, i) |
| +добавлено | #endif |
| +добавлено | // All three loops below are split in two: a cheap pass sets one bit per item that can matter at |
| +добавлено | // this pixel, then the expensive body runs once per set bit. With the body behind a plain |
| +добавлено | // "if (culled) continue;" the D3D compiler (ANGLE) predicates it and every pixel paid for every |
| +добавлено | // light; a loop whose trip count is the bit count cannot be flattened. |
| +добавлено | #define NEXT_BIT(mask, i) { uint bit_ = mask & (~mask + 1u); mask ^= bit_; i = int(log2(float(bit_)) + 0.5); } |
| +добавлено | |
| +добавлено | // LIGHTS_GLSL's capsuleShadow, culled: an occluder only matters if its capsule (plus the widest |
| +добавлено | // penumbra) reaches the bounding sphere of the shadow ray; stops once fully shadowed. |
| +добавлено | float arenaCapsuleShadow(vec3 p, vec3 lp) { |
| +добавлено | vec3 dir = lp - p; |
| +добавлено | float len = length(dir); |
| +добавлено | p += dir * min(0.15 / max(len, 1e-3), 0.5); |
| +добавлено | vec3 c = 0.5 * (p + lp); |
| +добавлено | float R = 0.5 * length(lp - p) + 0.04 + 0.18 * len; |
| +добавлено | int n = int(uWorldCounts.w); |
| +добавлено | uint mask = 0u; |
| +добавлено | for (int i = 0; i < ${MAX_OCCLUDERS}; i++) { |
| +добавлено | if (i >= n) break; |
| +добавлено | vec4 a = WO(i * 2); |
| +добавлено | vec3 q = closestOnSegment(a.xyz, WO(i * 2 + 1).xyz, c) - c; |
| +добавлено | float reach = R + a.w; |
| +добавлено | if (dot(q, q) <= reach * reach) mask |= 1u << uint(i); |
| +добавлено | } |
| +добавлено | float vis = 1.0; |
| +добавлено | while (mask != 0u) { |
| +добавлено | int i; NEXT_BIT(mask, i) |
| +добавлено | vec4 a = WO(i * 2), b = WO(i * 2 + 1); |
| +добавлено | float s, d = segSegDist(p, lp, a.xyz, b.xyz, s); |
| +добавлено | float pen = 0.04 + 0.18 * s * len; |
| +добавлено | vis *= smoothstep(a.w - pen * 0.5, a.w + pen, d); |
| +добавлено | if (vis < 0.003) return 0.0; |
| +добавлено | } |
| +добавлено | return vis; |
| +добавлено | } |
| +добавлено | // A light hovering over the pedestal (the focus orb, a spell charging at the focus) throws the |
| +добавлено | // pedestal's shadow as a soft disc on the floor around its foot: analytic, so the orb light needs |
| +добавлено | // no capsule shadow (a capsule's round top would also shade far too wide a disc). |
| +добавлено | float pedestalShadow(vec3 p, vec3 lp) { |
| +добавлено | vec2 c = vec2(${f(ARENA.pedestal.pos.x)}, ${f(ARENA.pedestal.pos.z)}); |
| +добавлено | float hl = lp.y - p.y; |
| +добавлено | if (length(lp.xz - c) > 0.3 || hl < 1.2) return 1.0; |
| +добавлено | float d0 = 0.45 * hl / (hl - 1.15); // umbra edge: the ray grazing the capital's rim |
| +добавлено | return smoothstep(d0 * 0.8, d0 * 1.25, length(p.xz - c)); |
| +добавлено | } |
| +добавлено | // Spell lights (LIGHTS_GLSL's spellLightPBR, restructured for the hot path): lights are culled |
| +добавлено | // on their window (range) before any shadow or BRDF work; a surface facing away skips the capsule |
| +добавлено | // shadow, and the shadow is traced once (at the diffuse point) and shared with the line light's |
| +добавлено | // specular point. base: luminance of the pixel's other lighting; a light adding less than 4% of it |
| +добавлено | // skips its capsule shadow (invisible there, and a wide dim light shadow-tracing 20 occluders over |
| +добавлено | // the whole screen cost ~0.4 ms at 3.3 MP). The pool and the ice shell pass 0: always traced. |
| +добавлено | void arenaSpellLights(vec3 p, vec3 n, vec3 v, float rough, vec3 f0, vec3 diffColor, float base, out vec3 diffuse, out vec3 specular) { |
| +добавлено | diffuse = vec3(0.0); specular = vec3(0.0); |
| +добавлено | int count = int(uWorldCounts.x); |
| +добавлено | uint mask = 0u; |
| +добавлено | for (int i = 0; i < ${MAX_LIGHTS}; i++) { |
| +добавлено | if (i >= count) break; |
| +добавлено | vec4 la = WL(i * 4); |
| +добавлено | vec3 lp = WL(i * 4 + 1).a == 1.0 ? closestOnSegment(la.xyz, WL(i * 4 + 2).xyz, p) : la.xyz; |
| +добавлено | vec3 d = lp - p; |
| +добавлено | if (dot(d, d) < la.w * la.w) mask |= 1u << uint(i); |
| +добавлено | } |
| +добавлено | if (mask == 0u) return; |
| +добавлено | float a = max(rough * rough, 0.002); |
| +добавлено | float nv = max(dot(n, v), 1e-4); |
| +добавлено | vec3 r = reflect(-v, n); |
| +добавлено | while (mask != 0u) { |
| +добавлено | int i; NEXT_BIT(mask, i) |
| +добавлено | vec4 la = WL(i * 4), lb = WL(i * 4 + 1), lc = WL(i * 4 + 2); |
| +добавлено | int type = int(lb.a); |
| +добавлено | vec3 lp = type == 1 ? closestOnSegment(la.xyz, lc.xyz, p) : la.xyz; |
| +добавлено | vec3 d = lp - p; |
| +добавлено | float dist = length(d); |
| +добавлено | vec3 l = d / max(dist, 1e-4), ls = l; |
| +добавлено | float dists = dist; |
| +добавлено | if (type == 1) { vec3 sp = closestOnSegmentToRay(la.xyz, lc.xyz, p, r) - p; dists = length(sp); ls = sp / max(dists, 1e-4); } |
| +добавлено | float nl = dot(n, l), nls = dot(n, ls); |
| +добавлено | if (nl <= 0.0 && nls <= 0.0) continue; |
| +добавлено | vec3 col = lb.rgb; |
| +добавлено | if (type == 2) col *= lightCookie(SpellLight(la.xyz, la.w, lb.rgb, type, lc.xyz, lc.w, WL(i * 4 + 3)), p); |
| +добавлено | #ifdef ARENA_FLOOR |
| +добавлено | col *= pedestalShadow(p, lp); |
| +добавлено | #endif |
| +добавлено | vec3 dl = nl > 0.0 ? col * (lightFalloff(dist, la.w) * nl / PI) * diffColor : vec3(0.0), sl = vec3(0.0); |
| +добавлено | if (nls > 0.0) { |
| +добавлено | vec3 h = normalize(ls + v); |
| +добавлено | float nh = max(dot(n, h), 0.0), vh = max(dot(v, h), 0.0); |
| +добавлено | vec3 F = f0 + (1.0 - f0) * pow(1.0 - vh, 5.0); |
| +добавлено | sl = col * F * (lightFalloff(dists, la.w) * spellD_GGX(nh, a) * spellV_Smith(nv, nls, a) * nls); |
| +добавлено | // line lights: Karis's energy normalization, or a long segment's highlight clips into a white bar |
| +добавлено | if (type == 1) sl *= a / min(a + length(lc.xyz - la.xyz) / (2.0 * dists), 1.0); |
| +добавлено | } |
| +добавлено | if (lc.w > 0.5 && !gLightNoShadow && dot(dl + sl, vec3(0.2126, 0.7152, 0.0722)) > 0.04 * base) { |
| +добавлено | float sh = arenaCapsuleShadow(p, lp); |
| +добавлено | dl *= sh; sl *= sh; |
| +добавлено | } |
| +добавлено | diffuse += dl; specular += sl; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | void arenaSpellLights(vec3 p, vec3 n, vec3 v, float rough, vec3 f0, vec3 diffColor, out vec3 diffuse, out vec3 specular) { |
| +добавлено | arenaSpellLights(p, n, v, rough, f0, diffColor, 0.0, diffuse, specular); |
| +добавлено | } |
| +добавлено | `; |
| +добавлено | |
| +добавлено | // IMPACTS_GLSL's impactWeights, culled the same way; the type is routed with a mask (dynamic vector |
| +добавлено | // indexing is emulated on D3D, and slow). |
| +добавлено | // Same world-texture layout as common.js (row 2: pos+radius, type/age/amount, colour). |
| +добавлено | const IMPACT_FN_GLSL = /* glsl */` |
| +добавлено | void arenaImpacts(vec3 p, out vec4 wa, out vec4 wb, out vec3 glowColor) { |
| +добавлено | wa = vec4(0.0); wb = vec4(0.0); glowColor = vec3(0.0); |
| +добавлено | int n = int(uWorldCounts.z); |
| +добавлено | uint mask = 0u; |
| +добавлено | for (int i = 0; i < ${MAX_IMPACTS}; i++) { |
| +добавлено | if (i >= n) break; |
| +добавлено | vec4 a = WI(i * 4); |
| +добавлено | vec3 d = p - a.xyz; |
| +добавлено | if (dot(d, d) < a.w * a.w) mask |= 1u << uint(i); |
| +добавлено | } |
| +добавлено | while (mask != 0u) { |
| +добавлено | int i; NEXT_BIT(mask, i) |
| +добавлено | vec4 a = WI(i * 4), b = WI(i * 4 + 1); |
| +добавлено | float w = b.z * smoothstep(1.0, 0.55, length(p - a.xyz) / a.w); |
| +добавлено | wa += w * vec4(equal(vec4(b.x), vec4(0.0, 1.0, 2.0, 3.0))); |
| +добавлено | wb += w * vec4(equal(vec4(b.x), vec4(4.0, 5.0, 6.0, 7.0))); |
| +добавлено | glowColor += WI(i * 4 + 2).rgb * w; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | `; |
| +добавлено | |
| +добавлено | export const SURFACE_PARS = COMMON_GLSL + NOISE_GLSL + WORLD_GLSL + LIGHTS_GLSL + LIGHT_FN_GLSL + IMPACT_FN_GLSL + GROUND_GLSL + /* glsl */` |
| +добавлено | uniform sampler2D uStoneNoise; |
| +добавлено | uniform samplerCube uSkyCube; |
| +добавлено | uniform highp sampler2DShadow uShadowMap; |
| +добавлено | uniform mat4 uShadowMatrix; |
| +добавлено | uniform float uShadowOn; |
| +добавлено | uniform vec3 uSunDir; |
| +добавлено | uniform vec3 uSunColor; |
| +добавлено | uniform vec3 uAmbient; |
| +добавлено | uniform vec3 uRuneColor; |
| +добавлено | uniform vec3 uFocusColor; |
| +добавлено | uniform float uEnvScale; |
| +добавлено | uniform float uKind; |
| +добавлено | varying vec3 vWPos; |
| +добавлено | varying vec3 vNrm; |
| +добавлено | varying vec3 vLocal; |
| +добавлено | varying float vAO; |
| +добавлено | flat varying float vSeed; |
| +добавлено | float gAO = 1.0; // cavity occlusion of ambient |
| +добавлено | float gSpecAO = 1.0; // ... and of reflections |
| +добавлено | float gGroove = 0.0; // in a narrow groove (floor grout): spell lights low over the floor can't reach in |
| +добавлено | float gHeatOpen = -1.0; // where heat glows through (>= 0 overrides crevice: the floor's grout barely glows) |
| +добавлено | float gFrostGlint = 0.0;// hoarfrost micro-facet glint, x sun |
| +добавлено | float stFrostImp = 0.0; // frost from impacts alone (the floor re-reads the field's own) |
| +добавлено | uniform vec4 uCrackSrc[4]; |
| +добавлено | uniform vec4 uFissA[4]; |
| +добавлено | uniform vec4 uFissB[4]; |
| +добавлено | // metres from p to fissure i's line, and where along it (u) and across it (v) |
| +добавлено | float fissDist(int i, vec2 p, out float u, out float v, out float L) { |
| +добавлено | vec2 ab = uFissA[i].zw - uFissA[i].xy; |
| +добавлено | L = max(length(ab), 1e-3); |
| +добавлено | vec2 T = ab / L, q = p - uFissA[i].xy; |
| +добавлено | u = dot(q, T); v = dot(q, vec2(-T.y, T.x)); |
| +добавлено | return length(q - T * clamp(u, 0.0, L)); |
| +добавлено | } |
| +добавлено | float gVent = 0.0; // craterNear() of this floor pixel (computed once by the floor) |
| +добавлено | // how near a crater or a fissure vent this is (their own fractures carry the glow there, not the |
| +добавлено | // generic thermal crackle or the field's cell network) |
| +добавлено | float craterNear(vec2 p) { |
| +добавлено | float c = 0.0, u, v, L; |
| +добавлено | if (dot(vec4(uCrackSrc[0].w, uCrackSrc[1].w, uCrackSrc[2].w, uCrackSrc[3].w) + vec4(uFissB[0].y, uFissB[1].y, uFissB[2].y, uFissB[3].y), vec4(1.0)) <= 0.0) return 0.0; |
| +добавлено | for (int i = 0; i < 4; i++) { |
| +добавлено | c = max(c, smoothstep(2.6, 1.9, length(p - uCrackSrc[i].xy) / max(uCrackSrc[i].z, 0.1)) * min(uCrackSrc[i].w, 1.0)); |
| +добавлено | c = max(c, smoothstep(2.6, 1.8, fissDist(i, p, u, v, L)) * min(uFissB[i].y, 1.0)); |
| +добавлено | } |
| +добавлено | return c; |
| +добавлено | } |
| +добавлено | // coverage of a crack d metres away, half-width w, pixel footprint px (a crack narrower than a pixel |
| +добавлено | // dims instead of aliasing) |
| +добавлено | float crackCov(float d, float w, float px) { return (1.0 - smoothstep(w * 0.3, w + px, d)) * w / (w + 0.75 * px); } |
| +добавлено | // F1, F2, F3 to jittered feature points (3x3 cells), and the nearest cell |
| +добавлено | vec3 vor3(vec2 x, float seed, out vec2 id) { |
| +добавлено | vec2 c = floor(x), fr = x - c; |
| +добавлено | vec3 d = vec3(8.0); |
| +добавлено | id = c; |
| +добавлено | for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) { |
| +добавлено | vec2 g = vec2(float(i), float(j)); |
| +добавлено | float e = length(g + hash33(vec3(c + g, seed)).xy * 0.8 + 0.1 - fr); |
| +добавлено | if (e < d.x) { d = vec3(e, d.xy); id = c + g; } else if (e < d.y) d = vec3(d.x, e, d.y); else d.z = min(d.z, e); |
| +добавлено | } |
| +добавлено | return d; |
| +добавлено | } |
| +добавлено | // Desiccation / lava-crust network: ~2.6 m primary plates, each broken into its own secondary cells |
| +добавлено | // (0.35-1.1 m; a fifth of the plates stay whole), so cell size varies several times over and the |
| +добавлено | // secondaries end on the primaries; every line tapers into its junctions (F3 - F2 -> 0 there). |
| +добавлено | // x: primary coverage, y: secondary coverage, z: metres to a primary |
| +добавлено | vec3 crackNet(vec2 p, float px, float wP, float wS) { |
| +добавлено | vec2 idP, idS; |
| +добавлено | vec3 a = vor3(p * ${f(1 / 2.6)}, 11.0, idP); |
| +добавлено | vec3 hc = hash33(vec3(idP, 5.0)); |
| +добавлено | float sS = mix(0.35, 1.1, hc.x); |
| +добавлено | vec3 b = vor3(p / sS, 12.0 + floor(hc.y * 8.0), idS); |
| +добавлено | float eP = (a.y - a.x) * 1.3, eS = (b.y - b.x) * 0.5 * sS; |
| +добавлено | float tP = mix(0.2, 1.0, smoothstep(0.0, 0.25, (a.z - a.y) * 2.6)), tS = mix(0.15, 1.0, smoothstep(0.0, 0.3, b.z - b.y)); |
| +добавлено | return vec3(crackCov(eP, wP * tP, px), crackCov(eS, wS * tS, px) * step(0.2, hc.z), eP); |
| +добавлено | } |
| +добавлено | #ifdef ARENA_FLOOR |
| +добавлено | // The rim wall's sun shadow, exact: where the wall meets the floor the shadow map's bias leaks a |
| +добавлено | // lit sliver a few cm wide, and on the polished floor facing a low sun it glints as a row of |
| +добавлено | // white dashes (one per shadow texel) along the far wall. A ray towards the sun leaves the arena |
| +добавлено | // through the wall's inner face (r = 17.98); it is clear only if it is above the coping by then. |
| +добавлено | float rimWallSun(vec2 p, vec3 s) { |
| +добавлено | float dd = dot(s.xz, s.xz); |
| +добавлено | if (dd < 1e-6) return 1.0; |
| +добавлено | float b = dot(p, s.xz), c = dot(p, p) - ${f((ARENA.radius - 0.02) ** 2)}; |
| +добавлено | float t = (-b + sqrt(max(b * b - dd * c, 0.0))) / dd; |
| +добавлено | return smoothstep(${f(ARENA.wallHeight - 0.04)}, ${f(ARENA.wallHeight + 0.04)}, t * s.y); |
| +добавлено | } |
| +добавлено | #endif |
| +добавлено | |
| +добавлено | // running-bond blocks: distance to the nearest joint (uv units), id |
| +добавлено | float blocks(vec2 uv, vec2 size, float stagger, out vec2 id) { |
| +добавлено | vec2 q = uv / size; |
| +добавлено | q.x += floor(q.y) * stagger; |
| +добавлено | id = floor(q); |
| +добавлено | vec2 d = (0.5 - abs(fract(q) - 0.5)) * size; |
| +добавлено | return min(d.x, d.y); |
| +добавлено | } |
| +добавлено | float segDist(vec2 p, vec2 a, vec2 b) { vec2 pa = p - a, ba = b - a; return length(pa - ba * clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0)); } |
| +добавлено | // carved rune in a unit cell: 4 strokes between the nodes of a 3x3 lattice, picked by hash |
| +добавлено | float rune(vec2 q, float seed) { |
| +добавлено | float d = 1e3; |
| +добавлено | for (int k = 0; k < 4; k++) { |
| +добавлено | vec4 h = hash41(seed * 13.7 + float(k) * 3.1); |
| +добавлено | vec2 a = floor(h.xy * 2.999) * 0.5, b = floor(h.zw * 2.999) * 0.5; |
| +добавлено | if (all(equal(a, b))) b = vec2(1.0) - a; |
| +добавлено | d = min(d, segDist(q, a, b)); |
| +добавлено | } |
| +добавлено | return d; |
| +добавлено | } |
| +добавлено | // split-sum environment BRDF, analytic (Karis 2014, mobile) |
| +добавлено | vec2 envBRDF(float rough, float nv) { |
| +добавлено | vec4 r = rough * vec4(-1.0, -0.0275, -0.572, 0.022) + vec4(1.0, 0.0425, 1.04, -0.04); |
| +добавлено | float a004 = min(r.x * r.x, exp2(-9.28 * nv)) * r.x + r.y; |
| +добавлено | return vec2(-1.04, 1.04) * a004 + r.zw; |
| +добавлено | } |
| +добавлено | `; |
| +добавлено | |
| +добавлено | const VERT = (pars, main) => /* glsl */` |
| +добавлено | attribute float aAO; |
| +добавлено | varying vec3 vWPos; |
| +добавлено | varying vec3 vNrm; |
| +добавлено | varying vec3 vLocal; |
| +добавлено | varying float vAO; |
| +добавлено | flat varying float vSeed; |
| +добавлено | ${pars} |
| +добавлено | void main() { |
| +добавлено | vec4 lp = vec4(position, 1.0); |
| +добавлено | vec3 nl = normal; |
| +добавлено | vSeed = 0.0; |
| +добавлено | #ifdef USE_INSTANCING |
| +добавлено | lp = instanceMatrix * lp; |
| +добавлено | nl = mat3(instanceMatrix) * nl; |
| +добавлено | vSeed = fract(sin(dot(instanceMatrix[3].xyz, vec3(12.9898, 78.233, 37.719))) * 43758.5453); |
| +добавлено | #endif |
| +добавлено | vec4 wp = modelMatrix * lp; |
| +добавлено | vWPos = wp.xyz; |
| +добавлено | vNrm = mat3(modelMatrix) * nl; |
| +добавлено | vLocal = position; |
| +добавлено | vAO = aAO; |
| +добавлено | gl_Position = projectionMatrix * viewMatrix * wp; |
| +добавлено | ${main} |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | // --- surfaces ------------------------------------------------------------------------------- |
| +добавлено | // Each sets albedo / rough / metal / nW (world normal) / emit / crevice (0..1: grout, grooves, |
| +добавлено | // cracks; where heat and holy light seep out) and may read stA / stB (state). |
| +добавлено | const COPING = 0.35; |
| +добавлено | const FLOOR_SURFACE = /* glsl */` |
| +добавлено | { |
| +добавлено | vec2 p = vWPos.xz; |
| +добавлено | float r = length(p); |
| +добавлено | vec2 dq = abs(p - vec2(${f(P.center.x)}, ${f(P.center.y)})) - vec2(${f(P.half.x)}, ${f(P.half.y)}); |
| +добавлено | float dBox = max(dq.x, dq.y); |
| +добавлено | vec2 tid; float e, coping = 0.0; |
| +добавлено | if (dBox < ${f(COPING)}) { |
| +добавлено | // pool coping: slabs along each side |
| +добавлено | bool sideX = dq.x > dq.y; |
| +добавлено | float s = (sideX ? p.y : p.x) / 0.7; |
| +добавлено | e = min(${f(COPING)} - dBox, (0.5 - abs(fract(s) - 0.5)) * 0.7); |
| +добавлено | tid = vec2(floor(s), sideX ? 1.0 : 2.0); |
| +добавлено | coping = 1.0; |
| +добавлено | } else { |
| +добавлено | e = min(blocks(p, vec2(1.2), 0.5, tid), dBox - ${f(COPING)}); |
| +добавлено | } |
| +добавлено | vec3 h = hash33(vec3(tid, coping * 7.0 + 3.0)); |
| +добавлено | vec4 nA = texture(uStoneNoise, p * 0.09); |
| +добавлено | // polished basalt: near black, cool grey, some slabs browner; mottled. Coping: paler stone. |
| +добавлено | albedo = mix(vec3(0.036, 0.040, 0.046), vec3(0.052, 0.044, 0.037), h.y) * (0.7 + 0.6 * h.z) * (0.78 + 0.44 * nA.r); |
| +добавлено | albedo = mix(albedo, vec3(0.11, 0.105, 0.098) * (0.8 + 0.3 * h.z), coping); |
| +добавлено | rough = mix(mix(0.1, 0.32, h.x * h.x) * (0.8 + 0.4 * nA.a), 0.35, coping); |
| +добавлено | // grout, and a slight random tilt per slab so the reflections break up slab by slab |
| +добавлено | const float G = 0.004; |
| +добавлено | float grout = 1.0 - smoothstep(G - px * 0.5, G + px * 0.5, e); |
| +добавлено | vec2 slope = (h.yz - 0.5) * 0.03 * (1.0 - grout); |
| +добавлено | albedo = mix(albedo, vec3(0.012), grout); |
| +добавлено | rough = mix(rough, 0.8, grout); |
| +добавлено | // grout is a recessed 8 mm joint: under a bright light it reads darker than the slab or the same, |
| +добавлено | // never as a lit line (no holy glow out of it, spell lights shadowed by the slab edges) |
| +добавлено | gGroove = grout; |
| +добавлено | // contact occlusion: pillars, rim wall, pedestal, dummies |
| +добавлено | float pa = atan(p.y, p.x) / ${f(Math.PI / 4)} - 0.5; |
| +добавлено | float pk = (floor(pa + 0.5) + 0.5) * ${f(Math.PI / 4)}; |
| +добавлено | float dp = length(p - vec2(cos(pk), sin(pk)) * ${f(ARENA.pillarRing)}) - ${f(ARENA.pillarRadius)}; |
| +добавлено | float dd = length(p - vec2(${f(ARENA.pedestal.pos.x)}, ${f(ARENA.pedestal.pos.z)})) - 0.4; |
| +добавлено | ${ARENA.dummies.map((d) => ` dd = min(dd, length(p - vec2(${f(d.x)}, ${f(d.z)})) - 0.25);`).join('\n')} |
| +добавлено | gAO = mix(0.35, 1.0, smoothstep(0.0, 1.6, dp)) * mix(0.3, 1.0, smoothstep(0.0, 2.2, ${f(ARENA.radius)} - r)) * mix(0.45, 1.0, smoothstep(0.0, 0.7, dd)); |
| +добавлено | gSpecAO = mix(1.0, gAO, 0.6); |
| +добавлено | // cracks: flat fissures along the voronoi network (the same tap), only where the field cracked; |
| +добавлено | // crevice lets the heat response glow magma in them |
| +добавлено | float ck = min(stB.x, 1.0); |
| +добавлено | gVent = craterNear(p); |
| +добавлено | float cr = smoothstep((0.02 + 0.1 * ck) * (0.5 + nA.g), 0.0, nA.b) * step(0.01, ck), crHot = cr; |
| +добавлено | if (ck > 0.01) { |
| +добавлено | // near a crater the field's vein-crawling crack fronts would cut the cell network into curly |
| +добавлено | // fragments: there the crater's own fractures (below) are the cracks |
| +добавлено | cr *= 1.0 - gVent; |
| +добавлено | // round a crater the slab network gives way to fractures radiating from the pit (7, each |
| +добавлено | // forking once further out, jagged, tapering to their tips) and broken concentric arcs |
| +добавлено | // between them (quarry-blast rock, lava crust round a vent) |
| +добавлено | vec4 nj = texture(uStoneNoise, p * 0.9 + vec2(0.37, 0.71)); |
| +добавлено | float jag = (nj.r - 0.5) * 0.16 + (nj.g - 0.5) * 0.07, rc = 0.0, rh = 0.0, wr = 0.0; |
| +добавлено | for (int i = 0; i < 4; i++) { |
| +добавлено | vec4 s = uCrackSrc[i]; |
| +добавлено | vec2 q = p - s.xy; |
| +добавлено | float r = length(q), R = max(s.z, 0.1); |
| +добавлено | float wi = smoothstep(1.9 * R, 1.35 * R, r) * min(s.w, 1.0); |
| +добавлено | if (wi <= 0.0) continue; |
| +добавлено | float h0 = fract(s.x * 0.173 + s.y * 0.311) * 13.0, th = atan(q.y, q.x) / 6.2831853 + 0.5, line = 0.0; |
| +добавлено | float hot = smoothstep(1.25 * R, 0.4 * R, r + jag * 2.0); |
| +добавлено | for (int o = 0; o < 2; o++) { |
| +добавлено | float k = 7.0 * float(1 + o), fo = float(o); |
| +добавлено | float an = th * k + h0 + fo * 0.37 + jag * k / (6.2831853 * max(r, 0.15)); |
| +добавлено | float ci = floor(an + 0.5), hs = fract(sin(ci * 12.9898 + fo * 78.233 + h0) * 43758.5453); |
| +добавлено | float len = R * (0.95 + 0.75 * hs), st = fo < 0.5 ? 0.12 * R : (0.5 + 0.35 * hs) * R; |
| +добавлено | float w = (0.006 + 0.03 * clamp(1.0 - r / len, 0.0, 1.0)) * smoothstep(len, 0.7 * len, r) * smoothstep(st, st + 0.25, r) * (fo < 0.5 ? 1.0 : 0.6 * step(0.3, hs)); |
| +добавлено | line = max(line, crackCov(abs(an - ci) * 6.2831853 * r / k, w, px)); |
| +добавлено | } |
| +добавлено | for (int j = 0; j < 2; j++) { |
| +добавлено | float fj = float(j), cell = floor(th * 7.0 + h0); |
| +добавлено | float on = step(0.45, fract(sin(cell * 7.77 + fj * 3.3 + h0) * 43758.5453)); |
| +добавлено | float wob = sin(th * 18.85 + h0 + fj * 2.1) * 0.05 + sin(th * 43.98 + h0 * 1.7) * 0.025; // smooth: no cusps |
| +добавлено | line = max(line, crackCov(abs(r - R * (0.5 + 0.4 * fj) * (1.0 + wob) - jag * 0.5), 0.011 * on, px)); |
| +добавлено | } |
| +добавлено | rc = max(rc, line); rh = max(rh, line * hot); wr = max(wr, wi); |
| +добавлено | } |
| +добавлено | crHot = mix(cr, rh, wr); |
| +добавлено | cr = mix(cr, rc, wr); |
| +добавлено | } |
| +добавлено | if (uFissB[0].y + uFissB[1].y + uFissB[2].y + uFissB[3].y > 0.0) { |
| +добавлено | // a fissure vent (Fagradalsfjall, Holuhraun): the long main fissure, wandering a little and |
| +добавлено | // pinching out at its ends, a few short en-echelon cracks stepped beside it, slightly oblique; |
| +добавлено | // spatter and a dark cooling crust along its lips. Hot only on and near the vent line. |
| +добавлено | float fz = 0.0, fh = 0.0, fw = 0.0, fe = 0.0, vm = 9.0; |
| +добавлено | for (int i = 0; i < 4; i++) { |
| +добавлено | vec4 b = uFissB[i]; |
| +добавлено | if (b.y <= 0.0) continue; |
| +добавлено | float u, v, L, dist = fissDist(i, p, u, v, L); |
| +добавлено | float wi = smoothstep(2.4, 1.6, dist) * min(b.y, 1.0); |
| +добавлено | if (wi <= 0.0) continue; |
| +добавлено | vec4 nw = textureLod(uStoneNoise, vec2(u * 0.11, b.z * 0.371 + 0.13), 0.0); // (no derivatives in this loop) |
| +добавлено | vec4 nw2 = textureLod(uStoneNoise, vec2(u * 0.6, b.z * 0.533 + 0.71), 0.0); |
| +добавлено | float v0 = (nw.r - 0.5) * 0.45 + (nw2.g - 0.5) * 0.14; |
| +добавлено | float ends = clamp(min(u, L - u) / 0.7, 0.0, 1.0); |
| +добавлено | // pinches and swells along its length; hot in pockets, not one even ribbon |
| +добавлено | float line = crackCov(abs(v - v0), (0.006 + 0.03 * ends) * (0.3 + 1.4 * nw2.r) * step(0.0, ends), px); |
| +добавлено | float hot = line * (0.45 + 0.55 * smoothstep(0.3, 0.7, nw.g)); |
| +добавлено | // en-echelon: one short crack per 1.3 m of fissure on alternating-ish sides |
| +добавлено | float k = floor(u / 1.3); |
| +добавлено | vec3 h = hash33(vec3(k, b.z, 7.0)); |
| +добавлено | float side = h.x < 0.5 ? -1.0 : 1.0, off = side * (0.45 + 0.45 * h.y) * clamp(b.x / 0.75, 0.5, 2.0), len = 0.5 + 0.7 * h.z; |
| +добавлено | float du = u - k * 1.3 - (1.3 - len) * fract(h.x * 7.3), su = du / len; |
| +добавлено | float ve = off + (du - 0.5 * len) * 0.22 * side + v0; |
| +добавлено | float we = 0.009 * sin(3.14159 * clamp(su, 0.0, 1.0)) * step(0.0, su) * step(su, 1.0) * step(0.3, fract(h.y * 5.1)) * step(0.5, ends + 0.5); |
| +добавлено | float ech = crackCov(abs(v - ve), we, px); |
| +добавлено | line = max(line, ech); |
| +добавлено | // the side cracks erupt too while the vent is young (their own glow: the field's heat stays on |
| +добавлено | // the main line), then crust over |
| +добавлено | fe = max(fe, ech * wi * smoothstep(1.0, 1.9, b.y) * (0.5 + 0.5 * h.z)); |
| +добавлено | fz = max(fz, line * wi); fh = max(fh, hot * wi); fw = max(fw, wi); |
| +добавлено | vm = min(vm, abs(v - v0) + (1.0 - ends) * 0.5 + (1.0 - wi) * 2.0); |
| +добавлено | } |
| +добавлено | if (fw > 0.0) { |
| +добавлено | // lips: a dark, fresh crust; spatter flung onto it, still glowing in spots right at the vent |
| +добавлено | vec4 nsp = texture(uStoneNoise, p * 2.3 + vec2(0.53, 0.29)); |
| +добавлено | float lip = exp(-vm / 0.45) * fw; |
| +добавлено | albedo *= 1.0 - 0.7 * lip; |
| +добавлено | rough = mix(rough, 0.85, lip); |
| +добавлено | float spatter = smoothstep(0.7, 0.85, nsp.r) * smoothstep(0.6, 0.8, nsp.g) * exp(-vm / 0.14) * fw; |
| +добавлено | crHot = max(mix(crHot, fh, fw), spatter * 0.4); |
| +добавлено | cr = max(mix(cr, fz, fw), spatter * 0.3); |
| +добавлено | emit += blackbody(1250.0) * fe * 2.0; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | albedo *= 1.0 - 0.92 * cr; |
| +добавлено | rough = mix(rough, 0.9, cr); |
| +добавлено | gAO *= 1.0 - 0.8 * cr; |
| +добавлено | gSpecAO *= 1.0 - 0.9 * cr; |
| +добавлено | crevice = max(crevice, cr); |
| +добавлено | gHeatOpen = max(grout * 0.04 * (1.0 - gVent), crHot); // crater / vent fractures glow only in the hot core; no grout grid there |
| +добавлено | nW = normalize(vec3(slope.x, 1.0, slope.y)); |
| +добавлено | sp2 = p; |
| +добавлено | } |
| +добавлено | `; |
| +добавлено | |
| +добавлено | const STONE_SURFACE = /* glsl */` |
| +добавлено | { |
| +добавлено | vec3 gn = nW; |
| +добавлено | sp2 = abs(gn.y) > 0.7 ? vWPos.xz : abs(gn.x) > abs(gn.z) ? vWPos.zy : vWPos.xy; |
| +добавлено | vec4 nA = texture(uStoneNoise, sp2 * 0.35 + vSeed); |
| +добавлено | gAO = vAO; |
| +добавлено | gSpecAO = vAO; |
| +добавлено | if (uKind < 0.5) { |
| +добавлено | // pillar: warm limestone, grime at the foot, two glowing rune bands |
| +добавлено | float ang = atan(vLocal.z, vLocal.x), y = vLocal.y; |
| +добавлено | albedo = vec3(0.30, 0.27, 0.235) * (0.72 + 0.5 * nA.r) * mix(0.5, 1.0, smoothstep(0.0, 1.6, y)); |
| +добавлено | rough = 0.55 + 0.3 * nA.a; |
| +добавлено | float b0 = (y - 1.62) / 0.24, b1 = (y - 4.34) / 0.18; |
| +добавлено | float bv = b0 > 0.0 && b0 < 1.0 ? b0 : b1 > 0.0 && b1 < 1.0 ? b1 : -1.0; |
| +добавлено | if (bv >= 0.0) { |
| +добавлено | float gu = (ang / 6.2831853 + 0.5) * 14.0; |
| +добавлено | float gi = floor(gu); |
| +добавлено | vec2 q = (vec2(fract(gu), bv) - 0.5) * vec2(1.5, 1.15) + 0.5; |
| +добавлено | float dr = rune(q, gi + floor(y) * 31.0 + vSeed * 97.0); |
| +добавлено | float aa = length(fwidth(q)); |
| +добавлено | float stroke = smoothstep(0.075 + aa, 0.075 - aa, dr) * step(0.0, q.x) * step(q.x, 1.0) * step(0.0, q.y) * step(q.y, 1.0); |
| +добавлено | float pulse = 0.65 + 0.35 * sin(uTime * 1.3 + gi * 0.7 + vSeed * 20.0); |
| +добавлено | albedo *= 1.0 - 0.6 * stroke; |
| +добавлено | emit += uRuneColor * stroke * pulse; |
| +добавлено | crevice = max(crevice, stroke); |
| +добавлено | } |
| +добавлено | } else if (uKind < 1.5) { |
| +добавлено | // rim wall: ashlar courses (coping blocks on top) |
| +добавлено | float ang = atan(vWPos.z, vWPos.x), R = length(vWPos.xz); |
| +добавлено | vec2 id; |
| +добавлено | float e = gn.y > 0.7 ? blocks(vec2(ang * R, 0.5), vec2(1.0, 10.0), 0.0, id) : blocks(vec2(ang * R, vWPos.y - 0.14), vec2(1.15, 0.45), 0.5, id); |
| +добавлено | vec3 h = hash33(vec3(id, 5.0)); |
| +добавлено | albedo = vec3(0.24, 0.215, 0.19) * (0.7 + 0.45 * h.x) * (0.75 + 0.45 * nA.r) * mix(0.55, 1.0, smoothstep(0.0, 0.6, vWPos.y)); |
| +добавлено | rough = 0.6 + 0.3 * nA.a; |
| +добавлено | float joint = 1.0 - smoothstep(0.006 - px * 0.5, 0.006 + px * 0.5, e); |
| +добавлено | albedo = mix(albedo, vec3(0.03), joint); |
| +добавлено | crevice = joint; |
| +добавлено | gAO *= 1.0 - 0.5 * joint; |
| +добавлено | } else if (uKind < 2.5) { |
| +добавлено | // pedestal: polished dark marble, brass bands, a rune band glowing in the focus colour |
| +добавлено | float y = vLocal.y; |
| +добавлено | float vein = smoothstep(0.03, 0.0, abs(nA.g - 0.5)); |
| +добавлено | albedo = mix(vec3(0.018, 0.026, 0.024), vec3(0.2, 0.21, 0.2), vein * 0.4); |
| +добавлено | rough = 0.1; |
| +добавлено | float brass = step(abs(y - 0.19), 0.025) + step(abs(y - 1.0), 0.02) + step(abs(y - 1.12), 0.02); |
| +добавлено | albedo = mix(albedo, vec3(0.9, 0.62, 0.32), brass); |
| +добавлено | metal = brass; rough = mix(rough, 0.22, brass); |
| +добавлено | float bv = (y - 0.62) / 0.2; |
| +добавлено | if (bv > 0.0 && bv < 1.0 && brass < 0.5) { |
| +добавлено | float ang = atan(vLocal.z, vLocal.x); |
| +добавлено | float gu = (ang / 6.2831853 + 0.5) * 8.0, gi = floor(gu); |
| +добавлено | vec2 q = (vec2(fract(gu), bv) - 0.5) * vec2(1.4, 1.1) + 0.5; |
| +добавлено | float aa = length(fwidth(q)); |
| +добавлено | float stroke = smoothstep(0.08 + aa, 0.08 - aa, rune(q, gi + 300.0)) * step(0.0, q.y) * step(q.y, 1.0); |
| +добавлено | emit += uFocusColor * stroke * 1.5; |
| +добавлено | albedo *= 1.0 - 0.7 * stroke; |
| +добавлено | } |
| +добавлено | } else if (uKind < 4.5) { |
| +добавлено | // pool basin: small teal-black mosaic |
| +добавлено | vec2 id; |
| +добавлено | float e = blocks(sp2, vec2(0.11), 0.0, id); |
| +добавлено | vec3 h = hash33(vec3(id, 9.0)); |
| +добавлено | albedo = mix(vec3(0.008, 0.03, 0.034), vec3(0.02, 0.05, 0.05), h.x) * (0.7 + 0.6 * h.y); |
| +добавлено | float joint = 1.0 - smoothstep(0.0025 - px * 0.5, 0.0025 + px * 0.5, e); |
| +добавлено | albedo = mix(albedo, vec3(0.06, 0.065, 0.06), joint); |
| +добавлено | rough = mix(0.15 + 0.1 * h.z, 0.7, joint); |
| +добавлено | } else { |
| +добавлено | // brass (orb rings) |
| +добавлено | albedo = vec3(0.92, 0.66, 0.34); |
| +добавлено | metal = 1.0; |
| +добавлено | rough = 0.25; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | `; |
| +добавлено | |
| +добавлено | // responses to the state (a = heat, char, wet, frost; b = crack, acid, corruption, glow); at most |
| +добавлено | // two noise taps on top of the surface's |
| +добавлено | const RESPONSES = /* glsl */` |
| +добавлено | if (any(greaterThan(stA, vec4(0.004))) || any(greaterThan(stB, vec4(0.004))) || stElec > 0.004) { |
| +добавлено | vec4 nS = texture(uStoneNoise, sp2 * 0.11 + 0.31); |
| +добавлено | bool flat_ = nW.y > 0.9; |
| +добавлено | // char: soot, uneven |
| +добавлено | float ch = clamp(stA.y * (0.75 + 0.5 * nS.r), 0.0, 1.0); |
| +добавлено | albedo *= 1.0 - 0.85 * ch; |
| +добавлено | rough = mix(rough, 0.9, ch); |
| +добавлено | metal *= 1.0 - ch; |
| +добавлено | // wet: darker, glossy film; on the floor it pools where the noise is low |
| +добавлено | float wt = clamp(stA.z, 0.0, 1.0); |
| +добавлено | float puddle = flat_ ? smoothstep(0.35, 0.7, wt * (0.6 + 0.8 * nS.g)) : 0.0; |
| +добавлено | albedo *= 1.0 - 0.4 * wt; |
| +добавлено | rough = mix(rough, 0.04, max(wt * 0.75, puddle)); |
| +добавлено | nW = normalize(mix(nW, vec3(0.0, 1.0, 0.0), puddle)); |
| +добавлено | crevice *= 1.0 - puddle; |
| +добавлено | // frost: hoarfrost, matched to frost-front macro timelapses. The field only says how much frost |
| +добавлено | // there is; on the floor it is re-read through a smooth warp of about a texel, so no front ever |
| +добавлено | // shows the field's grid (4 cm texels, 8 cm at Low). The crystals come from the MIPMAPPED stone |
| +добавлено | // noise, so they filter down to their average with distance instead of aliasing into speckle. |
| +добавлено | // Coverage: a solid carpet where the field plus lumps at three scales clears a threshold, and |
| +добавлено | // ahead of it a fringe of crystals that nucleate on grain boundaries (two voronoi scales) and |
| +добавлено | // needles (ridged fbm), sparse at first and closing up towards the carpet: a feathery, broken |
| +добавлено | // front at every distance, never a smooth rim. Density varies (thin grey frost where the stone |
| +добавлено | // shows, thicker drifts), and even the thickest stays well under snow-white. Sparkle: one hashed |
| +добавлено | // micro-facet per 7 mm cell glints at the sun (view-dependent, still when the camera is), faded |
| +добавлено | // out before a cell shrinks to a pixel. Over water: an ice sheet. |
| +добавлено | float fr = clamp(stA.w, 0.0, 1.0); |
| +добавлено | float cover = 0.0, sheet = 0.0; |
| +добавлено | if (fr > 0.004) { |
| +добавлено | vec4 nF = texture(uStoneNoise, sp2 * 2.3 + vec2(0.17, 0.61)); // 43 cm tile: 11 cm lumps, 3.6 cm grains, 1.3 cm grit |
| +добавлено | vec4 nG = texture(uStoneNoise, sp2 * 0.6 + vec2(0.43, 0.09)); // 1.7 m tile: the front's lobes, 14 cm grains |
| +добавлено | #ifdef ARENA_FLOOR |
| +добавлено | vec2 wq = (vec2(nG.g, nF.g) - 0.5) * 2.4 / vec2(textureSize(uGroundA, 0)); |
| +добавлено | // an impact's frost is a sphere's footprint: cut its fade band into lobes (the edge falls |
| +добавлено | // anywhere from 0.1 to 0.9 of the band, on 1.7 m and 8 m noise) and keep its middle short of |
| +добавлено | // saturation, so it never lands as one flat disc with a round rim |
| +добавлено | float lobe = texture(uStoneNoise, sp2 * 0.13 + vec2(0.61, 0.37)).r * 0.55 + nG.r * 0.45; |
| +добавлено | float fT = clamp(0.5 + (0.5 - lobe) * 2.2, 0.1, 0.9); |
| +добавлено | float fi = smoothstep(fT - 0.12, fT + 0.12, stFrostImp) * (0.62 + 0.3 * lobe); |
| +добавлено | fr = clamp(max(texture(uGroundA, groundUV(vWPos.xz) + wq).w, fi), 0.0, 1.0); |
| +добавлено | #endif |
| +добавлено | float g = fr - 0.45 + (nS.r - 0.5) * 0.34 + (nG.r - 0.5) * 0.36 + (nF.r - 0.5) * 0.2; |
| +добавлено | float lace = max(1.0 - smoothstep(0.0, 0.16, nF.b), 0.8 - 0.8 * smoothstep(0.0, 0.09, nG.b)); |
| +добавлено | float needle = pow(1.0 - abs(nF.g * 2.0 - 1.0), 6.0) * (1.0 - smoothstep(0.004, 0.012, px)); // a mipmapped ridge goes flat-bright: fade first |
| +добавлено | float gf = max(lace, needle) * (0.7 + 0.6 * nF.a) - 1.0 + 1.25 * smoothstep(-0.34, 0.04, g); |
| +добавлено | float aw = fwidth(g) * 0.7 + 0.004, af = fwidth(gf) * 0.7 + 0.01; |
| +добавлено | cover = max(smoothstep(-aw, aw, g), smoothstep(-af, af, gf) * smoothstep(-0.36, -0.24, g)); |
| +добавлено | sheet = min(cover, max(puddle, wt)); |
| +добавлено | float rime = cover * (1.0 - sheet); |
| +добавлено | // depth of the crystal carpet: thin and grey at the front and in patches, drifts deeper |
| +добавлено | float thick = smoothstep(0.0, 0.45, g) * (0.3 + 0.7 * smoothstep(0.3, 0.75, nS.g * 0.4 + nG.a * 0.6 + 0.2 * (fr - 0.6))); |
| +добавлено | vec3 rimeCol = mix(vec3(0.30, 0.34, 0.40), vec3(0.68, 0.74, 0.82), thick) * (0.8 + 0.4 * nF.a); |
| +добавлено | albedo = mix(albedo, rimeCol, rime * mix(0.5, 0.9, thick)); |
| +добавлено | albedo = mix(albedo, albedo * vec3(0.7, 0.9, 1.1), sheet); |
| +добавлено | rough = mix(mix(rough, 0.48, rime), 0.05, sheet); |
| +добавлено | metal *= 1.0 - cover; |
| +добавлено | crevice *= 1.0 - cover * 0.8; |
| +добавлено | // glints: a random plate per cell, its normal anywhere within ~50 degrees of up |
| +добавлено | vec2 gq = sp2 * 140.0; |
| +добавлено | vec3 gh = hash33(vec3(floor(gq), 23.0)); |
| +добавлено | float fine = (1.0 - smoothstep(0.3, 0.75, px * 140.0)) * rime * step(0.55, gh.z); |
| +добавлено | if (fine > 0.0) { |
| +добавлено | vec3 nf = normalize(vec3((gh.x - 0.5) * 2.4, 1.0, (gh.y - 0.5) * 2.4)); |
| +добавлено | vec3 Hs = normalize(uSunDir + normalize(cameraPosition - vWPos)); |
| +добавлено | vec2 sd = fract(gq) - 0.5 - (gh.yx - 0.5) * 0.35; |
| +добавлено | float aa = fwidth(gq.x) + fwidth(gq.y); |
| +добавлено | float spot = 1.0 - smoothstep(0.16 - aa, 0.16 + aa, length(sd)); |
| +добавлено | gFrostGlint = spot * pow(max(dot(nf, Hs), 0.0), 900.0) * fine * 60.0; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // heat: hot stone glows only where it is open (thermal cracks that open with heat, the field's |
| +добавлено | // own cracks, pores) through a dark char crust; grout barely. Temperature follows the field |
| +добавлено | // heat, radiance ~T^4 above the Draper point, so the glow dies off well inside the hot area |
| +добавлено | // instead of ending in a disc; the crust itself only goes dull red right at the centre. |
| +добавлено | float ht = clamp(stA.x, 0.0, 1.0); |
| +добавлено | if (ht > 0.01) { |
| +добавлено | vec4 nH = texture(uStoneNoise, sp2 * 0.55 + vec2(0.71, 0.23)); // 1.8 m tile: ~15 cm crack cells, 6 cm pores |
| +добавлено | float crust = smoothstep(0.04, 0.45, ht); |
| +добавлено | albedo *= 1.0 - 0.8 * crust; |
| +добавлено | rough = mix(rough, 0.88, crust); |
| +добавлено | metal *= 1.0 - crust; |
| +добавлено | // local temperature: the field heat broken into hot and cooler patches (a plateau of saturated |
| +добавлено | // field heat must not read as one uniform disc) |
| +добавлено | float hl = clamp(ht * (0.6 + 0.55 * nH.r) * (0.85 + 0.3 * nS.g), 0.0, 1.0); |
| +добавлено | // fractures across the slabs (~75 cm cells, the tap the responses already made), segment by |
| +добавлено | // segment as the heat rises; a fine crackle (~15 cm) only in the hottest patches |
| +добавлено | // (thin and coverage-preserving: a crack narrower than a pixel dims instead of aliasing; width and |
| +добавлено | // glow vary along each crack, which also breaks the network into segments) |
| +добавлено | float bw = (0.005 + 0.014 * hl) * (0.4 + 1.2 * nH.r), fb = fwidth(nS.b); |
| +добавлено | float big = (1.0 - smoothstep(bw * 0.3, bw + fb, nS.b)) * bw / (bw + 0.75 * fb) * smoothstep(0.25, 0.55, hl) * smoothstep(0.42, 0.62, nH.g + 0.12 * hl); |
| +добавлено | float fw = 0.006 + 0.012 * hl, ff = fwidth(nH.b); |
| +добавлено | float fine = (1.0 - smoothstep(fw * 0.3, fw + ff, nH.b)) * fw / (fw + 0.75 * ff) * smoothstep(0.72, 0.95, hl) * smoothstep(0.45, 0.6, nH.g); |
| +добавлено | float tc = max(big, fine * 0.7) * (1.0 - gVent); // round a crater the glow comes out of its fractures (gHeatOpen) alone |
| +добавлено | float op = max(tc, gHeatOpen >= 0.0 ? gHeatOpen : crevice); |
| +добавлено | albedo *= 1.0 - 0.7 * tc; |
| +добавлено | float pore = smoothstep(0.8, 0.86, nH.a) * smoothstep(0.55, 0.9, hl); // a few open vesicles, hottest patches only |
| +добавлено | float Tc = 620.0 + 1250.0 * hl, Ts = Tc - 200.0; |
| +добавлено | float Rc = pow(Tc / 1500.0, 4.0) * smoothstep(760.0, 1050.0, Tc); |
| +добавлено | float Rs = pow(Ts / 1500.0, 4.0) * smoothstep(760.0, 1100.0, Ts); |
| +добавлено | emit += blackbody(Tc) * (Rc * 3.2 * op) |
| +добавлено | + blackbody(Ts) * (Rs * (0.35 * pore + 0.08 * smoothstep(0.75, 1.0, hl) + 0.12 * tc * tc)); |
| +добавлено | } |
| +добавлено | float ac = clamp(stB.y, 0.0, 1.0); |
| +добавлено | if (ac > 0.01 || stElec > 0.004) { |
| +добавлено | // one more tap: acid foam cells (the baked voronoi, scrolling), or electric's lines |
| +добавлено | float tj = floor(uTime * 20.0); |
| +добавлено | // (acid: a still tap, so the etched grain stays put; the fizz is animated per cell by phase) |
| +добавлено | vec4 nF = texture(uStoneNoise, ac > 0.01 ? sp2 * 0.9 : sp2 * 0.21 + vec2(tj * 0.137, tj * 0.291)); |
| +добавлено | // acid eating stone (etched limestone and concrete): where it is still wet with acid the stone |
| +добавлено | // is dark and glossy under a thin yellow-green film; round it the stain rusts yellow-brown (the |
| +добавлено | // iron in the stone) in soft blotches, never one flat disc, its grain etched rough (a texture that |
| +добавлено | // fades to its mean before it can alias into specks); a pale, chalky salt bloom dries along the |
| +добавлено | // stain's edge. Only fresh acid fizzes: small grey-green bubbles cell by cell, a faint glow. |
| +добавлено | float mott = nS.a * 0.6 + nS.r * 0.4 - 0.5; |
| +добавлено | float stain = smoothstep(0.02, 0.45, ac + mott * 0.35); |
| +добавлено | float wetA = smoothstep(0.35, 0.9, ac + mott * 0.5); |
| +добавлено | float grain = (nF.a - 0.5) * (1.0 - smoothstep(0.004, 0.015, px)); |
| +добавлено | float bloom = stain * (1.0 - smoothstep(0.08, 0.35, ac + mott * 0.4)) * (0.6 + 0.8 * (nF.a - 0.5)); |
| +добавлено | float ph = fract(uTime * 0.7 + nF.r * 3.0); |
| +добавлено | float foam = smoothstep(0.1 + 0.2 * ph, 0.04 + 0.16 * ph, nF.b) * (1.0 - smoothstep(0.8, 1.0, ph)) * step(nF.g, ac * 1.1 - 0.3); |
| +добавлено | albedo = mix(albedo, albedo * vec3(0.78, 0.64, 0.42), stain * 0.8); |
| +добавлено | albedo = mix(albedo, vec3(0.58, 0.57, 0.5), bloom * 0.45); |
| +добавлено | albedo *= (1.0 + grain * 0.3 * stain) * (1.0 - 0.45 * wetA); |
| +добавлено | albedo *= mix(vec3(1.0), vec3(0.85, 1.0, 0.6), wetA * 0.6); |
| +добавлено | albedo = mix(albedo, vec3(0.4, 0.46, 0.3), foam * ac); |
| +добавлено | rough = mix(mix(rough, 0.9, stain * (1.0 - wetA)), 0.12, max(wetA * 0.85, foam * ac)); |
| +добавлено | metal *= 1.0 - stain; |
| +добавлено | emit += vec3(0.25, 1.0, 0.08) * ac * (0.004 + 0.1 * foam); |
| +добавлено | // electric: thin wandering lines, reseeded at 20 Hz |
| +добавлено | float line = smoothstep(0.03, 0.0, abs(nF.r - 0.5)) + 0.6 * smoothstep(0.02, 0.0, abs(nF.g - 0.5)); |
| +добавлено | vec3 ec = mix(vec3(0.45, 0.65, 1.0), stGlow, step(1e-3, dot(stGlow, stGlow)) * 0.6); |
| +добавлено | emit += ec * line * min(stElec, 1.0) * 10.0; |
| +добавлено | } |
| +добавлено | // corruption: lava-crust / desiccation cracks (crackNet): dark, dead fissures through a blackened |
| +добавлено | // stain, glowing only in a connected patch near the source, primaries further out than the |
| +добавлено | // secondaries, fading with distance (the field's raw value: potential above 1 near the source, |
| +добавлено | // falling off with the front) and with time |
| +добавлено | float co = clamp(stB.z, 0.0, 1.0); |
| +добавлено | if (co > 0.01) { |
| +добавлено | vec4 nC = texture(uStoneNoise, sp2 * 0.23 + vec2(0.29, 0.83)); // 4.3 m tile: warp (apparent cell size wanders) |
| +добавлено | vec4 nJ = texture(uStoneNoise, sp2 * 1.7 + vec2(0.61, 0.17)); // 59 cm: jag, width along the cracks |
| +добавлено | float wv = 0.5 + nJ.b; |
| +добавлено | vec3 cn = crackNet(sp2 + (nC.rg - 0.5) * 0.6 + (nJ.rg - 0.5) * 0.035, px, (0.006 + 0.016 * co) * wv, (0.003 + 0.005 * co) * wv); |
| +добавлено | float crack = max(cn.x, cn.y * smoothstep(0.1, 0.4, co)); |
| +добавлено | float liveP = smoothstep(0.9, 2.0, stB.z), liveS = smoothstep(1.5, 2.6, stB.z); |
| +добавлено | float halo = exp(-cn.z / 0.03) * liveP; |
| +добавлено | float pulse = 0.75 + 0.25 * sin(uTime * 2.3 - length(sp2) * 1.5 + nC.b * 6.0); |
| +добавлено | albedo = mix(albedo, vec3(0.02, 0.0, 0.03), co * 0.5); |
| +добавлено | albedo *= 1.0 - 0.9 * crack; |
| +добавлено | rough = mix(rough, 0.9, crack * co); |
| +добавлено | // the glow is the crack's hot core (narrower than the dark gap), a faint bloom round it |
| +добавлено | emit += (vec3(0.3, 0.04, 0.8) * (halo * 0.45) + vec3(0.7, 0.22, 1.0) * ((cn.x * cn.x * liveP + cn.y * cn.y * liveS * 0.6) * 3.0)) * (co * pulse); |
| +добавлено | crevice = max(crevice, crack * co); |
| +добавлено | } |
| +добавлено | // holy glow: gold-white light pouring out of the joints, a soft sheen on the surface |
| +добавлено | float gl = clamp(stB.w, 0.0, 1.0); |
| +добавлено | vec3 gc = mix(vec3(1.0, 0.8, 0.48), stGlow, step(1e-3, dot(stGlow, stGlow)) * 0.5); |
| +добавлено | emit += gc * gl * (0.35 + 3.0 * crevice) * 2.5; |
| +добавлено | } |
| +добавлено | `; |
| +добавлено | |
| +добавлено | // state from impacts (and the field, per mode); mapped onto the field's channels so one set of |
| +добавлено | // responses serves both |
| +добавлено | const STATE = /* glsl */` |
| +добавлено | vec4 stA = vec4(0.0), stB = vec4(0.0); |
| +добавлено | float stElec = 0.0; |
| +добавлено | vec3 stGlow = vec3(0.0); |
| +добавлено | { |
| +добавлено | vec4 wa, wb; vec3 gc; |
| +добавлено | arenaImpacts(vWPos, wa, wb, gc); |
| +добавлено | float wsum = dot(wa, vec4(1.0)) + dot(wb, vec4(1.0)); |
| +добавлено | stGlow = gc / max(wsum, 1e-4); |
| +добавлено | // scorch: char + a little heat while fresh; magma: heat in fresh cracks |
| +добавлено | stA += vec4(0.3 * wa.x * wa.x + wa.w, wa.x, wa.z, wa.y); |
| +добавлено | stFrostImp = wa.y; |
| +добавлено | stB += vec4(0.6 * wa.w, wb.x, wb.z, wb.y); |
| +добавлено | stElec = wb.w; |
| +добавлено | #if defined(ARENA_FLOOR) || defined(ARENA_STONE) |
| +добавлено | vec2 guv = groundUV(vWPos.xz); |
| +добавлено | float gw = all(greaterThan(guv, vec2(0.0))) && all(lessThan(guv, vec2(1.0))) ? 1.0 : 0.0; |
| +добавлено | #ifdef ARENA_STONE |
| +добавлено | gw *= 1.0 - smoothstep(0.03, 0.55, vWPos.y); // creeps up the foot of walls and pillars |
| +добавлено | #endif |
| +добавлено | if (gw > 0.0) { |
| +добавлено | stA = max(stA, texture(uGroundA, guv) * gw); |
| +добавлено | stB = max(stB, texture(uGroundB, guv) * gw); |
| +добавлено | } |
| +добавлено | #endif |
| +добавлено | } |
| +добавлено | `; |
| +добавлено | |
| +добавлено | // Lighting: sun (or moon) GGX + Lambert with one hardware-PCF shadow tap; ambient from the sky's |
| +добавлено | // baked irradiance (U.uAmbient, the same the particles use; walls see half the sky, undersides a |
| +добавлено | // little bounce); reflections from the sky cube blurred by roughness (on the floor the horizon |
| +добавлено | // darkens where the rim wall would hide it); spell lights. U.uSunColor is E / pi. |
| +добавлено | const FRAG = (surface, pars) => SURFACE_PARS + pars + /* glsl */` |
| +добавлено | out vec4 fragColor; |
| +добавлено | void main() { |
| +добавлено | vec3 albedo = vec3(0.5), emit = vec3(0.0); |
| +добавлено | float rough = 0.5, metal = 0.0, crevice = 0.0; |
| +добавлено | vec3 nW = normalize(vNrm) * (gl_FrontFacing ? 1.0 : -1.0); |
| +добавлено | vec2 sp2 = vWPos.xz; |
| +добавлено | vec3 fwp = fwidth(vWPos); |
| +добавлено | float px = max(max(fwp.x, fwp.y), fwp.z); |
| +добавлено | ${STATE} |
| +добавлено | ${surface} |
| +добавлено | ${RESPONSES} |
| +добавлено | vec3 V = normalize(cameraPosition - vWPos); |
| +добавлено | float nv = max(dot(nW, V), 1e-4); |
| +добавлено | float a = max(rough * rough, 0.002); |
| +добавлено | vec3 f0 = mix(vec3(0.04), albedo, metal), dc = albedo * (1.0 - metal); |
| +добавлено | vec3 col = vec3(0.0); |
| +добавлено | float nl = dot(nW, uSunDir); |
| +добавлено | if (nl > 0.0) { |
| +добавлено | float sh = 1.0; |
| +добавлено | if (uShadowOn > 0.5) { |
| +добавлено | vec4 sc = uShadowMatrix * vec4(vWPos + nW * 0.03, 1.0); |
| +добавлено | if (all(greaterThan(sc.xy, vec2(0.0))) && all(lessThan(sc.xyz, vec3(1.0)))) sh = texture(uShadowMap, vec3(sc.xy, sc.z - 0.0004)); |
| +добавлено | #ifdef ARENA_FLOOR |
| +добавлено | sh = min(sh, rimWallSun(vWPos.xz, uSunDir)); |
| +добавлено | #endif |
| +добавлено | } |
| +добавлено | vec3 h = normalize(uSunDir + V); |
| +добавлено | vec3 F = f0 + (1.0 - f0) * pow(1.0 - max(dot(V, h), 0.0), 5.0); |
| +добавлено | col += uSunColor * (sh * nl) * (dc + PI * F * spellD_GGX(max(dot(nW, h), 0.0), a) * spellV_Smith(nv, nl, a)) |
| +добавлено | + uSunColor * (sh * gFrostGlint); |
| +добавлено | } |
| +добавлено | col += uAmbient * (0.55 + 0.45 * nW.y) * dc * gAO; |
| +добавлено | vec3 R = reflect(-V, nW); |
| +добавлено | vec3 env = textureLod(uSkyCube, R, 8.0 * sqrt(rough)).rgb; |
| +добавлено | #ifdef ARENA_FLOOR |
| +добавлено | env *= mix(0.15, 1.0, smoothstep(0.0, 0.18, R.y)); |
| +добавлено | #endif |
| +добавлено | vec2 ab = envBRDF(rough, nv); |
| +добавлено | col += env * (f0 * ab.x + ab.y) * (gSpecAO * uEnvScale); |
| +добавлено | vec3 sd, ss; |
| +добавлено | arenaSpellLights(vWPos, nW, V, rough, f0, dc, dot(col + emit, vec3(0.2126, 0.7152, 0.0722)), sd, ss); |
| +добавлено | fragColor = vec4(col + (sd + ss) * (1.0 - 0.85 * gGroove) + emit, 1.0); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | const SURFACES = { floor: FLOOR_SURFACE, stone: STONE_SURFACE }; |
| +добавлено | const DEFINES = { floor: 'ARENA_FLOOR', stone: 'ARENA_STONE', dummy: 'ARENA_DUMMY' }; |
| +добавлено | |
| +добавлено | // mode: 'floor' | 'stone' | 'dummy'. surface: GLSL for a custom mode (dummies); uniforms: extra |
| +добавлено | // per-material uniforms (the status vectors for dummies); parsGLSL goes into both stages, |
| +добавлено | // vertexParsGLSL (attributes) and vertexGLSL (end of main) into the vertex one. |
| +добавлено | export function arenaMaterial({ mode = 'stone', kind = 0, uniforms = {}, surface = SURFACES[mode], parsGLSL = '', vertexParsGLSL = '', vertexGLSL = '' } = {}) { |
| +добавлено | return new THREE.ShaderMaterial({ |
| +добавлено | glslVersion: THREE.GLSL3, |
| +добавлено | defines: { ...worldDefines(), [DEFINES[mode]]: '' }, |
| +добавлено | uniforms: { ...U, ...arenaUniforms, ...worldUniforms, uKind: { value: kind }, ...uniforms }, |
| +добавлено | vertexShader: VERT(vertexParsGLSL + parsGLSL, vertexGLSL), |
| +добавлено | fragmentShader: FRAG(surface, parsGLSL), |
| +добавлено | }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // every geometry drawn with an arena material needs aAO (missing attributes read stale state) |
| +добавлено | export function withAO(geometry, value = 1) { |
| +добавлено | if (!geometry.attributes.aAO) geometry.setAttribute('aAO', new THREE.Float32BufferAttribute(new Float32Array(geometry.attributes.position.count).fill(value), 1)); |
| +добавлено | return geometry; |
| +добавлено | } |
| +добавлено | |
| +добавлено | export const STONE = { pillar: 0, rim: 1, pedestal: 2, basin: 4, brass: 6 }; |
| +добавлено | export const stoneMaterial = (kind) => arenaMaterial({ mode: 'stone', kind }); |
| +добавлено | export const floorMaterial = () => arenaMaterial({ mode: 'floor' }); |
| +добавлено | // Copy this file to add an element (CONTRIBUTING.md). A spell is a plain module: |
| +добавлено | // params / ranges: the GUI folder (numbers first; colours as '#rrggbb') |
| +добавлено | // kinds: particle behaviours registered at load, named '<id>.<kind>' |
| +добавлено | // timing: phase durations; shape picks how travel works |
| +добавлено | // create(fx): runs once at load, allocates everything; returns { phase, update } |
| +добавлено | // Per-cast state lives in c.data. Never allocate in update. |
| +добавлено | export default { |
| +добавлено | id: 'template', name: 'Template', key: '', hue: '#9fd8ff', |
| +добавлено | shape: 'projectile', forms: ['Orb'], speed: 14, radius: 0.25, |
| +добавлено | params: { speed: 14, sparks: 1, color: '#9fd8ff' }, |
| +добавлено | ranges: { speed: [4, 40, 0.1], sparks: [0, 3, 0.01] }, |
| +добавлено | timing: { charge: 0.4, impact: 0.15, linger: 1.5 }, |
| +добавлено | kinds: { |
| +добавлено | spark: { style: 'glow', drag: 0.8, gravity: 6, restitution: 0.4, friction: 0.3, life: [0.4, 1.2], size: [0.035, 0.01], stretch: 0.03, emissive: 30, color: ['#bfe6ff', '#2a7fff'], alpha: [1, 0] }, |
| +добавлено | puff: { style: 'media', drag: 2, buoyancy: 0.6, curl: 0.6, life: [0.8, 1.6], size: [0.4, 1.4], emissive: 0, color: ['#8899aa', '#556677'], alpha: [0.5, 0], density: 2 }, |
| +добавлено | }, |
| +добавлено | create(fx) { |
| +добавлено | const S = this, P = fx.particles; // called as spell.create(fx): S.params is the live GUI state |
| +добавлено | const spark = P.emitter('template.spark', { shape: 'sphere', radius: 0.05, spread: 6 }); |
| +добавлено | const trail = P.emitter('template.spark', { shape: 'sphere', radius: 0.08, spread: 0.6 }); |
| +добавлено | const puff = P.emitter('template.puff', { shape: 'sphere', radius: 0.4, spread: 1.2 }); |
| +добавлено | return { |
| +добавлено | phase(c, name) { |
| +добавлено | const p = S.params; |
| +добавлено | if (name === 'charge') { |
| +добавлено | c.data.light = fx.lights.acquire(); |
| +добавлено | if (c.data.light) Object.assign(c.data.light, { range: 8, intensity: 0 }); |
| +добавлено | c.data.light?.color.set(p.color); |
| +добавлено | } else if (name === 'impact') { |
| +добавлено | spark.pos.copy(c.pos); spark.burst(400 * p.sparks); |
| +добавлено | puff.pos.copy(c.pos); puff.burst(40); |
| +добавлено | fx.ground.splat({ x: c.pos.x, z: c.pos.z, radius: 1.5, heat: 0.6, char: 0.4 }); |
| +добавлено | fx.rig.shake(0.35, 18); |
| +добавлено | if (c.data.light) c.data.light.intensity = 60; |
| +добавлено | } else if (name === 'done') { |
| +добавлено | c.data.light?.release(); |
| +добавлено | c.data.light = null; |
| +добавлено | } |
| +добавлено | }, |
| +добавлено | update(c, dt) { |
| +добавлено | const L = c.data.light; |
| +добавлено | if (L) { |
| +добавлено | L.pos.copy(c.pos); |
| +добавлено | if (c.phase === 'charge') L.intensity = 8 * c.t / c.durations.charge; |
| +добавлено | else if (c.phase === 'travel') L.intensity = 10; |
| +добавлено | else L.intensity *= Math.exp(-dt * 6); |
| +добавлено | } |
| +добавлено | if (c.phase === 'travel') { trail.pos.copy(c.pos); trail.rate(300, dt); } |
| +добавлено | }, |
| +добавлено | }; |
| +добавлено | }, |
| +добавлено | }; |
| +добавлено | import * as THREE from 'three'; |
| +добавлено | import { |
| +добавлено | COMMON_GLSL, NOISE_GLSL, ARENA_GLSL, LIGHTS_GLSL, GROUND_GLSL, FX_VERT_HEAD, FX_FRAG_HEAD, FX_OUT_GLSL, FX_BLENDING, MAX_OCCLUDERS, |
| +добавлено | } from '../vfx/common.js'; |
| +добавлено | import { REFRACT_GLSL } from '../vfx/Refraction.js'; |
| +добавлено | import { arenaUniforms } from '../scene/arenaMaterial.js'; |
| +добавлено | import { FluidVolume } from '../vfx/FluidVolume.js'; |
| +добавлено | |
| +добавлено | // Acid (PLAN 3), matched against film acid (Alien's blood eating through a deck: yellow-green |
| +добавлено | // liquid, white acrid fumes, violent froth, dark pitted stone) and chlorine release footage (the |
| +добавлено | // Jack Rabbit II trials: a pale yellow-green cloud that slumps and runs along the ground). |
| +добавлено | // Toxic Bloom: a lobbed blob of glowing acid (the shared metaball renderer, acid preset) splashes |
| +добавлено | // onto the target: beads slap the floor and flatten, some cling to the dummy and ooze down it. The |
| +добавлено | // liquid then stands on the floor as its own refract-pass layer (the ground field's acid, shaped by |
| +добавлено | // noise into a pool with fingers and stranded beads: meniscus, murky Beer-Lambert body over the |
| +добавлено | // eaten stone, drifting luminous swirls, a two-scale froth of swelling and popping bubbles where it |
| +добавлено | // touches material and along its eating front, a dark pocked etch round it). Froth domes of mixed |
| +добавлено | // size cluster on it and pop into spits and vapour; pale heavy vapour rolls out along the floor, |
| +добавлено | // white fumes rise where it reacts; drips fall off the dummy as it dissolves. |
| +добавлено | // Corrosion Cloud: the blob bursts into a simulated dense gas over the target (the shared 3D fluid, |
| +добавлено | // its soot channel used as a heavy gas that carries no heat), matched to the chlorine plumes of the |
| +добавлено | // Jack Rabbit II trials and the Graniteville release: it falls as a slug, slumps and runs out |
| +добавлено | // along the floor as a low, dense, pale carpet (a gravity current), lobes and fingers at its front, |
| +добавлено | // billowing only near the source, soft edges curling into wisps, thinning to a haze. Never self-lit: |
| +добавлено | // sun and sky shadowed through its own depth light the tops pale and leave the underside olive; |
| +добавлено | // drips spit, etch and pit the floor. Without a free fluid slot: a raymarched cloud. |
| +добавлено | // The liquid body (charge, flight, splash) is isolated in the BLOB section below, so it can move to |
| +добавлено | // the shared particle fluid ('acid' preset) by swapping those five functions. |
| +добавлено | |
| +добавлено | const N_BUB = 768; // froth dome ring (High tier) |
| +добавлено | const POP = 0.08; // s, spray ring after a dome's life |
| +добавлено | const SURF = 0.011; // m, the liquid's surface over the floor |
| +добавлено | const MAX_POOLS = 3; |
| +добавлено | |
| +добавлено | // --- froth domes: sphere impostors in the fx pass (WBOIT), sitting half-sunk in the liquid ------ |
| +добавлено | // Motion is analytic (no state): surface point + drift + wobble, mirrored in JS for the pops. |
| +добавлено | const BUBBLE_VERT = FX_VERT_HEAD + COMMON_GLSL + /* glsl */` |
| +добавлено | uniform float uNow; |
| +добавлено | in vec4 aB0; // surface point xyz, birth (module clock, s) |
| +добавлено | in vec4 aB1; // radius m, life s, -, seed 0..1 |
| +добавлено | in vec4 aB2; // drift x, drift z (m/s), wobble amplitude m, wobble rad/s |
| +добавлено | out vec2 vUv; |
| +добавлено | out vec3 vC; // view-space centre |
| +добавлено | flat out vec4 vB; // radius m, age 0..1, pop 0..1, seed |
| +добавлено | flat out float vSurf; // world height of the liquid surface |
| +добавлено | out float vGain; |
| +добавлено | void main() { |
| +добавлено | float tau = uNow - aB0.w, life = aB1.y; |
| +добавлено | gl_Position = vec4(2.0, 2.0, 2.0, 1.0); |
| +добавлено | vB = vec4(0.0); vC = vec3(0.0); vUv = vec2(0.0); vGain = 0.0; vSurf = 0.0; |
| +добавлено | if (tau < 0.0 || tau > life + ${POP.toFixed(3)} || life <= 0.0) return; |
| +добавлено | float ph = aB1.w * 6.2832, k = clamp(tau / life, 0.0, 1.0); |
| +добавлено | vec3 c = aB0.xyz + vec3(aB2.x * tau + aB2.z * sin(aB2.w * tau + ph), 0.0, aB2.y * tau + aB2.z * cos(aB2.w * 0.83 * tau + aB1.w * 11.0)); |
| +добавлено | // swells up out of the liquid, then sits on it as a dome (centre below the surface) |
| +добавлено | float r = aB1.x * (0.4 + 0.6 * sqrt(min(k * 3.0, 1.0))); |
| +добавлено | c.y += r * mix(-0.9, -0.3, smoothstep(0.0, 0.3, k)); |
| +добавлено | float pop = clamp((tau - life) / ${POP.toFixed(3)}, 0.0, 1.0); |
| +добавлено | vec3 cv = (viewMatrix * vec4(c, 1.0)).xyz; |
| +добавлено | float viewZ = -cv.z; |
| +добавлено | if (viewZ < 0.25) return; |
| +добавлено | // never below one fx pixel, energy kept |
| +добавлено | float pxW = 2.0 * viewZ / (projectionMatrix[1][1] * uFxResolution.y); |
| +добавлено | float rr = max(r, pxW); |
| +добавлено | vGain = (r / rr) * (r / rr) * smoothstep(0.25, 1.0, viewZ); |
| +добавлено | float ext = (1.0 + 1.3 * pop) * 1.08; // slack for perspective, room for the spray ring |
| +добавлено | gl_Position = projectionMatrix * vec4(cv + vec3(position.xy * rr * ext, 0.0), 1.0); |
| +добавлено | vUv = position.xy * ext; |
| +добавлено | vC = cv; |
| +добавлено | vB = vec4(rr, k, pop, aB1.w); |
| +добавлено | vSurf = aB0.y; |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | const BUBBLE_FRAG = FX_FRAG_HEAD + COMMON_GLSL + NOISE_GLSL + FX_OUT_GLSL + /* glsl */` |
| +добавлено | uniform mat4 projectionMatrix; |
| +добавлено | uniform samplerCube uSkyCube; |
| +добавлено | uniform vec3 uSunDir; |
| +добавлено | uniform vec3 uSunColor; |
| +добавлено | uniform vec3 uTint; // acid glow, linear (the pool's light from below) |
| +добавлено | uniform vec3 uHot; // spray of a pop, linear |
| +добавлено | uniform vec2 uIri; // reflection gain, interference saturation 0..1 |
| +добавлено | in vec2 vUv; |
| +добавлено | in vec3 vC; |
| +добавлено | flat in vec4 vB; |
| +добавлено | flat in float vSurf; |
| +добавлено | in float vGain; |
| +добавлено | |
| +добавлено | // Spectrally integrated cos(2 pi opd / lambda) against the CIE XYZ matching functions, with the |
| +добавлено | // Gaussian fits in Fourier space of Belcour & Barla 2017 ("A Practical Extension to Microfacet |
| +добавлено | // Theory for the Modeling of Varying Iridescence"), to linear sRGB, normalised so opd 0 is white. |
| +добавлено | const mat3 XYZ2RGB = mat3(3.2404542, -0.9692660, 0.0556434, -1.5371385, 1.8760108, -0.2040259, -0.4985314, 0.0415560, 1.0572252); |
| +добавлено | vec3 filmCos(float opd) { |
| +добавлено | float ph = 6.2831853e-9 * opd; // opd in nm |
| +добавлено | vec3 var = vec3(4.3278e9, 9.3046e9, 6.6121e9); |
| +добавлено | vec3 xyz = vec3(5.4856e-13, 4.4201e-13, 5.2481e-13) * sqrt(6.2831853 * var) * cos(vec3(1.6810e6, 1.7953e6, 2.2084e6) * ph) * exp(-var * ph * ph); |
| +добавлено | xyz.x += 9.7470e-14 * sqrt(6.2831853 * 4.5282e9) * cos(2.2399e6 * ph) * exp(-4.5282e9 * ph * ph); |
| +добавлено | return XYZ2RGB * (xyz / 1.0685e-7) / vec3(1.2048, 0.9483, 0.9088); |
| +добавлено | } |
| +добавлено | // liquid film in air: R(lambda) ~ sin^2(delta / 2), spectral mean 0.5 (1 - filmCos), through Airy's |
| +добавлено | // F s / (1 + F s). A viscous acid film is microns thick, so it reflects near-white; only as it |
| +добавлено | // drains thin before the pop do interference colours come up, and black just before it bursts. |
| +добавлено | vec3 filmReflect(float NoV, float dnm) { |
| +добавлено | float cosT = sqrt(1.0 - (1.0 - NoV * NoV) / 1.85); // n = 1.36 |
| +добавлено | float R0 = 0.023 + 0.977 * pow(1.0 - NoV, 5.0); |
| +добавлено | vec3 s = clamp(0.5 * (1.0 - filmCos(2.72 * dnm * cosT)), 0.0, 1.0); |
| +добавлено | float F = 4.0 * R0 / max((1.0 - R0) * (1.0 - R0), 1e-3); |
| +добавлено | return F * s / (1.0 + F * s); |
| +добавлено | } |
| +добавлено | float film(vec3 n, float age, float seed) { |
| +добавлено | float sw = noise3(n * 0.23 + vec3(seed * 7.1, uTime * 0.045 + seed, seed * 3.7)); |
| +добавлено | float drain = mix(1.4, 0.5, n.y * 0.5 + 0.5); |
| +добавлено | return mix(2400.0, 30.0, age * age * age) * drain * (0.4 + 1.2 * sw); |
| +добавлено | } |
| +добавлено | // the sky above, the glowing liquid below |
| +добавлено | vec3 envAt(vec3 r) { return textureLod(uSkyCube, r, 1.5).rgb + uTint * smoothstep(0.15, -0.5, r.y); } |
| +добавлено | void main() { |
| +добавлено | float r2 = dot(vUv, vUv), pop = vB.z, viewZ = -vC.z; |
| +добавлено | if (pop > 0.0) { // burst: a ring of fine spray thrown off the rim |
| +добавлено | float x = (sqrt(r2) - (1.0 + 1.2 * pop)) / 0.16; |
| +добавлено | float ring = exp(-x * x) * (1.0 - pop); |
| +добавлено | if (ring < 0.01) discard; |
| +добавлено | fxOut(vec3(0.0), 0.0, uHot * ring * vGain * 0.5, vec2(0.0), viewZ); |
| +добавлено | return; |
| +добавлено | } |
| +добавлено | if (r2 >= 1.0) discard; |
| +добавлено | float z = sqrt(1.0 - r2); |
| +добавлено | mat3 toW = transpose(mat3(viewMatrix)); |
| +добавлено | vec3 pv = vC + vec3(vUv, z) * vB.x; |
| +добавлено | vec3 pw = toW * (pv - viewMatrix[3].xyz); |
| +добавлено | // what is under the liquid surface doesn't show: a dome, anti-aliased over a pixel |
| +добавлено | float px = 2.0 * viewZ / (projectionMatrix[1][1] * uFxResolution.y); |
| +добавлено | float above = clamp((pw.y - vSurf) / px + 0.5, 0.0, 1.0); |
| +добавлено | if (above <= 0.0) discard; |
| +добавлено | viewZ -= z * vB.x; |
| +добавлено | vec3 rd = toW * normalize(pv); |
| +добавлено | vec3 nF = toW * vec3(vUv, z), nB = toW * vec3(vUv, -z); |
| +добавлено | float NoV = clamp(dot(nF, -rd), 0.0, 1.0); |
| +добавлено | vec3 RF = filmReflect(NoV, film(nF, vB.y, vB.w)), RB = filmReflect(NoV, film(nB, vB.y, vB.w)); |
| +добавлено | float mF = dot(RF, vec3(0.3333)), mB = dot(RB, vec3(0.3333)); |
| +добавлено | RF = mix(vec3(mF), RF, uIri.y); RB = mix(vec3(mB), RB, uIri.y); |
| +добавлено | vec3 rF = reflect(rd, nF), rB = reflect(rd, nB); |
| +добавлено | vec3 col = envAt(rF) * RF + envAt(rB) * RB * (1.0 - RF); |
| +добавлено | col += uSunColor * pow(max(dot(rF, uSunDir), 0.0), 600.0) * 25.0 * RF; |
| +добавлено | // the film is the acid itself: tinted, lit through by the pool's glow, most along the rim |
| +добавлено | float rim = pow(1.0 - NoV, 2.0); |
| +добавлено | float edge = clamp((1.0 - sqrt(r2)) * vB.x / px * 1.5, 0.0, 1.0) * vGain * above; |
| +добавлено | float a = clamp((mF + mB) * 0.5 * uIri.x + 0.06 + 0.4 * rim, 0.0, 0.85) * edge; |
| +добавлено | if (a < 0.002) discard; |
| +добавлено | fxOut(col * uIri.x * edge / max(a, 1e-4), a, uTint * (0.2 + 1.1 * rim) * edge, vec2(0.0), viewZ); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | // --- the standing liquid: a refract-pass layer over the floor ---------------------------------- |
| +добавлено | const POOL_VERT = /* glsl */` |
| +добавлено | out vec3 vW; |
| +добавлено | void main() { |
| +добавлено | vec4 w = modelMatrix * vec4(position, 1.0); |
| +добавлено | vW = w.xyz; |
| +добавлено | gl_Position = projectionMatrix * viewMatrix * w; |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | const POOL_FRAG = /* glsl */` |
| +добавлено | uniform vec4 uPoolA; // centre x, z, radius m, liquid 0..1 (how much of the field's acid stands) |
| +добавлено | uniform vec4 uPoolB; // reaction 0..1, -, corrosion 0..2, seed |
| +добавлено | uniform vec3 uGlowCol; // linear liquid glow (x glow) |
| +добавлено | uniform vec3 uHotCol; // linear reaction glow |
| +добавлено | uniform vec3 uAbsorb; // 1/m |
| +добавлено | uniform vec3 uSunDir; |
| +добавлено | uniform vec3 uSunColor; |
| +добавлено | uniform vec3 uAmbient; |
| +добавлено | uniform sampler2D uStoneNoise; // the arena's mipmapped noise: r, g fbm (4 cells/tile), a fbm (32) |
| +добавлено | ${COMMON_GLSL} |
| +добавлено | ${NOISE_GLSL} |
| +добавлено | ${ARENA_GLSL} |
| +добавлено | ${LIGHTS_GLSL} |
| +добавлено | ${GROUND_GLSL} |
| +добавлено | ${REFRACT_GLSL} |
| +добавлено | in vec3 vW; |
| +добавлено | out vec4 fragColor; |
| +добавлено | |
| +добавлено | // froth: a jittered grid of bubbles (cell metres), each swelling and popping on its own clock, |
| +добавлено | // present in a cell with probability dens. Coverage of the dome under p, nb its normal (world). |
| +добавлено | float froth(vec2 p, float cell, float dens, float rate, out vec3 nb) { |
| +добавлено | vec2 g = p / cell, i0 = floor(g); |
| +добавлено | float best = 9.0, cov = 0.0; |
| +добавлено | nb = vec3(0.0, 1.0, 0.0); |
| +добавлено | for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) { |
| +добавлено | vec2 c = i0 + vec2(float(x), float(y)); |
| +добавлено | vec3 hh = hash33(vec3(c, cell * 97.0)); |
| +добавлено | if (hh.z > dens) continue; |
| +добавлено | float life = fract(hh.x * 7.31 + uTime * rate * (0.5 + hh.y)); |
| +добавлено | float rad = (0.3 + 0.45 * hh.y) * sqrt(life); |
| +добавлено | vec2 o = g - c - 0.5 - (hh.yx - 0.5) * 0.6; |
| +добавлено | float l = length(o), d = l / rad; |
| +добавлено | if (d < 1.0 && l < best) { |
| +добавлено | best = l; |
| +добавлено | nb = vec3(o.x / rad, sqrt(1.0 - d * d), o.y / rad); |
| +добавлено | cov = 1.0 - smoothstep(0.8, 1.0, d); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | return cov; |
| +добавлено | } |
| +добавлено | |
| +добавлено | void main() { |
| +добавлено | gLightNoShadow = true; |
| +добавлено | vec2 xz = vW.xz; |
| +добавлено | // liquid where the field's acid (blurred: surface tension rounds everything off below a few cm), |
| +добавлено | // shifted by broad noise into lobes, clears the bar: a pool with rounded fingers, stranded beads |
| +добавлено | // and a soft eating front; h > 0 is liquid |
| +добавлено | const vec2 e = vec2(0.07, -0.07); |
| +добавлено | float ac = min(0.25 * (groundB(xz + e.xx).y + groundB(xz + e.xy).y + groundB(xz + e.yx).y + groundB(xz + e.yy).y), 1.6); |
| +добавлено | vec2 sd = vec2(uPoolB.w, uPoolB.w * 1.7); |
| +добавлено | float big = texture(uStoneNoise, xz * 0.19 + sd).r, fine = texture(uStoneNoise, xz * 0.8 + sd.yx).a; |
| +добавлено | float rad = length(xz - uPoolA.xy) / uPoolA.z; |
| +добавлено | float h = ac * 1.3 * uPoolA.w - 0.45 + (big - 0.5) * 1.1 + (fine - 0.5) * 0.15 - smoothstep(0.7, 1.0, rad) * 2.0; |
| +добавлено | float depth = 0.004 + 0.016 * smoothstep(0.0, 0.5, h); // m |
| +добавлено | // every screen derivative before any branch: the AA width and the surface slope (the depth's |
| +добавлено | // derivatives solved back to world xz: a steep meniscus where it thins at the edge) |
| +добавлено | float fw = max(fwidth(h), 1e-4); |
| +добавлено | vec2 dx = dFdx(xz), dy = dFdy(xz); |
| +добавлено | float hx = dFdx(depth), hy = dFdy(depth), det = dx.x * dy.y - dx.y * dy.x; |
| +добавлено | vec2 g = abs(det) > 1e-14 ? vec2(hx * dy.y - hy * dx.y, hy * dx.x - hx * dy.x) / det : vec2(0.0); |
| +добавлено | float pxw = max(length(dx), length(dy)); // pixel footprint (m) |
| +добавлено | float cov = smoothstep(-fw, fw, h); |
| +добавлено | float etch = smoothstep(-0.5, -0.03, h) * smoothstep(0.03, 0.15, ac) * min(uPoolB.z, 1.0); |
| +добавлено | if (cov <= 0.0 && etch <= 0.004) discard; |
| +добавлено | |
| +добавлено | vec3 v = normalize(cameraPosition - vW); |
| +добавлено | vec3 under = textureLod(uSceneColor, gl_FragCoord.xy / uResolution, 0.0).rgb; |
| +добавлено | // the eaten stone round the liquid. The stain itself (rust-brown blotches, etched grain, salt |
| +добавлено | // bloom) is the floor's own acid response; here it is only damp, darker and browner towards the |
| +добавлено | // liquid, in soft blotches (a hard threshold on the fine noise printed a camouflage of specks), |
| +добавлено | // and wet and glossy at the edge |
| +добавлено | float damp = etch * smoothstep(-0.55, -0.05, h + (big - 0.5) * 0.3); |
| +добавлено | vec3 col = under * mix(vec3(1.0), vec3(0.5, 0.45, 0.36), damp); |
| +добавлено | float wet = smoothstep(-0.15, 0.0, h); |
| +добавлено | col += envReflect(reflect(-v, vec3(0.0, 1.0, 0.0)), 0.15) * fresnel(v.y, 0.03) * wet * 0.8; |
| +добавлено | float alpha = etch * 0.92; |
| +добавлено | |
| +добавлено | if (cov > 0.0) { |
| +добавлено | // what stands in it (dummies, pillars, spikes): the occluder capsules at their foot |
| +добавлено | float contact = 0.0; |
| +добавлено | int nOcc = int(uWorldCounts.w); |
| +добавлено | for (int i = 0; i < ${MAX_OCCLUDERS}; i++) { |
| +добавлено | if (i >= nOcc) break; |
| +добавлено | vec4 a = worldTexel(3, i * 2), b = worldTexel(3, i * 2 + 1); |
| +добавлено | float y0 = min(a.y, b.y); |
| +добавлено | if (y0 - a.w > 0.3) continue; |
| +добавлено | float d = sdCapsule(vec3(xz.x, max(y0, 0.0), xz.y), a.xyz, b.xyz, a.w); |
| +добавлено | contact = max(contact, 1.0 - smoothstep(-0.05, 0.35, d)); |
| +добавлено | } |
| +добавлено | float react = uPoolB.x; |
| +добавлено | float boil = clamp(contact * 1.3 + 0.3 * smoothstep(0.5, 1.2, ac) - 0.1, 0.0, 1.0) * react; |
| +добавлено | // simmering surface: slow undulation, choppy where it boils; fades once a pixel spans it |
| +добавлено | vec3 rq = vec3(xz * 1.1, uTime * 0.3); |
| +добавлено | vec2 rip = vec2(noise3(rq), noise3(rq + vec3(0.37, 0.61, 0.0))) - 0.5; |
| +добавлено | g = clamp(g * 3.0, -2.5, 2.5) + rip * (0.08 + 0.9 * boil) * (1.0 - smoothstep(0.004, 0.03, pxw)); |
| +добавлено | vec3 n = normalize(vec3(-g.x, 1.0, -g.y)); |
| +добавлено | float NoV = max(dot(n, v), 1e-3); |
| +добавлено | float F = fresnel(NoV, 0.025); |
| +добавлено | vec3 refl = envReflect(reflect(-v, n), 0.05); |
| +добавлено | vec3 H = normalize(uSunDir + v); |
| +добавлено | float NoL = max(dot(n, uSunDir), 0.0); |
| +добавлено | vec3 spec = uSunColor * (PI * spellD_GGX(max(dot(n, H), 0.0), 0.02) * spellV_Smith(NoV, NoL, 0.02) * NoL * fresnel(dot(v, H), 0.025)); |
| +добавлено | vec3 dS, sS; |
| +добавлено | spellLightPBR(vW, n, v, 0.1, vec3(0.025), vec3(0.0), dS, sS); |
| +добавлено | // body: the stone seen through the murky liquid (absorbed and clouded over the path down and |
| +добавлено | // back up: only the thin edges show what is under it) |
| +добавлено | float behind; |
| +добавлено | vec3 floorC = sceneRefract(vW, n, v, 1.36, depth * 8.0, behind); |
| +добавлено | float path = depth * (1.0 + 1.0 / max(NoV, 0.2)); |
| +добавлено | vec3 T = exp(-(uAbsorb + 50.0) * path); |
| +добавлено | vec3 murk = (uAmbient * 1.2 + uSunColor * max(uSunDir.y, 0.0) * 0.2) * vec3(0.06, 0.075, 0.025) + dS * 0.05; |
| +добавлено | vec3 body = floorC * T + murk * (1.0 - T); |
| +добавлено | // its own light: luminous veins drifting through a darker body, brightest where deep and |
| +добавлено | // where it eats |
| +добавлено | float fineFlow = (noise3(vec3(xz * 3.4 + sd, uTime * 0.12)) - 0.5) * (1.0 - smoothstep(0.003, 0.012, pxw)); |
| +добавлено | float sw = noise3(vec3(xz * 0.45 + sd, uTime * 0.035)) * 0.6 + noise3(vec3(xz * 1.3 + sd.yx, uTime * 0.06 + 0.5)) * 0.4 + fineFlow * 0.3; |
| +добавлено | float vein = smoothstep(0.3, 0.8, sw); |
| +добавлено | float deep = 1.0 - exp(-depth * 110.0); |
| +добавлено | vec3 emit = mix(uGlowCol, uHotCol, 0.2 + 0.5 * boil) * deep * (0.15 + 0.85 * vein * vein) * (0.4 + 0.6 * react + 0.8 * boil) * 0.7; |
| +добавлено | vec3 liq = mix(body, refl, F) + spec + sS + emit; |
| +добавлено | |
| +добавлено | // froth where it reacts (along what stands in it, a little along its eating front), in clumps |
| +добавлено | float clump = smoothstep(0.38, 0.62, texture(uStoneNoise, xz * 0.6 + sd * 1.3).g); |
| +добавлено | float foamW = clamp(boil * 1.3 * (0.35 + 0.65 * clump) + smoothstep(0.08, 0.0, h) * 0.3 * react * clump, 0.0, 1.0); |
| +добавлено | if (foamW > 0.02) { |
| +добавлено | vec3 nb1, nb2; |
| +добавлено | float c1 = froth(xz, 0.034, foamW * 0.6, 0.8, nb1); |
| +добавлено | float c2 = froth(xz + 0.37, 0.012, foamW * 0.9, 1.5, nb2); |
| +добавлено | // cells smaller than a few pixels fade to their mean (no shimmer): fine froth reads milky |
| +добавлено | float s1 = smoothstep(1.5, 4.0, 0.034 / pxw), s2 = smoothstep(1.5, 4.0, 0.012 / pxw); |
| +добавлено | bool one = c1 * s1 > 0.0; |
| +добавлено | float fc = one ? c1 : max(mix(foamW * 0.3, c1, s1), mix(foamW * 0.45, c2, s2)); |
| +добавлено | float sharp = one ? s1 : s2; |
| +добавлено | vec3 nf = normalize(mix(vec3(0.0, 1.0, 0.0), one ? nb1 : nb2, sharp * 0.9)); |
| +добавлено | float NoVf = max(dot(nf, v), 0.0); |
| +добавлено | vec3 rf = reflect(-v, nf); |
| +добавлено | // big domes are clear (the liquid through a film, glints, a bright rim), small ones milky |
| +добавлено | float milk = one ? 0.12 : mix(0.75, 0.45, s2); |
| +добавлено | vec3 milkCol = (uAmbient * 1.5 + uSunColor * max(dot(nf, uSunDir), 0.0) * 0.5) * vec3(0.6, 0.64, 0.48) + uHotCol * (0.15 + 0.4 * boil); |
| +добавлено | float Ff = fresnel(NoVf, 0.03); |
| +добавлено | vec3 foamCol = mix(liq * 0.9 + uHotCol * 0.06, milkCol, milk) * (1.0 - Ff) + envReflect(rf, 0.04) * Ff |
| +добавлено | + uSunColor * pow(max(dot(rf, uSunDir), 0.0), 500.0) * 8.0 * sharp |
| +добавлено | + uHotCol * 0.35 * pow(1.0 - NoVf, 3.0) * sharp; |
| +добавлено | liq = mix(liq, foamCol, fc); |
| +добавлено | } |
| +добавлено | col = mix(col, liq, cov); |
| +добавлено | alpha = max(alpha, cov); |
| +добавлено | } |
| +добавлено | fragColor = vec4(col, alpha); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | // --- corrosion cloud: raymarched body (Volumes) --------------------------------------------------- |
| +добавлено | const CLOUD_GLSL = /* glsl */` |
| +добавлено | uniform vec4 uCloud; // glow, age s, density 0..1, seed |
| +добавлено | uniform vec4 uCloudShape; // slump 0..1, -, -, - |
| +добавлено | uniform vec3 uCloudGlow; // linear glow colour |
| +добавлено | uniform vec3 uCloudAlb; // gas albedo, linear (pale yellow-green) |
| +добавлено | void volumeSample(vec3 pw, vec3 pl, out float sigma, out vec3 albedo, out vec3 emission) { |
| +добавлено | float age = uCloud.y, rr = length(pl.xz), slump = uCloudShape.x; |
| +добавлено | // slow roll about the vertical (faster inside); the gas pattern drifts down (heavy) |
| +добавлено | float ang = age * (0.12 + 0.2 * (1.0 - rr)), ca = cos(ang), sa = sin(ang); |
| +добавлено | vec3 q = vec3(ca * pl.x - sa * pl.z, pl.y, sa * pl.x + ca * pl.z) * uVolScale; |
| +добавлено | q.y += age * 0.16; |
| +добавлено | q = q * 0.3 + uCloud.w; |
| +добавлено | // two taps per sample: the coarse one's worley, the fine one's fbm |
| +добавлено | vec4 nc = noise3v(q), nv = noise3v(q * 2.3 + vec3(0.37, age * 0.02, 0.0)); |
| +добавлено | float n = nc.r * 0.7 + nv.r * 0.3; |
| +добавлено | // a domed top; a belly that sags and hangs lobes as the heavy gas slumps |
| +добавлено | float body = 1.0 - length(pl * vec3(1.0, pl.y > 0.0 ? 1.15 + 0.45 * slump : 0.9 - 0.15 * slump, 1.0)); |
| +добавлено | float lobes = (1.0 - smoothstep(-0.6, 0.1, pl.y)) * (nc.g - 0.5) * 0.9; |
| +добавлено | float d = body + (n - 0.5) * 1.2 + (nv.g - 0.5) * 0.35 + lobes; |
| +добавлено | // faded well inside the bounding sphere, so the noise never shows its clipped silhouette |
| +добавлено | sigma = smoothstep(0.0, 0.3, d) * 1.5 * uCloud.z * smoothstep(1.0, 0.55, length(pl)); |
| +добавлено | albedo = uCloudAlb; |
| +добавлено | // glowing droplet pockets drifting in the core, breathing; their light fills the gas round them |
| +добавлено | float core = smoothstep(0.12, 0.7, d); |
| +добавлено | float pocket = smoothstep(0.52, 0.85, nv.r) * 4.0; |
| +добавлено | float pulse = 0.6 + 0.4 * sin(age * 1.7 + n * 11.0); |
| +добавлено | emission = uCloudGlow * uCloud.x * (core * core * (0.01 + 0.2 * pocket) * pulse) * sigma; |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | const SPL = { x: 0, z: 0, radius: 1, acid: 0, pattern: 'noise', seed: 0 }; // reused ground splat |
| +добавлено | const clamp01 = (x) => (x < 0 ? 0 : x > 1 ? 1 : x); |
| +добавлено | const sstep = (a, b, x) => { const t = clamp01((x - a) / (b - a)); return t * t * (3 - 2 * t); }; |
| +добавлено | |
| +добавлено | export default { |
| +добавлено | id: 'acid', name: 'Acid', key: '9', hue: '#8aff3c', |
| +добавлено | shape: 'projectile', forms: ['Toxic Bloom', 'Corrosion Cloud'], radius: 0.3, |
| +добавлено | lob: 4, // cast.js: gravity on in flight; phase 'travel' replaces the launch with an exact arc |
| +добавлено | params: { size: 1, speed: 10, glow: 1, drips: 1, fog: 1, bubbles: 1, iridescence: 0.35, corrosion: 1, cloudTime: 8, color: '#7cff2a', fogColor: '#bfd895', cloudColor: '#bfe08a' }, |
| +добавлено | ranges: { |
| +добавлено | size: [0.4, 2.5, 0.01], speed: [4, 30, 0.1], glow: [0, 3, 0.01], drips: [0, 3, 0.01], fog: [0, 2, 0.01], |
| +добавлено | bubbles: [0, 3, 0.01], iridescence: [0, 1, 0.01], corrosion: [0, 2, 0.01], cloudTime: [3, 15, 0.1], |
| +добавлено | }, |
| +добавлено | presets: { |
| +добавлено | bile: { color: '#d8ff3a', fogColor: '#dcd8a0', cloudColor: '#e0eb86', glow: 0.85 }, |
| +добавлено | venom: { color: '#c24dff', fogColor: '#d2c0dc', cloudColor: '#b98ad8', bubbles: 1.6 }, |
| +добавлено | radioactive: { color: '#a0ff00', fogColor: '#c8e2a8', cloudColor: '#b0f070', glow: 2.2, fog: 0.7, iridescence: 0.15 }, |
| +добавлено | }, |
| +добавлено | timing: { charge: 0.6, impact: 0.3, linger: 6 }, |
| +добавлено | kinds: { |
| +добавлено | // a falling drop of acid; on landing it bounces into a spit (morph) that etches the floor |
| +добавлено | drip: { style: 'glow', drag: 0.25, gravity: 9.8, restitution: 0.45, friction: 0.6, life: [1.4, 2.2], size: [0.018, 0.012], stretch: 0.014, emissive: 1.0, color: ['#c8ff70', '#3c8a10'], alpha: [1, 0.85], fadeIn: 0.02, fadeOut: 0.1, paints: 'acid', paintAmount: 0.25, morph: 'acid.sizzle', forceResponse: 0.2 }, |
| +добавлено | // spits: tiny hot droplets thrown up by the reaction and by bursting froth; never lie on the floor |
| +добавлено | sizzle: { style: 'glow', drag: 1.2, gravity: 6, life: [0.12, 0.35], size: [0.011, 0.004], stretch: 0.012, emissive: 5, color: ['#f6ffd0', '#7cff2a'], alpha: [1, 0], fadeIn: 0.01, fadeOut: 0.4, restitution: -1, paints: 'acid', paintAmount: 0.18 }, |
| +добавлено | // heavy vapour: pale, lit by the sun and the liquid's glow, rolling out along the floor |
| +добавлено | fog: { style: 'media', drag: 0.9, buoyancy: -2.2, curl: 0.9, curlScale: 0.14, life: [2.8, 4.8], size: [0.32, 0.95], sizePow: 0.5, emissive: 0, color: ['#bfd895', '#7a8a5a'], alpha: [0.22, 0], fadeIn: 0.12, fadeOut: 0.5, density: 0.8, erosion: 0.85, restitution: 0, friction: 0.03, lightResponse: 0.8, forceResponse: 0.8 }, |
| +добавлено | // droplet haze over the liquid: pale, lit by the sun and the pool, never self-lit |
| +добавлено | miasma: { style: 'media', drag: 1.1, buoyancy: -1.6, curl: 1.2, curlScale: 0.18, life: [2.5, 4.5], size: [0.35, 0.9], sizePow: 0.6, emissive: 0, color: ['#b4c88a', '#6f7d50'], alpha: [0.35, 0], fadeIn: 0.15, fadeOut: 0.4, density: 1.6, erosion: 0.75, restitution: 0, friction: 0.05, forceResponse: 0.8, lightResponse: 0.8 }, |
| +добавлено | // white acrid fumes rising where it reacts |
| +добавлено | fume: { style: 'media', drag: 1.4, buoyancy: 0.55, curl: 1.2, curlScale: 0.3, life: [1.4, 2.8], size: [0.12, 0.85], sizePow: 0.7, emissive: 0, color: ['#eef2e2', '#b9c2a8'], alpha: [0.3, 0], fadeIn: 0.15, density: 1.6, erosion: 0.6, lightResponse: 0.9 }, |
| +добавлено | // droplets drawn in while the blob gathers |
| +добавлено | bead: { style: 'glow', drag: 1.5, life: [0.4, 0.8], size: [0.013, 0.006], stretch: 0.01, emissive: 3, color: ['#e8ffa8', '#7cff2a'], alpha: [0.2, 1], fadeIn: 0.3, fadeOut: 0.1, restitution: -1 }, |
| +добавлено | }, |
| +добавлено | |
| +добавлено | create(fx) { |
| +добавлено | const S = this, P = fx.particles, Q = fx.Q; |
| +добавлено | const dripE = P.emitter('acid.drip', { shape: 'sphere', radius: 0.22, spread: 0.3 }); |
| +добавлено | const splashE = P.emitter('acid.drip', { shape: 'sphere', radius: 0.3, spread: 1.5, radial: 3.2 }); |
| +добавлено | const rainE = P.emitter('acid.drip', { shape: 'disk', radius: 2, spread: 0.15 }); |
| +добавлено | const runE = P.emitter('acid.drip', { shape: 'ring', radius: 0.3, spread: 0.05 }); |
| +добавлено | const sizzleE = P.emitter('acid.sizzle', { shape: 'disk', radius: 1.6, spread: 1.2 }); |
| +добавлено | const spitE = P.emitter('acid.sizzle', { shape: 'ring', radius: 0.36, spread: 0.9 }); |
| +добавлено | const popE = P.emitter('acid.sizzle', { shape: 'sphere', radius: 0.02, spread: 0.7 }); |
| +добавлено | const moteE = P.emitter('acid.bead', { shape: 'shell', radius: 1.1, spread: 0.15, radial: -2.2 }); |
| +добавлено | const fogE = P.emitter('acid.fog', { shape: 'disk', radius: 0.6, spread: 0.6, radial: 3.6 }); |
| +добавлено | const miasmaE = P.emitter('acid.miasma', { shape: 'disk', radius: 0.8, spread: 0.5, radial: 2.4 }); |
| +добавлено | const vaporE = P.emitter('acid.fume', { shape: 'sphere', radius: 0.25, spread: 0.4, size: 0.7, life: 0.6 }); |
| +добавлено | const steamE = P.emitter('acid.fume', { shape: 'ring', radius: 0.32, spread: 0.25 }); |
| +добавлено | const puffE = P.emitter('acid.fume', { shape: 'sphere', radius: 0.02, spread: 0.15, size: 0.35, life: 0.6 }); |
| +добавлено | const cloudE = P.emitter('acid.fog', { shape: 'sphere', radius: 2.2, spread: 0.3, life: 0.6 }); |
| +добавлено | const sinkE = P.emitter('acid.fog', { shape: 'disk', radius: 1.8, spread: 0.3 }); |
| +добавлено | const glowE = P.emitter('acid.miasma', { shape: 'sphere', radius: 1.6, spread: 0.3 }); |
| +добавлено | // the field fumes and spits by itself wherever it holds strong acid (anyone's) |
| +добавлено | P.fieldEmitter('acid.fume', { slots: 768, b: [0, 1, 0, 0], threshold: 0.35, rate: 5, up: 0.25 }); |
| +добавлено | P.fieldEmitter('acid.sizzle', { slots: 256, b: [0, 1, 0, 0], threshold: 0.6, rate: 8, up: 1.1 }); |
| +добавлено | |
| +добавлено | // --- froth domes --------------------------------------------------------------------------- |
| +добавлено | const geo = new THREE.InstancedBufferGeometry(); |
| +добавлено | geo.setAttribute('position', new THREE.Float32BufferAttribute([-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0], 3)); |
| +добавлено | geo.setIndex([0, 1, 2, 0, 2, 3]); |
| +добавлено | const attr = (name) => { const a = new THREE.InstancedBufferAttribute(new Float32Array(N_BUB * 4), 4); a.setUsage(THREE.DynamicDrawUsage); geo.setAttribute(name, a); return a; }; |
| +добавлено | const A0 = attr('aB0'), A1 = attr('aB1'), A2 = attr('aB2'); |
| +добавлено | const B0 = A0.array, B1 = A1.array, B2 = A2.array; |
| +добавлено | geo.instanceCount = 0; |
| +добавлено | const bubU = { uNow: { value: 0 }, uTint: { value: new THREE.Color() }, uHot: { value: new THREE.Color() }, uIri: { value: new THREE.Vector2(1, 0.35) } }; |
| +добавлено | const bubbles = new THREE.Mesh(geo, new THREE.RawShaderMaterial({ |
| +добавлено | glslVersion: THREE.GLSL3, vertexShader: BUBBLE_VERT, fragmentShader: BUBBLE_FRAG, |
| +добавлено | uniforms: { ...fx.U, ...bubU }, ...FX_BLENDING, |
| +добавлено | })); |
| +добавлено | bubbles.frustumCulled = false; |
| +добавлено | bubbles.visible = false; |
| +добавлено | fx.scenes.fx.add(bubbles); |
| +добавлено | let now = 0, ring = 0, bubbleUntil = -1, dirty = false; |
| +добавлено | |
| +добавлено | function spawnBubble(x, z, r, life, delay, drift) { |
| +добавлено | const i = ring++ % N_BUB, o = i * 4, a = fx.rand() * 6.2832; |
| +добавлено | B0[o] = x; B0[o + 1] = SURF; B0[o + 2] = z; B0[o + 3] = now + delay; |
| +добавлено | B1[o] = r; B1[o + 1] = life; B1[o + 2] = 0; B1[o + 3] = fx.rand(); |
| +добавлено | B2[o] = Math.cos(a) * drift; B2[o + 1] = Math.sin(a) * drift; B2[o + 2] = r * (0.1 + 0.3 * fx.rand()); B2[o + 3] = 2 + 4 * fx.rand(); |
| +добавлено | bubbleUntil = Math.max(bubbleUntil, now + delay + life + POP); |
| +добавлено | dirty = true; |
| +добавлено | } |
| +добавлено | function bubbleAt(i, tau, out) { |
| +добавлено | const o = i * 4, ph = B1[o + 3] * 6.2832; |
| +добавлено | return out.set( |
| +добавлено | B0[o] + B2[o] * tau + B2[o + 2] * Math.sin(B2[o + 3] * tau + ph), |
| +добавлено | B0[o + 1], |
| +добавлено | B0[o + 2] + B2[o + 1] * tau + B2[o + 2] * Math.cos(B2[o + 3] * 0.83 * tau + B1[o + 3] * 11)); |
| +добавлено | } |
| +добавлено | // a clump of froth round (x, z): mixed sizes, mostly small, a few big boil domes (share big) |
| +добавлено | function froth(x, z, spread, n, big, delay) { |
| +добавлено | n *= Q.emission * Q.auto.emission; |
| +добавлено | n = Math.floor(n + fx.rand()); |
| +добавлено | for (let k = 0; k < n; k++) { |
| +добавлено | const a = fx.rand() * 6.2832, d = Math.sqrt(fx.rand()) * spread, u = fx.rand(); |
| +добавлено | const boil = fx.rand() < big; |
| +добавлено | const r = boil ? 0.02 + 0.035 * fx.rand() : 0.004 + 0.016 * u * u; |
| +добавлено | const life = boil ? 0.25 + 0.4 * fx.rand() : 0.4 + 1.5 * fx.rand(); |
| +добавлено | spawnBubble(x + Math.cos(a) * d, z + Math.sin(a) * d, r, life, delay * fx.rand(), 0.005 + 0.025 * fx.rand()); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | |
| +добавлено | // --- standing liquid layers (refract pass), one per live cast ------------------------------ |
| +добавлено | const poolGeo = new THREE.PlaneGeometry(2, 2).rotateX(-Math.PI / 2); |
| +добавлено | const pools = []; |
| +добавлено | for (let i = 0; i < MAX_POOLS; i++) { |
| +добавлено | const u = { |
| +добавлено | uPoolA: { value: new THREE.Vector4() }, uPoolB: { value: new THREE.Vector4() }, |
| +добавлено | uGlowCol: { value: new THREE.Color() }, uHotCol: { value: new THREE.Color() }, uAbsorb: { value: new THREE.Color() }, |
| +добавлено | }; |
| +добавлено | const m = new THREE.Mesh(poolGeo, new THREE.ShaderMaterial({ |
| +добавлено | glslVersion: THREE.GLSL3, vertexShader: POOL_VERT, fragmentShader: POOL_FRAG, |
| +добавлено | uniforms: { ...fx.U, uStoneNoise: arenaUniforms.uStoneNoise, ...u }, |
| +добавлено | transparent: true, depthWrite: false, blending: THREE.NormalBlending, |
| +добавлено | })); |
| +добавлено | m.visible = false; |
| +добавлено | m.renderOrder = -1; // under the other refract-pass translucents |
| +добавлено | fx.scenes.refract.add(m); |
| +добавлено | pools.push({ mesh: m, u, busy: false }); |
| +добавлено | } |
| +добавлено | function poolAcquire(x, z, R, seed) { |
| +добавлено | for (const pl of pools) if (!pl.busy) { |
| +добавлено | pl.busy = true; |
| +добавлено | pl.mesh.visible = true; |
| +добавлено | pl.mesh.position.set(x, 0.005, z); |
| +добавлено | pl.mesh.scale.set(R, 1, R); |
| +добавлено | pl.u.uPoolA.value.set(x, z, R, 0); |
| +добавлено | pl.u.uPoolB.value.set(0, 0, 0, (seed % 97) * 0.0731); |
| +добавлено | return pl; |
| +добавлено | } |
| +добавлено | return null; |
| +добавлено | } |
| +добавлено | function poolRelease(pl) { if (pl) { pl.busy = false; pl.mesh.visible = false; } } |
| +добавлено | function poolStyle(pl, p, liquid, react) { |
| +добавлено | const u = pl.u; |
| +добавлено | u.uPoolA.value.w = liquid; |
| +добавлено | u.uPoolB.value.x = react; u.uPoolB.value.z = p.corrosion; |
| +добавлено | u.uGlowCol.value.copy(glowLin).multiplyScalar(1.1 * p.glow); |
| +добавлено | u.uHotCol.value.copy(hotLin).multiplyScalar(1.4 * p.glow); |
| +добавлено | // murky: blue and red absorbed, the liquid's own hue transmitted |
| +добавлено | const c = glowLin; |
| +добавлено | u.uAbsorb.value.setRGB(6 + 30 * (1 - c.r) ** 1.5, 6 + 30 * (1 - c.g) ** 1.5, 6 + 30 * (1 - c.b) ** 1.5); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // --- the gas: the shared fluid, in its soot channel ------------------------------------------ |
| +добавлено | const fluid = FluidVolume.get(fx); |
| +добавлено | // shares the fluid's render program, so warming this spell alone compiles it |
| +добавлено | const fluidStub = new THREE.Mesh(poolGeo, fluid.domains[0].material); |
| +добавлено | fluidStub.visible = false; fluidStub.frustumCulled = false; |
| +добавлено | fx.scenes.fx.add(fluidStub); |
| +добавлено | const SRC = { pos: new THREE.Vector3(), vel: new THREE.Vector3(), radius: 1, fuel: 0, temp: 0, soot: 0, radial: 0, noise: 0, noiseScale: 1, seed: 0, coupling: 0, burst: false }; |
| +добавлено | function gasSrc(f, x, y, z, radius, soot, temp, burst, noise, noiseScale, seed, vx, vy, vz, radial, coupling) { |
| +добавлено | SRC.pos.set(x, y, z); SRC.radius = radius; SRC.soot = soot; SRC.temp = temp; SRC.burst = burst; SRC.noise = noise; SRC.noiseScale = noiseScale; SRC.seed = seed; |
| +добавлено | SRC.vel.set(vx, vy, vz); SRC.radial = radial; SRC.coupling = coupling; |
| +добавлено | f.emit(SRC); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // --- per-cast state (indexed by the cast record, preallocated) ------------------------------ |
| +добавлено | const clouds = []; |
| +добавлено | for (let i = 0; i < 2; i++) { |
| +добавлено | const v = fx.volumes.add({ |
| +добавлено | shape: 'sphere', glsl: CLOUD_GLSL, maxSteps: 12, |
| +добавлено | uniforms: { uCloud: { value: new THREE.Vector4() }, uCloudShape: { value: new THREE.Vector4() }, uCloudGlow: { value: new THREE.Color() }, uCloudAlb: { value: new THREE.Color() } }, |
| +добавлено | }); |
| +добавлено | v.g = 0.35; v.ambient = 1.1; v.sun = 1.0; |
| +добавлено | clouds.push(v); |
| +добавлено | } |
| +добавлено | const st = Array.from({ length: 16 }, () => ({ |
| +добавлено | orb: null, light: null, vortex: null, cloud: null, gas: null, pool: null, |
| +добавлено | blob: new Float32Array(8 * 8), splashT: -1, splashFall: true, nextSplat: 0, froth: 0, |
| +добавлено | })); |
| +добавлено | const col = new THREE.Color(), _a = new THREE.Vector3(), _b = new THREE.Vector3(); |
| +добавлено | const glowLin = new THREE.Color(), hotLin = new THREE.Color(), _white = new THREE.Color(1, 1, 1), _hot = new THREE.Color(1, 1, 0.72); |
| +добавлено | let kindsColor = '', kindsFog = ''; |
| +добавлено | |
| +добавлено | // particle and metaball colours follow the params (texels only, nothing recompiles) |
| +добавлено | const hex = (c) => `#${c.getHexString()}`; |
| +добавлено | function syncColors() { |
| +добавлено | const p = S.params; |
| +добавлено | glowLin.set(p.color); |
| +добавлено | hotLin.copy(glowLin).lerp(_hot, 0.45); |
| +добавлено | if (p.color === kindsColor && p.fogColor === kindsFog) return; |
| +добавлено | kindsColor = p.color; kindsFog = p.fogColor; |
| +добавлено | const dark = hex(col.set(p.color).multiplyScalar(0.3)), light = hex(col.set(p.color).lerp(_white, 0.7)), drop = hex(col.set(p.color).lerp(_white, 0.3)); |
| +добавлено | P.setKind('acid.drip', { color: [drop, dark] }); |
| +добавлено | P.setKind('acid.sizzle', { color: [light, p.color] }); |
| +добавлено | P.setKind('acid.bead', { color: [light, p.color] }); |
| +добавлено | P.setKind('acid.miasma', { color: [hex(col.set(p.fogColor).lerp(glowLin, 0.2)), hex(col.set(p.fogColor).lerp(glowLin, 0.2).multiplyScalar(0.55))] }); // pale gas, a hint of the acid's hue |
| +добавлено | P.setKind('acid.fog', { color: [p.fogColor, hex(col.set(p.fogColor).multiplyScalar(0.6))] }); |
| +добавлено | P.setKind('acid.fume', { color: [hex(col.set(p.fogColor).lerp(_white, 0.7)), hex(col.set(p.fogColor).lerp(_white, 0.25).multiplyScalar(0.85))] }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // === BLOB: the liquid body (charge, flight, splash). Swap these five for the shared particle |
| +добавлено | // fluid's 'acid' preset when it lands; nothing else touches s.orb or s.blob. ================== |
| +добавлено | function blobAcquire(s, p) { |
| +добавлено | s.orb = fx.metaballs?.acquire({ preset: 'acid' }) ?? null; |
| +добавлено | if (s.orb) blobStyle(s.orb, p); |
| +добавлено | } |
| +добавлено | function blobStyle(h, p) { |
| +добавлено | const c = glowLin; |
| +добавлено | h.emission.copy(c).lerp(hotLin, 0.3).multiplyScalar(4.5 * p.glow); |
| +добавлено | h.scatterColor.copy(c).multiplyScalar(0.05); |
| +добавлено | h.absorption.setRGB(2.5 + 25 * (1 - c.r) ** 2, 2.5 + 25 * (1 - c.g) ** 2, 2.5 + 25 * (1 - c.b) ** 2); |
| +добавлено | h.wobble = 0.03; |
| +добавлено | h.turbidity = 14; // murky: the floor under a bead shouldn't show through |
| +добавлено | h.bubbles = 0.5; |
| +добавлено | } |
| +добавлено | // the gathering / flying blob: a core, four churning satellites, a teardrop tail and a drop |
| +добавлено | // tearing off it (vel null while it gathers) |
| +добавлено | function blobShape(s, pos, R, t, vel, spiral) { |
| +добавлено | const h = s.orb; |
| +добавлено | if (!h) return; |
| +добавлено | h.set(0, pos.x, pos.y, pos.z, R * 0.3 * (1 + 0.07 * Math.sin(t * 7.3))); |
| +добавлено | for (let i = 1; i <= 4; i++) { |
| +добавлено | const a = t * (1.9 + i * 0.37) + i * 2.4, b = t * 1.3 + i * 1.7; |
| +добавлено | const d = R * (0.19 + 0.05 * Math.sin(t * 3.1 + i)) + spiral; |
| +добавлено | h.set(i, pos.x + d * Math.cos(a) * Math.cos(b), pos.y + d * Math.sin(b), pos.z + d * Math.sin(a) * Math.cos(b), R * (0.15 + 0.04 * Math.sin(t * 4.7 + i * 2.1))); |
| +добавлено | } |
| +добавлено | if (!vel) { h.count = 5; return; } |
| +добавлено | _a.copy(vel).normalize(); |
| +добавлено | for (let j = 0; j < 2; j++) { |
| +добавлено | const back = R * (0.3 + 0.18 * j); |
| +добавлено | h.set(5 + j, pos.x - _a.x * back, pos.y - _a.y * back - 0.03 * j, pos.z - _a.z * back, R * (0.17 - 0.06 * j)); |
| +добавлено | } |
| +добавлено | const u = (t * 1.7) % 1, back = R * (0.42 + 0.9 * u); |
| +добавлено | h.set(7, pos.x - _a.x * back, pos.y - _a.y * back - 0.5 * u * u * R, pos.z - _a.z * back, R * 0.1 * (1 - u * u)); |
| +добавлено | h.count = 8; |
| +добавлено | } |
| +добавлено | // impact: the blob breaks into 8 (fall: they slap the floor and flatten into beads, the ones |
| +добавлено | // that hit the target cling and ooze down it; burst: they blow outward and thin out) |
| +добавлено | // B per blob: x y z, vx vy vz, r0, stuck |
| +добавлено | function blobSplash(s, pos, size, fall) { |
| +добавлено | const B = s.blob; |
| +добавлено | for (let i = 0; i < 8; i++) { |
| +добавлено | const o = i * 8, a = fx.rand() * 6.2832, sp = i === 0 ? 0.3 : (fall ? 1.2 + 2.4 * fx.rand() : 2.5 + 2 * fx.rand()); |
| +добавлено | const up = i === 0 ? -0.5 : (fall ? 0.4 + 1.8 * fx.rand() : (fx.rand() - 0.3) * 3); |
| +добавлено | B[o] = pos.x; B[o + 1] = pos.y; B[o + 2] = pos.z; |
| +добавлено | B[o + 3] = Math.cos(a) * sp; B[o + 4] = up; B[o + 5] = Math.sin(a) * sp; |
| +добавлено | B[o + 6] = size * (i === 0 ? 0.26 : 0.07 + 0.08 * fx.rand()); |
| +добавлено | B[o + 7] = 0; |
| +добавлено | } |
| +добавлено | s.splashT = 0; s.splashFall = fall; |
| +добавлено | if (s.orb) s.orb.bubbles = 0.15; |
| +добавлено | } |
| +добавлено | function blobUpdate(s, dt, dm) { |
| +добавлено | const h = s.orb, B = s.blob; |
| +добавлено | s.splashT += dt; |
| +добавлено | const dur = s.splashFall ? 1.8 : 0.45, u = s.splashT / dur; |
| +добавлено | if (u >= 1 || !h) { blobRelease(s); return; } |
| +добавлено | for (let i = 0; i < 8; i++) { |
| +добавлено | const o = i * 8; |
| +добавлено | if (s.splashFall) B[o + 4] -= 9.81 * dt; else { B[o + 3] *= 0.9; B[o + 4] *= 0.9; B[o + 5] *= 0.9; } |
| +добавлено | B[o] += B[o + 3] * dt; B[o + 1] += B[o + 4] * dt; B[o + 2] += B[o + 5] * dt; |
| +добавлено | // fall: the beads drain into the pool layer over the second half (they shrink) |
| +добавлено | const r = s.splashFall ? B[o + 6] * (1 - sstep(0.3, 1, u)) ** 0.7 : B[o + 6] * (1 - u) ** 0.6; |
| +добавлено | if (s.splashFall && dm) { |
| +добавлено | // clinging to the target: held on its surface, sliding down slowly |
| +добавлено | const dx = B[o] - dm.pos.x, dz = B[o + 2] - dm.pos.z, d = Math.hypot(dx, dz), lim = 0.3 + r * 0.35; |
| +добавлено | if (d < lim && B[o + 1] > 0.25 && B[o + 1] < 1.75) { |
| +добавлено | const k = lim / Math.max(d, 1e-3); |
| +добавлено | B[o] = dm.pos.x + dx * k; B[o + 2] = dm.pos.z + dz * k; |
| +добавлено | B[o + 3] = 0; B[o + 5] = 0; B[o + 4] = Math.max(B[o + 4], -0.35); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // on the floor: a flattened bead (centre below the floor), sliding to a stop |
| +добавлено | const fy = -0.45 * r; |
| +добавлено | if (s.splashFall && B[o + 1] < fy) { B[o + 1] = fy; B[o + 4] = 0; const f = Math.exp(-dt * 6); B[o + 3] *= f; B[o + 5] *= f; } |
| +добавлено | h.set(i, B[o], B[o + 1], B[o + 2], r); |
| +добавлено | } |
| +добавлено | h.count = 8; |
| +добавлено | } |
| +добавлено | function blobRelease(s) { s.orb?.release(); s.orb = null; s.splashT = -1; } |
| +добавлено | // === end BLOB ================================================================================ |
| +добавлено | |
| +добавлено | function dissolveNear(x, z, R, base, add) { |
| +добавлено | for (const dm of fx.dummies) { |
| +добавлено | const d = Math.hypot(dm.pos.x - x, dm.pos.z - z); |
| +добавлено | if (d < R) { |
| +добавлено | dm.status.dissolve = Math.max(dm.status.dissolve, base * (1 - d / R) + add); |
| +добавлено | dm.hit(_b.set(dm.pos.x - x, 0, dm.pos.z - z), 0.35 * (1 - d / R)); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // a dummy being eaten: acid running off its bulge and arm tips, white fumes off its body, |
| +добавлено | // spits round its foot where the pool boils against it (k 0..1) |
| +добавлено | function eatDummy(dm, k, dt) { |
| +добавлено | const p = S.params; |
| +добавлено | // a few fixed drip points: under the sack's bulge and at the arm tips |
| +добавлено | const j = Math.floor(fx.rand() * 6), a = dm.pos.x * 1.7 + dm.pos.z * 2.3 + j * 2.1; |
| +добавлено | if (j < 4) runE.pos.set(dm.pos.x + Math.cos(a) * 0.27, 0.78, dm.pos.z + Math.sin(a) * 0.22); |
| +добавлено | else runE.pos.set(dm.pos.x + (j === 4 ? -0.58 : 0.58), 1.22, dm.pos.z); |
| +добавлено | runE.radius = 0.01; runE.vel.set(0, -0.1, 0); runE.rate(14 * k * p.drips, dt); |
| +добавлено | steamE.pos.set(dm.pos.x, 0.15 + 1.3 * fx.rand(), dm.pos.z); steamE.radius = 0.32; steamE.vel.set(0, 0.25, 0); steamE.size = 0.7; steamE.rate(45 * k * p.fog, dt); |
| +добавлено | spitE.pos.set(dm.pos.x, 0.03, dm.pos.z); spitE.radius = 0.38; spitE.vel.set(0, 1.4, 0); spitE.rate(90 * k * p.glow, dt); |
| +добавлено | } |
| +добавлено | |
| +добавлено | return { |
| +добавлено | onParam(k) { if (k === 'color' || k === 'fogColor') syncColors(); }, |
| +добавлено | |
| +добавлено | phase(c, name) { |
| +добавлено | const p = S.params, s = st[c.index], size = p.size, cloud = c.form === 'Corrosion Cloud'; |
| +добавлено | if (name === 'charge') { |
| +добавлено | syncColors(); |
| +добавлено | s.splashT = -1; s.nextSplat = 0; s.froth = 0; s.cloud = null; s.gas = null; s.vortex = null; s.pool = null; |
| +добавлено | c.durations.linger = cloud ? p.cloudTime : S.timing.linger; |
| +добавлено | blobAcquire(s, p); |
| +добавлено | s.light = fx.lights.acquire(); |
| +добавлено | if (s.light) { s.light.range = 7; s.light.intensity = 0; s.light.color.copy(glowLin); s.light.shadow = true; } |
| +добавлено | } else if (name === 'release') { |
| +добавлено | fx.rig.shake(0.08, 9); |
| +добавлено | } else if (name === 'travel') { |
| +добавлено | // an exact ballistic arc onto the target: flight time from the horizontal speed |
| +добавлено | const D = Math.hypot(c.to.x - c.pos.x, c.to.z - c.pos.z), T = Math.max(0.35, D / Math.max(p.speed, 1)); |
| +добавлено | c.vel.subVectors(c.to, c.pos).multiplyScalar(1 / T); |
| +добавлено | c.vel.y += 0.5 * 9.81 * T; |
| +добавлено | } else if (name === 'impact') { |
| +добавлено | if (s.orb) blobSplash(s, c.pos, size, !cloud); |
| +добавлено | if (cloud) bloomCloud(c, p, s); |
| +добавлено | else bloom(c, p, s); |
| +добавлено | } else if (name === 'done') { |
| +добавлено | blobRelease(s); |
| +добавлено | s.light?.release(); s.light = null; |
| +добавлено | s.vortex?.release(); s.vortex = null; |
| +добавлено | if (s.cloud) s.cloud.visible = false; |
| +добавлено | s.cloud = null; |
| +добавлено | s.gas?.release(); s.gas = null; |
| +добавлено | poolRelease(s.pool); s.pool = null; |
| +добавлено | } |
| +добавлено | }, |
| +добавлено | |
| +добавлено | update(c, dt) { |
| +добавлено | const p = S.params, s = st[c.index], L = s.light, size = p.size, cloud = c.form === 'Corrosion Cloud'; |
| +добавлено | const flick = 0.85 + 0.15 * Math.sin(c.age * 23 + c.seed) * Math.sin(c.age * 9.1); |
| +добавлено | if (c.phase === 'charge') { |
| +добавлено | const k = c.t / c.durations.charge; |
| +добавлено | if (s.orb) { blobStyle(s.orb, p); blobShape(s, c.pos, size * (0.15 + 0.85 * (1 - (1 - k) ** 2)), c.age, null, (1 - k) * 0.5 * size); } |
| +добавлено | moteE.pos.copy(c.pos); moteE.rate(260 * k * p.glow, dt); |
| +добавлено | vaporE.pos.copy(c.pos); vaporE.vel.set(0, 0, 0); vaporE.radius = 0.3 * size; vaporE.size = 0.5 * size; vaporE.rate(20 * k * p.fog, dt); |
| +добавлено | if (L) { L.pos.copy(c.pos); L.intensity = 6 * k * flick * p.glow; } |
| +добавлено | } else if (c.phase === 'travel') { |
| +добавлено | blobShape(s, c.pos, size, c.age, c.vel, 0); |
| +добавлено | dripE.pos.copy(c.pos); dripE.vel.copy(c.vel).multiplyScalar(0.25); dripE.radius = 0.22 * size; dripE.rate(110 * p.drips, dt); |
| +добавлено | vaporE.pos.copy(c.pos); vaporE.vel.copy(c.vel).multiplyScalar(0.1); vaporE.radius = 0.25 * size; vaporE.size = 0.7 * size; vaporE.rate(60 * p.fog, dt); |
| +добавлено | if (L) { L.pos.copy(c.pos); L.intensity = 9 * flick * p.glow; } |
| +добавлено | } else { |
| +добавлено | if (s.splashT >= 0) blobUpdate(s, dt, c.target >= 0 ? fx.dummies[c.target] : null); |
| +добавлено | if (cloud) updateCloud(c, p, s, dt, flick); |
| +добавлено | else updatePool(c, p, s, dt, flick); |
| +добавлено | } |
| +добавлено | }, |
| +добавлено | |
| +добавлено | // froth domes: clock, pops, upload (main calls this every frame) |
| +добавлено | tick(dt) { |
| +добавлено | const prev = now; |
| +добавлено | now += dt; |
| +добавлено | if (bubbleUntil < now - 0.5) { bubbles.visible = false; return; } |
| +добавлено | bubbles.visible = true; |
| +добавлено | geo.instanceCount = N_BUB; |
| +добавлено | bubU.uNow.value = now; |
| +добавлено | bubU.uIri.value.set(1, S.params.iridescence); |
| +добавлено | bubU.uTint.value.copy(glowLin).multiplyScalar(0.35 * S.params.glow); |
| +добавлено | bubU.uHot.value.copy(hotLin).multiplyScalar(S.params.glow); |
| +добавлено | if (dirty) { A0.needsUpdate = A1.needsUpdate = A2.needsUpdate = true; dirty = false; } |
| +добавлено | // pops: spits (and a wisp off the big ones) where the dome was, at most 4 a frame |
| +добавлено | let pops = 0; |
| +добавлено | for (let i = 0; i < N_BUB && pops < 4; i++) { |
| +добавлено | const o = i * 4, life = B1[o + 1], tau = now - B0[o + 3]; |
| +добавлено | if (life <= 0 || tau < life || prev - B0[o + 3] >= life) continue; |
| +добавлено | const r = B1[o]; |
| +добавлено | if (r < 0.006 && fx.rand() < 0.7) continue; |
| +добавлено | bubbleAt(i, life, popE.pos); |
| +добавлено | popE.radius = r; popE.vel.set(0, 0.8 + 30 * r, 0); popE.burst(1 + r * 140); |
| +добавлено | if (r > 0.014) { puffE.pos.copy(popE.pos); puffE.size = 0.25 + 6 * r; puffE.burst(1); } |
| +добавлено | pops++; |
| +добавлено | } |
| +добавлено | }, |
| +добавлено | }; |
| +добавлено | |
| +добавлено | // --- Toxic Bloom impact --------------------------------------------------------------------- |
| +добавлено | function bloom(c, p, s) { |
| +добавлено | const pos = c.pos, size = p.size; |
| +добавлено | const R = 2.6 * size; |
| +добавлено | splashE.pos.copy(pos); splashE.vel.set(0, 1.2, 0); splashE.radius = 0.3 * size; splashE.burst(180 * p.drips); |
| +добавлено | sizzleE.pos.copy(pos).setY(0.05); sizzleE.radius = 0.9 * size; sizzleE.vel.set(0, 1.6, 0); sizzleE.burst(160 * p.glow); |
| +добавлено | fogE.pos.copy(pos).setY(0.25); fogE.radius = 0.8 * size; fogE.radial = 4.2 * size; fogE.size = size; fogE.burst(150 * p.fog); |
| +добавлено | vaporE.pos.copy(pos).setY(0.4); vaporE.vel.set(0, 0.8, 0); vaporE.radius = 0.5 * size; vaporE.size = 1.2 * size; vaporE.burst(50 * p.fog); |
| +добавлено | miasmaE.pos.copy(pos).setY(0.2); miasmaE.radius = 0.7 * size; miasmaE.size = 0.8 * size; miasmaE.burst(30 * p.fog); |
| +добавлено | SPL.x = pos.x; SPL.z = pos.z; SPL.pattern = 'noise'; |
| +добавлено | SPL.radius = 1.4 * size; SPL.acid = 0.85 * p.corrosion; SPL.seed = c.seed % 97; fx.ground.splat(SPL); |
| +добавлено | SPL.pattern = 'radial'; SPL.radius = 0.7 * size; SPL.acid = 0.6 * p.corrosion; SPL.seed = c.seed % 89; fx.ground.splat(SPL); |
| +добавлено | fx.shocks?.spawn({ pos: _a.copy(pos).setY(0.05), radius0: 0.3, radius1: 3.2 * size, duration: 0.45, thickness: 0.5, distortion: 0.025, ground: true, intensity: 0 }); |
| +добавлено | s.pool = poolAcquire(pos.x, pos.z, 3.4 * size, c.seed); |
| +добавлено | // the first violent froth: at the target's foot and scattered through the splash |
| +добавлено | for (let k = 0; k < 14; k++) { |
| +добавлено | const a = fx.rand() * 6.2832, d = 0.3 + 1.2 * Math.sqrt(fx.rand()) * size; |
| +добавлено | froth(pos.x + Math.cos(a) * d, pos.z + Math.sin(a) * d, 0.12, 9 * p.bubbles, 0.12, 0.5); |
| +добавлено | } |
| +добавлено | dissolveNear(pos.x, pos.z, R, 0.45 * p.corrosion, 0.2 * p.corrosion); |
| +добавлено | if (c.target >= 0) { const dm = fx.dummies[c.target]; dm.status.dissolve = Math.max(dm.status.dissolve, 0.6 * p.corrosion); } |
| +добавлено | if (s.light) { s.light.intensity = 12 * p.glow; s.light.range = 9 * size; s.light.pos.copy(pos).setY(Math.max(pos.y, 0.5)); } |
| +добавлено | fx.flash(0.06 * p.glow); |
| +добавлено | fx.rig.shake(0.25, 14); |
| +добавлено | if (!fx.reduced) fx.rig.punch(1.2, 0.06); |
| +добавлено | s.nextSplat = 0.1; |
| +добавлено | } |
| +добавлено | // the pool spreads for a second, rolls vapour out, then glows, froths and fumes while it eats; |
| +добавлено | // over the last two seconds it soaks in (the liquid layer shrinks to beads and goes) |
| +добавлено | function updatePool(c, p, s, dt, flick) { |
| +добавлено | const size = p.size, pos = c.pos; |
| +добавлено | const T = c.phase === 'impact' ? c.t : c.durations.impact + c.t; |
| +добавлено | const left = c.durations.impact + c.durations.linger - T; |
| +добавлено | const fade = clamp01(left / 2.5), react = (0.25 + 0.75 * Math.exp(-T / 2.2)) * fade; |
| +добавлено | if (s.pool) poolStyle(s.pool, p, sstep(0, 0.35, T) * (0.35 + 0.65 * fade), react); |
| +добавлено | s.nextSplat -= dt; |
| +добавлено | if (T < 1.3 && s.nextSplat <= 0) { |
| +добавлено | s.nextSplat = 0.12; |
| +добавлено | SPL.x = pos.x; SPL.z = pos.z; SPL.pattern = 'noise'; SPL.radius = (1.4 + 1.3 * T) * size; SPL.acid = 0.13 * p.corrosion; SPL.seed = (c.seed + T * 37) % 97; |
| +добавлено | fx.ground.splat(SPL); |
| +добавлено | } |
| +добавлено | if (T < 1.6) { |
| +добавлено | const k = 1 - T / 1.6; |
| +добавлено | fogE.pos.copy(pos).setY(0.25); fogE.radius = 1.0 * size; fogE.radial = 2.4 * size; fogE.size = size; fogE.rate(240 * p.fog * k, dt); |
| +добавлено | } |
| +добавлено | // the liquid keeps fuming: a heavy low layer rolling off it, white wisps rising out of it |
| +добавлено | fogE.pos.copy(pos).setY(0.15); fogE.radius = 1.4 * size; fogE.radial = 0.9 * size; fogE.size = 0.8 * size; fogE.rate(30 * p.fog * fade, dt); |
| +добавлено | vaporE.pos.copy(pos).setY(0.05); vaporE.vel.set(0, 0.4, 0); vaporE.radius = 1.1 * size; vaporE.size = 0.9 * size; vaporE.rate(30 * p.fog * react, dt); |
| +добавлено | // froth: clumps where it touches what stands in it, and through the pool |
| +добавлено | s.froth += 34 * react * p.bubbles * dt; |
| +добавлено | while (s.froth >= 1) { |
| +добавлено | s.froth -= 1; |
| +добавлено | let x, z; |
| +добавлено | const dm = c.target >= 0 ? fx.dummies[c.target] : null; |
| +добавлено | if (dm && fx.rand() < 0.55 && Math.hypot(dm.pos.x - pos.x, dm.pos.z - pos.z) < 2 * size) { |
| +добавлено | const a = fx.rand() * 6.2832, d = 0.36 + 0.12 * fx.rand(); |
| +добавлено | x = dm.pos.x + Math.cos(a) * d; z = dm.pos.z + Math.sin(a) * d; |
| +добавлено | } else { |
| +добавлено | const a = fx.rand() * 6.2832, d = 1.5 * size * Math.sqrt(fx.rand()); |
| +добавлено | x = pos.x + Math.cos(a) * d; z = pos.z + Math.sin(a) * d; |
| +добавлено | } |
| +добавлено | froth(x, z, 0.08, 6, 0.08, 0.05); |
| +добавлено | } |
| +добавлено | // standing in it keeps eating |
| +добавлено | for (const dm of fx.dummies) { |
| +добавлено | if (Math.hypot(dm.pos.x - pos.x, dm.pos.z - pos.z) > 1.8 * size) continue; |
| +добавлено | if (c.phase === 'linger' && left > 1) dm.status.dissolve = Math.min(0.85, dm.status.dissolve + (0.08 + 0.05 * p.corrosion) * dt); |
| +добавлено | eatDummy(dm, react, dt); |
| +добавлено | } |
| +добавлено | if (s.light) { |
| +добавлено | const glowT = 4.5 * flick * p.glow * (0.4 + 0.6 * react) * Math.min(1, left / 2); |
| +добавлено | s.light.intensity = Math.max(s.light.intensity * Math.exp(-dt / 0.25), glowT); |
| +добавлено | s.light.pos.y += (0.6 - s.light.pos.y) * Math.min(1, dt * 4); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | |
| +добавлено | // --- Corrosion Cloud ------------------------------------------------------------------------ |
| +добавлено | function bloomCloud(c, p, s) { |
| +добавлено | const size = p.size, to = c.to; |
| +добавлено | s.cloud = null; |
| +добавлено | const f = s.gas = fluid.acquire({ size: [15 * size, 3 * size, 15 * size], res: Math.round(fluid.res * 1.3) }); |
| +добавлено | if (f) { |
| +добавлено | f.position.set(to.x, 0.5 * f.size.y - f.h, to.z); |
| +добавлено | Object.assign(f, { |
| +добавлено | ignition: 10, burnRate: 0, heatPerFuel: 0, sootYield: 0, expansion: 0, cooling: 1.6, radiative: 0, sootDecay: 0.03, fuelDecay: 2, |
| +добавлено | buoyancy: 0, sootWeight: 6, vorticity: 6, damping: 0.04, forceCoupling: 0.6, |
| +добавлено | // chlorine is never emissive: its colour is absorption and scattering only |
| +добавлено | emission: 0, temperature: 2400, sootDensity: 6, flameDensity: 0, fuelDensity: 0, g: 0.3, sun: 1.6, sky: 1.0, fireLight: 0, |
| +добавлено | // soft edges that curl into fine wisps (a strong curl displacement), billows broad and low |
| +добавлено | // (a light Worley erosion); a camera standing in it sees the near gas thin over metres |
| +добавлено | // (a light cell erosion: strong, it carves cumulus cauliflower, cotton wool, where a dense |
| +добавлено | // gas rolls in smooth, slumping lobes) |
| +добавлено | upres: 2.8, upresScale: 2.2, edgeFade: 4, |
| +добавлено | detailFreq: 0.3 / size, detailErode: 0.12, detailHeat: 0, nearFade: 2.6 * size, |
| +добавлено | // cost: a wide, mostly thin layer marched end to end. Below 0.05 /m the haze is treated |
| +добавлено | // as empty (skipped), and the lattice is 1.4 voxels, for about 0.4 ms at its widest |
| +добавлено | emptyBelow: 0.05, stepScale: 1.4, |
| +добавлено | }); |
| +добавлено | f.detailCenter.set(to.x, 0, to.z); |
| +добавлено | // chlorine reads near off-white where thin and yellow-green where deep: a pale albedo, the |
| +добавлено | // colour coming from the light losing red and blue on its way in (chroma). The arena's low sun |
| +добавлено | // and sky are both orange (sun ~ 3.1 : 1.2 : 0.24), which turns any yellow-green albedo khaki: |
| +добавлено | // the albedo's red is pulled down so the lit gas reads as Jack Rabbit II's pale yellow-green |
| +добавлено | f.sootColor.set(p.cloudColor); |
| +добавлено | f.sootColor.r *= 0.72; f.sootColor.b *= 1.25; |
| +добавлено | f.sootColor.lerp(_white, 0.25); |
| +добавлено | f.chroma = 1.4; |
| +добавлено | f.tint.copy(glowLin); |
| +добавлено | // the blob bursts: a dense, lumpy slug over the target, its lobes already slumping outwards |
| +добавлено | const sd = c.seed % 97; |
| +добавлено | gasSrc(f, to.x, 0.9 * size, to.z, 1.2 * size, 1.9, 0, true, 1, 1.8, sd, 0, -2.6, 0, 2.8, 6); |
| +добавлено | for (let i = 0; i < 5; i++) { |
| +добавлено | const a = sd + i * 1.2566 + 0.4 * Math.sin(i * 2.3 + sd), r = (0.95 + 0.25 * Math.sin(i * 1.7 + sd)) * size, ca = Math.cos(a), sa = Math.sin(a); |
| +добавлено | gasSrc(f, to.x + ca * r, (0.45 + 0.2 * Math.sin(i * 2.9 + sd)) * size, to.z + sa * r, (0.65 + 0.2 * Math.cos(i * 1.3 + sd)) * size, 1.7, 0, true, 1, 2.4, sd + i * 3.1, |
| +добавлено | ca * 3.0, -1.6, sa * 3.0, 1.2, 6); |
| +добавлено | } |
| +добавлено | } else { |
| +добавлено | for (const v of clouds) if (!v.visible) { s.cloud = v; break; } |
| +добавлено | if (s.cloud) { |
| +добавлено | s.cloud.visible = true; |
| +добавлено | s.cloud.uniforms.uCloud.value.set(0, 0, 0, (c.seed % 97) * 0.173); |
| +добавлено | s.cloud.uniforms.uCloudAlb.value.set(p.cloudColor); |
| +добавлено | } |
| +добавлено | cloudE.pos.set(to.x, 1.6 * size, to.z); cloudE.radius = 1.2 * size; cloudE.size = 1.4 * size; cloudE.burst(120 * p.fog); |
| +добавлено | miasmaE.pos.copy(c.pos); miasmaE.radius = 0.6 * size; miasmaE.size = size; miasmaE.burst(90 * p.fog); |
| +добавлено | } |
| +добавлено | s.vortex = fx.forces.acquire(); |
| +добавлено | if (s.vortex) { |
| +добавлено | const v = s.vortex; |
| +добавлено | v.type = 1; v.p[0] = 0.6 * size; v.p[1] = 2.6 * size; v.p[2] = -0.1; v.p[3] = 0; v.w = 4 * size; |
| +добавлено | v.pos.set(to.x, 0, to.z); v.dir.set(0, 1, 0); |
| +добавлено | } |
| +добавлено | s.pool = poolAcquire(to.x, to.z, 3.6 * size, c.seed); |
| +добавлено | sizzleE.pos.copy(c.pos); sizzleE.radius = 0.4 * size; sizzleE.vel.set(0, 0.5, 0); sizzleE.burst(160 * p.glow); |
| +добавлено | if (s.light) { s.light.intensity = 3 * p.glow; s.light.range = 8 * size; } |
| +добавлено | SPL.x = to.x; SPL.z = to.z; SPL.pattern = 'noise'; SPL.radius = 1.6 * size; SPL.acid = 0.3 * p.corrosion; SPL.seed = c.seed % 91; |
| +добавлено | fx.ground.splat(SPL); |
| +добавлено | fx.flash(0.05 * p.glow); |
| +добавлено | fx.rig.shake(0.18, 10); |
| +добавлено | s.nextSplat = 0.5; |
| +добавлено | } |
| +добавлено | function updateCloud(c, p, s, dt, flick) { |
| +добавлено | const size = p.size, to = c.to; |
| +добавлено | const T = c.phase === 'impact' ? c.t : c.durations.impact + c.t; |
| +добавлено | const left = c.durations.impact + c.durations.linger - T; |
| +добавлено | const grow = 1 - Math.exp(-T * 2.2), fade = clamp01(left / 2); |
| +добавлено | // heavy gas: it sinks and spreads as it ages, its belly sagging towards the floor |
| +добавлено | const sink = sstep(0.3, 0.85 * (c.durations.impact + c.durations.linger), T); |
| +добавлено | const f = s.gas; |
| +добавлено | const cy = size * (1.75 - 0.8 * sink), R = (f ? 4.6 : 2.5) * size * (0.45 + 0.55 * grow) * (1 + 0.3 * sink); |
| +добавлено | const hy = 1.25 * size * (0.5 + 0.5 * grow) * (1 - 0.3 * sink), base = f ? 2.2 * size : cy - 0.65 * hy; |
| +добавлено | if (f) { |
| +добавлено | // the slug goes on feeding from above for a while, then the floor layer feeds the current; the |
| +добавлено | // gas thins fast only at the end |
| +добавлено | const seed = c.seed % 97, k = Math.max(0, 1 - T / 1.1); |
| +добавлено | if (k > 0) gasSrc(f, to.x, 1.0 * size, to.z, 1.1 * size, 3.2 * k * p.fog, 0, false, 1, 2.2, seed + T * 0.5, 0, -2.0, 0, 2.4, 1.5); |
| +добавлено | const k2 = sstep(0.3, 0.8, T) * clamp01((p.cloudTime - 3.5 - T) / 1.5); |
| +добавлено | if (k2 > 0) { |
| +добавлено | gasSrc(f, to.x, 0.4 * size, to.z, 1.2 * size, 1.2 * k2 * p.fog, 0, false, 1, 1.4, seed + 11 + T * 0.3, 0, -0.1, 0, 2.2, 1.5); |
| +добавлено | // the front: lobes pushing out along the floor from under the mass, each on its own heading |
| +добавлено | // and clock, so it runs out in tongues with clefts between them (a gravity current's head) |
| +добавлено | const front = (1.2 + 2.6 * (1 - Math.exp(-T / 2.2))) * size; |
| +добавлено | for (let i = 0; i < 5; i++) { |
| +добавлено | const a = i * 1.2566 + seed + 0.5 * Math.sin(T * 0.37 + i * 2.1), w = 0.75 + 0.25 * Math.sin(i * 3.7 + seed), r = front * w; |
| +добавлено | const ca = Math.cos(a), sa = Math.sin(a), pulse = Math.sin(T * 1.6 + i * 2.4); |
| +добавлено | if (pulse <= 0) continue; // in surges: each one rolls up its own head |
| +добавлено | gasSrc(f, to.x + ca * r, 0.32, to.z + sa * r, (0.55 + 0.35 * w) * size, 1.8 * pulse * pulse * k2 * p.fog, 0, false, 1, 2.6, seed + i * 3 + T * 0.6, ca * 1.5, -0.05, sa * 1.5, 0, 1.8); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // old gas thins out, so it never fills the box; the layer stops being pressed flat once it has |
| +добавлено | // landed, and keeps its billows |
| +добавлено | f.sootDecay = 0.2 + 0.3 * sstep(2.5, 5, T) + 1.5 * (1 - fade) * (1 - fade); |
| +добавлено | f.sootWeight = 4.2 - 2.4 * sstep(1.2, 3.5, T); // (heavy: chlorine is 2.5x air, it slumps within a second) |
| +добавлено | } else { |
| +добавлено | if (s.cloud) { |
| +добавлено | s.cloud.position.set(to.x, cy, to.z); |
| +добавлено | s.cloud.scale.set(R, hy, R); |
| +добавлено | s.cloud.uniforms.uCloud.value.set(0.7 * p.glow, T, grow * fade, s.cloud.uniforms.uCloud.value.w); |
| +добавлено | s.cloud.uniforms.uCloudShape.value.x = sink; |
| +добавлено | s.cloud.uniforms.uCloudGlow.value.copy(glowLin).lerp(hotLin, 0.3); |
| +добавлено | } |
| +добавлено | cloudE.pos.set(to.x, cy, to.z); cloudE.radius = 0.75 * R; cloudE.size = 1.3 * size; cloudE.rate(70 * p.fog * fade, dt); |
| +добавлено | glowE.pos.set(to.x, cy, to.z); glowE.radius = 0.5 * R; glowE.size = size; glowE.rate(40 * p.fog * fade, dt); |
| +добавлено | // gas pouring off its underside, running out along the floor |
| +добавлено | sinkE.pos.set(to.x, base, to.z); sinkE.radius = 0.55 * R; sinkE.vel.set(0, -0.7, 0); sinkE.size = size; sinkE.rate(70 * p.fog * fade * grow, dt); |
| +добавлено | fogE.pos.set(to.x, 0.2, to.z); fogE.radius = 0.5 * R; fogE.radial = 1.3 * size; fogE.size = 0.9 * size; fogE.rate(45 * p.fog * fade * grow, dt); |
| +добавлено | } |
| +добавлено | // (a gas leaves condensate, not a lake: scattered beads and small puddles that barely glow) |
| +добавлено | if (s.pool) poolStyle(s.pool, p, 0.42 * fade, 0.2 * fade); |
| +добавлено | // corrosive rain out of it |
| +добавлено | if (T > 0.4) { rainE.pos.set(to.x, base, to.z); rainE.radius = 0.7 * R; rainE.vel.set(0, -1.5, 0); rainE.rate(170 * p.drips * fade, dt); } |
| +добавлено | s.nextSplat -= dt; |
| +добавлено | if (s.nextSplat <= 0 && fade > 0.2) { |
| +добавлено | s.nextSplat = 0.45; |
| +добавлено | SPL.x = to.x; SPL.z = to.z; SPL.pattern = 'noise'; SPL.radius = 0.85 * R; SPL.acid = 0.11 * p.corrosion; SPL.seed = (c.seed + T * 13) % 97; |
| +добавлено | fx.ground.splat(SPL); |
| +добавлено | } |
| +добавлено | // where the rain pools it fizzes |
| +добавлено | s.froth += 14 * fade * grow * p.bubbles * dt; |
| +добавлено | while (s.froth >= 1) { |
| +добавлено | s.froth -= 1; |
| +добавлено | const a = fx.rand() * 6.2832, d = 0.7 * R * Math.sqrt(fx.rand()); |
| +добавлено | froth(to.x + Math.cos(a) * d, to.z + Math.sin(a) * d, 0.05, 4, 0.05, 0.05); |
| +добавлено | } |
| +добавлено | // inside the cloud: dissolving gradually, fuming, running |
| +добавлено | if (fade > 0.2) for (const dm of fx.dummies) { |
| +добавлено | if (Math.hypot(dm.pos.x - to.x, dm.pos.z - to.z) > R * 0.85) continue; |
| +добавлено | dm.status.dissolve = Math.min(0.97, dm.status.dissolve + (0.1 + 0.11 * p.corrosion) * dt); |
| +добавлено | eatDummy(dm, 0.5 * grow * fade, dt); |
| +добавлено | } |
| +добавлено | if (s.light) { |
| +добавлено | const pulse = (f ? 0.5 : 1) * (2.6 + 1.1 * Math.sin(T * 2.1) + 0.6 * Math.sin(T * 5.3)) * flick * p.glow * fade * grow; |
| +добавлено | s.light.intensity = Math.max(s.light.intensity * Math.exp(-dt / 0.3), pulse); |
| +добавлено | s.light.pos.set(to.x, f ? 0.5 : cy * 0.8, to.z); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | }, |
| +добавлено | }; |
| +добавлено | import * as THREE from 'three'; |
| +добавлено | import { U, COMMON_GLSL, NOISE_GLSL, LINES_BLENDING, arenaStatic } from '../vfx/common.js'; |
| +добавлено | import { REFRACT_GLSL } from '../vfx/Refraction.js'; |
| +добавлено | import { instanced } from '../vfx/Ribbons.js'; |
| +добавлено | |
| +добавлено | // Arcane (PLAN 3). Reference: Doctor Strange spell work (burning mandalas, grinder sparks) and |
| +добавлено | // UE5 Niagara plasma/energy-shield showcases: energy reads as incandescent plasma that lights the |
| +добавлено | // world, never as flat glowing UI. |
| +добавлено | // Arcane Barrage: a runic launch circle opens in front of the caster's orb, then fires 8 missiles |
| +добавлено | // from its rim 60 ms apart. Each missile is a CPU head steered by true proportional navigation |
| +добавлено | // (a = N Vc (Omega x r^), plus a weak pursuit term that grows with age so a missile that launched |
| +добавлено | // away from the target always comes back), a corkscrew weave and a thrust to cruise speed. |
| +добавлено | // Look: a white-hot plasma knot with crawling filaments and a dispersed halo, motion-streaked |
| +добавлено | // along its screen velocity (own instanced lines-scene quad); a ribbon trail with heat shimmer; |
| +добавлено | // streaking sparks. The swarm is one line light (first to last missile), so the floor lights |
| +добавлено | // along its path. Each impact: a plasma burst sprite (chromatic shock ring, spark rays), a spark |
| +добавлено | // burst, a distortion shock, a light flash, a ring in the ground field. |
| +добавлено | // Aegis: a dome of energy membrane (soap-film optics, plasma emission), one sphere mesh in the |
| +добавлено | // refract pass, shaded per pixel as two walls (the far wall from an analytic ray-sphere exit): |
| +добавлено | // - thin-film interference on the sky reflection (Airy, film thickness swirling and draining |
| +добавлено | // down), Fresnel, a limb-brightened sheath (the path through a glowing film grows at grazing) |
| +добавлено | // - plasma filaments: ridged fbm warped by curl noise, crawling over the shell |
| +добавлено | // - refraction with per-channel dispersion where the membrane bends: the rim lens, ripples, the |
| +добавлено | // burning fronts, a heat-haze wobble; an interior haze measured along the chord (so what |
| +добавлено | // stands inside cuts a darker silhouette in it) |
| +добавлено | // - ripples: wave packets travelling over the sphere (amplitude ~ 1/sqrt(sin theta), so the |
| +добавлено | // ring refocuses at the antipode), crests bright as caustics with RGB-split fringes, sparks |
| +добавлено | // shed along the ring, a caustic cookie light flashing at the hit, an l = 2 membrane wobble |
| +добавлено | // - forming: a ragged incandescent front climbs from the floor ring to the crown shedding sparks; |
| +добавлено | // dissolving: holes burn through it (crown first) with white-hot edges and a spark/mote burst |
| +добавлено | // - a hot contact line where it cuts the floor or a dummy (scene depth) |
| +добавлено | // It registers a sphere occluder, so particles and debris bounce off it. inst.hit(worldPos, |
| +добавлено | // strength) ripples the nearest shield (other spells, combos); other casts' impacts near a shield |
| +добавлено | // and Barrage missiles that strike one ripple it automatically. |
| +добавлено | |
| +добавлено | const TAU = Math.PI * 2; |
| +добавлено | const MAX_MISSILES = 12, LAUNCH_GAP = 0.06, MAX_CASTS = 16; |
| +добавлено | const MAX_SHIELDS = 3, MAX_HITS = 8, MAX_SPRITES = 128, MAX_POPS = 48; |
| +добавлено | const FORM_TIME = 0.45, DISSOLVE_TIME = 0.8; |
| +добавлено | |
| +добавлено | // --- shield GLSL (refract scene, ShaderMaterial) -------------------------------------------------- |
| +добавлено | const SHIELD_VERT = /* glsl */` |
| +добавлено | uniform vec4 uSphere; // centre, radius (0 = hidden) |
| +добавлено | uniform vec4 uWobble; // x: l = 2 membrane mode amplitude (fraction of r) |
| +добавлено | out vec3 vPos; |
| +добавлено | out float vViewZ; |
| +добавлено | void main() { |
| +добавлено | vec3 n = normalize(position); |
| +добавлено | vPos = uSphere.xyz + n * uSphere.w * (1.0 + uWobble.x * (1.5 * n.y * n.y - 0.5)); |
| +добавлено | vec4 view = viewMatrix * vec4(vPos, 1.0); |
| +добавлено | vViewZ = -view.z; |
| +добавлено | gl_Position = uSphere.w > 0.0 ? projectionMatrix * view : vec4(2.0, 2.0, 2.0, 1.0); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | const SHIELD_FRAG = /* glsl */` |
| +добавлено | uniform vec4 uSphere; |
| +добавлено | uniform vec4 uForm; // rise front (0 floor .. 1.25 past the crown), dissolve 0..1, intensity, seed |
| +добавлено | uniform vec4 uHits[${MAX_HITS}]; // live ripples first: dir * strength, age s |
| +добавлено | uniform vec3 uHitC[${MAX_HITS}]; // the attacker's colour (linear) per ripple |
| +добавлено | uniform int uHitN; |
| +добавлено | uniform vec4 uLook; // filaments, distortion, ripple speed rad/s, thin film |
| +добавлено | uniform vec3 uColor; |
| +добавлено | uniform vec3 uCore; |
| +добавлено | uniform vec3 uGlow; |
| +добавлено | uniform float uInside; // 1: the camera is inside, the wall is the back faces (no far wall) |
| +добавлено | in vec3 vPos; |
| +добавлено | in float vViewZ; |
| +добавлено | out vec4 fragColor; |
| +добавлено | |
| +добавлено | float gField; // fbm at the last wall point: film thickness, ragged fronts |
| +добавлено | |
| +добавлено | // plasma filaments crawling over the membrane: ridged fbm, domain-warped by curl noise. Main veins |
| +добавлено | // are a white-hot ^16 core in a soft ^4 sheath; fine veins (second octave) crawl faster and |
| +добавлено | // flicker; a Worley mask leaves calm patches between the burning ones |
| +добавлено | float filaments(vec3 n) { |
| +добавлено | float t = uTime; |
| +добавлено | vec3 w = curl3(n * 0.31 + vec3(uForm.w, t * 0.05, 0.0)); |
| +добавлено | vec3 p = n * 0.83 + w * 0.12 + vec3(t * 0.025, -t * 0.06, uForm.w); |
| +добавлено | vec4 A = noise3v(p); |
| +добавлено | float b = noise3(p * 2.17 + w * 0.1 + vec3(0.37, 0.37 - t * 0.22, 0.37)); |
| +добавлено | gField = A.r; |
| +добавлено | float ra = 1.0 - abs(A.r * 2.0 - 1.0), rb = 1.0 - abs(b * 2.0 - 1.0); |
| +добавлено | float r4 = ra * ra; r4 *= r4; |
| +добавлено | float r16 = r4 * r4; r16 *= r16; |
| +добавлено | float f4 = rb * rb; f4 *= f4; |
| +добавлено | float f16 = f4 * f4; f16 *= f16; |
| +добавлено | float mask = smoothstep(0.3, 0.75, A.g); |
| +добавлено | return (r16 * 1.5 + r4 * 0.06 + f16 * 0.45) * (0.15 + 0.85 * mask); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // hexagonal lattice: xy = offset from the cell centre (edge at |.| ~ 0.5), zw = cell id |
| +добавлено | vec4 hexCell(vec2 p) { |
| +добавлено | const vec2 k = vec2(1.0, 1.7320508); |
| +добавлено | vec4 hc = floor(vec4(p, p - vec2(0.5, 1.0)) / k.xyxy) + 0.5; |
| +добавлено | vec4 h = vec4(p - hc.xy * k, p - (hc.zw + 0.5) * k); |
| +добавлено | return dot(h.xy, h.xy) < dot(h.zw, h.zw) ? vec4(h.xy, hc.xy) : vec4(h.zw, hc.zw + 0.5); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // ripple packets: slope along the great circle (tilt, for refraction), crest light per channel |
| +добавлено | // (focusing; the RGB phase split is the dispersion fringe) and the hot spot where it struck. |
| +добавлено | // ink: what the hit throws onto the shell, in the attacker's colour. Its energy splashes out over |
| +добавлено | // the membrane and tears along the plasma (fil) instead of passing through, and the field's hex |
| +добавлено | // lattice lights cell by cell as the front sweeps past (film shield-impact language) |
| +добавлено | void ripples(vec3 n, float fil, out vec3 tilt, out vec3 crest, out float spot, out vec3 ink) { |
| +добавлено | tilt = vec3(0.0); crest = vec3(0.0); spot = 0.0; ink = vec3(0.0); |
| +добавлено | for (int i = 0; i < ${MAX_HITS}; i++) { |
| +добавлено | if (i >= uHitN) break; |
| +добавлено | vec4 H = uHits[i]; |
| +добавлено | float s = length(H.xyz); |
| +добавлено | vec3 hd = H.xyz / s; |
| +добавлено | float c = clamp(dot(n, hd), -1.0, 1.0), ang = acos(c); |
| +добавлено | float fr = H.w * uLook.z, x = (ang - fr) / 0.15; |
| +добавлено | float A = s * exp(-1.4 * H.w - x * x) * inversesqrt(max(sin(ang), 0.15)); |
| +добавлено | vec3 ph = x * 4.2 + vec3(-0.22, 0.0, 0.22); |
| +добавлено | vec3 cr = max(cos(ph), 0.0); cr *= cr; cr *= cr; |
| +добавлено | crest += A * cr; |
| +добавлено | vec3 away = n * c - hd; |
| +добавлено | float al = sqrt(dot(away, away)); |
| +добавлено | tilt += away * (A * sin(ph.y) / max(al, 1e-3)); |
| +добавлено | spot += s * exp(-ang * ang * 45.0 - H.w * 6.0); |
| +добавлено | // splash: spreads like a thrown liquid (radius ~ sqrt t), thinning and tearing as it goes |
| +добавлено | float sp = 0.12 + 0.95 * sqrt(H.w); |
| +добавлено | float splash = s * exp(-2.2 * H.w) * smoothstep(sp, sp * 0.35, ang) * (0.25 + 2.5 * fil + 0.6 * smoothstep(0.3, 0.0, ang)); |
| +добавлено | // hex cells in the impact's own azimuthal-equidistant frame (true near the hit, where they show) |
| +добавлено | vec3 t1 = normalize(cross(hd, abs(hd.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0))), t2 = cross(hd, t1); |
| +добавлено | vec2 q = vec2(dot(away, t1), dot(away, t2)) * (ang / max(al, 1e-4)) / 0.11; |
| +добавлено | vec4 hx = hexCell(q); |
| +добавлено | float he = max(dot(abs(hx.xy), vec2(0.5, 0.8660254)), abs(hx.x)); // 0.5 on the cell border |
| +добавлено | float ca = length(q - hx.xy) * 0.11, d = fr - ca; // the cell centre's angle, front lead |
| +добавлено | float lit = smoothstep(-0.04, 0.02, d) * exp(-max(d, 0.0) * 4.5) * smoothstep(1.7, 0.5, ca); |
| +добавлено | float hexE = s * exp(-1.2 * H.w) * lit * (smoothstep(0.38, 0.49, he) + 0.1) * (0.4 + hash12(hx.zw + float(i) * 7.3)); |
| +добавлено | ink += uHitC[i] * (splash * 2.2 + hexE * 2.5 * uLook.x); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | |
| +добавлено | // emission of the membrane at p (unit normal n); lb = 1 - |cos| (0 face-on, 1 grazing). |
| +добавлено | // alive: membrane present (the rise front passed, not burnt away); edge: the incandescent fronts |
| +добавлено | vec3 wall(vec3 p, vec3 n, float lb, out float alive, out float edge, out vec3 tilt) { |
| +добавлено | float fil = filaments(n); |
| +добавлено | // u: arc length up the dome, 0 on the floor ring, 1 at the crown (fronts move at even surface speed) |
| +добавлено | float phi0 = acos(clamp(-uSphere.y / uSphere.w, -1.0, 1.0)); |
| +добавлено | float u = clamp(1.0 - acos(clamp(n.y, -1.0, 1.0)) / phi0, 0.0, 1.0); |
| +добавлено | float f = uForm.x - u - 0.2 * (gField - 0.5); // ragged rise front |
| +добавлено | float g = gField * 0.9 + (1.0 - u) * 0.45 + 0.05 - uForm.y * 1.45; // burn-through holes, crown first |
| +добавлено | alive = step(0.0, f) * step(0.0, g); |
| +добавлено | // fronts: a thin white-hot line in a narrow coloured sheath |
| +добавлено | edge = exp(-f * f * 5000.0) + 0.15 * exp(-f * f * 500.0); |
| +добавлено | if (uForm.y > 0.0) edge += exp(-g * g * 6000.0) + 0.15 * exp(-g * g * 600.0); |
| +добавлено | vec3 crest, ink; float spot; |
| +добавлено | ripples(n, fil, tilt, crest, spot, ink); |
| +добавлено | float rim = lb * lb * lb, wave = crest.g; |
| +добавлено | // a thin glowing film: near-clear face-on, limb-brightened where the eye grazes through it |
| +добавлено | vec3 e = uGlow * (0.012 + 0.55 * rim) // sheath |
| +добавлено | + mix(uColor, uCore, 0.3) * fil * uLook.x * (0.3 + 1.4 * rim + 2.5 * wave) // filaments |
| +добавлено | + (uCore * 1.5 + uColor) * crest * 1.1 // caustic crests |
| +добавлено | + ink + (uCore * 4.0 + ink * 0.5) * spot; |
| +добавлено | return e * alive + (uCore * 3.0 + uColor * 2.0) * edge; |
| +добавлено | } |
| +добавлено | |
| +добавлено | void main() { |
| +добавлено | bool inside = uInside > 0.5; |
| +добавлено | if (gl_FrontFacing == inside) discard; |
| +добавлено | vec3 C = uSphere.xyz; |
| +добавлено | float R = uSphere.w; |
| +добавлено | vec3 rd = normalize(vPos - cameraPosition); |
| +добавлено | vec3 n = normalize(vPos - C); |
| +добавлено | float cv = -dot(n, rd), ac = abs(cv), lb = 1.0 - ac; |
| +добавлено | float alive, edge; vec3 tilt; |
| +добавлено | vec3 emit = wall(vPos, n, lb, alive, edge, tilt); |
| +добавлено | float field = gField; |
| +добавлено | float sceneZ = linearDepth(texelFetch(uSceneDepth, ivec2(gl_FragCoord.xy), 0).r); |
| +добавлено | // the hot line where the membrane cuts the floor or a dummy |
| +добавлено | float dz = max(sceneZ - vViewZ, 0.0); |
| +добавлено | emit += (uCore * exp(-dz / 0.035) * 2.5 + uColor * exp(-dz / 0.18)) * alive; |
| +добавлено | if (!inside) { |
| +добавлено | // the far wall through this one: the ray's exit from the sphere, unless the floor or what |
| +добавлено | // stands inside is in front of it; then the glowing haze along the chord in between |
| +добавлено | vec3 oc = cameraPosition - C; |
| +добавлено | float b = dot(oc, rd); |
| +добавлено | float tOut = -b + sqrt(max(b * b - dot(oc, oc) + R * R, 0.0)); |
| +добавлено | vec3 pB = cameraPosition + rd * tOut; |
| +добавлено | float kz = max(dot(rd, -vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2])), 1e-3); |
| +добавлено | float zB = tOut * kz; |
| +добавлено | if (zB < sceneZ && pB.y > 0.0) { |
| +добавлено | float aB, eB; vec3 tB; |
| +добавлено | emit += wall(pB, (pB - C) / R, lb, aB, eB, tB) * 0.45; |
| +добавлено | } |
| +добавлено | float dzB = abs(sceneZ - zB); |
| +добавлено | emit += (uCore * exp(-dzB / 0.035) * 1.8 + uColor * exp(-dzB / 0.18) * 0.7) * alive * step(-0.2, pB.y); |
| +добавлено | float chord = clamp(min(tOut, sceneZ / kz) - vViewZ / kz, 0.0, 2.0 * R); |
| +добавлено | emit += uGlow * chord * 0.02 * alive; |
| +добавлено | } |
| +добавлено | // optics. Thin film (n = 1.33): R = 4 F sin^2(pi OPD / lambda), OPD = 2 n d cos(theta_t); the film |
| +добавлено | // swirls with the plasma and drains down (thicker low), thinning to black near the crown |
| +добавлено | vec3 nf = cv < 0.0 ? -n : n; |
| +добавлено | float F = fresnel(ac, 0.02) * alive; |
| +добавлено | float y01 = clamp(vPos.y / max(C.y + R, 1e-3), 0.0, 1.0); |
| +добавлено | float dnm = mix(120.0, 680.0, field) + 280.0 * (1.0 - y01); |
| +добавлено | float ct = sqrt(1.0 - (1.0 - ac * ac) / 1.769); |
| +добавлено | vec3 sp = sin(PI * 2.66 * dnm * ct / vec3(650.0, 532.0, 450.0)); |
| +добавлено | vec3 film = min(4.0 * F * sp * sp, vec3(1.0)) * uLook.w; |
| +добавлено | vec3 refl = envReflect(reflect(rd, nf), 0.06) * film; |
| +добавлено | // refraction where the membrane bends (rim lens, ripples, burning fronts) plus a heat-haze wobble |
| +добавлено | // there, each channel displaced a little differently (dispersion). Elsewhere a thin film passes |
| +добавлено | // the scene straight through: blend weight w, so whatever was drawn before shows unharmed |
| +добавлено | vec3 bend = (tilt * 0.05 + nf * (0.03 * lb * lb + 0.05 * edge)) * (alive + edge); |
| +добавлено | vec3 haze = curl3(vPos * 0.45 + vec3(0.0, -uTime * 0.3, uForm.w)) * 0.006; |
| +добавлено | float hh = 0.5 * projectionMatrix[1][1] / max(vViewZ, 1e-3); |
| +добавлено | vec2 sc = vec2(hh * uResolution.y / uResolution.x, hh) * uLook.y; |
| +добавлено | vec2 off = -(mat3(viewMatrix) * bend).xy * sc; |
| +добавлено | float w = smoothstep(0.3, 1.5, length(off * uResolution)); |
| +добавлено | off -= (mat3(viewMatrix) * haze).xy * sc * w; |
| +добавлено | vec2 uv0 = gl_FragCoord.xy / uResolution; |
| +добавлено | float z1 = linearDepth(textureLod(uSceneDepth, uv0 + off, 0.0).r); |
| +добавлено | off *= smoothstep(vViewZ - 0.2, vViewZ + 0.2, z1); // never pull in what is in front of the membrane |
| +добавлено | vec3 refr = vec3(textureLod(uSceneColor, uv0 + off * 0.8, 0.0).r, textureLod(uSceneColor, uv0 + off, 0.0).g, |
| +добавлено | textureLod(uSceneColor, uv0 + off * 1.2, 0.0).b); |
| +добавлено | vec3 col = refr * (1.0 - F) * w + refl + emit * uForm.z; |
| +добавлено | if (uDebug > 0.5 && uDebug < 1.5) { fragColor = vec4(0.04, 0.012, 0.004, 0.0); return; } // overdraw view |
| +добавлено | // premultiplied over: col + dst (1 - a), dst passes as (1 - F) when unbent |
| +добавлено | fragColor = vec4(col, 1.0 - (1.0 - F) * (1.0 - w)); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | // --- missile core / impact pop sprites (full-res additive) -------------------------------------- |
| +добавлено | const SPRITE_VERT = /* glsl */` |
| +добавлено | in vec4 aA; // centre, size m (0 = dead) |
| +добавлено | in vec4 aB; // rgb * intensity, type: [0, 1) missile (seed), [1, 2] pop (1 + age 0..1) |
| +добавлено | in vec4 aV; // world velocity (missiles: motion streak), seed |
| +добавлено | out vec2 vQ; // sprite units: head at the origin, +x along the screen velocity |
| +добавлено | out float vL; // streak length (sprite units, trailing to -x) |
| +добавлено | out vec3 vCol; |
| +добавлено | out vec2 vT; // type, seed |
| +добавлено | void main() { |
| +добавлено | vQ = vec2(0.0); vCol = vec3(0.0); vT = vec2(0.0); vL = 0.0; |
| +добавлено | if (aA.w <= 0.0) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; } |
| +добавлено | vec4 view = viewMatrix * vec4(aA.xyz, 1.0); |
| +добавлено | float viewZ = max(-view.z, 0.05); |
| +добавлено | float pxW = 2.0 * viewZ / (projectionMatrix[1][1] * uResolution.y); |
| +добавлено | float s = max(aA.w, 4.0 * pxW), aa = aA.w / s; // clamp to 4 px, keep the energy |
| +добавлено | vec2 vel = (mat3(viewMatrix) * aV.xyz).xy; |
| +добавлено | float sp = length(vel); |
| +добавлено | vec2 dir = sp > 1e-3 ? vel / sp : vec2(1.0, 0.0); |
| +добавлено | float L = aB.w < 1.0 ? min(sp * 0.016 / s, 2.0) : 0.0; // one 60 Hz frame of motion blur |
| +добавлено | if (aB.w >= 1.0) dir = vec2(cos(aV.w), sin(aV.w)); |
| +добавлено | float x = position.x < 0.0 ? -1.0 - L : 1.0; |
| +добавлено | view.xy += (dir * x + vec2(-dir.y, dir.x) * position.y) * s; |
| +добавлено | gl_Position = projectionMatrix * view; |
| +добавлено | vQ = vec2(x, position.y); |
| +добавлено | vL = L; |
| +добавлено | // a streak spreads the same energy over a longer quad (motion-blur conservation) |
| +добавлено | vCol = aB.rgb * aa * aa * smoothstep(0.15, 0.6, viewZ) / (1.0 + 0.6 * L); |
| +добавлено | vT = vec2(aB.w, aV.w); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | const SPRITE_FRAG = /* glsl */` |
| +добавлено | in vec2 vQ; |
| +добавлено | in float vL; |
| +добавлено | in vec3 vCol; |
| +добавлено | in vec2 vT; |
| +добавлено | out vec4 fragColor; |
| +добавлено | float pnoise(float x, float period) { // smooth periodic value noise |
| +добавлено | float i = floor(x), f = fract(x); |
| +добавлено | f = f * f * (3.0 - 2.0 * f); |
| +добавлено | return mix(hash11(mod(i, period) + 0.37), hash11(mod(i + 1.0, period) + 0.37), f); |
| +добавлено | } |
| +добавлено | void main() { |
| +добавлено | float peak = max(vCol.r, max(vCol.g, vCol.b)); |
| +добавлено | float ang = atan(vQ.y, vQ.x) / 6.2832 + 0.5; |
| +добавлено | vec3 col; |
| +добавлено | if (vT.x < 1.0) { |
| +добавлено | // plasma knot: capsule from the head back along the streak |
| +добавлено | float tf = clamp(-vQ.x / max(vL, 1e-3), 0.0, 1.0); |
| +добавлено | vec2 p = vec2(vQ.x - clamp(vQ.x, -vL, 0.0), vQ.y); |
| +добавлено | float r2 = dot(p, p), r = sqrt(r2); |
| +добавлено | if (r >= 1.0) discard; |
| +добавлено | float sd = vT.y * 37.0; |
| +добавлено | float tail = mix(1.0, 0.3, tf); |
| +добавлено | float flick = 0.8 + 0.4 * pnoise(uTime * 31.0 + sd, 4096.0); |
| +добавлено | float core = exp(-r2 * 110.0) * tail * flick; |
| +добавлено | float sheath = exp(-r2 * 22.0) * tail; |
| +добавлено | // filaments crawling round the knot (two periodic octaves over the angle, counter-rotating) |
| +добавлено | float fil = pnoise(ang * 9.0 + uTime * 2.3 + sd, 9.0) * 0.6 + pnoise(ang * 17.0 - uTime * 3.9 + sd * 2.0, 17.0) * 0.4; |
| +добавлено | fil *= fil; fil *= fil * fil; |
| +добавлено | float tend = fil * exp(-r * 6.0) * smoothstep(0.03, 0.14, r) * mix(1.0, 0.4, tf); |
| +добавлено | // halo: inverse-square scatter round the knot, red reaching further than blue (dispersion) |
| +добавлено | vec3 halo = (0.012 / (r2 * vec3(0.8, 1.0, 1.3) + 0.012) - 0.012) * 0.45 * mix(1.0, 0.4, tf); |
| +добавлено | float edge = 1.0 - r2; edge *= edge; |
| +добавлено | col = (vec3(peak) * (core * 2.6 + sheath * 0.25) + vCol * (core * 0.6 + sheath * 0.6 + tend * 2.0 + halo)) * edge; |
| +добавлено | } else { |
| +добавлено | // plasma burst: white flash, a shock ring split per channel, thin spark rays flying out |
| +добавлено | float r2 = dot(vQ, vQ), r = sqrt(r2); |
| +добавлено | if (r >= 1.0) discard; |
| +добавлено | float x = clamp(vT.x - 1.0, 0.0, 1.0), k = 1.0 - x; |
| +добавлено | // the luminous shock front: a soft shell of compressed glowing air, not a drawn ring |
| +добавлено | vec3 y = (r - (0.06 + 0.8 * sqrt(x)) * vec3(1.035, 1.0, 0.965)) / (0.14 + 0.22 * x); |
| +добавлено | vec3 ring = exp(-y * y) * k * k * smoothstep(0.0, 0.5, r); |
| +добавлено | float fl = exp(-r2 * 30.0) * k * k * k; |
| +добавлено | float slot = floor(ang * 32.0), h = hash11(slot * 1.31 + vT.y); |
| +добавлено | float head = 0.12 + (0.5 + 0.5 * h) * 0.9 * x; |
| +добавлено | float u = (fract(ang * 32.0) - 0.5) * 6.2832 * r / 32.0; |
| +добавлено | float along = clamp(r - head, -0.22, 0.0); |
| +добавлено | float ray = step(0.45, h) * exp(-u * u / 0.0001) * exp(along * 12.0) * step(r, head) * k * k; |
| +добавлено | float edge = 1.0 - r2; edge *= edge; |
| +добавлено | col = (vec3(peak) * (fl * 2.4 + ray * 1.2) + vCol * (ring * 0.45 + fl * 1.5 + ray * 0.7)) * edge; |
| +добавлено | } |
| +добавлено | if (uDebug > 0.5 && uDebug < 1.5) col = vec3(0.04, 0.012, 0.004); |
| +добавлено | fragColor = vec4(col, 1.0); |
| +добавлено | }`; |
| +добавлено | |
| +добавлено | // module scratch (no allocations after create) |
| +добавлено | const _a = new THREE.Vector3(), _b = new THREE.Vector3(), _c = new THREE.Vector3(), _d = new THREE.Vector3(); |
| +добавлено | const _e1 = new THREE.Vector3(), _e2 = new THREE.Vector3(), _om = new THREE.Vector3(), _t = new THREE.Vector3(); |
| +добавлено | const _pa = new THREE.Vector3(), _ba = new THREE.Vector3(); |
| +добавлено | const UP = new THREE.Vector3(0, 1, 0); |
| +добавлено | |
| +добавлено | function capsuleDist(p, a, b, r) { |
| +добавлено | _pa.subVectors(p, a); _ba.subVectors(b, a); |
| +добавлено | const h = Math.min(1, Math.max(0, _pa.dot(_ba) / Math.max(_ba.dot(_ba), 1e-6))); |
| +добавлено | return _pa.addScaledVector(_ba, -h).length() - r; |
| +добавлено | } |
| +добавлено | |
| +добавлено | export default { |
| +добавлено | id: 'arcane', name: 'Arcane', key: '0', hue: '#ff4fd8', |
| +добавлено | shape: 'projectile', forms: ['Arcane Barrage', 'Aegis'], speed: 24, radius: 0.2, |
| +добавлено | params: { |
| +добавлено | missiles: 8, speed: 24, homing: 4, spread: 1, weave: 0.6, sparkles: 1, intensity: 1, |
| +добавлено | shield: 1.45, duration: 6, hex: 1, distortion: 1, pulse: 0.6, anchor: 'target', |
| +добавлено | color: '#ff4fd8', core: '#ffe3fb', glow: '#b347ff', |
| +добавлено | }, |
| +добавлено | ranges: { |
| +добавлено | missiles: [1, MAX_MISSILES, 1], speed: [8, 45, 0.1], homing: [2, 8, 0.1], spread: [0, 2, 0.01], weave: [0, 2, 0.01], |
| +добавлено | sparkles: [0, 3, 0.01], intensity: [0.1, 3, 0.01], shield: [0.8, 3, 0.01], duration: [1, 20, 0.1], hex: [0, 3, 0.01], |
| +добавлено | distortion: [0, 3, 0.01], pulse: [0, 3, 0.01], anchor: ['target', 'caster'], |
| +добавлено | }, |
| +добавлено | presets: { |
| +добавлено | 'frost ward': { color: '#4fc8ff', core: '#e6faff', glow: '#2f5bff' }, |
| +добавлено | 'golden aegis': { color: '#ffb54a', core: '#fff4dc', glow: '#ff6a1a', hex: 1.4 }, |
| +добавлено | 'void swarm': { color: '#a35cff', core: '#f1e6ff', glow: '#2a0a6e', missiles: 12, weave: 1.3, homing: 5.5 }, |
| +добавлено | }, |
| +добавлено | timing: { charge: 0.55, impact: 0.12, linger: 1.1 }, |
| +добавлено | kinds: { |
| +добавлено | spark: { style: 'glow', drag: 1.1, gravity: 5, restitution: 0.35, friction: 0.4, life: [0.2, 0.6], size: [0.028, 0.006], stretch: 0.04, emissive: 7, color: ['#ffe3fb', '#ff4fd8'], alpha: [1, 0] }, |
| +добавлено | sparkle: { style: 'glow', drag: 2.2, curl: 1.4, curlScale: 0.5, life: [0.25, 0.7], size: [0.024, 0.004], stretch: 0.02, emissive: 6, color: ['#ffe3fb', '#b347ff'], alpha: [1, 0], fadeIn: 0.01, fadeOut: 0.5 }, |
| +добавлено | mote: { style: 'glow', drag: 0.3, life: [0.4, 0.6], size: [0.012, 0.026], stretch: 0.05, emissive: 5, color: ['#ffe3fb', '#ff4fd8'], alpha: [0.2, 1], fadeIn: 0.3, fadeOut: 0.15, forceResponse: 0.3 }, |
| +добавлено | // incandescent grit: blackbody, whatever the spell's colour (grinder sparks) |
| +добавлено | deflect: { style: 'glow', drag: 0.7, gravity: 9.8, restitution: 0.35, friction: 0.15, life: [0.25, 0.8], size: [0.022, 0.006], stretch: 0.05, emissive: 4, temp: [2600, 1100], alpha: [1, 0], fadeOut: 0.3 }, |
| +добавлено | }, |
| +добавлено | |
| +добавлено | create(fx) { |
| +добавлено | const S = this, P = fx.particles; |
| +добавлено | const spark = P.emitter('arcane.spark', { shape: 'sphere', radius: 0.05, spread: 3.5, radial: 3 }); |
| +добавлено | const sparkle = P.emitter('arcane.sparkle', { shape: 'sphere', radius: 0.05, spread: 1.4 }); |
| +добавлено | const mote = P.emitter('arcane.mote', { shape: 'shell', radius: 1.2, spread: 0.1, radial: -2.4 }); |
| +добавлено | const rise = P.emitter('arcane.mote', { shape: 'ring', radius: 1, spread: 0.15 }); |
| +добавлено | const shellMote = P.emitter('arcane.mote', { shape: 'shell', radius: 1.45, spread: 0.05, radial: 0.25 }); |
| +добавлено | const shellSpark = P.emitter('arcane.spark', { shape: 'shell', radius: 1.45, spread: 0.8, radial: 2.2 }); |
| +добавлено | const ringSpark = P.emitter('arcane.spark', { shape: 'ring', radius: 1, spread: 1, radial: 2.5 }); |
| +добавлено | const waveSpark = P.emitter('arcane.spark', { shape: 'sphere', radius: 0.03, spread: 0.6 }); |
| +добавлено | const deflect = P.emitter('arcane.deflect', { shape: 'sphere', radius: 0.12, spread: 4.5 }); |
| +добавлено | const tintC = new THREE.Color(); |
| +добавлено | |
| +добавлено | // colours: linear, shared by reference with every shield material |
| +добавлено | const col = new THREE.Color(), core = new THREE.Color(), glow = new THREE.Color(); |
| +добавлено | const uColor = new THREE.Vector3(), uCore = new THREE.Vector3(), uGlow = new THREE.Vector3(); |
| +добавлено | const look = new THREE.Vector4(1, 1, 2.4, 1); |
| +добавлено | let cC = '', cK = '', cG = ''; |
| +добавлено | function syncColors() { |
| +добавлено | const p = S.params; |
| +добавлено | if (p.color === cC && p.core === cK && p.glow === cG) return; |
| +добавлено | cC = p.color; cK = p.core; cG = p.glow; |
| +добавлено | col.set(cC); core.set(cK); glow.set(cG); |
| +добавлено | uColor.set(col.r, col.g, col.b); uCore.set(core.r, core.g, core.b); uGlow.set(glow.r, glow.g, glow.b); |
| +добавлено | P.setKind('arcane.spark', { color: [cK, cC] }); |
| +добавлено | P.setKind('arcane.sparkle', { color: [cK, cG] }); |
| +добавлено | P.setKind('arcane.mote', { color: [cK, cC] }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // reusable option objects for the pooled systems (they copy what they need) |
| +добавлено | const SIG = { pos: new THREE.Vector3(), normal: new THREE.Vector3(), radius: 1, color: new THREE.Color(), intensity: 0, reveal: 0, rotation: 0, style: 'arcane', seed: 0 }; |
| +добавлено | const SHOCK = { pos: new THREE.Vector3(), radius0: 0.05, radius1: 1, duration: 0.3, thickness: 0.25, distortion: 0.02, color: new THREE.Color(), intensity: 0, ground: false }; |
| +добавлено | const SPLAT = { x: 0, z: 0, radius: 1, glow: 0, corruption: 0, heat: 0, char: 0, pattern: 'ring', seed: 0 }; |
| +добавлено | const SCORCH = new THREE.Color(1, 0.4, 0.1); |
| +добавлено | |
| +добавлено | // --- sprites: missile cores + impact pops, one instanced draw --- |
| +добавлено | const sgeo = new THREE.InstancedBufferGeometry(); |
| +добавлено | sgeo.setAttribute('position', new THREE.Float32BufferAttribute([-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0], 3)); |
| +добавлено | sgeo.setIndex([0, 1, 2, 0, 2, 3]); |
| +добавлено | const aA = instanced(sgeo, 'aA', MAX_SPRITES), aB = instanced(sgeo, 'aB', MAX_SPRITES), aV = instanced(sgeo, 'aV', MAX_SPRITES); |
| +добавлено | sgeo.instanceCount = 0; |
| +добавлено | const sprites = new THREE.Mesh(sgeo, new THREE.ShaderMaterial({ |
| +добавлено | glslVersion: THREE.GLSL3, uniforms: { ...U }, ...LINES_BLENDING, |
| +добавлено | vertexShader: COMMON_GLSL + SPRITE_VERT, fragmentShader: COMMON_GLSL + SPRITE_FRAG, |
| +добавлено | })); |
| +добавлено | sprites.frustumCulled = false; |
| +добавлено | sprites.visible = false; |
| +добавлено | fx.scenes.lines.add(sprites); |
| +добавлено | const pops = Array.from({ length: MAX_POPS }, () => ({ pos: new THREE.Vector3(), age: 1, life: 0, size: 0, r: 0, g: 0, b: 0, seed: 0 })); |
| +добавлено | let popHead = 0; |
| +добавлено | function addPop(pos, size, c, k, life) { |
| +добавлено | const q = pops[popHead]; popHead = (popHead + 1) % MAX_POPS; |
| +добавлено | q.pos.copy(pos); q.size = size; q.life = life; q.age = 0; q.seed = fx.rand() * TAU; |
| +добавлено | q.r = c.r * k; q.g = c.g * k; q.b = c.b * k; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // --- missiles: one group per cast record (cast.js keeps 16), all 8+ live in c.data.g --- |
| +добавлено | const groups = Array.from({ length: MAX_CASTS }, () => ({ |
| +добавлено | n: 0, launched: 0, landed: 0, |
| +добавлено | ms: Array.from({ length: MAX_MISSILES }, () => ({ pos: new THREE.Vector3(), vel: new THREE.Vector3(), off: new THREE.Vector3(), alive: false, age: 0, ph: 0, w: 0, trail: null })), |
| +добавлено | })); |
| +добавлено | |
| +добавлено | // --- shields: one sphere per shield in the refract pass (premultiplied over, no depth write) --- |
| +добавлено | const shellGeo = new THREE.IcosahedronGeometry(1, 18); |
| +добавлено | const shields = []; |
| +добавлено | for (let i = 0; i < MAX_SHIELDS; i++) { |
| +добавлено | const su = { |
| +добавлено | uSphere: { value: new THREE.Vector4() }, uForm: { value: new THREE.Vector4() }, uWobble: { value: new THREE.Vector4() }, |
| +добавлено | uHits: { value: Array.from({ length: MAX_HITS }, () => new THREE.Vector4()) }, uHitC: { value: Array.from({ length: MAX_HITS }, () => new THREE.Vector3()) }, |
| +добавлено | uHitN: { value: 0 }, uInside: { value: 0 }, |
| +добавлено | uLook: { value: look }, uColor: { value: uColor }, uCore: { value: uCore }, uGlow: { value: uGlow }, |
| +добавлено | }; |
| +добавлено | const mat = new THREE.ShaderMaterial({ |
| +добавлено | glslVersion: THREE.GLSL3, uniforms: { ...U, ...su }, side: THREE.DoubleSide, |
| +добавлено | transparent: true, depthWrite: false, depthTest: true, |
| +добавлено | blending: THREE.CustomBlending, blendEquation: THREE.AddEquation, |
| +добавлено | blendSrc: THREE.OneFactor, blendDst: THREE.OneMinusSrcAlphaFactor, |
| +добавлено | blendEquationAlpha: THREE.AddEquation, blendSrcAlpha: THREE.ZeroFactor, blendDstAlpha: THREE.OneFactor, |
| +добавлено | vertexShader: COMMON_GLSL + SHIELD_VERT, |
| +добавлено | fragmentShader: COMMON_GLSL + NOISE_GLSL + REFRACT_GLSL + SHIELD_FRAG, |
| +добавлено | }); |
| +добавлено | const mesh = new THREE.Mesh(shellGeo, mat); |
| +добавлено | mesh.frustumCulled = false; |
| +добавлено | mesh.visible = false; |
| +добавлено | mesh.renderOrder = -1; // first of the refract-pass translucents: sparks inside stay unbent but visible |
| +добавлено | fx.scenes.refract.add(mesh); |
| +добавлено | shields.push({ |
| +добавлено | active: false, formed: false, mesh, u: su, cast: null, center: new THREE.Vector3(), R: 1, r: 0, t: 0, end: 0, |
| +добавлено | flash: 0, phase: 0, burst: false, resplat: 0, caster: false, occ: null, light: null, hitLight: null, hitK: 0, |
| +добавлено | sigil: null, head: 0, wob: 0, wobV: 0, |
| +добавлено | hits: Array.from({ length: MAX_HITS }, () => ({ dir: new THREE.Vector3(), age: 0, s: 0, col: new THREE.Color() })), |
| +добавлено | }); |
| +добавлено | } |
| +добавлено | const seen = Array.from({ length: MAX_CASTS }, () => 'done'); |
| +добавлено | |
| +добавлено | function aim(c, m, out) { |
| +добавлено | if (c.target >= 0) { const dp = fx.dummies[c.target].pos; out.set(dp.x, c.to.y, dp.z); } else out.copy(c.to); |
| +добавлено | return out.add(m.off); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // floor, rim and capsules, minus the pedestal under the launch circle and any shield the caster stands in |
| +добавлено | function sceneDist(p, from) { |
| +добавлено | let d = arenaStatic(p); |
| +добавлено | for (const o of fx.occluders.list) { |
| +добавлено | if (o.kind === 4) continue; |
| +добавлено | if (o.kind === 3 && from.distanceToSquared(o.a) < o.radius * o.radius) continue; |
| +добавлено | d = Math.min(d, capsuleDist(p, o.a, o.b, o.radius)); |
| +добавлено | } |
| +добавлено | return d; |
| +добавлено | } |
| +добавлено | |
| +добавлено | function shieldNear(pos) { |
| +добавлено | let best = null, bd = 1e9; |
| +добавлено | for (const sh of shields) { |
| +добавлено | if (!sh.active || !sh.formed) continue; |
| +добавлено | const dist = pos.distanceTo(sh.center); |
| +добавлено | if (dist > sh.r + 0.9) continue; |
| +добавлено | const k = Math.abs(dist - sh.r); |
| +добавлено | if (k < bd) { bd = k; best = sh; } |
| +добавлено | } |
| +добавлено | return best; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // tint: the attacker's colour (null: the shield's own) |
| +добавлено | function ripple(sh, pos, s, tint = null) { |
| +добавлено | _d.subVectors(pos, sh.center); |
| +добавлено | const l = _d.length(); |
| +добавлено | if (l < 1e-4) _d.set(0, 1, 0); else _d.multiplyScalar(1 / l); |
| +добавлено | const h = sh.hits[sh.head]; |
| +добавлено | sh.head = (sh.head + 1) % MAX_HITS; |
| +добавлено | h.dir.copy(_d); h.age = 0; h.s = s; |
| +добавлено | h.col.copy(tint ?? col); |
| +добавлено | sh.flash = Math.min(1.5, sh.flash + 0.4 * s); |
| +добавлено | sh.wobV += 0.12 * s; // the membrane rings |
| +добавлено | // caustic light thrown through the struck patch (just inside it): flashes, then fades |
| +добавлено | const L = sh.hitLight; |
| +добавлено | if (L) { |
| +добавлено | L.pos.copy(sh.center).addScaledVector(_d, Math.max(sh.r - 0.25, 0.1)); sh.hitK = Math.min(2, sh.hitK + s); |
| +добавлено | L.color.copy(h.col).lerp(core, 0.45); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | |
| +добавлено | // public hook: ripple the shield nearest pos (within 0.9 m outside its shell, or inside it). |
| +добавлено | // tint (THREE.Color, optional): the attacker's colour, splashed over the shell |
| +добавлено | function hit(pos, strength = 1, tint = null) { |
| +добавлено | const sh = shieldNear(pos); |
| +добавлено | if (!sh) return false; |
| +добавлено | ripple(sh, pos, strength, tint); |
| +добавлено | _e1.subVectors(pos, sh.center).normalize(); |
| +добавлено | _a.copy(sh.center).addScaledVector(_e1, sh.r); |
| +добавлено | spark.pos.copy(_a); spark.vel.copy(_e1).multiplyScalar(2.5); spark.burst(30 * strength * S.params.sparkles); |
| +добавлено | spark.vel.set(0, 0, 0); |
| +добавлено | // white-hot grit skids off along the shell: its occluder deflects it round the curve |
| +добавлено | _a.addScaledVector(_e1, 0.07); |
| +добавлено | deflect.pos.copy(_a); deflect.vel.copy(_e1).multiplyScalar(1.2); deflect.burst(70 * strength * S.params.sparkles); |
| +добавлено | deflect.vel.set(0, 0, 0); |
| +добавлено | addPop(_a, 0.55 + 0.25 * Math.min(strength, 2), tint ?? col, 6 * S.params.intensity, 0.25); |
| +добавлено | return true; |
| +добавлено | } |
| +добавлено | // '#rrggbb' -> linear colour, without allocating |
| +добавлено | const hx = (str, i) => { const c = str.charCodeAt(i); return c <= 57 ? c - 48 : (c | 32) - 87; }; |
| +добавлено | function hueOf(spell, out) { |
| +добавлено | const h = spell.hue; |
| +добавлено | if (typeof h !== 'string' || h.length !== 7) return out.copy(col); |
| +добавлено | return out.setRGB((hx(h, 1) * 16 + hx(h, 2)) / 255, (hx(h, 3) * 16 + hx(h, 4)) / 255, (hx(h, 5) * 16 + hx(h, 6)) / 255, THREE.SRGBColorSpace); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // --- barrage --- |
| +добавлено | function launchCentre(c, out) { return out.copy(c.from).addScaledVector(c.dir, 0.45); } |
| +добавлено | |
| +добавлено | function launch(c, g, i, p) { |
| +добавлено | const m = g.ms[i]; |
| +добавлено | _e1.crossVectors(c.dir, UP); |
| +добавлено | if (_e1.lengthSq() < 1e-6) _e1.set(1, 0, 0); |
| +добавлено | _e1.normalize(); |
| +добавлено | _e2.crossVectors(_e1, c.dir); |
| +добавлено | const a = (i / g.n) * TAU + (c.seed % 628) * 0.01 + (fx.rand() - 0.5) * 0.5; |
| +добавлено | _c.copy(_e1).multiplyScalar(Math.cos(a)).addScaledVector(_e2, Math.sin(a)); // out of the rim |
| +добавлено | launchCentre(c, m.pos).addScaledVector(_c, 0.55); |
| +добавлено | m.vel.copy(_c).multiplyScalar((4 + 3 * fx.rand()) * p.spread).addScaledVector(c.dir, 4) |
| +добавлено | .addScaledVector(UP, (0.5 + 1.5 * fx.rand()) * p.spread) |
| +добавлено | .add(_t.set(fx.rand() - 0.5, fx.rand() - 0.5, fx.rand() - 0.5).multiplyScalar(1.5)); |
| +добавлено | // where on the target this one lands |
| +добавлено | m.off.set(fx.rand() - 0.5, fx.rand() - 0.5, fx.rand() - 0.5).multiplyScalar(c.target >= 0 ? 0.45 : 0.9); |
| +добавлено | if (c.target < 0) m.off.y = 0; |
| +добавлено | m.age = 0; m.alive = true; |
| +добавлено | m.ph = fx.rand() * TAU; |
| +добавлено | m.w = (7 + 5 * fx.rand()) * (fx.rand() < 0.5 ? -1 : 1); |
| +добавлено | m.trail = fx.trails.acquire(); |
| +добавлено | const tr = m.trail; |
| +добавлено | if (tr) { |
| +добавлено | tr.width = 0.016; tr.intensity = 2.6 * p.intensity; tr.glow = 9; tr.glowIntensity = 0.12; tr.fadeTime = 0.13; tr.spacing = 0.08; |
| +добавлено | tr.distortion = 0.04 * p.distortion; tr.color.copy(col).lerp(core, 0.35); // heat shimmer in the wake |
| +добавлено | } |
| +добавлено | addPop(m.pos, 0.45, col, 6 * p.intensity, 0.2); |
| +добавлено | spark.pos.copy(m.pos); spark.vel.copy(m.vel).multiplyScalar(0.3); spark.burst(14 * p.sparkles); |
| +добавлено | spark.vel.set(0, 0, 0); |
| +добавлено | c.data.flash = Math.max(c.data.flash, 0.5); |
| +добавлено | } |
| +добавлено | |
| +добавлено | function steer(c, m, p, dt) { |
| +добавлено | const tgt = aim(c, m, _b); |
| +добавлено | const r = _a.subVectors(tgt, m.pos), dist = r.length(); |
| +добавлено | const speed = m.vel.length(); |
| +добавлено | if (dist < 0.22 + speed * dt * 0.6) return true; |
| +добавлено | const rh = r.multiplyScalar(1 / dist); |
| +добавлено | // PN: Omega = (v x r^) / |r| (LOS rate, static target), a = N V (Omega x r^): the heading |
| +добавлено | // turns N times as fast as the line of sight (closing speed floored at the missile's own) |
| +добавлено | _om.crossVectors(m.vel, rh).multiplyScalar(1 / dist); |
| +добавлено | _d.crossVectors(_om, rh).multiplyScalar(p.homing * Math.max(speed, 4)); |
| +добавлено | // pursuit: weak at first (PN does the curving), grows so nothing orbits forever |
| +добавлено | _d.addScaledVector(_t.copy(rh).multiplyScalar(p.speed).sub(m.vel), 1.5 + 4 * Math.max(0, m.age - 0.5)); |
| +добавлено | // corkscrew weave, fading out on the final approach |
| +добавлено | const vh = _t.copy(m.vel).multiplyScalar(1 / Math.max(speed, 1e-3)); |
| +добавлено | _e1.crossVectors(vh, UP); |
| +добавлено | if (_e1.lengthSq() < 1e-6) _e1.set(1, 0, 0); |
| +добавлено | _e1.normalize(); |
| +добавлено | _e2.crossVectors(_e1, vh); |
| +добавлено | const ph = m.ph + m.age * m.w, wa = p.weave * 28 * Math.min(1, dist / 4); |
| +добавлено | _d.addScaledVector(_e1, Math.cos(ph) * wa).addScaledVector(_e2, Math.sin(ph) * wa); |
| +добавлено | // lateral g limit, then thrust towards cruise speed |
| +добавлено | const along = _d.dot(vh); |
| +добавлено | _d.addScaledVector(vh, -along); |
| +добавлено | const lat = _d.length(), amax = 220; |
| +добавлено | if (lat > amax) _d.multiplyScalar(amax / lat); |
| +добавлено | // thrust once it points at the target, brake while it points away (tighter turn) |
| +добавлено | const aimK = vh.dot(rh); |
| +добавлено | _d.addScaledVector(vh, aimK > 0 ? (p.speed - speed) * 5 * aimK : -speed * 1.5 * -aimK); |
| +добавлено | m.vel.addScaledVector(_d, dt); |
| +добавлено | m.pos.addScaledVector(m.vel, dt); |
| +добавлено | m.age += dt; |
| +добавлено | return m.age > 0.05 && sceneDist(m.pos, c.from) < 0.06; |
| +добавлено | } |
| +добавлено | |
| +добавлено | function land(c, g, m, p) { |
| +добавлено | m.alive = false; |
| +добавлено | g.landed++; |
| +добавлено | m.trail?.release(); m.trail = null; |
| +добавлено | const sh = shieldNear(m.pos); |
| +добавлено | if (sh) ripple(sh, m.pos, 0.9); |
| +добавлено | _e1.copy(m.vel).normalize(); |
| +добавлено | spark.pos.copy(m.pos); spark.vel.copy(_e1).multiplyScalar(-2.2); spark.burst(30 * p.sparkles); |
| +добавлено | spark.vel.set(0, 0, 0); |
| +добавлено | // white-hot spatter off the struck surface, falling and skipping over the floor |
| +добавлено | deflect.pos.copy(m.pos); deflect.vel.copy(_e1).multiplyScalar(-2.6); deflect.burst(34 * p.sparkles); |
| +добавлено | deflect.vel.set(0, 0, 0); |
| +добавлено | addPop(m.pos, 0.7, col, 2.2 * p.intensity, 0.28); |
| +добавлено | if (!sh) fx.impacts.add('scorch', m.pos, 0.32, 0.35, 7, SCORCH); |
| +добавлено | SHOCK.pos.copy(m.pos); SHOCK.radius0 = 0.05; SHOCK.radius1 = 1.1; SHOCK.duration = 0.28; SHOCK.thickness = 0.22; |
| +добавлено | SHOCK.distortion = 0.03 * p.distortion; SHOCK.color.copy(col); SHOCK.intensity = 1.5 * p.intensity; SHOCK.ground = false; |
| +добавлено | fx.shocks?.spawn(SHOCK); |
| +добавлено | if (m.pos.y < 2.2) { |
| +добавлено | SPLAT.x = m.pos.x; SPLAT.z = m.pos.z; SPLAT.radius = 0.55; SPLAT.glow = 0.12; SPLAT.corruption = 0.12; SPLAT.heat = 0.35; SPLAT.char = 0.3; |
| +добавлено | SPLAT.pattern = 'noise'; SPLAT.seed = (c.seed + g.landed * 17) % 100; |
| +добавлено | fx.ground.splat(SPLAT); |
| +добавлено | SPLAT.heat = SPLAT.char = 0; |
| +добавлено | } |
| +добавлено | if (g.landed === 1 || g.landed === g.n) fx.impacts.add('holy', m.pos, 0.8, 0.6, 1.5, col); |
| +добавлено | if (!sh && c.target >= 0) fx.dummies[c.target].hit(_e1, 0.18); |
| +добавлено | fx.rig.shake(0.05, 22); |
| +добавлено | c.pos.copy(m.pos); |
| +добавлено | // the swarm light snaps to the impact and flashes, then slides back along the swarm |
| +добавлено | const L = c.data.light; |
| +добавлено | if (L) { L.pos.copy(m.pos); L.end.copy(m.pos); c.data.flash = 1; } |
| +добавлено | } |
| +добавлено | |
| +добавлено | // --- aegis --- |
| +добавлено | function aegisCharge(c, p, d) { |
| +добавлено | c.durations.charge = 0.4; c.durations.impact = 0.35; c.durations.linger = p.duration + 2; |
| +добавлено | let sh = null; |
| +добавлено | for (const s of shields) if (!s.active) { sh = s; break; } |
| +добавлено | d.sh = sh; |
| +добавлено | if (!sh) { c.durations.linger = 0; return; } // all shields up: this cast fizzles |
| +добавлено | const caster = p.anchor === 'caster'; |
| +добавлено | const R = caster ? Math.max(p.shield, 1.4) : p.shield; |
| +добавлено | if (caster) _a.set(c.from.x, 0, c.from.z); |
| +добавлено | else if (c.target >= 0) _a.copy(fx.dummies[c.target].pos).setY(0); |
| +добавлено | else _a.set(c.to.x, 0, c.to.z); |
| +добавлено | sh.center.copy(_a).setY(0.55 * R); |
| +добавлено | // renew: a live shield in the same spot dissolves while this one forms |
| +добавлено | for (const s of shields) if (s !== sh && s.active && s.formed && s.center.distanceToSquared(sh.center) < 0.25) s.end = Math.min(s.end, s.t + 0.6); |
| +добавлено | sh.active = true; sh.formed = false; sh.cast = c; sh.R = R; sh.r = R; sh.t = 0; sh.end = FORM_TIME + p.duration; |
| +добавлено | sh.flash = 0; sh.burst = false; sh.resplat = 0; sh.head = 0; sh.caster = caster; sh.hitK = 0; sh.wob = 0; sh.wobV = 0; |
| +добавлено | sh.phase = fx.rand(); |
| +добавлено | for (const h of sh.hits) h.s = 0; |
| +добавлено | c.pos.copy(sh.center); |
| +добавлено | SIG.pos.set(sh.center.x, 0.02, sh.center.z); SIG.normal.set(0, 1, 0); SIG.radius = 0.835 * R * 1.15; |
| +добавлено | SIG.color.copy(col); SIG.intensity = 0; SIG.reveal = 0; SIG.rotation = 0; SIG.seed = c.seed % 1000; |
| +добавлено | sh.sigil = fx.sigils.acquire(SIG); |
| +добавлено | sh.light = fx.lights.acquire(); |
| +добавлено | if (sh.light) { sh.light.range = 3.2 * R; sh.light.intensity = 0; sh.light.color.copy(col); sh.light.pos.copy(sh.center).addScaledVector(UP, 0.35 * R); } |
| +добавлено | } |
| +добавлено | |
| +добавлено | function aegisForm(c, p, sh) { |
| +добавлено | c.pos.copy(sh.center); |
| +добавлено | sh.formed = true; |
| +добавлено | sh.t = 0; |
| +добавлено | sh.flash = 1.2; |
| +добавлено | sh.wob = -0.05; sh.wobV = 0.4; // it snaps up taut and rings |
| +добавлено | // a shield on the caster would stop the caster's own spells: it collides only on others |
| +добавлено | sh.occ = sh.caster ? null : fx.occluders.add(sh.center, sh.center, sh.r, 3); |
| +добавлено | sh.hitLight = fx.lights.acquire(); |
| +добавлено | const H = sh.hitLight; |
| +добавлено | if (H) { H.type = 2; H.cookie[0] = 1; H.cookie[1] = 2.4; H.range = 2.6 * sh.R; H.shadow = true; H.intensity = 0; H.color.copy(col).lerp(core, 0.5); H.pos.copy(sh.center); } |
| +добавлено | const rf = 0.835 * sh.R; // floor ring radius (centre at 0.55 R) |
| +добавлено | SHOCK.pos.set(sh.center.x, 0.05, sh.center.z); SHOCK.radius0 = rf * 0.5; SHOCK.radius1 = rf * 3; SHOCK.duration = 0.45; |
| +добавлено | SHOCK.thickness = 0.5; SHOCK.distortion = 0.04 * p.distortion; SHOCK.color.copy(col); SHOCK.intensity = 2 * p.intensity; SHOCK.ground = true; |
| +добавлено | fx.shocks?.spawn(SHOCK); |
| +добавлено | ringSpark.pos.set(sh.center.x, 0.08, sh.center.z); ringSpark.radius = rf; ringSpark.vel.set(0, 2.5, 0); |
| +добавлено | ringSpark.burst(160 * p.sparkles); |
| +добавлено | SPLAT.x = sh.center.x; SPLAT.z = sh.center.z; SPLAT.radius = rf; SPLAT.glow = 0.7; SPLAT.corruption = 0.3; |
| +добавлено | SPLAT.pattern = 'ring'; SPLAT.seed = c.seed % 100; |
| +добавлено | fx.ground.splat(SPLAT); |
| +добавлено | fx.rig.shake(0.15, 14); |
| +добавлено | fx.flash(0.08 * p.intensity); |
| +добавлено | } |
| +добавлено | |
| +добавлено | function release(c) { |
| +добавлено | const d = c.data, g = d.g; |
| +добавлено | if (g) { |
| +добавлено | for (const m of g.ms) { m.alive = false; m.trail?.release(); m.trail = null; } |
| +добавлено | g.n = g.launched = g.landed = 0; |
| +добавлено | } |
| +добавлено | const sh = d.sh; |
| +добавлено | if (sh && sh.cast === c) { |
| +добавлено | sh.occ?.release(); sh.light?.release(); sh.hitLight?.release(); sh.sigil?.release(); |
| +добавлено | sh.occ = sh.light = sh.hitLight = sh.sigil = null; |
| +добавлено | sh.active = sh.formed = false; sh.cast = null; |
| +добавлено | } |
| +добавлено | d.light?.release(); d.sig?.release(); |
| +добавлено | d.g = d.sh = d.light = d.sig = null; |
| +добавлено | } |
| +добавлено | |
| +добавлено | syncColors(); |
| +добавлено | |
| +добавлено | return { |
| +добавлено | hit, |
| +добавлено | // a formed shield whose dome covers (x, z): writes its centre to out, returns its radius (0: none) |
| +добавлено | shieldOver(x, z, out) { |
| +добавлено | for (const sh of shields) { |
| +добавлено | if (!sh.active || !sh.formed || (x - sh.center.x) ** 2 + (z - sh.center.z) ** 2 > sh.r * sh.r) continue; |
| +добавлено | out.copy(sh.center); |
| +добавлено | return sh.r; |
| +добавлено | } |
| +добавлено | return 0; |
| +добавлено | }, |
| +добавлено | onParam(k) { if (k === 'color' || k === 'core' || k === 'glow') syncColors(); }, |
| +добавлено | |
| +добавлено | phase(c, name) { |
| +добавлено | const p = S.params, d = c.data; |
| +добавлено | syncColors(); |
| +добавлено | if (name === 'charge') { |
| +добавлено | d.g = d.sh = d.light = d.sig = null; |
| +добавлено | d.flash = 0; |
| +добавлено | d.shielded = false; |
| +добавлено | if (c.form === 'Aegis') { aegisCharge(c, p, d); return; } |
| +добавлено | const g = d.g = groups[c.index]; |
| +добавлено | g.n = Math.round(p.missiles); g.launched = 0; g.landed = 0; |
| +добавлено | for (const m of g.ms) { m.alive = false; m.trail = null; } |
| +добавлено | d.light = fx.lights.acquire(); |
| +добавлено | if (d.light) { d.light.type = 1; d.light.range = 9; d.light.intensity = 0; d.light.color.copy(col); launchCentre(c, d.light.pos); d.light.end.copy(d.light.pos); } |
| +добавлено | // the launch circle in front of the orb, facing the target (missiles leave from its rim) |
| +добавлено | launchCentre(c, SIG.pos); SIG.normal.copy(c.dir); SIG.radius = 0.8; SIG.color.copy(col); |
| +добавлено | SIG.intensity = 0; SIG.reveal = 0; SIG.rotation = 0; SIG.seed = c.seed % 1000; |
| +добавлено | d.sig = fx.sigils.acquire(SIG); |
| +добавлено | } else if (name === 'release') { |
| +добавлено | if (c.form !== 'Aegis') fx.rig.shake(0.08, 12); |
| +добавлено | } else if (name === 'impact') { |
| +добавлено | if (c.form === 'Aegis' && d.sh) aegisForm(c, p, d.sh); |
| +добавлено | } else if (name === 'done') release(c); |
| +добавлено | }, |
| +добавлено | |
| +добавлено | // projectile travel: Barrage flies its missiles here, Aegis has no flight |
| +добавлено | travel(c, dt) { |
| +добавлено | if (c.form === 'Aegis') return true; |
| +добавлено | const p = S.params, g = c.data.g; |
| +добавлено | if (!g) return true; |
| +добавлено | while (g.launched < g.n && c.t >= g.launched * LAUNCH_GAP) launch(c, g, g.launched++, p); |
| +добавлено | for (let i = 0; i < g.launched; i++) { |
| +добавлено | const m = g.ms[i]; |
| +добавлено | if (m.alive && (steer(c, m, p, dt) || c.t > 6)) land(c, g, m, p); |
| +добавлено | } |
| +добавлено | return g.landed >= g.n; |
| +добавлено | }, |
| +добавлено | |
| +добавлено | update(c, dt) { |
| +добавлено | const p = S.params, d = c.data; |
| +добавлено | if (c.form === 'Aegis') { updateAegis(c, p, d, dt); return; } |
| +добавлено | const L = d.light, k = c.phase === 'charge' ? c.t / c.durations.charge : 1; |
| +добавлено | const fade = c.phase === 'linger' ? Math.max(0, 1 - c.t / c.durations.linger) : 1; |
| +добавлено | d.flash = Math.max(0, d.flash - dt * 6); |
| +добавлено | if (d.sig) { |
| +добавлено | // closes 0.35 s after the last launch (intensity 0 drops it from the sigil draw) |
| +добавлено | const close = c.phase === 'charge' ? 1 : c.phase === 'travel' ? Math.min(1, Math.max(0, 1 - (c.t - d.g.n * LAUNCH_GAP) / 0.35)) : 0; |
| +добавлено | launchCentre(c, d.sig.pos); |
| +добавлено | d.sig.reveal = Math.min(1, k * 1.25); |
| +добавлено | d.sig.intensity = (2.6 + 2 * k + 4 * d.flash) * p.intensity * close; |
| +добавлено | d.sig.rotation = c.age * 0.9; |
| +добавлено | } |
| +добавлено | if (c.phase === 'charge') { |
| +добавлено | launchCentre(c, mote.pos); mote.rate(500 * k * p.sparkles, dt); |
| +добавлено | if (L) { launchCentre(c, L.pos); L.end.copy(L.pos); L.intensity = 6 * k * p.intensity; } |
| +добавлено | return; |
| +добавлено | } |
| +добавлено | const g = d.g; |
| +добавлено | let n = 0, first = null, last = null; |
| +добавлено | if (g && c.phase === 'travel') for (let i = 0; i < g.launched; i++) { |
| +добавлено | const m = g.ms[i]; |
| +добавлено | if (!m.alive) continue; |
| +добавлено | m.trail?.push(m.pos); |
| +добавлено | // sparks shed sideways off the knot: velocity streaks |
| +добавлено | sparkle.pos.copy(m.pos); sparkle.vel.copy(m.vel).multiplyScalar(-0.15); sparkle.rate(90 * p.sparkles, dt); |
| +добавлено | if (!first) first = m; |
| +добавлено | last = m; |
| +добавлено | n++; |
| +добавлено | } |
| +добавлено | if (L) { |
| +добавлено | // the swarm is a line light from the first live missile to the last (lights the floor along it) |
| +добавлено | if (n > 0 && d.flash < 0.3) { |
| +добавлено | const kk = Math.min(1, dt * 12); |
| +добавлено | L.pos.lerp(first.pos, kk); L.end.lerp(last.pos, kk); |
| +добавлено | } |
| +добавлено | L.intensity = (n > 0 ? 8 + 2.4 * n : 2 * fade) * p.intensity + 20 * d.flash * p.intensity; |
| +добавлено | } |
| +добавлено | }, |
| +добавлено | |
| +добавлено | tick(dt) { |
| +добавлено | syncColors(); |
| +добавлено | const p = S.params; |
| +добавлено | look.set(p.hex, p.distortion, 2.4, 2); // w: thin-film strength (a soap film shows its swirls face-on against a bright sky) |
| +добавлено | // other spells landing on a shield ripple it |
| +добавлено | const list = fx.casts?.list; |
| +добавлено | if (list) for (const c of list) { |
| +добавлено | const was = seen[c.index]; |
| +добавлено | seen[c.index] = c.alive ? c.phase : 'done'; |
| +добавлено | if (!c.alive || c.phase !== 'impact' || was === 'impact' || c.spell === S || c.data.shielded) continue; |
| +добавлено | const sh = shieldNear(c.pos); |
| +добавлено | if (!sh) continue; |
| +добавлено | _a.subVectors(c.pos, sh.center); |
| +добавлено | if (_a.length() < sh.r * 0.8) { // landed inside (a strike): show it where it came through |
| +добавлено | if (c.spell.shape === 'strike') _a.copy(UP); else _a.subVectors(c.from, sh.center); |
| +добавлено | _a.normalize().multiplyScalar(sh.r).add(sh.center); |
| +добавлено | } else _a.copy(c.pos); |
| +добавлено | hit(_a, 1.6, hueOf(c.spell, tintC)); |
| +добавлено | } |
| +добавлено | // shields -> uniforms |
| +добавлено | const cam = fx.camera.position; |
| +добавлено | for (const sh of shields) { |
| +добавлено | const on = sh.active && sh.formed; |
| +добавлено | sh.mesh.visible = on; |
| +добавлено | if (!on) continue; |
| +добавлено | const u = sh.u; |
| +добавлено | const rise = 1.25 * (1 - (1 - Math.min(1, sh.t / FORM_TIME)) ** 2); |
| +добавлено | const dis = Math.min(1, Math.max(0, 1 - (sh.end - sh.t) / DISSOLVE_TIME)); |
| +добавлено | // slow uneven breathing of the plasma, a surge as it lets go |
| +добавлено | const breathe = 0.93 + 0.07 * Math.sin(sh.t * 5.1 + sh.phase * 9) * Math.sin(sh.t * 2.3); |
| +добавлено | u.uSphere.value.set(sh.center.x, sh.center.y, sh.center.z, sh.r); |
| +добавлено | u.uForm.value.set(rise, dis, p.intensity * (1 + 0.35 * sh.flash) * breathe * (1 + 0.5 * dis), sh.phase * 7.3); |
| +добавлено | u.uWobble.value.x = sh.wob; |
| +добавлено | u.uInside.value = cam.distanceToSquared(sh.center) < sh.r * sh.r ? 1 : 0; |
| +добавлено | let nh = 0; // live ripples packed first: the shader loops over uHitN only |
| +добавлено | for (const h of sh.hits) { |
| +добавлено | if (h.s > 0) { h.age += dt; if (h.age > 3) h.s = 0; } |
| +добавлено | if (h.s <= 0) continue; |
| +добавлено | u.uHitC.value[nh].set(h.col.r, h.col.g, h.col.b); |
| +добавлено | u.uHits.value[nh++].set(h.dir.x * h.s, h.dir.y * h.s, h.dir.z * h.s, h.age); |
| +добавлено | } |
| +добавлено | u.uHitN.value = nh; |
| +добавлено | } |
| +добавлено | // sprites: missile cores, then pops |
| +добавлено | const A = aA.array, B = aB.array, V = aV.array; |
| +добавлено | let n = 0; |
| +добавлено | const I = 5 * p.intensity; |
| +добавлено | for (const g of groups) { |
| +добавлено | if (g.n === 0) continue; |
| +добавлено | for (let i = 0; i < g.launched && n < MAX_SPRITES; i++) { |
| +добавлено | const m = g.ms[i]; |
| +добавлено | if (!m.alive) continue; |
| +добавлено | const o = n * 4; |
| +добавлено | A[o] = m.pos.x; A[o + 1] = m.pos.y; A[o + 2] = m.pos.z; A[o + 3] = 0.42 * (1 + 0.15 * Math.sin(m.age * 40 + m.ph)); |
| +добавлено | B[o] = col.r * I; B[o + 1] = col.g * I; B[o + 2] = col.b * I; B[o + 3] = m.ph / TAU * 0.999; |
| +добавлено | V[o] = m.vel.x; V[o + 1] = m.vel.y; V[o + 2] = m.vel.z; V[o + 3] = m.ph; |
| +добавлено | n++; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | for (const q of pops) { |
| +добавлено | if (q.age >= q.life) continue; |
| +добавлено | q.age += dt; |
| +добавлено | if (q.age >= q.life || n >= MAX_SPRITES) continue; |
| +добавлено | const o = n * 4; |
| +добавлено | A[o] = q.pos.x; A[o + 1] = q.pos.y; A[o + 2] = q.pos.z; A[o + 3] = q.size; |
| +добавлено | B[o] = q.r; B[o + 1] = q.g; B[o + 2] = q.b; B[o + 3] = 1 + q.age / q.life; |
| +добавлено | V[o] = 0; V[o + 1] = 0; V[o + 2] = 0; V[o + 3] = q.seed; |
| +добавлено | n++; |
| +добавлено | } |
| +добавлено | sgeo.instanceCount = n; |
| +добавлено | sprites.visible = n > 0; |
| +добавлено | if (n > 0) aA.needsUpdate = aB.needsUpdate = aV.needsUpdate = true; |
| +добавлено | }, |
| +добавлено | }; |
| +добавлено | |
| +добавлено | function updateAegis(c, p, d, dt) { |
| +добавлено | const sh = d.sh; |
| +добавлено | if (!sh || sh.cast !== c) return; |
| +добавлено | const rf = 0.835 * sh.R; |
| +добавлено | if (c.phase === 'charge') { |
| +добавлено | const k = c.t / c.durations.charge; |
| +добавлено | if (sh.sigil) { sh.sigil.reveal = k; sh.sigil.intensity = 4 * p.intensity; sh.sigil.rotation = c.age * 0.6; } |
| +добавлено | rise.pos.set(sh.center.x, 0.05, sh.center.z); rise.radius = rf; rise.vel.set(0, 1.6 + 2 * k, 0); |
| +добавлено | rise.rate(500 * k * p.sparkles, dt); |
| +добавлено | if (sh.light) sh.light.intensity = 6 * k * p.intensity; |
| +добавлено | return; |
| +добавлено | } |
| +добавлено | sh.t += dt; |
| +добавлено | sh.flash = Math.max(0, sh.flash - dt * 2.5); |
| +добавлено | const t = sh.t; |
| +добавлено | // membrane l = 2 mode: a damped spring (2.4 Hz), kicked by forming and by every hit |
| +добавлено | const om = TAU * 2.4; |
| +добавлено | sh.wobV += (-om * om * sh.wob - 2 * 0.16 * om * sh.wobV) * dt; |
| +добавлено | sh.wob = Math.max(-0.08, Math.min(0.08, sh.wob + sh.wobV * dt)); |
| +добавлено | const dis = Math.min(1, Math.max(0, 1 - (sh.end - t) / DISSOLVE_TIME)); |
| +добавлено | if (dis > 0 && !sh.burst) { |
| +добавлено | sh.burst = true; |
| +добавлено | shellMote.pos.copy(sh.center); shellMote.radius = sh.r; shellMote.radial = 1.2; shellMote.burst(400 * p.sparkles); |
| +добавлено | shellMote.radial = 0.25; |
| +добавлено | } |
| +добавлено | if (t >= sh.end) { c.durations.linger = 0; sh.formed = false; return; } |
| +добавлено | // forming: the rising front sheds sparks round its ring (front at arc fraction u of the dome) |
| +добавлено | const riseK = Math.min(1, t / FORM_TIME), uF = Math.min(1, 1.25 * (1 - (1 - riseK) ** 2)); |
| +добавлено | if (uF < 1) { |
| +добавлено | const pol = (1 - uF) * Math.acos(-sh.center.y / sh.r), yF = sh.center.y + sh.r * Math.cos(pol); |
| +добавлено | ringSpark.pos.set(sh.center.x, yF, sh.center.z); ringSpark.radius = sh.r * Math.sin(pol); |
| +добавлено | ringSpark.vel.set(0, 1.2, 0); ringSpark.rate(420 * p.sparkles, dt); |
| +добавлено | } |
| +добавлено | // dissolving: sparks spit from the burning holes |
| +добавлено | if (dis > 0) { shellSpark.pos.copy(sh.center); shellSpark.radius = sh.r; shellSpark.rate(500 * p.sparkles * (1 - dis), dt); } |
| +добавлено | // the newest ripple sheds sparks along its travelling ring (one small burst a frame) |
| +добавлено | let hb = null; |
| +добавлено | for (const h of sh.hits) if (h.s > 0 && h.age < 0.9 && (!hb || h.age < hb.age)) hb = h; |
| +добавлено | if (hb && dis === 0) { |
| +добавлено | const th = hb.age * look.z; |
| +добавлено | if (th < 2.8) { |
| +добавлено | _e1.crossVectors(hb.dir, Math.abs(hb.dir.y) < 0.9 ? UP : _t.set(1, 0, 0)).normalize(); |
| +добавлено | _e2.crossVectors(hb.dir, _e1); |
| +добавлено | const az = fx.rand() * TAU, ca = Math.cos(az), sa = Math.sin(az); |
| +добавлено | _c.copy(_e1).multiplyScalar(ca).addScaledVector(_e2, sa); // azimuth direction |
| +добавлено | _d.copy(hb.dir).multiplyScalar(Math.cos(th)).addScaledVector(_c, Math.sin(th)); // ring point (unit) |
| +добавлено | _a.copy(sh.center).addScaledVector(_d, sh.r); |
| +добавлено | if (_a.y > 0.05) { |
| +добавлено | _b.copy(hb.dir).multiplyScalar(-Math.sin(th)).addScaledVector(_c, Math.cos(th)); // along the propagation |
| +добавлено | waveSpark.pos.copy(_a); waveSpark.vel.copy(_b).multiplyScalar(3.5).addScaledVector(_d, 1.5); |
| +добавлено | waveSpark.burst(4 * hb.s * p.sparkles * Math.exp(-2 * hb.age)); |
| +добавлено | } |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // alive: idle ripples, motes on the shell, the floor ring kept glowing |
| +добавлено | if (dis === 0 && fx.rand() < p.pulse * dt) { |
| +добавлено | _a.set(fx.rand() - 0.5, 0.1 + 0.8 * fx.rand(), fx.rand() - 0.5).normalize().multiplyScalar(sh.r).add(sh.center); |
| +добавлено | ripple(sh, _a, 0.45); |
| +добавлено | } |
| +добавлено | shellMote.pos.copy(sh.center); shellMote.radius = sh.r * 1.01; shellMote.rate(40 * p.sparkles * (1 - dis), dt); |
| +добавлено | sh.resplat -= dt; |
| +добавлено | if (sh.resplat <= 0 && dis === 0) { |
| +добавлено | sh.resplat = 1.5; |
| +добавлено | SPLAT.x = sh.center.x; SPLAT.z = sh.center.z; SPLAT.radius = rf; SPLAT.glow = 0.25; SPLAT.corruption = 0; |
| +добавлено | SPLAT.pattern = 'ring'; SPLAT.seed = (c.seed + Math.floor(t)) % 100; |
| +добавлено | fx.ground.splat(SPLAT); |
| +добавлено | } |
| +добавлено | // the floor circle hands over to the shell's own floor-contact line |
| +добавлено | if (sh.sigil) { sh.sigil.intensity = 4 * p.intensity * Math.max(0, 1 - t / 0.8); sh.sigil.rotation = c.age * 0.6; } |
| +добавлено | if (sh.light) sh.light.intensity = ((9 + 22 * sh.flash) * riseK * (1 - dis) + 20 * dis * (1 - dis)) * p.intensity; |
| +добавлено | sh.hitK *= Math.exp(-dt / 0.14); |
| +добавлено | if (sh.hitLight) { sh.hitLight.intensity = 28 * sh.hitK * p.intensity; sh.hitLight.cookie[2] = t * 0.7; } |
| +добавлено | } |
| +добавлено | }, |
| +добавлено | }; |