-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vertices are all over the place #91
Comments
Hi Alo! That's an interesting project! It will take me a few days before I can look into this, would you mind sharing a video exposing the problem? Also, the OpenGL module that you added in your branch, does it work fine on the desktop? (just asking if there could be errors in it) |
Sure, here's the game running on Dolphin 2024-12-09.20-37-28-00.00.01.145-00.01.14.652.mp4
Yeah, it was taken from another port and I tested it before on my PC and using Mesa software render on a VM. |
Wow, that's amazing! Good job! I tested it locally, and it works better than in your video :-) The vertices are still all over the place, but the issue with the screen being half black is fixed. Did you try on a real wii? (I'll try myself soon!) Note that opengx requires a couple of Dolphin settings in order to work properly (I should actually document them in the readme...):
In the "Graphics -> Enhancements" page I've also per-pixel lighting enabled, though I'm not sure whether it's needed. The vertex issue seems due to clipping, it looks like not all polygons are drawn, so you can see the things behind them. I suspect the near clipping plane is computed wrong, I'll try to play with it. |
OK, to fix the initialization issue and get the game to run on a Wii, I did: diff --git a/Makefile b/Makefile
index c115f5a..7cdafa0 100644
--- a/Makefile
+++ b/Makefile
@@ -509,7 +509,7 @@ ifeq ($(TARGET_GX),1)
endif
ifeq ($(ENABLE_OPENGX),1)
PLATFORM_CFLAGS := $(MACHDEP) -DTARGET_GX -DENABLE_OPENGX -fomit-frame-pointer -fno-strict-aliasing -I$(LIBOGC)/include -I$(PORTLIBS)/include
- PLATFORM_LDFLAGS += $(MACHDEP) -L$(PORTLIBS)/lib -lopengx -lSDL2 -L$(LIBOGC)/lib/$(GX_PLATFORM) -g -lm -lasnd -laesnd -lfat $(WII_LIBS) -logc
+ PLATFORM_LDFLAGS += $(MACHDEP) -L$(PORTLIBS)/lib -lopengx -lSDL2 -lSDL2main -L$(LIBOGC)/lib/$(GX_PLATFORM) -g -lm -lasnd -laesnd -lfat $(WII_LIBS) -logc
else
PLATFORM_CFLAGS := $(MACHDEP) -DTARGET_GX -fomit-frame-pointer -fno-strict-aliasing -I$(LIBOGC)/include
PLATFORM_LDFLAGS := $(MACHDEP) -L$(LIBOGC)/lib/$(GX_PLATFORM) -g -lm -lasnd $(WII_LIBS) -lfat -logc
diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c
index b570fd1..79d3f26 100644
--- a/src/pc/pc_main.c
+++ b/src/pc/pc_main.c
@@ -22,6 +22,7 @@
#include "gfx/gfx_gx_wm.h"
#include "gfx/gfx_gx.h"
#endif
+#include <SDL2/SDL.h>
#include "audio/audio_api.h"
#include "audio/audio_wasapi.h" I don't think it's correct to include SDL.h from pc_main.c, it probably needs to be done from some other include file, but this works too :-) |
I have a branch with a proper implementation of glScissors, but it doesn't help with the exploding vertices. I also tried to forcefully enable and disable clipping, to play with the nar/far clipping planes, etc., but nothing helps. I noticed that when the sandy floor gets visible, the texture on it appears to be stretched and as if its texture coordinates are changing rapidly. I suspect that it may be an issue of vertex coordinates being invalid, and that they get properly culled or clamped by a compliant OpenGL implementation, whereas opengx doesn't handle them correctly. But I'm still investigating (and soon running out of ideas). It might also be some rounding issue, since I see that these defects tend to appear on triangles being located quite near the camera field. |
Hi @AloXado320, I've build the Linux OpenGL legacy version and I'm comparing the vertices being sent for drawing. They are different, so it looks like there is some error somewhere else in the code. I noticed that on the Wii version some vertices are being draw with a clipped value of diff --git a/src/pc/gfx/gfx_opengl_legacy.c b/src/pc/gfx/gfx_opengl_legacy.c
index 92d398e..e458600 100644
--- a/src/pc/gfx/gfx_opengl_legacy.c
+++ b/src/pc/gfx/gfx_opengl_legacy.c
@@ -475,6 +475,16 @@ static void gfx_opengl_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_
cur_buf_num_tris = buf_vbo_num_tris;
cur_buf_stride = cur_buf_size / (3 * cur_buf_num_tris);
+ {
+ fprintf(stderr, "gfx_opengl_pass_mix_texture %d triangles\n", cur_buf_num_tris);
+ float *ptr = cur_buf;
+ for (int i = 0; i < cur_buf_num_tris * 3; i++) {
+ float z = ptr[2] / ptr[3];
+ if (z < -1.0 || z > 1.0)
+ fprintf(stderr, " %f %f %f %f\n", ptr[0], ptr[1], ptr[2], ptr[3]);
+ ptr += cur_buf_stride / sizeof(float);
+ }
+ }
gfx_opengl_apply_shader(cur_shader);
// if there's two textures, set primary texture first I applied the same patch both to the Linux and to the Wii version, and the results are different: on Linux, the
|
My advice: try fixing your branch so that it can also be built on Linux, so that we can be 100% sure that the vertices passed to opengx are the same. Unfortunately, your tree is quite different from the DOS port you linked above, and I suspect that the bug is hidden in some of the changes. If you managed to build your branch for Linux, then it would be much easier to compare. |
Will try on Windows, WSL2 and Dolphin. |
@mardy Linux should build now using |
Thanks @AloXado320, I can see that manual clipping helps a lot in restoring the missing polygons, and also removes some of the undesired polygons, but it's still not perfect (though, looking at the code, I cannot really find anything wrong with it): there are still cases left where I will also try to understand if this is a temporary workaround, or if it's required because of a limitation of the GX processor: I suspect that if all vertexes of a triangle are well outside of the viewport (but on opposite sides, meaning that we have a very big triangle that stretches all over the viewport), the GX clipping algorithm might not detect it and discard it completely; this would explain why the manual clipping helps. I'll do some tests on a simpler program to understand if this is the case. A handful of other issues I noticed:
|
@mardy Wow, GX has some odd things going on it's scary, makes me wonder if other ports could potentially have the same matrix issue to workaround it. I enabled gamecube controllers because I was thinking on how to use them together with wii controllers like in some games, I could use SDL2 controllers but I prefer to use native functions to use their exclusive features, I'll keep that in mind though. I was also thinking of using SDL2 audio, though when I tried to use it there was some loud static noise, I could be missing something. |
@AloXado320 What I wrote above about clipping is just a theory of mine, and I'm not sure it's correct. I ran a quick test, modifying the triangle.c file in the wii-examples repository, and at a first sight GX behaves correctly. I need to look deeper into this. I figured out where the error with software clipping is: it's not in the functions for manual clipping, but in the place where we set the clipping flags: the code does not take into account the fact that diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c
index d50ebb1..462d7df 100644
--- a/src/pc/gfx/gfx_pc.c
+++ b/src/pc/gfx/gfx_pc.c
@@ -42,7 +42,7 @@
// Used on DOS and PS2 port, more or less a "temporary" workaround if enabled.
#ifdef TARGET_GX
// do manual clipping
-//#define GFX_MANUAL_CLIPPING 1
+#define GFX_MANUAL_CLIPPING 1
#endif
union RGBA {
@@ -691,8 +691,8 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti
if (x > w) d->clip_rej |= 2;
if (y < -w) d->clip_rej |= 4;
if (y > w) d->clip_rej |= 8;
- if (z < -w) d->clip_rej |= 16;
- if (z > w) d->clip_rej |= 32;
+ if (z/w < -1.0) d->clip_rej |= 16;
+ if (z/w > 1.0) d->clip_rej |= 32;
d->x = x;
d->y = y; Indeed, all the other As for the glPolygonOffset problem, I see that the OpenGL legacy driver has a check for the |
OK, I've now verified that if I set the othogonal projection matrix fields to be:
then the clipping is all right and manual clipping is not needed. But I still have to figure out how/why this works. :-) UPDATE: but indeed, these are also the values set by opengx. I got confused by my own changes when debugging the code. What is interesting here, is that indeed the software clipping is not needed, but what is needed is the fix from my previous comment about the negative |
Bug Report
What's the issue you encountered?
I tried to update an unfinished port of GC/Wii of SM64 due to lack of GX knowledge using a legacy OpenGL render and SDL2.
Though there's a warning in Dolphin, the game seems to render with some problems, like half of screen is filled with a black boxand most notably, there are a lot of vertex explosions and it's more noticeable when the camera is upclose.How can the issue be reproduced?
Compile the Wii port on my repo https://github.com/AloXado320/sm64-port/tree/gc_wii
make -j4 TARGET_WII=1 ENABLE_OPENGX=1
Instructions should be the same as the sm64 decomp project.
Environment?
I'm using Windows 11 using WSL2 Ubuntu, I compiled latest opengx since the one on devkitpro's package is outdated.
Additional context?
[N/A]
The text was updated successfully, but these errors were encountered: