OpenGL 3D viewport renderer
Moderator: OpenTTD Developers
OpenGL 3D viewport renderer
UPDATED. Fork https://github.com/Assert1/OpenTTD
General idea:
OTTD is a 2.5D game, having an adequate orthogonal XYZ space (Z is scaled by some factor, but it’s ok). OTTD draws everything with sprites. Each sprite represents some object, or a part of the object. So, we can say, OTTD scene consists of an objects in XYZ space represented by the sprites. And what if we replace the sprites, by a full scale 3D objects, and render everything with OpenGL 3D engine? We’ve got a 3D version of the OTTD that would be nice.
Sprite is an image coming from the GRF file. Each sprite can be identified by the GRFID of the GRF file, and it’s id inside this file. So, we can build a map, from the drawn sprite, to some 3D geometry. Now we just need to replace a 2.5D viewport rendering procedure with our 3D rendering procedure to render 3D objects instead of 2D sprites. Actual things are slightly more complex, but everything fits this idea. We are leaving all of the game logic, GUI and a hi level tile drawings untouched, intercepting only the output in terms of sprites mapped to the 3D resources. This is a general constraint that probably fits to the project goal. Having this in mind, I've started my experiments.
The intermediate result:
This is a test graphic set, to check that the new 3D engine is working properly. It’s able to render a huge amount of different objects with different textures, computing pixel lighting and casting 3D shadows, but still supporting palette recoloring and the global color palette animation. I’ve made some overrides, like a foundations drawing, because it was not possible to use original sprite mapping for the full 3D scene. Fixed trees Z positions on slopes, made vehicles positions change smoother, extracting fractional part of the speed, and correcting it’s trajectories on slopes and corners. But everything still from the bottom, on a renderer level. Original game logics was not changed, and still driving everything.
As you can see, nearly everything is working. The only missing thing, is an effects, like a broken down smoke. I am still thinking about it’s implementation (particle system or an animated sprites)… but, all of the other things, can be added with new 3D graphical resources, and we get a complete working and a nice looking game. Of course some things still needs refinement, but they are all already working correctly.
Compatibility and performance:
This is a case where the OpenGL 2D texture arrays and instancing is absolutely required to have a good performance. With it, it’s possible to make a really fast renderer. That’s why the 3D engine was designed to use OpenGL 3.3+ spec compatible hardware (and running best on 4.3). I think this should be ok, OpenGL 3.3 == 10 years old graphic cards. I am using all of benefits from the modern interface. With my computer, drawing everything each frame in 3D with AA and shadows, is even faster in some cases, than the default 2.5D renderer, with it’s dirty blocks and updates on demand. It’s possible to make a compatibility patches for the lower OpenGL versions (with a lot of coding), but the performance of this hardware is too low in any way.
Internal architecture: New graphic resources: Config file spec: Windows binaries:
General idea:
OTTD is a 2.5D game, having an adequate orthogonal XYZ space (Z is scaled by some factor, but it’s ok). OTTD draws everything with sprites. Each sprite represents some object, or a part of the object. So, we can say, OTTD scene consists of an objects in XYZ space represented by the sprites. And what if we replace the sprites, by a full scale 3D objects, and render everything with OpenGL 3D engine? We’ve got a 3D version of the OTTD that would be nice.
Sprite is an image coming from the GRF file. Each sprite can be identified by the GRFID of the GRF file, and it’s id inside this file. So, we can build a map, from the drawn sprite, to some 3D geometry. Now we just need to replace a 2.5D viewport rendering procedure with our 3D rendering procedure to render 3D objects instead of 2D sprites. Actual things are slightly more complex, but everything fits this idea. We are leaving all of the game logic, GUI and a hi level tile drawings untouched, intercepting only the output in terms of sprites mapped to the 3D resources. This is a general constraint that probably fits to the project goal. Having this in mind, I've started my experiments.
The intermediate result:
This is a test graphic set, to check that the new 3D engine is working properly. It’s able to render a huge amount of different objects with different textures, computing pixel lighting and casting 3D shadows, but still supporting palette recoloring and the global color palette animation. I’ve made some overrides, like a foundations drawing, because it was not possible to use original sprite mapping for the full 3D scene. Fixed trees Z positions on slopes, made vehicles positions change smoother, extracting fractional part of the speed, and correcting it’s trajectories on slopes and corners. But everything still from the bottom, on a renderer level. Original game logics was not changed, and still driving everything.
As you can see, nearly everything is working. The only missing thing, is an effects, like a broken down smoke. I am still thinking about it’s implementation (particle system or an animated sprites)… but, all of the other things, can be added with new 3D graphical resources, and we get a complete working and a nice looking game. Of course some things still needs refinement, but they are all already working correctly.
Compatibility and performance:
This is a case where the OpenGL 2D texture arrays and instancing is absolutely required to have a good performance. With it, it’s possible to make a really fast renderer. That’s why the 3D engine was designed to use OpenGL 3.3+ spec compatible hardware (and running best on 4.3). I think this should be ok, OpenGL 3.3 == 10 years old graphic cards. I am using all of benefits from the modern interface. With my computer, drawing everything each frame in 3D with AA and shadows, is even faster in some cases, than the default 2.5D renderer, with it’s dirty blocks and updates on demand. It’s possible to make a compatibility patches for the lower OpenGL versions (with a lot of coding), but the performance of this hardware is too low in any way.
Internal architecture: New graphic resources: Config file spec: Windows binaries:
Last edited by Assert on 15 Dec 2019 09:30, edited 4 times in total.
Re: OpenGL 3D viewport renderer
While I don't doubt the technical parts of this are good, there are two major conceptual issues I see:
First, there is a library of more than 15 years of NewGRF add-ons containing sprites that are not compatible with this mode. I see two possible outcomes, one is that nobody might want to use this 3D mode because it doesn't support their NewGRF. The other is that some kind of "re-wrapping" of sprites onto 3D models (or just as billboard sprites) that will look bad and possibly anger artists having their work poorly presented.
Second, and related, is that I think a large number of players stick with OpenTTD specifically because of the art style.
So yeah, sorry for being only negative, but I just can't see this becoming a popular feature.
First, there is a library of more than 15 years of NewGRF add-ons containing sprites that are not compatible with this mode. I see two possible outcomes, one is that nobody might want to use this 3D mode because it doesn't support their NewGRF. The other is that some kind of "re-wrapping" of sprites onto 3D models (or just as billboard sprites) that will look bad and possibly anger artists having their work poorly presented.
Second, and related, is that I think a large number of players stick with OpenTTD specifically because of the art style.
So yeah, sorry for being only negative, but I just can't see this becoming a popular feature.
- andythenorth
- Tycoon
- Posts: 5667
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: OpenGL 3D viewport renderer
It does look very good in the demo though
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: OpenGL 3D viewport renderer
This is a user choise. It's not blocking anything. At some point, somebody can make a 3D set for this NewGRF, and everything will work...
It's possible to reproduce any artstyle, and i am personally prefer to be as close as possible to the original dataset. Just in 3D. When somebody making a good sprites for OTTD, he is making a 3D model, then renders it with 3Ds MAX to the sprite... we just skipping this step.
Anyway, there was some requests for this "feature". And i am implemented it in a most harmless form. Minimum dependincies, and easy to maintain. Then community should choose of what to do with this.
Time will tell us. I've already get everything i want from this. It was a very nice and funny workout. If somebody will start to make a content for this, then it will be a motivation to continue.
Re: OpenGL 3D viewport renderer
Thanks, may be you know someone, who can help to make a 3D content for this? I know, A LOT of NewGRF developers have a 3D models of it's sprites...
Re: OpenGL 3D viewport renderer
It may not be a majorly popular feature, but I believe there would be a significant number of users who would jump onto this faster than they did zBase, who appreciate the 3D aspects and ultra-clean, simplified renderings over detailed 32bpp 2D or low-res 8bpp 2D graphics.jfs wrote: ↑02 Dec 2019 21:28 While I don't doubt the technical parts of this are good, there are two major conceptual issues I see:
First, there is a library of more than 15 years of NewGRF add-ons containing sprites that are not compatible with this mode. I see two possible outcomes, one is that nobody might want to use this 3D mode because it doesn't support their NewGRF. The other is that some kind of "re-wrapping" of sprites onto 3D models (or just as billboard sprites) that will look bad and possibly anger artists having their work poorly presented.
Second, and related, is that I think a large number of players stick with OpenTTD specifically because of the art style.
So yeah, sorry for being only negative, but I just can't see this becoming a popular feature.
And because it's a 3D engine, it may actually attract more new NewGRF developers on board to create graphics for them.
Do you like drones, quadcopters & flying toys? Check out Drone Strike Force!
Base Music Sets: OpenMSX | Scott Joplin Anthology | Traditional Winter Holiday Music | Modern Motion Music
Other Projects: 2CC Trams | Modern Waypoints | Sprite Sandbox & NewGRF Releases | Ideabox | Town Names | Isle of Sodor Scenario | Random Sprite Repository
Misc Topics: My Screenshots | Forgotten NewGRFs | Unfinished Graphics Sets | Stats Shack | GarryG's Auz Sets
Base Music Sets: OpenMSX | Scott Joplin Anthology | Traditional Winter Holiday Music | Modern Motion Music
Other Projects: 2CC Trams | Modern Waypoints | Sprite Sandbox & NewGRF Releases | Ideabox | Town Names | Isle of Sodor Scenario | Random Sprite Repository
Misc Topics: My Screenshots | Forgotten NewGRFs | Unfinished Graphics Sets | Stats Shack | GarryG's Auz Sets
-
- Traffic Manager
- Posts: 161
- Joined: 02 Mar 2009 02:07
Re: OpenGL 3D viewport renderer
OTTD 2.0.0 ?
I like what I see. It was time.
If this project continues many curent and future players of OTTD will in gratitude.
Thumbs up!
I like what I see. It was time.
If this project continues many curent and future players of OTTD will in gratitude.
Thumbs up!
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: OpenGL 3D viewport renderer
Hm, I like what I see!
And I'd totally love to see this brought further.
Arguably, NewGRFs will hardly be interchangeably be usable with the 2.5D version and a 3D version. That works for ground tiles and anything flat. It even may somewhat work for stuff where four views are provided like rail depots and stations (but not airports). But it will be extremely difficult for industries which are extended objects without rotation views provided.
However: There do exist blender files with models to start with for everything needed by vanilla OpenTTD in the zBase repository. Thus some models to start with do exist (look for the .blend files in all the sub-dirs). Do you happen to have any github repo instead of tar balls attached here?
And I'd totally love to see this brought further.
Arguably, NewGRFs will hardly be interchangeably be usable with the 2.5D version and a 3D version. That works for ground tiles and anything flat. It even may somewhat work for stuff where four views are provided like rail depots and stations (but not airports). But it will be extremely difficult for industries which are extended objects without rotation views provided.
However: There do exist blender files with models to start with for everything needed by vanilla OpenTTD in the zBase repository. Thus some models to start with do exist (look for the .blend files in all the sub-dirs). Do you happen to have any github repo instead of tar balls attached here?
- Attachments
-
- Bildschirmfoto von »2019-12-03 11-15-59«.png
- part of farm, without texture
- (327.44 KiB) Not downloaded yet
-
- Bildschirmfoto von »2019-12-03 11-15-09«.png
- part of gold mine, without texture
- (449.08 KiB) Not downloaded yet
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: OpenGL 3D viewport renderer
Hey,
I really like this idea and I am usually a big fan of 3D and realistic games. Though I just don't think it fits this game, just as I don't really like zoomed sprites either.
Other thing is, I can't get it to work on my side. I used the executable from the bin.zip you attached and it lets me activate the 3d viewport and then further on still renders like it would normally. Also, would be nice if you would attach the \lang folder aswell, as we require the lang files created when building. In the main menu I also get that weird blue sea background bug and I forgot what caused that, sorry. There's also an issue with the game finding music and sound sets.
Good luck developing this further!
I really like this idea and I am usually a big fan of 3D and realistic games. Though I just don't think it fits this game, just as I don't really like zoomed sprites either.
Other thing is, I can't get it to work on my side. I used the executable from the bin.zip you attached and it lets me activate the 3d viewport and then further on still renders like it would normally. Also, would be nice if you would attach the \lang folder aswell, as we require the lang files created when building. In the main menu I also get that weird blue sea background bug and I forgot what caused that, sorry. There's also an issue with the game finding music and sound sets.
Good luck developing this further!
- Attachments
-
- unknown.png
- (1.24 MiB) Not downloaded yet
Re: OpenGL 3D viewport renderer
Hi.
I wanted to write video driver for SDL2, but I have little trouble with understand frame flow. How does it work when _draw3d is disabled? Is it drawn directly on front framebuffer, or is there legacy intermediary surface? And there is no SwapBuffers at all in the code you provided, I can't see how it could work.
EDIT: OK, it was there, just commented out.
I wanted to write video driver for SDL2, but I have little trouble with understand frame flow. How does it work when _draw3d is disabled? Is it drawn directly on front framebuffer, or is there legacy intermediary surface? And there is no SwapBuffers at all in the code you provided, I can't see how it could work.
EDIT: OK, it was there, just commented out.
Re: OpenGL 3D viewport renderer
Yes, i hope this will be intrested to the community. And it's simplier to make a one 3D model, than prperly render A LOT of sprites. But the future is only possible, if this will be a part of the main branch i think...kamnet wrote: ↑02 Dec 2019 23:55 It may not be a majorly popular feature, but I believe there would be a significant number of users who would jump onto this faster than they did zBase, who appreciate the 3D aspects and ultra-clean, simplified renderings over detailed 32bpp 2D or low-res 8bpp 2D graphics.
And because it's a 3D engine, it may actually attract more new NewGRF developers on board to create graphics for them.
Re: OpenGL 3D viewport renderer
Thanks i've checked zBase files.planetmaker wrote: ↑03 Dec 2019 11:09 However: There do exist blender files with models to start with for everything needed by vanilla OpenTTD in the zBase repository. Thus some models to start with do exist (look for the .blend files in all the sub-dirs). Do you happen to have any github repo instead of tar balls attached here?
Re: OpenGL 3D viewport renderer
You should start it with -v win32ogl command line, to enable OGL driver.PNDA_ wrote: ↑03 Dec 2019 13:41 Hey,
I really like this idea and I am usually a big fan of 3D and realistic games. Though I just don't think it fits this game, just as I don't really like zoomed sprites either.
Other thing is, I can't get it to work on my side. I used the executable from the bin.zip you attached and it lets me activate the 3d viewport and then further on still renders like it would normally. Also, would be nice if you would attach the \lang folder aswell, as we require the lang files created when building. In the main menu I also get that weird blue sea background bug and I forgot what caused that, sorry. There's also an issue with the game finding music and sound sets.
Good luck developing this further!
Re: OpenGL 3D viewport renderer
Double buffer eats performance by the some unknown reason, so i am used a front buffer directly. But it's ok, because there is an internal framebuffer where everything is drawn, then flipped to the screen. There is a macro DEF_BUFFER, to select a target buffer for rendering, you can change it to GL_BACK and enable doublebuffering with adding SwapBuffers.milek7 wrote: ↑03 Dec 2019 16:33 Hi.
I wanted to write video driver for SDL2, but I have little trouble with understand frame flow. How does it work when _draw3d is disabled? Is it drawn directly on front framebuffer, or is there legacy intermediary surface? And there is no SwapBuffers at all in the code you provided, I can't see how it could work.
EDIT: OK, it was there, just commented out.
- orudge
- Administrator
- Posts: 25148
- Joined: 26 Jan 2001 20:18
- Skype: orudge
- Location: Banchory, UK
- Contact:
Re: OpenGL 3D viewport renderer
This looks interesting. However, what git revision should this be built/run against? If you could provide a link to a GitHub branch that would be most useful.
Re: OpenGL 3D viewport renderer
I tried to make it work on SDL2: https://github.com/Milek7/OpenTTD/tree/3d (for now it dirties whole frame always, because SDL doesn't provide intermediary buffer with InvalidateRect like windows)
It almost works, however it looks like that: https://i.imgur.com/4yPs6wE.png
Hovewer same thing happens when running your posted binaries on Wine, so I think this is shader problem. Sampling textures with half-pixel offset, or some filtering issue?
It almost works, however it looks like that: https://i.imgur.com/4yPs6wE.png
Hovewer same thing happens when running your posted binaries on Wine, so I think this is shader problem. Sampling textures with half-pixel offset, or some filtering issue?
Re: OpenGL 3D viewport renderer
No, this is just because the land generator do not invalidate all of the tiles, just save and load. I will fix this soon.milek7 wrote: ↑03 Dec 2019 23:29 I tried to make it work on SDL2: https://github.com/Milek7/OpenTTD/tree/3d (for now it dirties whole frame always, because SDL doesn't provide intermediary buffer with InvalidateRect like windows)
It almost works, however it looks like that: https://i.imgur.com/4yPs6wE.png
Hovewer same thing happens when running your posted binaries on Wine, so I think this is shader problem. Sampling textures with half-pixel offset, or some filtering issue?
Re: OpenGL 3D viewport renderer
It's branched from 20191126-master-m4233e11aa1, i will make a git repo as soon as understand that this thing have a future. Anyway, i am packed the whole src directory, so you can build it with any latest branch of the master.
Re: OpenGL 3D viewport renderer
Well done! This is the logical next step after 32bpp graphics.
(That said, I personally find 32bpp ugly and bloating. But apparently many people like it.)
(That said, I personally find 32bpp ugly and bloating. But apparently many people like it.)
My add-ons: • AdmiralAI fix • Persistence for vehicle evolution lines
My pictures: • The animation thread
My pictures: • The animation thread
- andythenorth
- Tycoon
- Posts: 5667
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: OpenGL 3D viewport renderer
Variant of this approach:
* fix the camera
* draw existing sprites as textures on planes with OpenGL, hardware accelerated
* see whether it's faster or slower than current 2D blitters??
* fix the camera
* draw existing sprites as textures on planes with OpenGL, hardware accelerated
* see whether it's faster or slower than current 2D blitters??
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Who is online
Users browsing this forum: Bing [Bot] and 4 guests