Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

light clipped to a scene scale ? #20

Open
jonlepage opened this issue Apr 30, 2018 · 4 comments
Open

light clipped to a scene scale ? #20

jonlepage opened this issue Apr 30, 2018 · 4 comments

Comments

@jonlepage
Copy link

jonlepage commented Apr 30, 2018

If we add a light to a scene.
And resize the scene with scale.
The light does not follow the zoom scale.

What would be the best approach?
Do I have to do it manually by multiplying each value by the scale of the scene.
Or there is already something native planned and that will consume less resource ?
ezgif com-optimize
If i need to myself, where the best place to add a update in the module?

@ivanpopelyshev
Copy link
Contributor

ivanpopelyshev commented Apr 30, 2018

According to
https://github.com/pixijs/pixi-lights/blob/master/src/lights/pointLight/point.frag.js#L19
and
https://github.com/pixijs/pixi-lights/blob/master/src/lights/pointLight/PointLight.js#L33

PointLight position is adjusted with matrix, and size is not. Divide lightVector by translationMatrix[0].x and translationMatrix[1].y, or adjust the radius somehow.

@ivanpopelyshev
Copy link
Contributor

I can fix it later when ill make another pass on pixi-lights. In a week, or a month, i dont know :)

@jonlepage
Copy link
Author

jonlepage commented Apr 30, 2018

@ivanpopelyshev ok for now i do it manually in outScope pixiLight.js, the result seem ok. I don't know for performance but it a temp fix.

      // storage
       if(CAGE.source.type === "light"){ // update session for light because not follow scale scene
           CAGE.session.brightness[1] = CAGE.brightness;
           CAGE.session.lightHeight[1] = CAGE.lightHeight;
           CAGE.radius && (CAGE.session.radius[1] = CAGE.radius);
       }

       // update light zoom
       if(InObjSprite && InObjSprite.source.type === "light"){
           const session = InObjSprite.session;
           InObjSprite.brightness = session.brightness[1]*Zoom.x;
           InObjSprite.lightHeight = session.lightHeight[1]*Zoom.x;
           InObjSprite.radius && (InObjSprite.radius = session.radius[1]*Zoom.x);
       };

edit:
radius are Infinity so need check if is finite

   function update_lightZoom() {
    const list = TilesMap._objLight;
    list.forEach(light => {
        const session = light.session;
        light.brightness = session.brightness[1]*Zoom.x;
        light.lightHeight = session.lightHeight[1]*Zoom.x;
        isFinite(light.radius) && (light.radius = session.radius[1]*Zoom.x);
    });
    if(InObjSprite && InObjSprite.source.type === "light"){
        const session = InObjSprite.session;
        InObjSprite.brightness = session.brightness[1]*Zoom.x;
        InObjSprite.lightHeight = session.lightHeight[1]*Zoom.x;
        isFinite(InObjSprite.radius) && (InObjSprite.radius = session.radius[1]*Zoom.x);
    };
   }

@ivanpopelyshev
Copy link
Contributor

oh, there are other parameters! Thanks, now I have more information what to fix there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants