Skip to content
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

Mech and Vehicle models replicated on screen #19

Open
igough opened this issue Jan 20, 2024 · 5 comments
Open

Mech and Vehicle models replicated on screen #19

igough opened this issue Jan 20, 2024 · 5 comments

Comments

@igough
Copy link

igough commented Jan 20, 2024

OS: Linux
GPU: AMD Radeon RX 6700, resolution 3440x1440

I eventually got the code built and all of the missing assets figured out, but all Mech and Vehicle models are rendered twice with the duplicate being to the right of the actual object as shown below.

Screenshot from 2024-01-20 11-08-19

In issue 15 you say "They are doubled because I have 2 different draw paths in the code" and "It should be easy to disable it." Without additional info I thought that the issue might be associated with g_debug_draw_calls in GameOS/gameos/gameos_graphics_debug.cpp, but that proved false. If you can give me a clue as to which file I should look in I will attempt to fix it.

@ktamail666
Copy link

I also experienced this issue there's a part in the code where it renders the model one more time with +100 pixels.

In shader "gos_tex_vertex_lighted.vert"
replace from
p.x = (p.x * rhw) * vp.z + vp.x + 100.0;
to
p.x = (p.x * rhw) * vp.z + vp.x;

this is a workaround, but probably rendering happens two times same position.

@igough
Copy link
Author

igough commented Jan 23, 2024

Thanks a lot for the workaround. Indeed that resulted in only one model being visible.

this is a workaround, but probably rendering happens two times same position

I agree. Unfortunately, shader coding is not part of my existing skill set, so I will read up on enough info to determine what exactly is happening here to come up with a proper fix.

@igough
Copy link
Author

igough commented Jan 25, 2024

In mclib/tgl.cpp, within TG_Shape::MultiTransformShape, some objects are being put onto 2 separate lists for rendering. Line 2453

mcTextureManager->addTriangle(theShape->listOfTextures[theShape->listOfTypeTriangles[j].localTextureHandle].mcTextureNodeIndex,MC2_DRAWSOLID | addFlags);

puts the object vertex data into

masterTextureNodes[nodeId].vertexData (in mclib/txmmgr.h).

Line 2492

mcTextureManager->addRenderShape(theShape->listOfTextures[theShape->listOfTypeTriangles[0].localTextureHandle].mcTextureNodeIndex, MC2_DRAWSOLID | addFlags);

puts the object vertex data into

masterTextureNodes[nodeId].hardwareVertexData.

For Mechs and likely other objects, both addTriangle and addRenderShape are being called. The data in vertexData is rendered one way (possibly a non-tex shader?) and the data in hardwareVertexData is rendered using the shader in shaders/gos_tex_vertex_lighted.vert. Since the shader in gos_tex_vertex_lighted.vert offsets the render by +100 in the x direction, this causes the model to be rendered in 2 different locations, one by the first mechanism and one by the second. So removing the +100 offset in the shader causes the 2 renders to perfectly overlap each other but is not particularly efficient. Possibly work was being done to change from one rendering mechanism to another and the work was interrupted before being completed.

Also, there looks like a typo bug in addRenderShape where I suspect that the code:
else if (masterTextureNodes[nodeId].vertexData
should be
else if (masterTextureNodes[nodeId].hardwareVertexData
since that function otherwise deals exclusively with the hardwareVertexData.

Although graphics code is not my strength, I will keep digging.

@igough
Copy link
Author

igough commented Feb 19, 2024

Submitted pull request #20 to deal with this issue and other bugs.

@alariq
Copy link
Owner

alariq commented Jun 13, 2024

Hi guys, double draw is just my debug code to make sure HW accelerated shader based code does same thing as my originally ported one. Second draw pass is not needed at all.
Sorry for a late reply, unfortunately I have no time at the moment to work on this project, hopefully things will change soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants