This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Yevano's profile picture

General Purpose 3D Renderer

Started by Yevano, 29 December 2015 - 03:09 AM
Yevano #1
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.

[media]http://www.youtube.com/watch?v=x4E-4keyeVM[/media]
[media]http://www.youtube.com/watch?v=bBRnJIACxt0[/media]
[media]http://www.youtube.com/watch?v=IP5v4dh2CdY[/media]
[media]http://www.youtube.com/watch?v=9f3goa7lZdY[/media]

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 on 25 May 2016 - 05:23 PM
SquidDev #2
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 :)/>.
Creator #3
Posted 29 December 2015 - 08:59 AM
How did you handle the OpenGL part? And the shaders?
Edited on 29 December 2015 - 08:01 AM
Bomb Bloke #4
Posted 29 December 2015 - 09:06 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.

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…
SquidDev #5
Posted 29 December 2015 - 09:18 AM
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.
Yevano #6
Posted 29 December 2015 - 09:56 AM
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.
Bomb Bloke #7
Posted 29 December 2015 - 10:27 AM
In my testing with 328x243, this demo runs at around 1 fps. :P/>

Oh, go on, give us a screenshot then. ;)/>
Yevano #8
Posted 29 December 2015 - 10:43 AM
Creator #9
Posted 29 December 2015 - 11:16 AM
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.
Bomb Bloke #10
Posted 29 December 2015 - 11:21 AM
Ah, it's nice to see those nice sharp lines. :)/>

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.
Creator #11
Posted 29 December 2015 - 11:24 AM
Ah, it's nice to see those nice sharp lines. :)/>

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.
Yevano #12
Posted 29 December 2015 - 05:23 PM
(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!"

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?
Creator #13
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.
Yevano #14
Posted 29 December 2015 - 09:31 PM
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.
Creator #15
Posted 29 December 2015 - 10:09 PM
I actually have downloaded it on my phone, but thank you. Bless tubemate.
Antelux #16
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/>
TheOddByte #17
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/>
Yevano #18
Posted 03 January 2016 - 05:48 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/>

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
oeed #19
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.
Yevano #20
Posted 04 January 2016 - 12:24 AM
: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.
Selim #21
Posted 05 January 2016 - 07:36 PM
That is quite impressive.
wilcomega #22
Posted 05 January 2016 - 08:22 PM
cant wait to make a simple dungeon crawler with this, is there support for transparent textures? or transformed sprites, like the old doom?
Yevano #23
Posted 05 January 2016 - 09:17 PM
is there support for transparent textures?

Not yet, but I'm sure it would not be very difficult to add.

or transformed sprites, like the old doom?

Do you mean how the sprite should change based on an enemies angle in relation to the camera? There is no direct support for this, however it would not be hard to implement yourself, I think.
zguystudios #24
Posted 07 January 2016 - 09:42 PM
Lua DirectX?
LuaX maybe.
LuaDX?
LDX???
Truth be told, this is nothing like DirectX. However, this is pretty cool. You should work on turning it into an API so people can make 3d-ish games!
>>L3D????<<
Edited on 08 January 2016 - 12:03 AM
Creeper9207 #25
Posted 11 January 2016 - 05:15 AM
How many polygons can it handle on-screen?
Yevano #26
Posted 11 January 2016 - 11:29 PM
How many polygons can it handle on-screen?

You can have as many polygons on the screen as you want! But I can't promise it will be fast. The good news is that since polygons not in clip space need not be drawn, you can still have fairly large worlds without losing much performance. (So long as your clip space is sufficiently limited.)
Quartz101 #27
Posted 12 January 2016 - 11:10 AM
This would be even better if CC had mouse movement intergration!
Creeper9207 #28
Posted 12 January 2016 - 11:08 PM
what i'm asking is, can it handle 173 polygons on-screen at a playable rate?
wilcomega #29
Posted 18 January 2016 - 09:23 AM
wait until its released and try it yourself, if OP doesnt want to or has no time to test it then just wait
Yevano #30
Posted 18 January 2016 - 05:01 PM
I've been out of town but I'll be back tomorrow and maybe I'll just release some dirty code so people can see how it works.
Edited on 18 January 2016 - 04:09 PM
Creeper9207 #31
Posted 31 January 2016 - 06:41 AM
i have an awesome idea i wanna do with this =D
Yevano #32
Posted 31 January 2016 - 09:50 PM
Just started messing around with this again and wrote code for hit detection.

[media]http://www.youtube.com/watch?v=IP5v4dh2CdY[/media]
Bomb Bloke #33
Posted 01 February 2016 - 01:29 AM
So next is a pickaxe, right? :)/>
Yevano #34
Posted 01 February 2016 - 01:31 AM
So next is a pickaxe, right? :)/>

I think you have the right idea. :P/>
wilcomega #35
Posted 01 February 2016 - 02:54 PM
Looks really cool, i still cant wait. Could you release a list of methods? to see how the interface would work.
HDeffo #36
Posted 06 February 2016 - 06:55 PM
I would kind of be interested to use the mojang skin servers, convert image format to CC, then use this program to display a player on a monitor. I feel like this is now entirely feasible and would look really impressive
justync7 #37
Posted 08 February 2016 - 05:53 AM
I would kind of be interested to use the mojang skin servers, convert image format to CC, then use this program to display a player on a monitor. I feel like this is now entirely feasible and would look really impressive
The only issue with that would be interpreting the image. Due to the fs api in CC it makes it quite difficult to read standard file formats, unless someone made a website which allows you to grab skins compatible for CC to interpret.
Edited on 08 February 2016 - 04:53 AM
Anavrins #38
Posted 08 February 2016 - 06:54 AM
The only issue with that would be interpreting the image. Due to the fs api in CC it makes it quite difficult to read standard file formats, unless someone made a website which allows you to grab skins compatible for CC to interpret.
What do you mean, the fs api can read in binary mode to prevent any string bugs, and Bomb Bloke made a GIF decoder, so it's definitely possible.
Bomb Bloke #39
Posted 08 February 2016 - 08:02 AM
Two problems; skins aren't stored as GIFs, and there's no way to open binary-mode web handles in ComputerCraft.

Well, other than CC Tweaks, at least. I'm not sure how many servers run that though. Has that made its way into the mainline packs yet? I don't keep up with such things.

But yeah my API makes it fairly easy to load in most images. And because this topic is veering dangerously close to a secret I've been entirely neglecting to work on since… CC 1.74, I might as well spill the beans before someone else thinks of it:

Spoiler

Yeah, I'm already using my GIF API on skin files… only the way I see it, the world's got a bit more colour depth than a CC display. ;)/>/>

In fact, back when Yevano first posted this thread I messaged him about maybe providing me with some "rendering" code. The plan's to be produce a script which allows you to pose characters, and save the poses so they can be used along with other skins. Maybe even throw in WorldPorter functionality and save props alongside them (eg a giant chair to sit on or whatever) as well.
Edited on 10 February 2016 - 10:21 PM
TheOddByte #40
Posted 08 February 2016 - 03:15 PM
- snip -
Seems like Minecraft in Minecraft is becoming closer and closer to a reality
- snip -
How come you have so much time to create so many awesome things? I wish I wasn't lazy and dedicated more of my time to programming instead of sleeping and doing nothing :P/>
Bomb Bloke #41
Posted 09 February 2016 - 01:08 AM
Heh, if I had time, I might've actually worked on that script this year. ;)/>
Yevano #42
Posted 25 May 2016 - 07:24 PM
Did some more playing around with this.

[media]http://www.youtube.com/watch?v=9f3goa7lZdY[/media]
LDDestroier #43
Posted 25 May 2016 - 08:42 PM
I hate to shout this again whenever someone makes a 3-D engine…but…


SquidDev #44
Posted 25 May 2016 - 08:46 PM
I wondered this when you first posted this and I'm still wondering it: How is it so smooth? I tried to make my renderer as efficient as possible and it still lags a lot. This still amazes me almost half a year later.
Edited on 25 May 2016 - 06:46 PM
ReBraLaCC #45
Posted 26 May 2016 - 04:49 PM
I wondered this when you first posted this and I'm still wondering it: How is it so smooth? I tried to make my renderer as efficient as possible and it still lags a lot. This still amazes me almost half a year later.

I know right! It's so hard to do it fast enough….. Well maybe….. there is a way because he can do it, why can't we?
jv110 #46
Posted 28 May 2016 - 08:33 PM
I hate to shout this again whenever someone makes a 3-D engine…but…



Why didn't you post that in VertexGL then?
RatcheT2497 #47
Posted 01 June 2016 - 03:00 PM
This looks absolutely astonishing.

Do you think it'd be possible to make a game similar to Crash Bandicoot, although heavily simplified (atleast on the graphics side)?
You don't really have control over the camera, and you just have two buttons, excluding movement.

Can't wait to when you release it :)/>
jv110 #48
Posted 06 June 2016 - 04:47 PM
This looks absolutely astonishing.

Do you think it'd be possible to make a game similar to Crash Bandicoot, although heavily simplified (atleast on the graphics side)?
You don't really have control over the camera, and you just have two buttons, excluding movement.

Can't wait to when you release it :)/>

You guys seeeriously need to stop that. Of course it's possible! May be hard, may be laggy, may be buggy, may be against the law, may explode, whatever. It's still possible.

Speaking of Crash Bandicoot, it's a full triple-A game. Its controls'n'stuff are pretty simple, but we're still talking about !BLINDLY! remaking a full game.

Also, why simplify the graphics at all? A PlayStation's CPU is about 30MHz, and the GPU is obviously much slower, plus it had only 2MB RAM.

Today's computers though, have ~2-4GHz CPUs, GPUs capable of rendering photorealistic 3D images and 4-16GB RAM.

The only problem here is that this runs purely on the CPU, so you have to split power with even Minecraft itself (very CPU intensive [cuz java]), plus Lua is running from Java which is extremely slow and CPU intensive.

CCEmuRedux doesn't fix it, it just makes it worse! It's also made in Java, and it's slower than Minecraft itself for some reason. Maybe the original ccemu works?
Edited on 07 June 2016 - 12:26 AM
Bomb Bloke #49
Posted 07 June 2016 - 02:41 AM
Speaking of Crash Bandicoot, it's a full triple-A game. Its controls'n'stuff are pretty simple, but we're still talking about !BLINDLY! remaking a full game.

Similar ~= the same.

Also, why simplify the graphics at all? A PlayStation's CPU is about 30MHz, and the GPU is obviously much slower, plus it had only 2MB RAM.

The Playstation can handle 640x480 output frames utilising 24bit colour. The average ComputerCraft display can handle 51x19 frames with 4bit colour (or 102x57 frames, with colour depth effectively reduced further). They're not even in the same ballpark.

Then there's the overhead you get for trying to run an interpreted language through another interpreted language alongside Minecraft and via a client/server mash-up. It's huge.

But still, yeah, anything's "possible". It's more a question as to whether it's "practical".
jv110 #50
Posted 17 June 2016 - 11:43 PM
Playstation can handle 640x480 output frames utilising 24bit colour. The average ComputerCraft display can handle 51x19 frames with 4bit colour (or 102x57 frames, with colour depth effectively reduced further). They're not even in the same ballpark.
Not talking about displaying the graphics, but about the polygons, textures 'n stuff themselves. I'm quite sure Crash Bandicoot level of polygons is fine. If you doubt it, I'll load 'em on VertexGL, just wait a little. Crash 1 is really low-poly.

Then there's the overhead you get for trying to run an interpreted language through another interpreted language alongside Minecraft and via a client/server mash-up. It's huge.

But still, yeah, anything's "possible". It's more a question as to whether it's "practical".

I thought I said that?

EDIT:
It takes constant 42 ticks (2.1 seconds) to render a single Crash Bandicoot model (loaded from an .obj), at X 0 Y -2 Z 0 (best pos), without texture. That should be because of the extremely low optimization of VertexGL. Again, my computer isn't very good (i3 2.1GHz/HD GFX 3000, can barely run Minecraft at 60FPS).

Spoiler

Would be great if Yevano saw this and ran it on his renderer!

EDIT2:
With the update, rendering at 328x243 takes 94 ticks, 4.7 seconds.
Edited on 20 June 2016 - 03:10 PM
bobasrty #51
Posted 09 July 2017 - 06:33 AM
My mind has been blown reading this whole thread. So much possibilities.