refactor: light prep

This commit is contained in:
cha0s 2024-07-27 15:28:08 -05:00
parent 5c619b26c0
commit b37d3513f6
5 changed files with 16 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import Component from '@/ecs/component.js';
export default class Light extends Component {
static properties = {
brightness: {defaultValue: 1, type: 'float32'},
radius: {type: 'uint8'},
};
}

View File

@ -5,7 +5,7 @@ import {useDebug} from '@/react/context/debug.js';
import {useMainEntity} from '@/react/context/main-entity.js';
import Emitter from './emitter.jsx';
// import Light from './light.jsx';
import Light from './light.jsx';
import Sprite from './sprite.jsx';
function Aabb({color, width = 0.5, x0, y0, x1, y1, ...rest}) {
@ -67,12 +67,13 @@ function Entity({entity, ...rest}) {
entity={entity}
/>
)}
{/* {entity.Light && (
{entity.Light && (
<Light
brightness={entity.Light.brightness}
x={entity.Position.x}
y={entity.Position.y}
/>
)} */}
)}
{debug && entity.Position && (
<Crosshair x={entity.Position.x} y={entity.Position.y} />
)}

View File

@ -3,8 +3,12 @@ import {PixiComponent} from '@pixi/react';
import {PointLight} from './lights.js';
const LightInternal = PixiComponent('Light', {
create({x, y}) {
const light = new PointLight(0xffffff - 0x2244cc, 1);
create({brightness, x, y}) {
const light = new PointLight(
0xffffff - 0x2244cc,
0//brightness,
);
light.position.set(x, y);
// light.shader.program.fragmentSrc = light.shader.program.fragmentSrc.replace(
// 'float D = length(lightVector)',
@ -16,7 +20,7 @@ const LightInternal = PixiComponent('Light', {
// );
// light.falloff = [0.5, 5, 50];
// light.falloff = light.falloff.map((n, i) => n / (2 + i));
// light.parentGroup = entityLighting.lightGroup;
// light.parentGroup = deferredLighting.lightGroup;
// delete light.parentGroup;
return light;
},
@ -25,9 +29,10 @@ const LightInternal = PixiComponent('Light', {
},
});
export default function Light({x, y}) {
export default function Light({brightness, x, y}) {
return (
<LightInternal
brightness={brightness}
x={x}
y={y}
/>

View File

@ -33,7 +33,7 @@ export default async function createPlayer(id) {
},
},
Health: {health: 100},
Light: {},
Light: {brightness: 4},
Magnet: {strength: 24},
Player: {},
Position: {x: 128, y: 448},

View File

@ -29,6 +29,7 @@ for (let i = 0; i < N; ++i) {
Controlled: {},
Direction: {direction: Math.TAU * (i / N)},
Forces: {},
Light: {brightness: 0.1},
Owned: {owner: Player ? Player.id : 0},
Position: {x: Position.x, y: Position.y},
Speed: {},