Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
What about some basic 3D support in Gideros ? - Gideros Forum

What about some basic 3D support in Gideros ?

hgy29hgy29 Maintainer
edited February 2015 in Suggestions & requests
Hi Gideros maintainers,

This is something that may have been discussed before, and yes I know that Gideros in mainly a 2D engine, but there are a few situations where minimalistic 3D support would have been handy (Star wars like effect for which a posted a solution was one of them).

I may not be very well documented on OpenGL (I coded a 3D engine with OpenGL ten years ago, but didn't touched OpenGL beside that), but it seems to me that implementing 3D would just be a matter of using:
 glVertexPointer(<strong>3</strong>, GL_FLOAT, 0, &vertices_[0]);
instead of:
 glVertexPointer(2, GL_FLOAT, 0, &vertices_[0]);
in gideros/gmesh.cpp, thus allowing a Z coordinate in Mesh object, and of course configuring a perspective transform matrix during init and clearing the depth buffer on every frame rendering...

It doesn't look like a huge modification at first, and while I am figuring out how to compile gideros from sources myself to try this, I would like to know your opinions about this.

What do you think ?
+1 -1 (+2 / -0 ) Share on Facebook

Comments

  • jdbcjdbc Member
    edited February 2015
    I recommend you to use another framework than Gideros if you are planning to develop a 3D game as Unity3D, libGDX or Gameplay.

    Therefore I guess it is more complicated than change a simple C++ class to support 3D in Gideros.
  • Maybe jdbc is right, anyway since you're good with meshes ;) and you're asking for "basic 3d stuff" there is a raycasting test project here:
    http://giderosmobile.com/forum/discussion/2100/raycasting-engine-3d-object-engine-release-by-biorhythmgames/p1
  • hgy29hgy29 Maintainer
    @jdbc, I have no particular plan to develop a 3D game. To be clear I am not asking this for myself, but merely as a generic topic since while digging in this forum I found people coding 'rotating cubes' in Gideros and other 3D related questions, which let me think that the matter may not be as off-topic as you suggest.
    Whatever, I will try myself and see wether it is actually complicated or not :)
  • I think it woudl be very useful - a mix of 3D and 2D works well. We would need a 4x4 matrix variation though. You need to speak to @john26 about it as he also had some ideas on 3D when I met up with him in London a few weeks ago.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • hgy29hgy29 Maintainer
    @pie, I saw this raycasting project already, and according to the comments about it, it looks like many gideros users indeed like the idea. So why not a native, more efficient way... From my past experience, 3D in OpenGL is not that complex to implement and may be worth a try.
  • @hgy29 any improvement to gideros is welcome on my side :) but I know nothing about 3d and its implications.

    I'd say to wait for @john26 and @marcelojunior to achieve their (our) big goal first :) and then add more cross-platform native features ;)

    Maybe could be worth to have a community "suggested features" system, where we all could post and vote for future developments - and willing people could pick them up to start other kickstarter projects.. ;)
  • hgy29hgy29 Maintainer
    To keep you all updated: I spent a few hours during the last three days to slightly modify a few .cpp/.h in Gideros in my attempt to add limited 3D support. I struggled a bit with compiling gideros at first, and replacing orthographic projection with a properly aligned perspective one in a second time, but at last it works! And even better, my changes don't break compatibility in the regular API.

    With my modification, Mesh now accept a boolean in the constructor to specify wether coordinates are to be handled as 3D or 2D, and the Z coordinate can be passed in vertices manipulation functions from lua.

    This is not full blown 3D support: no shadows, no lighting, no depth test (yet...), no 3D transforms (yet!), but I already can think of a few effects that become possible thanks to this even in 2D games:
    - flipping a card with real perpsective effect
    - spinning dice
    - the start wars effect becomes straight forward

    While I am at it, it will still go on working on this to add at least depth buffer checking and if possible 3d transforms.
    BTW, I came accross an way to implement clipping/masking using stencil buffers quite easily. I will have a try at this also..

    Likes: john26

    +1 -1 (+1 / -0 ) Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited February 2015
    @hgy29 That sounds great! :)

    Are you going to somehow push your changes to the liberton version of gideros that is being worked on?

    Is there any speed change with normal 2D - does it go slower or is there no difference?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • hgy29hgy29 Maintainer
    @SinisterSoft, Thanks :)

    I did not see any performance degradation, and currently it has only been tested with gideros player.

    I am currently setting up my own gideros repository, a fork of the main (not Liberton) gideros repo. I don't want to interfere with @john26 and @marcelojunior work for now.
    Of course at some point in the future my changes could be merged in the main repository if appropriate.
    +1 -1 (+2 / -0 ) Share on Facebook
  • nice addition, should be merged, and all this open-source possibilities are interesting, just one should be careful about maintaining a clean and logical api when adding new features.
  • @hgy29 that's good to hear! :)
  • john26john26 Maintainer
    This is great and very impressive @hgy29. Please make pull request when you are ready. You are right to make the pull request to gideros/gideros. We will do the same with the Win8/desktop stuff when ready.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    Thanks @john26, It still need some testing/polishing, but I am getting very close :)
    +1 -1 (+4 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    A little update on my project: I've implemented 4x4 transform matrix and added Z coordinate to Sprite.setXXX functions, and enabled depth buffer testing (not yet tested). I was happy about all of these until I tried to compile for android: OpenGLES 1.0 doesn't seem to like depth buffer, which limits the use of 3D...

    So I decided to switch OpenGL 1 support for OpenGL ES 2. It is been a complex work but I believe all is working again like it should. I've tested my changes on a few games of mine using GiderodPlayer for Windows and all seems ok. I've not yet tested with android, but at least now the code compiles without complaining for OpenGL missing functions.

    For those who can compile gideros and are interested in testing, my repo is https://github.com/hgy29/gideros/tree/hgy29 (branch hgy29).

    Current features are:
    - Support 3D meshes (boolean value added to Mesh constructor specifying wether its 3D or not)
    - Support for 3D transforms (setZ, scaleZ, rotationX,rotationY and so on added to Sprite API), works on all sprites not only meshes
    - Support for enabling perspective projection in the scene by application:setFieldOfView(angle), angle=0 to keep ortho projection.
    - Default vertex shader and fragment shader to mimic previous implementation
    - Depth buffer enabled on 3D meshes only

    To come:
    - Clipping/Masking thanks to stencil buffer ops





    +1 -1 (+3 / -0 ) Share on Facebook
  • @hgy29 This all sounds great. It would be good if somehow your changes were added so that they could be implimented also in the new desktop versions...
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • piepie Member
    Thank you @hgy29, for opening a gate to a new dimension! =D>

    +1 -1 (+2 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    Hi folks, at last I'm finished with 3D implementation and testing on all devices that I have access to. I've created a pull request for my changes. Here are what I've done:

    These changes introduce basic 3D support in meshes and frustum setting.
    This worked imposed some heavy changes in core Gideros graphics:

    Switch to OpenGL ES 2.0 programmable pipeline instead of OpenGL 1.1 fixed pipeline. Right now shaders are set up to mimic fixed pipeline behavior as used by gideros
    Implements 3D matrix transforms (i.e. 4x4 matrices), and add related API calls in Sprite class
    Add frustum setting API in Application class to enable perspective projection
    Add depth buffer setting and checking, and setup stencil buffers for future masking (or shading) option.
    Add a 3D parameter on mesh objetcs, merely specifying if vertex take two or three coordinates

    Note: I've currently tested the changes againts Windows gideros player, two different android devices, an iPhone 6. I am fairly confident that everything should work smoothly on all iOS devices starting from iPhone 3GS (won't work for earlier phones), and they should work on most recent android devices (theoretically starting from Froyo). I couldn't compile gideros player for macos yet, but since it is based on Qt things should be ok, however testing is really needed.

    Likes: pie, SinisterSoft

    +1 -1 (+2 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    A little teasing :) 3D horse model rendered (and animated) with Gideros.
    Model grabbed here: http://tf3dm.com/3d-model/horse-39028.html, file is .obj and is parsed completely in lua. Loading takes a fraction of second and animation is smooth.

    Likes: SinisterSoft, jdbc, pie

    HorseGideros.png
    818 x 687 - 75K
    +1 -1 (+3 / -0 ) Share on Facebook
  • Do sprites take a 3rd dimension? eg: setPosition(x,y,z)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • these look great.
    indeed just placing 2d objects into 3d space and moving the camera on them gives a lot of new opportunities already.
  • hgy29hgy29 Maintainer
    @SinisterSoft, yes sprites will accept a third dimension in positioning and scaling, and two more axis of rotation (X and Y, while we already rotate around Z in 2D).
    I don't think that camera will be positionnable, because it will break pure 2D stuff, but the 3D scene could be moved around to achieve the same result.

    Also, in order to avoid breaking 2D, depth testing (i.e., not rendering shapes behind already drawn ones), is only activated for 3D meshes.

    Another point to be aware of is that Sprite:hitTest and alike functions won't work if Sprite Z coordinate is not 0 (because of perspective frustum, X & Y coordinates on screen depends on the Z coordinate also). This could be sorted out, but I'd rather wait that community validate current changes before going on.

    Also, I found that now the GLES 2.0 stuff is done, advanced 3D rendering becomes possible: adding normal array, bump map, and lighting is quite an easy task.
    +1 -1 (+3 / -0 ) Share on Facebook
  • Great contribution @hgy29 . this is the exact reason why i like opensource .
    This new functionality will surely bring a whole new dimension to Gideros . Literally and practically :D

    Really great job =D>
  • SinisterSoftSinisterSoft Maintainer
    edited March 2015
    It would be great if there could be a mode/way where the Z would affect the draw order - so you could put the the -y position into z to draw based on their position down the screen (so sprites would be drawn behind sprites who's y was lower down on the screen) - z sorting? (but the size not be affected)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.