Pages: 1
  Print  
Author Topic: Isometric projection in 3D  (Read 243 times)
Offline (Unknown gender) impo
Posted on: February 23, 2019, 07:52:05 PM
Member
Joined: Feb 2019
Posts: 16

View Profile
Enigma has  few d3d functions unfamiliar to GM users, so I thought it would be useful to make an example of using undocumented EDL's d3d stuff and learn them out on the way

I started with d3d_set_projection_ortho_lookat, and  made an isometric camera projection with it (attachment1). there were few problems though. while using this function, the game still assumes that the actual coordinates of the camera remain at zero, so camera-position-dependent things like culling and fog are broken. are there ways to fix this?


for sure there are more optimal ways to render 3d scenes in isometrical projection in Enigma, however i couldn't get functions like d3d_set_perspective to work, perhaps projection matrix would work faster? what's actually the most computationally effective way in enigma to make isometric (or any other orthographic) projection in 3d?
« Last Edit: February 25, 2019, 03:13:06 PM by impo » Logged
Offline (Male) Goombert
Reply #1 Posted on: February 23, 2019, 11:44:25 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3151

View Profile
Hi again impo! I have to say I was happy to hear of your development with this as it seems to be a positive side effect of the matrix cleanup we did. What's even better is that to fix it, it only needs tweaked in a single location for all the graphics systems.
https://github.com/enigma-dev/enigma-dev/blob/5317421ad4aa3ac38d3e6e99515c993ccfa04320/ENIGMAsystem/SHELL/Graphics_Systems/General/GSmatrix.cpp#L245

If you could be more specific about how you think it should be changed to improve it, I would love to hear it and consider adding it to the official ENIGMA. Also, please try running your game in Direct3D systems and let us know if that produces different results with respect to the fog or lighting.

Quote from: impo
however i couldn't get functions like d3d_set_perspective to work
This particular function I'd like to comment on. This is actually a tricky to understand function due to its poor documentation in GM's original manual. And through API traces I can confirm that its behavior is the same in ENIGMA as it is in GM. Basically, the way it works is that GM resets the projection automatically at the beginning of each screen redraw. If 3D mode was turned on and perspective is enabled (default is on) then it will set a perspective projection, otherwise an orthographic one. You can see several of the pull requests below where I tested and confirmed the behavior of these functions for consistency.
https://github.com/enigma-dev/enigma-dev/pull/1528
https://github.com/enigma-dev/enigma-dev/pull/1396
https://github.com/enigma-dev/enigma-dev/pull/1388

You'll notice that 1528 was merged just 21 days ago, if you setup ENIGMA before that, you might want to consider updating.

Quote from: impo
perhaps projection matrix would work faster?
I am not sure if I understand this question. I have added the GMSv1.4 and GMS2 matrix_* family of functions to ENIGMA, though they are untested. Feel free to be the first person to give them a try.
https://github.com/enigma-dev/enigma-dev/blob/5317421ad4aa3ac38d3e6e99515c993ccfa04320/ENIGMAsystem/SHELL/Graphics_Systems/General/GSmatrix.h#L34

Quote from: impo
what's actually the most computationally effective way in enigma to make isometric (or any other orthographic) projection in 3d?
The way that you are doing it now basically. I have done a lot of benchmarking to ENIGMA's graphics such that you don't need to worry about it, and I have posted these benchmarks publicly on the GitHub repo on my various pull requests. ENIGMA, as a game engine, handles matrices in a very standard way that's not only compatible with GM but just as performant. Going even further, OpenGL Mathematics (GLM) is the dependency we use for the matrix computations and it uses SIMD and compiler intrinsics for optimization.
« Last Edit: February 23, 2019, 11:53:01 PM by Goombert » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) hpg678
Reply #2 Posted on: February 24, 2019, 12:01:17 AM

Member
Location: Barbados
Joined: Mar 2017
Posts: 259

View Profile Email
this looks really fantastic!


 :dance: :dance: :dance:
Logged
Hugar
Offline (Unknown gender) impo
Reply #3 Posted on: February 24, 2019, 10:36:50 PM
Member
Joined: Feb 2019
Posts: 16

View Profile
just figured out that culling and z-depth work perfectly fine with d3d_set_projection_ortho_lookat. it's just fog that is always calculated from 0;0;0

here you can see culling in action


and here's fog with lighting


please try running your game in Direct3D systems and let us know if that produces different results with respect to the fog or lighting.

here's comparison between different systems


opengl1.1 works well, except for  lighting looking inverted relative to the light source. i also couldn't get the other EDL's light functions to work (related to specular  lighting)
opengl3.3 has no fog, also broken transperancy
directx11 has no light/fog, problems with h/vrepeat and whatnot. opengl 1.1 actually has problems with that as well, texture hrepeat/vrepeat didn't work on cube primitive (but worked on floor)
directx9 just renders a single triangle.. lol. whatever i try to change, it still shows a triangle. directx9 worked fine in other tests as far as I remember, might be a problem with d3d_set_projection_ortho_lookat, i'll probably do some other tests on that


GM resets the projection automatically at the beginning of each screen redraw. If 3D mode was turned on and perspective is enabled (default is on) then it will set a perspective projection, otherwise an orthographic one
yeah i know, I tried to turn off the perspective before each draw event, with different projections, angles etc, but it just didnt seem to work

(GLM) is the dependency we use for the matrix computations and it uses SIMD and compiler intrinsics for optimization
that's great, alot of potential. i want to make some advanced stuff just for the sake of kicking game maker's ass
« Last Edit: February 25, 2019, 03:12:51 PM by impo » Logged
Offline (Male) Goombert
Reply #4 Posted on: February 25, 2019, 12:21:46 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3151

View Profile
Ok, that's good now I think you are still on an outdated version. Several of the issues/differences left that you are showing me here seem to be issues I have just fixed within the last month. So I would like you to update ENIGMA and see what the differences are then.

Here's the commands you can use to update your copy of ENIGMA if you don't want to do the entire installation over again. Just start the MSYS2 shell that you launch LateralGM from and make sure you are in your cloned enigma-dev directory.
Code: (Bash) [Select]
git pull
make clean
make -j4

NOTE: Here's a small tip, you can use [img width=300]http://url[/img] to give your images a custom width so this topic is easier to navigate. Our forum has built-in support so that left clicking the image will increase it in size.

Quote from: impo
opengl1.1 works well, except for  lighting looking inverted relative to the light source. i also couldn't get the other EDL's light functions to work (related to specular  lighting)
This is either the lighting normals in some of our shape functions or an issue with the fact that GL1 lighting is computed in eye space. I am leaning towards the former and haven't had time to look at the shape functions, since they've been deduplicated, and make the normals 100% like GM.

Quote from: impo
opengl3.3 has no fog, also broken transperancy
We are aware that this system's shader lacks fog support. Our shader in this system might also either lack vertex transparency or the blend states are configured incorrectly.

Quote from: impo
directx11 has no light/fog, problems with h/vrepeat and whatnot. opengl 1.1 actually has problems with that as well, texture hrepeat/vrepeat didn't work on cube primitive (but worked on floor)
This system is the same story as GL3 and we are aware there's no lighting and fog support in its default shader yet (I have yet to write it). Texture repetition issues has to do with texture state issues.
https://github.com/enigma-dev/enigma-dev/pull/1497
The GL1 issue with texture repetition problem is a new one I discovered recently that will also need to be solved.

Quote from: impo
directx9 just renders a single triangle.. lol. whatever i try to change, it still shows a triangle. directx9 worked fine in other tests as far as I remember, might be a problem with d3d_set_projection_ortho_lookat, i'll probably do some other tests on that
I am like 90% certain the issue is the lighting material, and I have fixed it in master. It also caused Project Mario not to draw anything, and this is why I would like you to update and try again.
https://github.com/enigma-dev/enigma-dev/pull/1530

Quote from: impo
yeah i know, I tried to turn off the perspective before each draw event, with different projections, angles etc, but it just didnt seem to work
It won't render anything because you have an outdated ENIGMA. You need to upgrade so that you have my perspective fixes.
https://github.com/enigma-dev/enigma-dev/pull/1528

Quote from: impo
that's great, alot of potential. i want to make some advanced stuff just for the sake of kicking game maker's ass
Sure, I was interested to see what you did here because I for a while wanted an isometric projection function in ENIGMA, but I did not know that we already had it. It was originally added by TheExDeus and I decided to keep it when I switched us to GLM and cleaned up all of the duplicate matrix code we had. So this is good, I am happy that it works and might want to use it to make a game myself.
« Last Edit: February 25, 2019, 12:28:40 PM by Goombert » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) impo
Reply #5 Posted on: February 25, 2019, 09:06:03 PM
Member
Joined: Feb 2019
Posts: 16

View Profile
Here's the commands you can use to update your copy of ENIGMA
nice, thanks. i just checked and I had enigma version from feb 7th, i just updated anyway

Quote from: impo
directx9 just renders a single triangle.. lol. whatever i try to change, it still shows a triangle. directx9 worked fine in other tests as far as I remember, might be a problem with d3d_set_projection_ortho_lookat, i'll probably do some other tests on that
I am like 90% certain the issue is the lighting material, and I have fixed it in master. It also caused Project Mario not to draw anything, and this is why I would like you to update and try again.
the problem is actually with how d3d_set_projection_ortho_lookat works. it looks like directx9 has a default znear distance assigned to the camera. so this cuts off the graphics except for one lucky triangle that remains from d3d floor. and although changing  x, y, width and height in d3d_set_projection_ortho_lookat doesn't move znear position, you can rotate the camera to change the znear angle.
so i got something like this:


ive made a huge 200000x200000 d3d_floor  to further test this theory and got zfar level displayed as well, the floor is cropped on the both sides now:


since fog basically acts the same, we can achieve simillar to znear/zfar effect in opengl. rotating the camera makes the fog move just like the znear/zfar distance in the screen above since both always drawn parallel to camera.



 i also tested project mario in dx9 and it works just fine 

It won't render anything because you have an outdated ENIGMA. You need to upgrade so that you have my perspective fixes.
the biggest problem with d3d_set_perspective is that i'm too lazy to try to make it work, especially when d3d_set_projection_ortho_lookat is somewhat working. it feels like d3d_set_perspective was just duct taped to gm one day before it's realease, i haven't seen anyone using it or getting it to work
« Last Edit: February 25, 2019, 09:21:28 PM by impo » Logged
Offline (Unknown gender) impo
Reply #6 Posted on: February 26, 2019, 11:12:39 PM
Member
Joined: Feb 2019
Posts: 16

View Profile
ok update, i just fixed all the problems i had with this example.
  • the fog works just fine
  • no znear problem in d3d9, the camera cuts the scene exactly where it needs to
  • i also wrote the conversion of the 2d position of the mouse into an orthographic three-dimensional projection, and tied it to the movement and selection of objects, maybe someone will find it useful
everything works like a charm now except for few problems with enigma
i noticed that the lighting is actually perfectly superimposed on the ellipsoid primitive. so the problem with lighting is most likely shape functions. the problem with d3d_set_projection_ortho_lookat was my fault. drawing 2d primitives like draw_circle doesnt work in 3d with d3d_set_culling on, however, im not sure if its because of the function itself, or because i "inverted" all the other primitives altogether with camera
Logged
Offline (Male) hpg678
Reply #7 Posted on: February 27, 2019, 01:35:11 AM

Member
Location: Barbados
Joined: Mar 2017
Posts: 259

View Profile Email
this was fantastic. i even got it to work on OpenGL 3.3. not sure but it showing kinda dark, should it be so or do i need to tweak it?

Logged
Hugar
Offline (Unknown gender) impo
Reply #8 Posted on: February 27, 2019, 09:58:41 PM
Member
Joined: Feb 2019
Posts: 16

View Profile
this was fantastic. i even got it to work on OpenGL 3.3. not sure but it showing kinda dark, should it be so or do i need to tweak it?
well the difference between gl3.3 and 1.1 is that there's still no fog support in 3.3, so without light source, fog-colored vertices in 1.1 will remain dark in 3.3. the lighting behaves differently in 3.3 too though
Logged
Offline (Male) Goombert
Reply #9 Posted on: March 09, 2019, 02:29:04 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3151

View Profile
As someone who worked on aspects of this internally along with Harri, who wrote the GL3.3 shader, I can say that the explanation impo gave to Hugar there is accurate. Further, I am also aware from talking with Hugar that his OpenGL drivers seem to have some issues (e.g, can't enable per-pixel fog in GL1.1; and we tried lots of stuff) so this could be compounding any rendering differences he has from the rest of us.
« Last Edit: March 09, 2019, 02:31:39 PM by Goombert » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: 1
  Print