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

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

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 2971
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: Let There Be Light 2
« Reply #165 on: July 29, 2019, 02:37:28 am »
Is there a way to only draw the lights for each lightSystem and not the dark parts?  :o
You could try drawing the second one using an additive blend mode.
See BlendMode documentation.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

Guido Bisocoli

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Let There Be Light 2
« Reply #166 on: July 29, 2019, 05:32:40 pm »
Thanks for the answer, but that didn't work, it still draws the dark parts twice and the lights very strong, that's not the result I want.
Maybe I need to create other sprites (penumbraTexture.png, etc.) with the dark parts as transparent for the second lightsystem. I don't know how to do that but I'll mess around with GIMP and see what's the result.

If lolz or someone has another easy answer for using 2 light systems it would be great.

grzyboleusz

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Let There Be Light 2
« Reply #167 on: March 12, 2020, 02:51:20 pm »
Hello, I've been using SFML for quite a while, but stumbled upon this gem of a library a few days ago.

I have successfully integrated Alia5's version of LTBL2 and I am VERY pleased with it but there's 1 thing missing for me to achive what I want:
I'd love to have a directional light source to interact with normal/specular maps - a way to lit the surface of every object drawn to normal map buffer from given angle, a kind of global light source.
I suspect it can be done after every other light source is drawn with slight modification of existing shaders, but currently it's beyond me. If I'll manage to do it I'll post it here, but feel free to be first if it's no biggie to you  :-*

Many thanks to everyone involved in this project and SFML itself.
« Last Edit: March 12, 2020, 05:07:30 pm by grzyboleusz »

grzyboleusz

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Let There Be Light 2
« Reply #168 on: March 17, 2020, 11:31:27 am »
As I said, there it is:

Shader to add global directional lighting, every pixel is lit from given direction vector without cosidering the distance (slightly modified version of the one included in the library, I only use it to draw light with additive blending):

(click to show/hide)

Also, I needed a shader to correct rotated normal maps of the sprites so there it is:
(click to show/hide)

As you can see, it uses vertex color channels to represent rotation and flipping, so you dont have to set any uniforms while drawing - useful for collective VertexArrays
Red color - if lower than 1.0 (or 255 in sf::Color) flips the normal map horizontally
Green  color - if lower than 1.0 (or 255 in sf::Color) flips the normal map vertically
Blue color - is angle in radians divided by Tau (2 * Pi)
Simply use it to draw normal maps
« Last Edit: March 17, 2020, 11:44:58 am by grzyboleusz »

Yuri

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Let There Be Light 2
« Reply #169 on: May 27, 2020, 03:09:11 pm »
Hello

I have problem thats my light point emmision is only a half of circle and i dont know how to fix it :/
I use fallowing code with Alia5 LTBL2:

Code: [Select]
#include "ltbl/lighting/LightSystem.hpp"
#include <SFML/Graphics.hpp>
#include <iostream>


int main() {
    sf::RenderTexture normal_texture_;
    sf::RenderTexture specular_texture_;
    sf::RenderWindow window{sf::VideoMode{800,600}, "LightShow"};
    ltbl::LightSystem lightSystem{normal_texture_,specular_texture_,true};
    lightSystem.create({ -1000.f, -1000.f, 1000.f, 1000.f }, window.getSize());


    sf::Texture pointLightTexture;
    pointLightTexture.loadFromFile("resources/pointLightTexture.png");
    pointLightTexture.setSmooth(true);


    auto* light = lightSystem.createLightPointEmission();
    light->setTexture(pointLightTexture);
    light->setOrigin(pointLightTexture.getSize().x / 2.f, pointLightTexture.getSize().y / 2.f);
    light->setScale(10.f,10.f);


    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
        sf::Vector2f pos(sf::Mouse::getPosition(window));
        light->setPosition(pos);


        window.clear(sf::Color::White);
        lightSystem.render(window);
        window.display();
    }
    return 0;
}
any tips?

edit: dummy me
 ltbl::LightSystem lightSystem{normal_texture_,specular_texture_,FALSE};
« Last Edit: May 28, 2020, 09:11:38 am by Yuri »

 

anything