Today i managed to fix that annoying bug who made a lot of pixel black at a certain camera angle.
I had this bug already and the other time was due to a power of 0 to 0, so i knew that a similar mathematical error would probably be the cause...and indeed i had a square root that, is some cases, was trying to calculate the root of a negative number. I surrounded the argument with an absolute value, and the bug was fixed.
In the picture i rendered on screen the content of the 5 main buffers i use (excluding depth and stencil, because they get overridden a lot and also require a lot of extra work to be rendered like i did with the other ones, fur reasons i'm yet to understand).
The top central one is the color, the top right one the normals, and the bottom left one the depth (used to retrieve position). These three are used in deferred rendering.
Then in bottom-center there is the shadow map for the dirctional light (the only one supported for now). And finally, in the bottom-left corner, the final image.
domenica 26 luglio 2015
sabato 25 luglio 2015
Day 39: Shadow mapping finally working
Today i finally managed to make shadow mapping working with the skybox.
All the other problems i had are still there: Peter panning, black artifacts, bad acne on little geometry, shadow casted by lights and so on, but the main problem is finally gone and that is a good news.
In the picture you can see a scene with a sky box and geometry casting shadows.
The shadows are only from directional light, probably i'll use shadow volumes for the point light because shadow map is not a good options.
For spotlights...well shadow mapping would be good i think, but i've never implemented them in the first place, i'll need to do that sooner or later
All the other problems i had are still there: Peter panning, black artifacts, bad acne on little geometry, shadow casted by lights and so on, but the main problem is finally gone and that is a good news.
In the picture you can see a scene with a sky box and geometry casting shadows.
The shadows are only from directional light, probably i'll use shadow volumes for the point light because shadow map is not a good options.
For spotlights...well shadow mapping would be good i think, but i've never implemented them in the first place, i'll need to do that sooner or later
venerdì 24 luglio 2015
Day 38: Shadow mapping part 3
Today i finally managed to implement shadows but i'm not happy at all.
First of all, i'm using a color texture instead of a depth one because i'm not succeding in using the depth one for an unknown reason.
Second, skyboxes are not working anymore, i need tho choose between shadows or them, i think the problem reside in the depth test but i couldn't make it work.
Third, i have some bad black artifacts on the border pixels of my models, no idea why.
And finally, using the bias to eliminate shadow acne from the shadows introduces some bad effects, like the whiter band you can see in the photo.
First of all, i'm using a color texture instead of a depth one because i'm not succeding in using the depth one for an unknown reason.
Second, skyboxes are not working anymore, i need tho choose between shadows or them, i think the problem reside in the depth test but i couldn't make it work.
And finally, using the bias to eliminate shadow acne from the shadows introduces some bad effects, like the whiter band you can see in the photo.
giovedì 23 luglio 2015
Day 37: Shadow map part 2
Today i was stuck again on this problem, i'm getting really tired, i hope i'll find a solution soon.
Maybe i made a little step forward today, but nothing is working yet
Maybe i made a little step forward today, but nothing is working yet
mercoledì 22 luglio 2015
Day 35,36: Shadow mapping part 1
In the last two days i studied how to implement shadows for directional lights (to begin with).
I'm struggling more than i expected, and i didn't manage to make it working yet.
Deferred rendering makes things harder i guess, or it is just me not seeing something obvious.
I'm struggling more than i expected, and i didn't manage to make it working yet.
Deferred rendering makes things harder i guess, or it is just me not seeing something obvious.
sabato 18 luglio 2015
Day 34: Cube Maps!
Today i decided i wanted cube maps in the engine, because they are one of those things that completly change how a game looks with minimum effort.
And thankfully the effort was really not that much.
It was slightly complicated by the fact that i'm doing deferred rendering, and i needed to tweak a few things, but now everything works and the effect is great.
I know it is quite easy to implement reflections and refractions with the cubemaps, but there are a lot of problems, for example how to block reflection if something is between the object and a cube face.
I'll have to decide if i want to go down that road or just try and implement something else.
And thankfully the effort was really not that much.
It was slightly complicated by the fact that i'm doing deferred rendering, and i needed to tweak a few things, but now everything works and the effect is great.
I know it is quite easy to implement reflections and refractions with the cubemaps, but there are a lot of problems, for example how to block reflection if something is between the object and a cube face.
I'll have to decide if i want to go down that road or just try and implement something else.
venerdì 17 luglio 2015
Day 33: Flatness
It's been a while since i was able to render a nice, flat color.
That's because now each model was forced to interact with light, and so it was impossible to make it 100% bright.
So i "invented" a new variable called Flatness, which is passed as alpha in the color (since alpha is not used for anything else because deferred shading doesn't support transparency).
This variable could vary between 0 and 1, where 0 is the original color and 1 is the color after light interaction. It is now possible to lerp between the two values.
I don't know if thats the classic way to do it, i just improvised, but it seems a reasonable way to do it.
In the image i rendered 50 light. the spheres are 100% flat, the walls are 100% non-flat.
The fps are around 12 at 800x600, and around 4 at 1920x1080, but we are talking about 50 dynamic ligths, each one of them so close to the camera that it is rendered at fullscreen. So i guess that the performace is quite good (with ~5 lights i can get 60 fps at fullscreen)
Enjoy the screenshot, today it's quite nice :)
That's because now each model was forced to interact with light, and so it was impossible to make it 100% bright.
So i "invented" a new variable called Flatness, which is passed as alpha in the color (since alpha is not used for anything else because deferred shading doesn't support transparency).
This variable could vary between 0 and 1, where 0 is the original color and 1 is the color after light interaction. It is now possible to lerp between the two values.
I don't know if thats the classic way to do it, i just improvised, but it seems a reasonable way to do it.
In the image i rendered 50 light. the spheres are 100% flat, the walls are 100% non-flat.
The fps are around 12 at 800x600, and around 4 at 1920x1080, but we are talking about 50 dynamic ligths, each one of them so close to the camera that it is rendered at fullscreen. So i guess that the performace is quite good (with ~5 lights i can get 60 fps at fullscreen)
Enjoy the screenshot, today it's quite nice :)
giovedì 16 luglio 2015
Day 32: Position from depth: part 2
Today i finally finished my last optimization, which is the rebuilding of the position from the depth.
Now i can finally render the sceen with a good framerate. A single light on a 1920x1080 screen is rendered at >60 fps (20 before optimizations)
Then i tried to render 36 lights (very close to each other, so they don't benefit from space optimizations) , and i get around 20/30 fps, while before i got 3 fps for about 10 light.
With a decent gpu i guess i could really render a lot of them, but it's a pretty good performance even on my pc.
Now i can finally render the sceen with a good framerate. A single light on a 1920x1080 screen is rendered at >60 fps (20 before optimizations)
Then i tried to render 36 lights (very close to each other, so they don't benefit from space optimizations) , and i get around 20/30 fps, while before i got 3 fps for about 10 light.
With a decent gpu i guess i could really render a lot of them, but it's a pretty good performance even on my pc.
mercoledì 15 luglio 2015
Day 31: Position fro depth, part 1
Today i started working on another big optimization, which is to build back the position of the g-buffer fragments from their depths.
This allows to use just the depth texture instead of a 4 32 bit texture for position.
Probably i'll need a second depth texture, because it's content is overriden during the stencil pass of the point ligths, but that's still 1/4 of the size of the position texture.
I started today with this process, but it is not working yet, i'm getting strange stuff on screen. I hope to finish tomorrow
This allows to use just the depth texture instead of a 4 32 bit texture for position.
Probably i'll need a second depth texture, because it's content is overriden during the stencil pass of the point ligths, but that's still 1/4 of the size of the position texture.
I started today with this process, but it is not working yet, i'm getting strange stuff on screen. I hope to finish tomorrow
lunedì 13 luglio 2015
Day 30: Big optimization part 2
Today i continued my optimizazion job.
I reduced the normal buffer to just two values, x and y, and i used a little math operation to calculate the third axis back inside the shader.
Then i noticed that my final texture (the one that it is printed to the screen) was using 3 floats for the color. I changed that to 3 8-bit values, and the performance is better then ever.
The GPU Profiler class i wrote a few days ago it's been incredibly useful to measure these performances variations.
The last thing i have yet to do is to completly remove the position buffer, because position can be calculated back from the depth buffer.
I reduced the normal buffer to just two values, x and y, and i used a little math operation to calculate the third axis back inside the shader.
Then i noticed that my final texture (the one that it is printed to the screen) was using 3 floats for the color. I changed that to 3 8-bit values, and the performance is better then ever.
The GPU Profiler class i wrote a few days ago it's been incredibly useful to measure these performances variations.
The last thing i have yet to do is to completly remove the position buffer, because position can be calculated back from the depth buffer.
domenica 12 luglio 2015
Day 29: Big Optimization
Today i managed to reduce the amount of texture data used in the deferred shading.
I reduce the color to 24 bits (instead of 4 floats) and the normals to 3 16-bit values.
The performance is way better, but i will have to make another two big optimizations:
1) Remove completly the position buffer, and built it back from the depth buffer
2) Pass only two axis of the normals, and build the third back
I know i can do these things, but i have not studied exactly how to do it.
In the next days i will have very little time, then i'll go back and do all these stuff
I reduce the color to 24 bits (instead of 4 floats) and the normals to 3 16-bit values.
The performance is way better, but i will have to make another two big optimizations:
1) Remove completly the position buffer, and built it back from the depth buffer
2) Pass only two axis of the normals, and build the third back
I know i can do these things, but i have not studied exactly how to do it.
In the next days i will have very little time, then i'll go back and do all these stuff
sabato 11 luglio 2015
Day 28: GPU Profiling
Today i continued to struggle against the bad fps, so i started by creating a GPUProfiler class, which is basically a wrapper over a OpenGL extension.
With it i can get a precise evaluation of how much time pass between two lines of code, taking also in consideration the code run on the gpu.
Using this method i was able to profile the time used by the shaders, and it is pretty high for all of them. Since they all have in commond the 3, big textures used in deferred rendering, i figure that thhe problem is bandwidth related.
Tomorrow i'll try to reduce the gbuffer size and hope for better results
With it i can get a precise evaluation of how much time pass between two lines of code, taking also in consideration the code run on the gpu.
Using this method i was able to profile the time used by the shaders, and it is pretty high for all of them. Since they all have in commond the 3, big textures used in deferred rendering, i figure that thhe problem is bandwidth related.
Tomorrow i'll try to reduce the gbuffer size and hope for better results
venerdì 10 luglio 2015
Day 27: Bad performance
Today i noticed that with 1920x1080 resolution my game runs at ~22 fps with just 5 simple models, one directional light and one point light.
I did a little optimization, which is to make a few operations in the vertex shader instead of the fragment one, but the fps are not better.
Maybe with my gpu i just can't expect to get high fps with a resolution that contains millions of pixels, but one light seem just not enough.
I did a little optimization, which is to make a few operations in the vertex shader instead of the fragment one, but the fps are not better.
Maybe with my gpu i just can't expect to get high fps with a resolution that contains millions of pixels, but one light seem just not enough.
giovedì 9 luglio 2015
Day 26: Tiling
Today i implemented a tiling system to adapt the texture to the surface the way i want.
This is done manually, and it's applied to all the faces of the model, so the correct usage would be on a model where you can actually see only the faces that get the desired effect
This is done manually, and it's applied to all the faces of the model, so the correct usage would be on a model where you can actually see only the faces that get the desired effect
martedì 7 luglio 2015
Day 23,24,25: Normal Mapping
In the last two days i didn't have much time, but i started studying how to implement normal mapping.
It was harder than i expected, and today i finally implemented it.
The result is great, it really makes everything more realistic. Now i will soon add specular mapping, it will be pretty easy, i'll just need to embed the specular map in the alpha channel of the normal map, and make reflections less intense where the specular map has a low value.
Now if i need to render a texture without normal map...i can't. I have a little hack to make it work but not good enough, i'm trying to make a system that can handle both, i'll think of something.
It was harder than i expected, and today i finally implemented it.
The result is great, it really makes everything more realistic. Now i will soon add specular mapping, it will be pretty easy, i'll just need to embed the specular map in the alpha channel of the normal map, and make reflections less intense where the specular map has a low value.
Now if i need to render a texture without normal map...i can't. I have a little hack to make it work but not good enough, i'm trying to make a system that can handle both, i'll think of something.
sabato 4 luglio 2015
Day 22: Specular directional light
I spent half a day trying to fix a few annoying problems with point lights.
Now everything is fine and the bounding box is exactly the size it needs to be.
Then i did the same with directional lights, which is of course less difficult.
Then i did the same with directional lights, which is of course less difficult.
In the photo you can see the point light with it's diffuse component and it's specular component, and for the directional light it is little difficult to see, but the color become darker near the corner, because the reflaction of the surface is less intense
venerdì 3 luglio 2015
Day 21: Specular Lights
Today i finished the refactoring of the shaders, and now they support specular lights...well actually only the point ligths for now, tomorrow i'll extend it to directional.
I worked in the past with shaders in Unity, which are quite the same thing of glsl, and this helped a lot.
I have a major problem though: the specular light apparently exceed the bounding box of the light, which lead to a light "cut off" at a certain distance from the emission point.
I must understand how this will affect the dimension of the box, i'll think on it tomorrow.
I worked in the past with shaders in Unity, which are quite the same thing of glsl, and this helped a lot.
I have a major problem though: the specular light apparently exceed the bounding box of the light, which lead to a light "cut off" at a certain distance from the emission point.
I must understand how this will affect the dimension of the box, i'll think on it tomorrow.
giovedì 2 luglio 2015
Day 20: Light Refactoring, part 1
Today i refactored all the light classes in C++, and added parameters like specular color or specular intensity, which i'll use in the future.
Now each light inherits from a AbstractLight class.
The engine does exactly what it did yesterday, but now the lights are way easier to manage.
Tomorrow i'll refactor the light calculations in the shaders, and soon I'll add specular lightning.
I also plan to add spot lights, which is not the most exciting thing, but needs to be done.
Now each light inherits from a AbstractLight class.
The engine does exactly what it did yesterday, but now the lights are way easier to manage.
Tomorrow i'll refactor the light calculations in the shaders, and soon I'll add specular lightning.
I also plan to add spot lights, which is not the most exciting thing, but needs to be done.
mercoledì 1 luglio 2015
Day 19: Giga Refactoring
Today i started by finding a problem which was killing the performances of the deferred rendering.
Basically i was using a bounding box for the ligths which was 255 times bigger than the correct size.
Now i can look at 121 lights on screen and 400 cubes with ~30 fps (image), which is pretty good for my card.
The same scene with 50 lights runs at 60 fps.
Then I created a DeferredRenderer class which handles all the important steps instead of having everything in a single enormous function. It tooks me quite a lot of times because i needed to refactor other things to make everything work together.
Tomorrow i'll make better PointLight and DirectionalLight classes, with additional stuff, like specular color etc..
Basically i was using a bounding box for the ligths which was 255 times bigger than the correct size.
Now i can look at 121 lights on screen and 400 cubes with ~30 fps (image), which is pretty good for my card.
The same scene with 50 lights runs at 60 fps.
Then I created a DeferredRenderer class which handles all the important steps instead of having everything in a single enormous function. It tooks me quite a lot of times because i needed to refactor other things to make everything work together.
Tomorrow i'll make better PointLight and DirectionalLight classes, with additional stuff, like specular color etc..
Iscriviti a:
Post (Atom)










