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

light clipped to a scene scale ? #20

Open jonlepage opened 6 years ago

jonlepage commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

jonlepage commented 6 years ago

@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 commented 6 years ago

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