SFML community forums

General => SFML projects => Topic started by: lolz123 on June 21, 2013, 09:22:19 pm

Title: GLLight2D
Post by: lolz123 on June 21, 2013, 09:22:19 pm
Hi,

The development of GLLight2D has resumed! Development might still be a bit slow (since I have a lot of other projects too  ;D), but I decided to work on GLLight2D (the "sequel" to Let There Be Light) some more during down times with my other projects. It has absolutely nothing in common with the original codebase I put on Github though, since it is now a 2D adaptation of my real-time path tracer, instead of just a cleaner and more generic version of LTBL.

Since it is a path tracer, it has full blown global illumination!

GitHub page: https://github.com/222464/GLLight2D (https://github.com/222464/GLLight2D)

Here is an image of the progress so far:

(http://i1218.photobucket.com/albums/dd401/222464/GLLight2D.png)
Title: Re: GLLight2D
Post by: eXpl0it3r on June 21, 2013, 09:40:28 pm
Looks very nice! :)

I hope we get to try it soon.
Title: Re: GLLight2D
Post by: foobarbaz on June 21, 2013, 11:19:15 pm
Woot! I can't wait for this!
Title: Re: GLLight2D
Post by: Nexus on June 21, 2013, 11:37:04 pm
Looks indeed very nice!

By the way, what does "GLLight2D" mean, does the "GL" refer to OpenGL? And I found "Let There Be Light" quite a fitting name :)
Title: Re: GLLight2D
Post by: lolz123 on June 22, 2013, 12:05:09 am
@ Nexus: Yes, the GL refers to OpenGL. It is a bit too different from LTBL to have the same name I think, since it isn't merely an improvement over LTBL, but an entirely different way of doing things.

SFML is used mostly for windowing and input, all the rendering is done manually with OpenGL.

For now, GLLight2D is real time @60fps / resolution of 900x600 on a moderate rig and remains dynamic but looks grainy unless you let it sit there and accumulate samples for a bit. If this is unacceptable, you could then just use it for computing static lighting on level load (a 2D light map). That, or you could just use a blur shader and blur away the graininess (although it doesn't look quite as good then).

Some technical details:

The scene is actually 3D with an orthographic projection. The scene is stored in a BSP tree, with all triangles stored in the leaves (duplicates are made if necessary). The tree, triangles, and material data are all loaded into OpenGL texture buffer objects for random access in the shader. Samples are accumulated in a GL_RGB32F FBO. Global illumination is rendered using a random Monte Carlo path sampling technique (that's where the graininess comes from).
Title: Re: GLLight2D
Post by: hayer on June 23, 2013, 12:00:48 am
This seems very interesting, and looks awesome!

But why not just put it up on GitHub? I would love to put in some work. Even if it is just my own fork it would still be epic :)
Title: Re: GLLight2D
Post by: lolz123 on June 23, 2013, 06:27:47 pm
Here it is on Github. I still need to add CMake support.

https://github.com/222464/GLLight2D (https://github.com/222464/GLLight2D)

I haven't gotten the release mode version to work yet, strange things going on  :P You can run it in debug if you have VS2012 though.
Title: Re: GLLight2D
Post by: panithadrum on June 25, 2013, 08:10:59 pm
Hi lolz123!

Very impressive work! I wanted to implement 2D Pixel Perfect Shadows (https://github.com/mattdesl/lwjgl-basics/wiki/2D-Pixel-Perfect-Shadows) but now I want to test path tracing!

I see you calculate the rays in the fragment shader... could you explain the process a bit? I mean, how you send the data and so.

I also wonder if you could provide a Windows executable! Thanks
Title: Re: GLLight2D
Post by: lolz123 on June 25, 2013, 08:29:16 pm
@ panithadrum: A windows executable (release mode) will come as soon as I fix the strange possible compiler bug I have going on  :P. For now, you can compile it yourself by just linking to SFML2, OpenGL, GLU, and GLEW (and the Source).

The tracer stores all occluders (3D triangles), the acceleration structure, and material data in texture buffer objects (textures that get their data from buffer objects). This way, I have random access to the triangles and the acceleration structure in the shader.
I then simply cast rays against the scene with an orthographic projection, and sample in random directions depending on how diffuse a surface is to achieve global illumination. The tree traversal itself works by ray marching in steps defined by the leaf sizes. Each sampling step, it also calculates direct illumination from the light sources with a random shadow sampling step. Steps are integrated, and the result is averaged over time in a 32 bit float FBO to reduce noise.
Title: Re: GLLight2D
Post by: panithadrum on June 25, 2013, 11:49:45 pm
Thank you for the explanation. I will look at your code tomorrow now I know what your code does :-).

By the way, I got it running with MinGW32 4.8, but nothing renders at all (just a black window). Any ideas what couldn't be working?
Title: Re: GLLight2D
Post by: lolz123 on June 25, 2013, 11:57:35 pm
Hmm, that's strange. Any errors in the console (like shader version errors perhaps)?
Title: Re: GLLight2D
Post by: panithadrum on June 26, 2013, 12:01:34 am
Hmm, that's strange. Any errors in the console (like shader version errors perhaps)?
Nothing at all! Shader is loaded, uniform locations are found and the event loop works fine.

I will investigate a bit more tomorrow.
Title: Re: GLLight2D
Post by: panithadrum on June 26, 2013, 08:35:50 pm
I've tested it in Visual Studio 2012, Windows 8. I've noticed that you don't actually link to Glu32.lib so it doesn't compile as is.

When I fix that I see a black screen another time.
Title: Re: GLLight2D
Post by: lolz123 on June 26, 2013, 08:47:50 pm
Can you use gDEBugger to see if the FBO has something drawn to it? You can also try changing the format of the FBO. It is possible that your machine doesn't support GL_RGB32F, so try GL_RGB16F.
Also, did you run it in debug or release? I can't get release to work at all for some very bizarre reason.

Thank you for helping me get this to work on more than my own machine :)
Title: Re: GLLight2D
Post by: panithadrum on June 26, 2013, 09:05:04 pm
I'm compiling in debug mode (I tried also linking to the debug SFML libraries). Just tried changing the format to GL_RGB16F in SamplerBuffer.cpp and TracerScene.cpp. No luck, I'm cursed!

My graphics card is a GTX295.

Edit: I'm installing gDEBugger, let's see how it works :P
Title: Re: GLLight2D
Post by: panithadrum on June 26, 2013, 09:37:59 pm
Here's a screenshot of what I get: http://snag.gy/gWRGg.jpg

After the first wglSwapBuffers I have 1 texture and 3 buffer textures. That's ok, although the third buffer texture is 0 width x 1 height. Is that correct?

The texture bound to the FBO is still black.  :'(
Title: Re: GLLight2D
Post by: lolz123 on June 26, 2013, 09:43:27 pm
The third one shouldn't be empty. I think that one is the material buffer, and no material probably results in black! I will look into it now.
Title: Re: GLLight2D
Post by: lolz123 on June 26, 2013, 10:01:08 pm
Hmm, that's not the problem. It actually says it is 0x1 for me too, but when I change the material, the render reflects those changes, so gDEBugger is not correct.

Try validating the shader by changing

bool TracerScene::Create(const std::string &shaderName)
{
        return m_traceShader.CreateAsset(shaderName);
}
 

To

bool TracerScene::Create(const std::string &shaderName)
{
        if(!m_traceShader.CreateAsset(shaderName))
                return false;

        return Shader::Validate(m_traceShader.GetProgID());
}
 
Title: Re: GLLight2D
Post by: panithadrum on June 26, 2013, 10:09:05 pm
Changed the code and nothing new happens. The shader loads fine, although, I checked the compiler log using gDEBugger:

Quote
0(4) : warning C7532: global type samplerBuffer requires "#version 140" or later
0(4) : warning C0000: ... or #extension GL_EXT_gpu_shader4 : enable
0(95) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(96) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(97) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(98) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(116) : warning C7551: OpenGL first class arrays require #version 120
0(116) : warning C7553: OpenGL array assignments require #version 120
0(124) : warning C7551: OpenGL first class arrays require #version 120
0(124) : warning C7553: OpenGL array assignments require #version 120
0(125) : warning C7551: OpenGL first class arrays require #version 120
0(125) : warning C7553: OpenGL array assignments require #version 120
0(126) : warning C7551: OpenGL first class arrays require #version 120
0(126) : warning C7553: OpenGL array assignments require #version 120
0(127) : warning C7551: OpenGL first class arrays require #version 120
0(127) : warning C7553: OpenGL array assignments require #version 120
0(174) : warning C7531: global function texelFetchBuffer requires "#extension GL_EXT_gpu_shader4 : enable" before use
0(423) : warning C7011: implicit cast from "int" to "float"
0(423) : warning C7011: implicit cast from "int" to "float"
0(457) : warning C7011: implicit cast from "int" to "float"
0(457) : warning C7011: implicit cast from "int" to "float"
0(465) : warning C7011: implicit cast from "int" to "float"
0(465) : warning C7011: implicit cast from "int" to "float"
0(465) : warning C7011: implicit cast from "int" to "float"
0(116) : warning C7553: OpenGL array assignments require #version 120
0(124) : warning C7553: OpenGL array assignments require #version 120
0(125) : warning C7553: OpenGL array assignments require #version 120
0(126) : warning C7553: OpenGL array assignments require #version 120
0(127) : warning C7553: OpenGL array assignments require #version 120

Maybe is that. I'm going to try to fix those warnings.
Title: Re: GLLight2D
Post by: panithadrum on June 26, 2013, 10:14:57 pm
I've fixed those warnings and nothing has changed. Here is the fragment shader code: https://gist.github.com/Skyrpex/7933a44438c50fc7049d
Title: Re: GLLight2D
Post by: Daffern on July 06, 2013, 07:06:29 pm
Thank you so much for this! Me and a friend are making a game and it would be awesome if we could use this for lightening  :)

Edit:

I (Think i) have correctly opened the project and linked it, but when its starts, the console thingy opens up and i get an error box saying:

---------------------------
The Game.exe - Application Error
---------------------------
The application was unable to start correctly (0xc000007b). Click OK to close the application.
---------------------------
OK   
---------------------------

Any clue why this happens?
Title: Re: GLLight2D
Post by: ThreeDumps on September 11, 2013, 09:57:41 pm
Well, I've install that lib and it's work but... Is there any documentation for this lib?

Rendering scene take some time (it's not immediate, take 1-2 seconds to get perfect) that is difference from the last project of this author. It's option to set that scene render immediate? Or this lib have other classes with that functionality? 

@Daffern,
Have same errors but I added all *.dll from sfml and glew32.dll and it's run nice.
Title: Re: GLLight2D
Post by: lolz123 on September 13, 2013, 03:46:52 am
Unfortunately there is no documentation... yet.

GLLight2D can be run in real-time on more powerful machines, but depending on your target platforms, you can pre-generate a light map (texture with all lighting rendered to it) on level load using it instead. GLLight2D operates entirely differently from LTBL, it is a path tracer, which has the benefit of giving you full global illumination, but is much more processing intensive. So, it is a looks vs. performance trade-off. If you want speed, go with LTBL, if you want global illumination, go with GLLight2D. I personally think GLLight2D is much cooler :)
Title: Re: GLLight2D
Post by: Estivo on September 13, 2013, 07:41:20 am
I'm using LTBL and I like it. I have to do some modification and it looks very good. Original had shity blend modes. Now I have real darkness and good looking light.
Title: Re: GLLight2D
Post by: emplace on November 15, 2013, 04:06:18 pm
Great work !
Title: Re: GLLight2D
Post by: Daffern on November 17, 2013, 12:36:37 am
I have a problem using LTBL with long hulls. The light sometimes goes through the hull, especially if the hull is long in one direction compared to the other direction. Do you (lolz123) or anyone else know why this happen or how i can fix it?
Title: AW: Re: GLLight2D
Post by: eXpl0it3r on November 17, 2013, 12:58:01 pm
I have a problem using LTBL with long hulls.
Why don't you post on the LTBL thread instead of here?
Also a detailed description would be required to help further.
Title: Re: GLLight2D
Post by: Daffern on November 18, 2013, 10:29:58 pm
I did post it there (http://en.sfml-dev.org/forums/index.php?topic=6635.255 (http://en.sfml-dev.org/forums/index.php?topic=6635.255) at the bottom), but it seemed no one else had the same problem and since i saw lolz123 here i wanted to ask if he knew what the problem was.