Page 2 of 2

Re: Friday Facts #333 - Terrain scrolling

Posted: Fri Feb 07, 2020 7:43 pm
by Klonan
PaszaVonPomiot wrote:
Fri Feb 07, 2020 7:38 pm
I would like to go back to previous FFF where we discussed new sounds and there were many critical voices. Would you mind commenting on that?
We got a lot of feedback, and will take our time digesting it and working on it, aswell as fixing all the issues and bugs that have been found since the new sounds were introduced.

Re: Friday Facts #333 - Terrain scrolling

Posted: Fri Feb 07, 2020 7:56 pm
by blackbat
Klonan wrote:
Fri Feb 07, 2020 7:43 pm
PaszaVonPomiot wrote:
Fri Feb 07, 2020 7:38 pm
I would like to go back to previous FFF where we discussed new sounds and there were many critical voices. Would you mind commenting on that?
We got a lot of feedback, and will take our time digesting it and working on it, aswell as fixing all the issues and bugs that have been found since the new sounds were introduced.
Now, there's a reply I appreciate and respect.
Hear the feedback and think it over, don't react immediately, and make sure not to make it work.
Great job guys!

Re: Friday Facts #333 - Terrain scrolling

Posted: Fri Feb 07, 2020 8:57 pm
by bobingabout
Your new method reminds me of how a NES/SNES works.

Heck, most of the old consoles of that era use that kind of screen drawing.

So... if thats how they used to do it, it makes sense that it would be more efficient.

Re: Friday Facts #333 - Terrain scrolling

Posted: Fri Feb 07, 2020 10:41 pm
by AshenSwift
Klonan wrote:
Fri Feb 07, 2020 7:43 pm
PaszaVonPomiot wrote:
Fri Feb 07, 2020 7:38 pm
I would like to go back to previous FFF where we discussed new sounds and there were many critical voices. Would you mind commenting on that?
We got a lot of feedback, and will take our time digesting it and working on it, aswell as fixing all the issues and bugs that have been found since the new sounds were introduced.
This is a sign of a good game dev. Other devs say this and it means, "We don't care." Factorio game devs say it, and you know they're actually looking at it and working on it. :D :lol: :P

Re: Friday Facts #333 - Terrain scrolling

Posted: Fri Feb 07, 2020 11:45 pm
by bw_mutley
...and then instead of copying all the terrain back to the buffer, we can just adjust the offset and update the parts that changed.
Just like 90% of video files do. When I started reading this FFF, this question just pop up in my eyes: Why they don't do just like MP4 files?

Still, Factorio video rendering where still better than a lot of 2D games, taking into consideration the properties carried over each tile.

Re: Friday Facts #333 - Terrain scrolling

Posted: Sat Feb 08, 2020 3:43 am
by valneq
bw_mutley wrote:
Fri Feb 07, 2020 11:45 pm
...and then instead of copying all the terrain back to the buffer, we can just adjust the offset and update the parts that changed.
Just like 90% of video files do. When I started reading this FFF, this question just pop up in my eyes: Why they don't do just like MP4 files?
The video compression algorithms used in MP4 use lossy compression: they throw away some information in order to be able to strongly compress the remaining information. They especially exploit how our vision works: individual pixels being slightly wrong don't bother our visual system that much. Additionally, many videos have larger areas that have similar colors for an extended amount of time – allowing for large scale comparison of many pixels in the same frame and even across several consecutive frames in the video stream. This compression helps in situation when you want to store video data on hard disks, or transmit them through data channels with a limited bandwidth. But both the compression and later decompression for rendering on screen require computation time.

With that in mind, it should become clear that this is absolutely not what a video game rendering engine should be doing. In a video game, you want to update the information for the screen as quickly as possible, and not lose any time on analyzing all the pixels in the generated frame to figure out how to compress all that. After all, the connection between graphics card and screen is designed for direct output of uncompressed video data.

In this week's FFF, the topic is figuring out how to minimize the number of changes that need to be done on the video buffer before it is being drawn on the screen. For terrain this is especially efficient because the terrain does not change when you walk around. What changes is which part of the terrain should be drawn on the screen. The parts that don't change in between frames can stay exactly where they are in the video buffer. You only need to take care of which pixels in the video buffer should be drawn where onto the screen.

Re: Friday Facts #333 - Terrain scrolling

Posted: Sat Feb 08, 2020 5:10 am
by maximm
I was playing with NEE, AAI, Space Exploration and all mods they depend on (namely Alien Biomes), all in HR. When zoomed out, I've seen FPS drops down to 30
And now, this optimization brought my FPS back to 60 when you zoom out (i7-6600k with 1070 GTX and 32 GB RAM)

Thank you for this improvement.

Re: Friday Facts #333 - Terrain scrolling

Posted: Sat Feb 08, 2020 9:45 am
by leadraven
All ingenious is simple. Really impressive optimization.

Re: Friday Facts #333 - Terrain scrolling

Posted: Sat Feb 08, 2020 8:16 pm
by liwers
So uh..

What's this optimization may really enhance on Kitty's computer, as it's i9-9900K+Z-390E+2080Ti..

Meow..!

Re: Friday Facts #333 - Terrain scrolling

Posted: Sat Feb 08, 2020 9:18 pm
by eradicator
@posila:
Did you measure the difference on high end cards? Even if it's "only" 0.1ms that's still some extra SPM before dropping below 60 UPS.
_________
KatherineOfSky wrote:
Fri Feb 07, 2020 7:30 pm
I've heard from so many people with self-described "potato" computers who are so happy they can play Factorio
Yea, the poor potato people. I'm so happy that i have a proper Intel HD Graphics 4000 toaster. :twisted:
_________
valneq wrote:
Sat Feb 08, 2020 3:43 am
bw_mutley wrote:
Fri Feb 07, 2020 11:45 pm
...and then instead of copying all the terrain back to the buffer, we can just adjust the offset and update the parts that changed.
Just like 90% of video files do. When I started reading this FFF, this question just pop up in my eyes: Why they don't do just like MP4 files?
The video compression algorithms used in MP4 use lossy compression: they throw away some information in order to be able to strongly compress the remaining information.
Lossyness isn't really the problem. The problem that factorio needs to solve is a movement of *all* screen pixels at the same time. This is something that video compression is infact quite bad at because it is optimized for small localized changes. I.e. if you watch the news then most of the time the only different between two frames would be the mouth of the speaker and all the other pixels would simply stay the same.

Re: Friday Facts #333 - Terrain scrolling

Posted: Sat Feb 08, 2020 11:16 pm
by mrudat
Depending on how complicated the tile transition rules are, could you not have a texture with 1 pixel/tile that stored the tile variation number, then have a shader use that to index into the tile texture during rendering? More or less a sharp-edged displacment map.

I suspect that it might go faster, if only for moving less bits, on the other hand, there's less locality of reference, so it might go slower?

Re: Friday Facts #333 - Terrain scrolling

Posted: Sun Feb 09, 2020 2:50 pm
by eradicator
mrudat wrote:
Sat Feb 08, 2020 11:16 pm
Depending on how complicated the tile transition rules are
Alien Biomes hits the tile limit of 255 tile types. So if all of these can transition to every other tile in eight directions that's about half a million possible tile combinations i think (≈ 8*255^2)?

Re: Friday Facts #333 - Terrain scrolling

Posted: Tue Feb 11, 2020 4:47 am
by DoubleThought
eradicator wrote:
Sun Feb 09, 2020 2:50 pm
Alien Biomes hits the tile limit of 255 tile types. So if all of these can transition to every other tile in eight directions that's about half a million possible tile combinations i think (≈ 8*255^2)?
Each of the eight adjacent tiles can be any of 255 tile types. The central tile can also be any of 255 tile types. Assuming that all nine of these tiles contribute to the tile transition, that's a total of 255^9 = 4,558,916,353,692,287,109,375 (4 sextillion or 4 * 10^21).

So, a bit worse than half a million tile combinations.

It's this exponential growth that would require that the transitions are programmatically generated as needed. If all of the images were prerendered, and each image took a millisecond to generate (a mild overestimation), it would take a whooping 144,466,308,206 (144 billion) years to pretender all the tile transitions, not to mention the frankly absurd amount of memory required. For comparison, the Earth is estimated at a mere 4,540,000,000 (4.54 billion) years of age, less than a third of how long it would take to prerender each tile transition.

On the other end of the scale, a modern GPU has a clock rate of around 1000 MHz. A tile has around 1000 pixels. Assuming rendering each pixel takes a single clock cycle (a mild underestimation), a tile would take a microsecond to render. With this estimation, it would take only 144,466,308 (144 million) years to render the tile transitions. This is approximately how long ago the Cretaceous period started (144 million years ago).

It's worse if there's an additional built-in no-tile type, which brings the total number of tile transitions to 256^9; there would be an additional 163 quintillion images needed to be rendered.

Prerendering all of tile transitions would take between the age of Earth to the age of dinosaurs.

Luckily for us, the Factorio devs are amazing; otherwise, starting up Factorio with Alien Biomes could take longer than it would take for the sun to scour all life from earth (7.5 billion years).

Re: Friday Facts #333 - Terrain scrolling

Posted: Tue Feb 11, 2020 6:02 am
by conn11
DoubleThought wrote:
Tue Feb 11, 2020 4:47 am
.
Luckily for us, the Factorio devs are amazing; otherwise, starting up Factorio with Alien Biomes could take longer than it would take for the sun to scour all life from earth (7.5 billion years).
This should actually happen much faster. The sun is slowly but continuously increasing in luminosity and therefore believed to shift earth out of the habitable zone and more into Venus territory in about a billion years. Meaning no liquid water, no life as we know it.
Luckily for all of us, Factorio is, even with a more constrained timeframe, efficient enough to start with Alien Biomes long before the surrounding landscape becomes an alien biome.

Re: Friday Facts #333 - Terrain scrolling

Posted: Tue Feb 11, 2020 5:38 pm
by daifeiya
Thank you so much for this optimization! Don't think this is less than 1 millisecond optimization is insignificant, this is a significant improvement for the super factory! Thank you so much!

Re: Friday Facts #333 - Terrain scrolling

Posted: Wed Feb 12, 2020 12:58 pm
by BattleFluffy
blackbat wrote:
Fri Feb 07, 2020 7:56 pm
Klonan wrote:
Fri Feb 07, 2020 7:43 pm
PaszaVonPomiot wrote:
Fri Feb 07, 2020 7:38 pm
I would like to go back to previous FFF where we discussed new sounds and there were many critical voices. Would you mind commenting on that?
We got a lot of feedback, and will take our time digesting it and working on it, aswell as fixing all the issues and bugs that have been found since the new sounds were introduced.
Now, there's a reply I appreciate and respect.
Hear the feedback and think it over, don't react immediately, and make sure not to make it work.
Great job guys!
Agreed, this is the right approach and I'm really glad to hear this after a week or two of silence on the subject. :>

The optimization to terrain scrolling is great! I have to confess I don't quite follow how it's working, but the benchmark time doesn't lie.. :>

Re: Friday Facts #333 - Terrain scrolling

Posted: Sun Feb 16, 2020 3:33 pm
by posila
I am pleasantly surprised by all the positive feedback on this FFF, thank you.

I feel like I need to clear some things up - the described optimization affects only GPU. GPU is already working in parallel to CPU. And in Factorio, render thread (which sends commands to GPU) runs in parallel to update thread. So if you have dedicated GPU, this has no benefit on UPS whatsoever. There might be some UPS improvement on integrated GPUs, which live on the same die as CPU, and they compete for resources, but I have not tried to measure that.