silphius/app/react/components/pixi/light.jsx

42 lines
1.1 KiB
React
Raw Normal View History

2024-07-17 05:07:50 -05:00
import {PixiComponent} from '@pixi/react';
2024-07-19 01:27:47 -05:00
import {PointLight} from './lights.js';
2024-07-17 05:07:50 -05:00
const LightInternal = PixiComponent('Light', {
2024-07-27 15:28:08 -05:00
create({brightness, x, y}) {
const light = new PointLight(
0xffffff - 0x2244cc,
0//brightness,
);
2024-07-17 05:07:50 -05:00
light.position.set(x, y);
2024-07-18 04:18:06 -05:00
// light.shader.program.fragmentSrc = light.shader.program.fragmentSrc.replace(
// 'float D = length(lightVector)',
2024-07-19 01:27:47 -05:00
// 'float D = length(lightVector) / 1.0',
// );
// light.shader.program.fragmentSrc = light.shader.program.fragmentSrc.replace(
// 'intensity = diffuse * attenuation',
// 'intensity = diffuse * (attenuation * 2.0)',
2024-07-18 04:18:06 -05:00
// );
2024-07-19 01:27:47 -05:00
// light.falloff = [0.5, 5, 50];
// light.falloff = light.falloff.map((n, i) => n / (2 + i));
2024-07-27 15:28:08 -05:00
// light.parentGroup = deferredLighting.lightGroup;
2024-07-19 01:27:47 -05:00
// delete light.parentGroup;
2024-07-17 05:07:50 -05:00
return light;
},
applyProps(light, oldProps, {x, y}) {
light.position.set(x, y);
},
});
2024-07-27 15:28:08 -05:00
export default function Light({brightness, x, y}) {
2024-07-17 05:07:50 -05:00
return (
<LightInternal
2024-07-27 15:28:08 -05:00
brightness={brightness}
2024-07-17 05:07:50 -05:00
x={x}
y={y}
/>
)
}