Page 1 of 1

function outputs two values, but i dont know how to use booth

Posted: Thu Jul 04, 2024 4:48 pm
by NoreoAlles
Hello, im writing a clipping algorythm for my 3D renderer and in one scenario its supposed to see if a triangle is clipping, turn it into two which arent and then return those, but i can only ever see one of them, despite each working seperatly
if i do this on line 58 of triangle.lua:

Code: Select all

return {3, triangle_out, triangle_out2 }

this is the result:
example1.png
example1.png (11.47 KiB) Viewed 2561 times
if is switch them around:

Code: Select all

        return {3, triangle_out2, triangle_out }
This happens (you can see both images would fill each others missing triangles):
example2.png
example2.png (8.82 KiB) Viewed 2561 times
The code which receives the clipped triangles looks like this:

Code: Select all

clippedTris = {}
                local result = Triangle.clipAgainstPlane({x = 0, y = 0, z = 0.01}, {x = 0, y = 0, z = 1}, triViewed)
                if result[1] == 1 then table.insert(clippedTris, triViewed) end
                if result[1] == 2 then table.insert(clippedTris, result[2]) end
                if result[1] == 3 then clippedTris[#clippedTris+1] =  result[2] clippedTris[#clippedTris+1] =  result[3] end
.love is attached, standard fps controlls (r resets the camera, press that if upon loading up the screen is blank), changing the mesh for testing purposes is possible by changing the string in LoadMesh() function
Just to make it clear im using post this as my last resort, ive checked my code against the tutorial and github and even ports to other languages of the engine.
https://github.com/OneLoneCoder/Javidx9 ... 3.cpp#L310

Re: function outputs two values, but i dont know how to use booth

Posted: Sat Jul 06, 2024 2:25 am
by RNavega
I'm on my phone so I can't test it, but could you clarify if the problem you're observing is that some triangles are missing from the result, or if all are there but some have flipped normals and are simply being backface-culled?
In other words, if all clipped triangles are there in the data, but the renderer only draws some of them to the screen (the front-facing ones).

Re: function outputs two values, but i dont know how to use booth

Posted: Sat Jul 06, 2024 6:54 am
by NoreoAlles
RNavega wrote: Sat Jul 06, 2024 2:25 am I'm on my phone so I can't test it, but could you clarify if the problem you're observing is that some triangles are missing from the result, or if all are there but some have flipped normals and are simply being backface-culled?
In other words, if all clipped triangles are there in the data, but the renderer only draws some of them to the screen (the front-facing ones).
I´ve since started to rewrite everything as shader based, because i could not get this to work. I just checked, thats not issues for whatever reason, culling happens before clipping, so i dont know anymore. I did do a little check to see if the triangles are indeed there by checking for the shade of purple i gave them for testing purposes and they are indeed there but dont get rendered for whatever reason.

Re: function outputs two values, but i dont know how to use booth

Posted: Tue Jul 09, 2024 9:25 pm
by vilonis
That’s weird, does it change anything if you use multiple return values instead of returning a table?