diff --git a/frontend/src/scripts/drawing/webgl2-renderer.ts b/frontend/src/scripts/drawing/webgl2-renderer.ts index c3e4512..fb5dbed 100644 --- a/frontend/src/scripts/drawing/webgl2-renderer.ts +++ b/frontend/src/scripts/drawing/webgl2-renderer.ts @@ -24,7 +24,7 @@ export class WebGl2Renderer implements Drawer { private multiplicativeQualityDecrease = 1.5; private timeSinceLastAdjusment = 0; private adjusmentRate = 500; - private maxRenderScale = 2; + private maxRenderScale = 1.5; private minRenderScale = 0.2; private exponentialDecayedDeltaTime = 0.0; diff --git a/frontend/src/scripts/objects/types/camera.ts b/frontend/src/scripts/objects/types/camera.ts index 4695603..f3cccfc 100644 --- a/frontend/src/scripts/objects/types/camera.ts +++ b/frontend/src/scripts/objects/types/camera.ts @@ -1,16 +1,16 @@ -import { GameObject } from '../game-object'; +import { vec2 } from 'gl-matrix'; +import { BeforeDrawCommand } from '../../commands/types/before-draw'; +import { CursorMoveCommand } from '../../commands/types/cursor-move-command'; import { MoveToCommand } from '../../commands/types/move-to'; import { ZoomCommand } from '../../commands/types/zoom'; -import { BeforeDrawCommand } from '../../commands/types/before-draw'; -import { PrimaryActionCommand } from '../../commands/types/primary-action'; -import { vec2 } from 'gl-matrix'; -import { CursorMoveCommand } from '../../commands/types/cursor-move-command'; +import { GameObject } from '../game-object'; +import { CircleLight } from './circle-light'; export class Camera extends GameObject { private inViewArea = 1920 * 1080; private cursorPosition = vec2.create(); - constructor() { + constructor(private light: CircleLight) { super(); this.addCommandExecutor(BeforeDrawCommand, this.draw.bind(this)); @@ -30,6 +30,15 @@ export class Camera extends GameObject { private moveTo(c: MoveToCommand) { this._position = c.position; + this.light.sendCommand( + new MoveToCommand( + vec2.add( + vec2.create(), + c.position, + vec2.scale(vec2.create(), this.boundingBoxSize, 0.5) + ) + ) + ); } private zoom(c: ZoomCommand) { diff --git a/frontend/src/scripts/objects/types/circle-light.ts b/frontend/src/scripts/objects/types/circle-light.ts index b403f93..3ae53f4 100644 --- a/frontend/src/scripts/objects/types/circle-light.ts +++ b/frontend/src/scripts/objects/types/circle-light.ts @@ -1,5 +1,6 @@ import { vec2, vec3 } from 'gl-matrix'; import { DrawCommand } from '../../commands/types/draw'; +import { MoveToCommand } from '../../commands/types/move-to'; import { GameObject } from '../game-object'; export class CircleLight extends GameObject { @@ -11,6 +12,7 @@ export class CircleLight extends GameObject { super(); this.addCommandExecutor(DrawCommand, this.draw.bind(this)); + this.addCommandExecutor(MoveToCommand, this.moveTo.bind(this)); } private draw(c: DrawCommand) { @@ -22,4 +24,8 @@ export class CircleLight extends GameObject { }); } } + + private moveTo(c: MoveToCommand) { + this.center = c.position; + } } diff --git a/frontend/src/scripts/objects/types/cursor-light.ts b/frontend/src/scripts/objects/types/cursor-light.ts deleted file mode 100644 index b5458a6..0000000 --- a/frontend/src/scripts/objects/types/cursor-light.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { vec2, vec3 } from 'gl-matrix'; -import { CursorMoveCommand } from '../../commands/types/cursor-move-command'; -import { DrawCommand } from '../../commands/types/draw'; -import { GameObject } from '../game-object'; - -export class CursorLight extends GameObject { - private mousePosition = vec2.create(); - - constructor(private radius: number, private value: vec3) { - super(); - - this.addCommandExecutor(DrawCommand, this.draw.bind(this)); - this.addCommandExecutor(CursorMoveCommand, this.setPosition.bind(this)); - } - - private draw(c: DrawCommand) { - const center = c.drawer.screenUvToWorldCoordinate(this.mousePosition); - if (c.drawer.isOnScreen(center)) { - c.drawer.appendToUniformList('lights', { - center, - radius: this.radius, - value: this.value, - }); - } - } - - private setPosition(c: CursorMoveCommand) { - this.mousePosition = c.position; - } -} diff --git a/frontend/src/scripts/objects/world/create-character.ts b/frontend/src/scripts/objects/world/create-character.ts index dab8c2b..a66ab79 100644 --- a/frontend/src/scripts/objects/world/create-character.ts +++ b/frontend/src/scripts/objects/world/create-character.ts @@ -1,12 +1,18 @@ -import { vec3 } from 'gl-matrix'; +import { vec2, vec3 } from 'gl-matrix'; import { ObjectContainer } from '../object-container'; import { Camera } from '../types/camera'; import { Character } from '../types/character'; -import { CursorLight } from '../types/cursor-light'; +import { CircleLight } from '../types/circle-light'; export const createCharacter = (objects: ObjectContainer) => { - const camera = new Camera(); + const light = new CircleLight( + vec2.create(), + 40, + vec3.fromValues(0.67, 0.0, 0.33) + ); + + const camera = new Camera(light); + objects.addObject(light); objects.addObject(camera); objects.addObject(new Character(camera)); - objects.addObject(new CursorLight(40, vec3.fromValues(0.67, 0.67, 0.33))); }; diff --git a/frontend/src/scripts/objects/world/create-dungeon.ts b/frontend/src/scripts/objects/world/create-dungeon.ts index 4024e1a..cdc86a2 100644 --- a/frontend/src/scripts/objects/world/create-dungeon.ts +++ b/frontend/src/scripts/objects/world/create-dungeon.ts @@ -24,7 +24,7 @@ export const createDungeon = (objects: ObjectContainer) => { Math.random() * 20 + 30, vec3.scale( vec3.create(), - vec3.normalize(vec3.create(), vec3.random(vec3.create())), + vec3.normalize(vec3.create(), vec3.fromValues(0.5, 0.1, 0.8)), Math.random() * 0.5 + 0.5 ) ) diff --git a/frontend/src/shaders/cave-distance-fs.glsl b/frontend/src/shaders/cave-distance-fs.glsl index 4718efb..1c61959 100644 --- a/frontend/src/shaders/cave-distance-fs.glsl +++ b/frontend/src/shaders/cave-distance-fs.glsl @@ -40,10 +40,10 @@ out vec4 fragmentColor; void main() { float distance = getDistance(worldCoordinates); - const vec3 caveColor = vec3(0.0); + const vec3 caveColor = vec3(0.36, 0.38, 0.76); const vec3 airColor = vec3(1.0); fragmentColor = vec4( - mix(caveColor, airColor, distance), + mix(caveColor, airColor, clamp(distance, 0.0, 1.0)), distance / 32.0 ); } diff --git a/frontend/src/shaders/lights-shading-fs.glsl b/frontend/src/shaders/lights-shading-fs.glsl index e282508..c41e4ec 100644 --- a/frontend/src/shaders/lights-shading-fs.glsl +++ b/frontend/src/shaders/lights-shading-fs.glsl @@ -4,7 +4,7 @@ precision mediump float; #define INFINITY 10000.0 #define LIGHT_COUNT 5 -#define AMBIENT_LIGHT vec3(0.05) +#define AMBIENT_LIGHT vec3(0.15) #define LIGHT_DROP 800.0 #define SHADOW_BIAS 0.01