Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Let There Be Light 2  (Read 147649 times)

0 Members and 4 Guests are viewing this topic.

mashedtatoes

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Let There Be Light 2
« Reply #75 on: August 15, 2015, 05:44:43 pm »
I still don't know what to do to fix the bug, cant find any files that I believe would make sense going into additional dependencies.

I didn't use CMake at all. Just added the source files to my project. Edited some of the #includes because visual studio was complaining. Then compiled. Pretty simple.

Guido_Ion

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Flow Soccer development
Re: Let There Be Light 2
« Reply #76 on: August 15, 2015, 08:50:09 pm »
Am I missing something?

You need to set the position of lightSprite when you move the camera.
lightSprite.setPosition(view.getCenter());
You will also need to set the sprite's origin so that the center of the sprite matches the center of he view.
lightSprite.setOrigin(view.getSize().x / 2.0f, view.getSize().y / 2.0f);
Do this before running the game.

Thanks! It is working now. LTBL2 is great :D

And this code compiles just fine. However, if I add any type of ltbl object (such as ltbl::LightSystem) anywhere in the code, the compiler just gives me three LNK2001 errors.

How do I fix this?

You need to add all cpp files of LTBL2 (those on /lighting, those on /quadtree and Math.cpp) to your project, you don't need to add anything to the Linker part, just to the C/C++ part "Additional Include Directories: C:\Users\Me\Desktop\Main\LTBL2-master\LTBL2\source\" as you did.

Cupcake26699

  • Guest
Re: Let There Be Light 2
« Reply #77 on: August 16, 2015, 06:07:57 am »
Thanks guys. It's working great now after following all your advice :)

Kori

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Let There Be Light 2
« Reply #78 on: August 24, 2015, 07:20:32 pm »
I have an interesting problem. Normally lights is falling into obiect from side. In side-scroller it's perfect, but how to make a sun light in a top-down game, something like that :

(click to show/hide)
not like that:
 
(click to show/hide)
Illusion of light from above, without this long penubra shadow. Any ideas?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Let There Be Light 2
« Reply #79 on: August 25, 2015, 03:05:09 pm »
The main part of the shadow seems to be exactly what you were aiming for but you have a faint shadow extending from it. You could try increasing the size of the light (or using many, multiple lights, probably in a circle) and/or increasing the strength of the lights.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Kori

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Let There Be Light 2
« Reply #80 on: August 25, 2015, 06:33:04 pm »
I just make two light systems, first is normal, second is with modified penubra texture (i just cut out this bright part :D ). But, i don't know how it will be works with more lights on scene (performance).
 Especially, that i can't remove lights (don't know why, just removeLight() not working), so i holding pretty lot of them at once. 


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Let There Be Light 2
« Reply #81 on: August 25, 2015, 06:54:20 pm »
I don't know how LTBL works. Does it provide you with a greyscale channel to multiply over the scene? If so, you can use adjustment on the channel to 'bump up' the light greys to white, thus removing all of the slight lighting.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Kori

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Let There Be Light 2
« Reply #82 on: August 25, 2015, 07:13:45 pm »
I think that this can make shadows very low intense and deformed. 2 light systems will be enought with posibility of deleting unusable lights.

This is my main problem. Does anyone know how to delete light and light Shape? In my opinion there is properly implemented remove function in code, but does nothing, or in some cases there is an error somewhere in QuadTree. Maybe just use ltbl 1.5?
« Last Edit: August 26, 2015, 12:59:13 am by Kori »

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Let There Be Light 2
« Reply #83 on: September 12, 2015, 07:55:00 pm »
Sorry for showing up here so rarely, I have been very busy lately (with AI related things! Info here for those interested: https://cireneikual.wordpress.com/2015/09/03/htsl2-evolving-the-neocortex-and-human-like-reinforcement-learning/).

I have hopefully fixed the removal bug. I also merged eXpl0it3r's changes (thanks for the help :) ).

Try pulling the latest!
« Last Edit: September 12, 2015, 08:03:41 pm by lolz123 »
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #84 on: October 11, 2015, 05:06:15 pm »
I'm trying to spawn a light for testing purposes, but i'm just seeing a hard rectangle shape instead of a smooth light. The rectangle is the same color as the light is supposed to be, but i only see the rectangle if i clear with white instead of standard black clear color.

This is the code i'm using:

#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <ltbl/lighting/lightSystem.h>

using namespace std;

int main(){
sf::ContextSettings Settings;
Settings.depthBits         = 24; // Request a 24 bits depth buffer
Settings.stencilBits       = 8;  // Request a 8 bits stencil buffer
Settings.antialiasingLevel = 0;  // Request 2 levels of antialiasing
// Set Screen Size
sf::Vector2<double> screenSize;
screenSize.x = 1000;
screenSize.y = 800;

//Create the Window
sf::RenderWindow App(sf::VideoMode(screenSize.x, screenSize.y, 32), "Test LTBL2", sf::Style::Close, Settings);

//Frame Limit
App.setFramerateLimit(0);

//Vertical sync
App.setVerticalSyncEnabled(true);

// lights setup
sf::Texture pointLightTexture;

if (!pointLightTexture.loadFromFile("resources/directionLightTexture.png"));

pointLightTexture.setSmooth(true);

sf::Texture penumbraTexture;

if (!penumbraTexture.loadFromFile("resources/penumbraTexture.png"));

penumbraTexture.setSmooth(true);

ltbl::LightSystem ls;

sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;

if (!unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag"));
if (!lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag"));

ls.create(ltbl::rectFromBounds(sf::Vector2f(-1000.0f, -1000.0f), sf::Vector2f(1000.0f, 1000.0f)), App.getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

std::shared_ptr<ltbl::LightPointEmission> light = std::make_shared<ltbl::LightPointEmission>();

light->_emissionSprite.setOrigin(sf::Vector2f(pointLightTexture.getSize().x * 0.5f, pointLightTexture.getSize().y * 0.5f));
light->_emissionSprite.setTexture(pointLightTexture);
light->_emissionSprite.setScale(sf::Vector2f(1.0f, 1.0f));
light->_emissionSprite.setColor(sf::Color(255, 230, 200));
light->_emissionSprite.setPosition(sf::Vector2f(500, 400));

ls.addLight(light);

while (App.isOpen()){
    sf::Event Event;
    while (App.pollEvent(Event)){
        // Window closed
        if (Event.type == sf::Event::Closed){
            App.close();
        }
        // Key Pressed
        if (Event.type == sf::Event::KeyPressed){
            //Quit
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
                App.close();
            }
        }
        if (Event.type == sf::Event::KeyReleased){
        }
    }



    App.clear(sf::Color(255,255,255));
    ls.render(App.getDefaultView(), unshadowShader, lightOverShapeShader);

    sf::Sprite sprite;
    sprite.setTexture(ls.getLightingTexture());

    sf::RenderStates lightRenderStates;
    lightRenderStates.blendMode = sf::BlendMultiply;

    App.draw(sprite, lightRenderStates);
    App.display();
}

return 0;
}
« Last Edit: October 11, 2015, 05:07:55 pm by Voroz »

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Let There Be Light 2
« Reply #85 on: October 11, 2015, 05:09:05 pm »
Hello Voroz,

It seems like you are loading the directional light texture instead of the point light one  ;)
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #86 on: October 11, 2015, 05:11:03 pm »
Hello Voroz,

It seems like you are loading the directional light texture instead of the point light one  ;)
woah, that was a fast reply :). Yeah you're right, now it works :D.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #87 on: October 11, 2015, 05:15:30 pm »
In your example of using directional light i got the same result with the rectangle light btw. This is from your example:

        sf::Texture pointLightTexture;

        pointLightTexture.loadFromFile("resources/directionLightTexture.png");

        pointLightTexture.setSmooth(true);

        sf::Texture penumbraTexture;

        penumbraTexture.loadFromFile("resources/penumbraTexture.png");

        penumbraTexture.setSmooth(true);

        ltbl::LightSystem ls;

        sf::Shader unshadowShader;

        unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");

        ls.create(ltbl::rectFromBounds(sf::Vector2f(-1000.0f, -1000.0f), sf::Vector2f(1000.0f, 1000.0f)), window.getSize(), penumbraTexture, unshadowShader);

        std::shared_ptr<ltbl::LightDirectionEmission> light = std::make_shared<ltbl::LightDirectionEmission>();

        light->_emissionSprite.setOrigin(sf::Vector2f(pointLightTexture.getSize().x * 0.5f, pointLightTexture.getSize().y * 0.5f));
        light->_emissionSprite.setTexture(pointLightTexture);
        light->_emissionSprite.setScale(sf::Vector2f(6.0f, 6.0f));
        light->_emissionSprite.setColor(sf::Color(255, 230, 200));
        light->_emissionSprite.setPosition(sf::Vector2f(0.0f, 0.0f));
        light->_castDirection = ltbl::vectorNormalize(sf::Vector2f(-0.1f, 0.6f));
ls.addLight(light);
« Last Edit: October 11, 2015, 05:17:18 pm by Voroz »

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #88 on: October 11, 2015, 05:22:46 pm »
I seem to have trouble with the directional light. This code is following your example and i only get a rectangle:
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <ltbl/lighting/lightSystem.h>

using namespace std;

int main(){
sf::ContextSettings Settings;
Settings.depthBits         = 24; // Request a 24 bits depth buffer
Settings.stencilBits       = 8;  // Request a 8 bits stencil buffer
Settings.antialiasingLevel = 0;  // Request 2 levels of antialiasing
// Set Screen Size
sf::Vector2<double> screenSize;
screenSize.x = 1000;
screenSize.y = 800;

//Create the Window
sf::RenderWindow App(sf::VideoMode(screenSize.x, screenSize.y, 32), "Test LTBL2", sf::Style::Close, Settings);

//Frame Limit
App.setFramerateLimit(0);

//Vertical sync
App.setVerticalSyncEnabled(true);

// lights setup
sf::Texture directionLightTexture;

if (!directionLightTexture.loadFromFile("resources/directionLightTexture.png"));

directionLightTexture.setSmooth(true);

sf::Texture penumbraTexture;

if (!penumbraTexture.loadFromFile("resources/penumbraTexture.png"));

penumbraTexture.setSmooth(true);

ltbl::LightSystem ls;

sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;

if (!unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag"));
if (!lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag"));

ls.create(ltbl::rectFromBounds(sf::Vector2f(-1000.0f, -1000.0f), sf::Vector2f(1000.0f, 1000.0f)), App.getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

std::shared_ptr<ltbl::LightDirectionEmission> light = std::make_shared<ltbl::LightDirectionEmission>();

light->_emissionSprite.setOrigin(sf::Vector2f(directionLightTexture.getSize().x * 0.5f, directionLightTexture.getSize().y * 0.5f));
light->_emissionSprite.setTexture(directionLightTexture);
light->_emissionSprite.setScale(sf::Vector2f(1.0f, 1.0f));
light->_emissionSprite.setColor(sf::Color(255, 230, 200));
light->_emissionSprite.setPosition(sf::Vector2f(500, 400));
light->_castDirection = ltbl::vectorNormalize(sf::Vector2f(-0.1f, 0.6f));

ls.addLight(light);

while (App.isOpen()){
    sf::Event Event;
    while (App.pollEvent(Event)){
        // Window closed
        if (Event.type == sf::Event::Closed){
            App.close();
        }
        // Key Pressed
        if (Event.type == sf::Event::KeyPressed){
            //Quit
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
                App.close();
            }
        }
        if (Event.type == sf::Event::KeyReleased){
        }
    }



    App.clear(sf::Color(255,255,255));
    ls.render(App.getDefaultView(), unshadowShader, lightOverShapeShader);

    sf::Sprite sprite;
    sprite.setTexture(ls.getLightingTexture());

    sf::RenderStates lightRenderStates;
    lightRenderStates.blendMode = sf::BlendMultiply;

    App.draw(sprite, lightRenderStates);
    App.display();
}

return 0;
}

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Let There Be Light 2
« Reply #89 on: October 11, 2015, 05:40:04 pm »
The sprite (the rectangle) should cover the screen. Try setting the dimensions to the screen size and positioning it so that it is centered on the screen.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.