pixijs / lights

Adds dynamic lighting via deferred shading to PixiJS
https://pixijs.io/lights/docs/index.html
MIT License
198 stars 29 forks source link

fix and add feature for update sync #54

Open jonlepage opened 1 year ago

jonlepage commented 1 year ago

fix uLightHeight update fix radius update geometry. add some cache optimisations overide destroy: just to be sure gc do it job.

those issue was so long here , now it fixed.

edit: sry when a save my ide installed a default formater, i reverse change without the uglyfi prettier to keep author formating


overview

This is a pull request that contains changes to two TypeScript files: src/lights/light/Light.ts and src/lights/pointLight/PointLight.ts.

In Light.ts, there is one change made to the _renderDefault method, which involves adding 47 lines of code and deleting 2 lines.

In PointLight.ts, there are multiple changes made. Firstly, a new constant DEFAULT_SHAPE_SEGMENTS is defined. Then, the PointLight class is modified to add three new properties: shapeCache, verticesCache, and indicesCache. shapeCache is a Circle object that is used to generate a mesh, while verticesCache and indicesCache are arrays used to store the vertices and indices of the mesh, respectively. The _shapeSegments property is also added, which sets the number of segments to use for the Circle mesh.

The constructor of PointLight is modified to take in a new parameter shapeSegments, which is used to set _shapeSegments. A new mesh is generated using the getCircleMesh function and the vertices and indices arrays are passed to the constructor of Light. Additionally, the drawMode property is set to DRAW_MODES.TRIANGLE_FAN.

Two new methods are added to PointLight: set radius and set shapeSegments. The former method updates the value of uLightRadius in the material.uniforms object and updates the buffers of the mesh with new vertices and indices generated using getCircleMesh. The latter method updates the value of _shapeSegments and also updates the mesh.

Finally, the destroy method is overridden to delete the shapeCache, verticesCache, and indicesCache properties before calling the superclass destroy method. by gpt