Issues with 3D graphics and Artifacting in love2d

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Issues with 3D graphics and Artifacting in love2d

Post by MaxGamz »

I am currently working on building a 3d engine using love as a frame work. Currently I am following this tutorial series here by javidx9:
https://www.youtube.com/watch?v=ih20l3pJoeU
https://www.youtube.com/watch?v=XgMWc6LumG4&t=967s
the second link includes the timestamp where I started experiencing my problem

So far I haven't had any issues; however, I did have some qualms with how love was drawing triangles. When my cube was rotating I saw some slight artifacting. It got worse when I tried to draw the cube so that it only draws the faces that you can see. I checked on chatgpt and apparently this is just how love2d draws graphics on the screen. Is there a method that I can use to mitigate or outright solve this issue? At least in the scope of love2d.

test here:
love3D.love
(2.96 KiB) Downloaded 51 times
User avatar
marclurr
Party member
Posts: 157
Joined: Fri Apr 22, 2022 9:25 am

Re: Issues with 3D graphics and Artifacting in love2d

Post by marclurr »

This is the main problem. Look closely, you're not squaring the z component correctly.

Code: Select all

l = math.sqrt(normal.x * normal.x + normal.y * normal.y + normal.x * normal.z)
But you're also calculating the cross product slightly wrong, though you've compensated by negating the incorrect value so it actually works fine.

Code: Select all

vec3d.new(line1.y * line2.z - line1.z * line2.y,
                            -(line1.x * line2.z - line1.z * line2.x),
                             line1.x * line2.y - line1.y * line2.x) 
if copied verbatim from javid's repo should be

Code: Select all

vec3d.new(line1.y * line2.z - line1.z * line2.y,
                            line1.z * line2.x - line1.x * line2.z,
                             line1.x * line2.y - line1.y * line2.x) 
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Re: Issues with 3D graphics and Artifacting in love2d

Post by MaxGamz »

marclurr wrote: Thu Dec 19, 2024 12:04 am This is the main problem. Look closely, you're not squaring the z component correctly.

Code: Select all

l = math.sqrt(normal.x * normal.x + normal.y * normal.y + normal.x * normal.z)
But you're also calculating the cross product slightly wrong, though you've compensated by negating the incorrect value so it actually works fine.

Code: Select all

vec3d.new(line1.y * line2.z - line1.z * line2.y,
                            -(line1.x * line2.z - line1.z * line2.x),
                             line1.x * line2.y - line1.y * line2.x) 
if copied verbatim from javid's repo should be

Code: Select all

vec3d.new(line1.y * line2.z - line1.z * line2.y,
                            line1.z * line2.x - line1.x * line2.z,
                             line1.x * line2.y - line1.y * line2.x) 
Thanks for your insight! My main issue right now is just the artifacting(small "sparks" on the screen), but when I shade in the triangles with the fill operator, I don't see the issue anymore. Do you think love is still a good tool for what I am trying to do?
User avatar
marclurr
Party member
Posts: 157
Joined: Fri Apr 22, 2022 9:25 am

Re: Issues with 3D graphics and Artifacting in love2d

Post by marclurr »

I wasn't able to see any artifacts that looked like sparks but when i set the line mode to rough it sometimes looked like line segments were extending too far.

I changed the code to make three calls to love.graphics.line and this didn't produce the problem. There may be some quirks with the polygon function but I don't know enough to say anything useful.

If you're going to take this series to its conclusion you'll end up writing your own triangle rasteriser anyway so I wouldn't worry too much.

As for whether love is a good tool for what you're doing. I'd say it's fine. I'm not sure how practical a software 3D renderer is aside from an interesting learning tool though. Definitely continue with it but if you want to do any serious 3D work you can make use of the GPU very easily with love - I like to think of it as a premade OpenGL application with a nicer API.

If you really want to use a software renderer "just because" (which is a fine reason), you'll have a lot of optimisation to make it workable, which its self will be a worthwhile learning experience :)
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Re: Issues with 3D graphics and Artifacting in love2d

Post by MaxGamz »

marclurr wrote: Thu Dec 19, 2024 7:11 am I wasn't able to see any artifacts that looked like sparks but when i set the line mode to rough it sometimes looked like line segments were extending too far.

I changed the code to make three calls to love.graphics.line and this didn't produce the problem. There may be some quirks with the polygon function but I don't know enough to say anything useful.

If you're going to take this series to its conclusion you'll end up writing your own triangle rasteriser anyway so I wouldn't worry too much.

As for whether love is a good tool for what you're doing. I'd say it's fine. I'm not sure how practical a software 3D renderer is aside from an interesting learning tool though. Definitely continue with it but if you want to do any serious 3D work you can make use of the GPU very easily with love - I like to think of it as a premade OpenGL application with a nicer API.

If you really want to use a software renderer "just because" (which is a fine reason), you'll have a lot of optimisation to make it workable, which its self will be a worthwhile learning experience :)
Thanks for the advice! I initially wanted to use OpenGL with c++ but it ended up being way too complicated just to draw a triangle on the screen. I assumed love2d would have been a better option for me since it has OpenGL prebuilt, and now since I know I could make better use of GPU rendering I can optimize my code even better! I will still continue on it, but for now I am using it as a prototyping tool in case I do want to build it in c++.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests