Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

3D engine... Much interest?
Started by richard11 Dec 23 2018 04:52 PM

92 replies to this topic
[TOPIC CONTROLS]
« Page 4 of 4 2 3 4
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#76

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,070 posts
  • Corona SDK

I've managed to get the code together and uploaded to github. The build even runs in a browser:

 

https://github.com/HoraceBury/3d


  • Michael Flad likes this

[TOPIC: post.html]
#77

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

Wow, thanks for posting that. I'd definitely like to devote some time to digging through your code a little. I've had a quick scroll through some of it but I'm far too sleepy to understand your maths right now!

[TOPIC: post.html]
#78

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

Right. I had a few hours to brush the dust off of this today!

 

Fixed a fairly critical bug that was previously preventing me from showing off the camera rotation, implemented some very basic off-screen culling, reworked the rendering to order faces by their distance instead of by the distance of the object they belong to (for slightly better handling of overlapping objects but it's not perfect), and experimented more with current performance figures. Definitely needs optimising better and I am now very much doubting that I'll be able to get any kind of proper intersecting faces support into this, but for those interested, here's an Android APK:

 

https://development.qweb.co.uk/q3d-test-2.apk

 

This creates 50 cubes located randomly around the camera, then rotates the camera around on a timer. Each face is currently made up of 32 triangles and because the culling is basic, on average it's rendering between 30 and 100 faces at any one time so we're looking at around 1000 - 3000 polygons.

 

I've only been able to test on my own phone so far - a slightly battered Samsung S8 - and the results aren't great. There's visible jutter when a large number of faces are being rendered because again the culling is basic - a good number of off-screen faces are actually still being rendered at the moment - and in all honesty a fair bit of the rendering code just needs thinking out better. The rotation timer for the demo itself isn't the best implementation either to be fair... it fires every 1ms and rotates by 0.005 degrees, but at 30fps there'll be around 33ms between each frame even when the renders can keep up, so that's 33 fires between each frame meaning 0.165 degrees of rotation between visual update, which was never going to be smooth.

 

Here's the entire code behind this demo, by the way:

-- This isn't really needed, but Android's navigation bar looks ugly so...
native.setProperty("androidSystemUiVisibility", "immersiveSticky")

-- First, tell q3dengine where 3D models and texture files are.
q3d.setAssetsFolder("assets")

-- Generate some cubes

math.randomseed( os.time() )

for i=1, 50, 1 do
	q3d.addCube({ name = "myCube" .. i, x = math.random(-20, 20), y = math.random(-1, 1), z = math.random(-20, 20) })
end

-- Initial camera placement
q3d.moveCamera({ x = 0, y = 6, z = -10 })
q3d.rotateCamera({ x = -30, y = 0, z = 0 })

-- Enable the main Q3D loop to render/update our world
q3d.activate()

-- And set up some auto camera rotation
local function doCameraRotation()
	q3d.rotateCamera({ y = .005 })
end
timer.performWithDelay(1, doCameraRotation, -1)

I'm tired. I'll tidy up properly later and hopefully squeeze better performance out, but for now I just wanted to post an update.


  • Michael Flad and sporkfin like this

[TOPIC: post.html]
#79

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

Proper off-screen culling now, reducing to an average of 15 faces at any one time (480 poly). Also replaced the timer based rotation with enterFrame. Much smoother results, I think. There's still a noticeable speed increase when only a couple of cubes are on screen compared to when there are a dozen or so, but it's a definite improvement...

 

https://development.qweb.co.uk/q3d-test-3.apk

 

I'm sure I can squeeze more performance out of this somewhere...



[TOPIC: post.html]
#80

Kevin H

[GLOBAL: userInfoPane.html]
Kevin H
  • Contributor

  • 132 posts
  • Corona SDK

I love this project. Amazing work!



[TOPIC: post.html]
#81

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

Thanks Kevin. It's a fun project to work on, I just hope I can squeeze enough out of it to be useful to people...

[TOPIC: post.html]
#82

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 765 posts
  • Corona SDK

Richard, I love this too.  My Samsung S8 is acting up but I'll give the APK a try when I get the issue resolved.



[TOPIC: post.html]
#83

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

Performance still isn't what I want it to be on the S8, but I've a plan for how to make the rendering considerably more efficient. I might not be able to crack on with that until the weekend though.

There's a bug in the above APK too - The culling happens slightly too early on some screens so you can see the faces disappear before they fully leave the screen. That's fixed now, just not in the demo.
  • Michael Flad likes this

[TOPIC: post.html]
#84

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 765 posts
  • Corona SDK

I got it running, that's really cool Richard!  I'm excited to see what comes next.


  • Michael Flad and richard11 like this

[TOPIC: post.html]
#85

vb66r55

[GLOBAL: userInfoPane.html]
vb66r55
  • Enthusiast

  • 67 posts
  • Corona SDK

This is really cool. I want to add some rotatable turrets to my game.
 
It is easy to do in Unity, but Corona is difficult.
 
I sincerely hope that it can be purchased in the near future, even if the price is higher than your other plugins.
 

  • Michael Flad and richard11 like this

[TOPIC: post.html]
#86

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

Thanks. There definitely will be some further development to this, I'm just struggling to squash internal projects in amongst client deadlines at the moment... We're a bit burried by them!

In a nutshell, client work pays the bills so client deadlines take priority. Normally it's client work through the week and internal projects over the weekend, but I just can't sustain that during busier periods.

We've been considering setting up a Patreon profile to help fund some of the non-client work, which would make prioritising them more feasible. The more backers we had, the fewer client projects we'd need to take on and the more important it would be to keep those backers updated and happy. There's still a lot that I'd like to add to Qiso, the 3D engine obviously has some way to go yet before it's complete enough to release, and our Argentauria game is frankly a massive project. I'd absolutely love to be able to give more time and resources to all of these.

That in mind and very cheekily of me I know, if anybody here would consider backing this on Patreon, please do drop me a private message just so that I've got a bit of a head count. I absolutely wouldn't hold anybody to such a promise, I just don't want to set anything up unless there are enough people likely to pledge that it actually makes a difference.

[TOPIC: post.html]
#87

vb66r55

[GLOBAL: userInfoPane.html]
vb66r55
  • Enthusiast

  • 67 posts
  • Corona SDK

Sounds pretty good, although I'm not sure what others think, but as far as I am concerned, I also spend some money on Patreon so that the other party will give me some practical small scripts for Unity (after all, unity is not my main tool )

 

If I can use donate to get some simple control script(move and rotation) of some 3D objects (The objects can with textures and materials), then I will be very interested.


  • richard11 likes this

[TOPIC: post.html]
#88

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

The engine still only has cubes built in, but eventually you'd be able to import .obj files which I believe most 3D software is able to export to. The renderer is actually already capable of pumping out any shape you give it, I just never got around to adding vertex maps for anything other than cubes, or building an importer.

 

Two important things to note though:

 

Firstly, performance. The cubes I've been playing with to date consist 32 triangles per face (more vertices = more accurate texture mapping), so in the lastest demo apk in this thread, it's rendering about 480 triangles at once and although there's still optimisations that can be made to how all of this works, I do think we're pushing Corona to its limits a little with this, given it's still as far as I'm aware creating single threaded binaries. I've tested on various devices and wouldn't currently like to throw any more vertices in there. Engines like Unity are able to make use of hardware capabilities that this engine just doesn't have access to, so keeping the screen below about 500 poly renders is definitely key. Point being, if you created a complex model and exported to .obj, the engine would be able to load that in to internal vertex maps no problem, but even without anything else on screen, this complex object might just be too high of a poly count to rotate/move/scale around smoothly.

 

Secondly, I'm still in two minds about the feasibility of implementing intersecting faces. I.e. if you positioned two objects in a way where you'd expect them to fuse together, currently what you'd actually see is the face of one object fully rendered over the top of the faces of the other object. The engine just doesn't yet handle individual pixel depths so doesn't know that "this part of face A wants to be behind face B, but this other part of face A wants to be in front". It's a performance thing again - we're already pushing Corona quite a bit to do this.

 

If your game isn't likely to ever have two models trying to use up the same x,y,z position, and you're not planning to show too many faces at once (hidden faces are already ignored and don't contribute to polygon counts during the render), then this should be a useful engine for you =).


  • vb66r55 likes this

[TOPIC: post.html]
#89

vb66r55

[GLOBAL: userInfoPane.html]
vb66r55
  • Enthusiast

  • 67 posts
  • Corona SDK

That's it.
However, the models with less than 500 triangles are basically too simple shapes.
 
I bought many models, one of which has more than 18,000 triangles (although I let it actions and effects in the unity to catch frame use), but even the lowpoly turret model has 800 Multiple triangles ...
 
It seems that there is still a long way to go, especially if the files exported from blender are not processed by lighting, it will not look very good.
 
Do you think Corona has a way to achieve the lighting of 3D objects?


[TOPIC: post.html]
#90

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

Ambient lighting is already in place. You set a direction and an amount and this controls how individual faces are lit. You can see this in action here: https://youtu.be/O4-dgfAVXpU

Positioned lighting is planned but not yet in place.

18,000 poly models are likely to be too detailed I'm afraid, but 800 is probably fine. Bear in mind that the engine never has to render all of those triangles - with a cube for example, it's impossible to see more than 3 faces at any one time, so an 800 poly cube would actually be a 400 poly render at most.
  • vb66r55 likes this

[TOPIC: post.html]
#91

vb66r55

[GLOBAL: userInfoPane.html]
vb66r55
  • Enthusiast

  • 67 posts
  • Corona SDK

I've been busy making effects in Unity recently, constantly switching between unity and corona, and finally have some time to follow the forum.
 
This looks awesome, and it seems that the color of the ambient light can also be modified?
 
Also a little curious, can Corona only import obj and not fbx?
 
After all, obj cannot have animation. :o
 
But if it is a pure model, I really hope to import about 2000 polygon models.
 
No matter what, this plugin will definitely be bought if it is launched. :D


[TOPIC: post.html]
#92

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 527 posts
  • Corona SDK

It's not a Corona limitation as such. Just that .obj files are plain text and reasonably documented so an importer can be built around them fairly easily, and most modelling software can export to them. I'd be happy to look at importing other formats too if the initial release gains traction.

Importing 2000 models would be an interesting test. Currently the way world's are set up isn't particularly optimised, but the goal is to have them work much like in Qiso, where everything outside of screen space is ignored so as long as you're not trying to actually display them all at once, it should just be a case of the device needing enough memory to store that much data at once.

The trick, in case interested, is arrays. Rather than iterating the entire world of data to look for elements that fit within the screen boundaries, my engines structure everything into arrays and then just reverse each screen corner to really quickly figure out which part of the arrays need iterating for on-screen content. That way it doesn't matter how large the arrays get, their size doesn't impact on the rendering performance. How much is actually on screen at the same time does, but not how big the world itself is.
  • vb66r55 likes this

[TOPIC: post.html]
#93

marcelopotty0

[GLOBAL: userInfoPane.html]
marcelopotty0
  • Observer

  • 12 posts
  • Corona SDK

I would love to see a 3D Corona engine! I've tried with some engines, and by far Corona is my favorite because it is lite, very fast, and lua is easy to use. And it would be awesome to see those features in a 3D engine.


  • richard11 likes this


[topic_controls]
« Page 4 of 4 2 3 4
 
[/topic_controls]