Jump to content




General Purpose 3D Renderer


50 replies to this topic

#1 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 December 2015 - 04:09 AM

Recently I started watching this series of tutorials and realized it wouldn't be all that hard to port the code to Lua. After a few days, these were the results.






If you're confused on what the camera is doing, I'm just controlling it myself with WASD and arrow keys. Here are some features for anyone wondering: perspective correct texture mapping, clipping, all the matrix transformations you would expect, camera projection, face culling, and of course a depth buffer. Also, this isn't really a feature of the renderer itself, but I'm using the 1.76 sub-pixel characters for the nicer resolution. At some point I'd like to add support for vertex and fragment shaders as well (well, shaders written in Lua :P).

I plan to release the library and demo code in full at some point.

Edited by Yevano, 25 May 2016 - 06:23 PM.


#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 29 December 2015 - 08:48 AM

That is the smoothest 3D library I've seen on the forums. Puts mine to shame really :P. Have you considered porting it to run on the Silica emulator? - 1.76's characters are good but CraftOS 2.0's resolution is even higher.

Looking forward to reading the code when you release it and seeing what I've done wrong :).

#3 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 29 December 2015 - 08:59 AM

How did you handle the OpenGL part? And the shaders?

Edited by Creator, 29 December 2015 - 09:01 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 December 2015 - 09:06 AM

View PostSquidDev, on 29 December 2015 - 08:48 AM, said:

That is the smoothest 3D library I've seen on the forums. Puts mine to shame really :P. Have you considered porting it to run on the Silica emulator? - 1.76's characters are good but CraftOS 2.0's resolution is even higher.

Werrlllll truth be told, an advanced external monitor, built to full size, has a higher effective resolution than COS2.0 is slated to get (at least, when using these teletext-drawing-characters, for which we sorely need some sort of abbreviation). 328x243, versus 320x200.

Of course, the characters are still relatively limited in what you can do with them, and I'm doubtful that nice smooth rendering rate would be possible at that resolution within ComputerCraft, but hey.

On the other hand, what Yevano's displayed here hardly seems to be struggling...

#5 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 29 December 2015 - 09:18 AM

View PostBomb Bloke, on 29 December 2015 - 09:06 AM, said:

Werrlllll truth be told, an advanced external monitor, built to full size, has a higher effective resolution than COS2.0 is slated to get (at least, when using these teletext-drawing-characters, for which we sorely need some sort of abbreviation). 328x243, versus 320x200.
On the other hand, what Yevano's displayed here hardly seems to be struggling...

Ah, I just presumed it would be higher - evidently not :). I'm still amazed about how much can be done using these new characters.

#6 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 December 2015 - 09:56 AM

View PostBomb Bloke, on 29 December 2015 - 09:06 AM, said:

Of course, the characters are still relatively limited in what you can do with them, and I'm doubtful that nice smooth rendering rate would be possible at that resolution within ComputerCraft, but hey.

On the other hand, what Yevano's displayed here hardly seems to be struggling...

In my testing with 328x243, this demo runs at around 1 fps. :P

Also, added more video sauce.

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 December 2015 - 10:27 AM

View PostYevano, on 29 December 2015 - 09:56 AM, said:

In my testing with 328x243, this demo runs at around 1 fps. :P

Oh, go on, give us a screenshot then. ;)

#8 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 December 2015 - 10:43 AM

Posted Image

#9 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 29 December 2015 - 11:16 AM

View PostCreator, on 29 December 2015 - 08:59 AM, said:

How did you handle the OpenGL part? And the shaders?

I was following the tutorial, and I saw the OpenGL and the shaders and since I could not make it work with Love2D I kinda stopped.

#10 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 December 2015 - 11:21 AM

Ah, it's nice to see those nice sharp lines. :)

View PostCreator, on 29 December 2015 - 08:59 AM, said:

How did you handle the OpenGL part? And the shaders?

I took a look at a few of the videos midway through the series (guy sets my ASMR off beautifully), and didn't see anything concerning those. You'll be shown how to perform the relevant math yourself - mind you, a fair bit of it's beyond high-school level, so depending on how much mathematical education you've done beyond that it may not immediately make sense without further study.

As for shading, I'm not seeing any going on here.

#11 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 29 December 2015 - 11:24 AM

View PostBomb Bloke, on 29 December 2015 - 11:21 AM, said:

Ah, it's nice to see those nice sharp lines. :)

View PostCreator, on 29 December 2015 - 08:59 AM, said:

How did you handle the OpenGL part? And the shaders?

I took a look at a few of the videos midway through the series (guy sets my ASMR off beautifully), and didn't see anything concerning those. You'll be shown how to perform the relevant math yourself - mind you, a fair bit of it's beyond high-school level, so depending on how much mathematical education you've done beyond that it may not immediately make sense without further study.

As for shading, I'm not seeing any going on here.

TheBennyBox uses shaders to rotate and color the meshes. That is where I got stuck.

#12 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 December 2015 - 05:23 PM

View PostBomb Bloke, on 29 December 2015 - 11:21 AM, said:

(guy sets my ASMR off beautifully)

Haha, I don't have ASMR but there's something I love about his voice and his quirky mannerisms. Getting to here him say "Hello everyone. It's benny." made each video just that little bit more worth watching. Actually for some reason he reminds me of alantutorial a little bit. I could totally picture him starting a video with "Hey tutorial heads!"

View PostCreator, on 29 December 2015 - 11:24 AM, said:

TheBennyBox uses shaders to rotate and color the meshes. That is where I got stuck.

Are you looking at the same videos I linked? The whole point of those tutorials is to not use OpenGL or any hardware accelerated library. Which video are you talking about specifically?

#13 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 29 December 2015 - 09:00 PM

3d game engine tutorial is what I looked at. I was on mobile so I might have seen the wrong playlist.

#14 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 December 2015 - 09:31 PM

View PostCreator, on 29 December 2015 - 09:00 PM, said:

3d game engine tutorial is what I looked at. I was on mobile so I might have seen the wrong playlist.

Yeah that's a different tutorial series. The one I watched was "3D Software Rendering." You can find the playlist in here.

#15 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 29 December 2015 - 10:09 PM

I actually have downloaded it on my phone, but thank you. Bless tubemate.

#16 Antelux

  • Members
  • 295 posts
  • LocationSomewhere in the middle of nowhere.

Posted 30 December 2015 - 07:27 PM

Looks pretty cool. I'll probably use it to make a game or two in the future :P

#17 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 03 January 2016 - 05:37 PM

It's so damn smooth, I remember when nitro first introduced his raycasting method and I thought that was cool, now it feels like nothing compared to this.
I'm interested, how did you create the objects for this? And you should create a program that lets you create 3D objects and sprites, so that people can use that to create 3D games :P

#18 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 03 January 2016 - 05:48 PM

View PostTheOddByte, on 03 January 2016 - 05:37 PM, said:

It's so damn smooth, I remember when nitro first introduced his raycasting method and I thought that was cool, now it feels like nothing compared to this.
I'm interested, how did you create the objects for this? And you should create a program that lets you create 3D objects and sprites, so that people can use that to create 3D games :P

Thanks for the kind words! Although, nitro's renderer was also using scanline, not raycasting, unless you're talking about something else he made. I created the first scene using a matrix transformation stack, similar to what you might do in OpenGL. Here's the code that drives the first demo.

local function renderScene()
    camera.update(keyboard)

    clearDepthBuffer()
    clearFrameBuffer(m_renderTarget, vec4(0, 0, 0, 1))
    rotCounter = rotCounter + 0.05

    pushMatrix(camera.getViewProjection())
            pushMatrix(Mat4().initRotation3(0, rotCounter, 0))
                pushMatrix(Mat4().initTranslation(0, 0, 0))
                    drawCube(t1, t2, t3, t4, cubeTexture)
                popMatrix()

                for i = 1, 3 do
                    pushMatrix(Mat4().initTranslation(2.5 * i, 0, 0))
                        drawCube(t1, t2, t3, t4, cubeTexture)
                    popMatrix()

                    pushMatrix(Mat4().initTranslation(-2.5 * i, 0, 0))
                        drawCube(t1, t2, t3, t4, cubeTexture)
                    popMatrix()
                end
            popMatrix()

            pushMatrix(Mat4().initTranslation(0, -5, 0))
                pushMatrix(Mat4().initScale(10, 0.5, 10))
                    drawCube(t1, t2, t3, t4, floorTexture)
                popMatrix()
            popMatrix()
    popMatrix()
end


#19 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 03 January 2016 - 11:35 PM

:o

This neeeeeeeeeeeds to be made for CraftOS 2.0. We'd actually be able to have proper 3D games that looked decent. I'm surprised how well those cubes looked, certainly is promising.

If you want help setting up the Silica emulator let me know, I'd be more than happy to assist you with getting this on it.

#20 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 04 January 2016 - 12:24 AM

View Postoeed, on 03 January 2016 - 11:35 PM, said:

:o

This neeeeeeeeeeeds to be made for CraftOS 2.0. We'd actually be able to have proper 3D games that looked decent. I'm surprised how well those cubes looked, certainly is promising.

If you want help setting up the Silica emulator let me know, I'd be more than happy to assist you with getting this on it.

I've been wondering about that actually. It would be really great if the new game was using LuaJIT, because then I could see higher resolutions and greater number of triangles on the screen as a real possibility. And yeah, I tried a little bit with the emulator though I couldn't get it running. If you could help me with it in the gitter chat I would be grateful.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users