Advertisement

3D Frustum Software Renderer implemented in Lua

Started by February 22, 2020 04:18 PM
0 comments, last by The_GTA 4 years, 8 months ago

Dear game developers,

I am looking forward to find people who are interested in 3D software rendering. In my opinion it is good to start in software to learn the basics, especially starting with a good implementation as foundation. If you understand everything you can move on to complex hardware acceleration APIs. The implementation is capable to render triangles and rectangles.

Mathematical definition of 3D frustum with screen space coordinates translated from frustum position, front, up and depth vectors.
Screenshot of MTA:SA rendering a 3D rectangle plane with depth information into color buffer.

Code to render a triangle looks sort of like this:

local viewFrustum = createViewFrustum(
    createVector(0, 0, 0),      -- position
    createVector(10, 0, 0),     -- right
    createVector(0, 0, 10),     -- up
    createVector(0, 20, 0)      -- front
);
local plane = createPlane(
    createVector(-3, 10, -3),
    createVector(6, 0, 0),
    createVector(0, 0, 6)
);
local function task_draw_scene(thread)
    local bbuf = create_backbuffer(640, 480, 255, 255, 0, 50);
    local dbuf = createDepthBuffer(640, 480, 1);
    
    local time_start = getTickCount();
    
    do
        local gotToDraw, numDrawn, numSkipped = draw_plane_on_bbuf(viewFrustum, bbuf, dbuf, plane, true, “tri”);
        
        if ( gotToDraw ) then
            outputDebugString( "drawn " .. numDrawn .. " pixels (skipped " .. numSkipped .. ")" );
        end
    end
    
   (…)
end

If I managed to capture your interest then I have to mention that you require the game “Grand Theft Auto San Andreas”, the multiplayer framework “MTA:SA” and the following MTA Server resource:

https://github.com/quiret/mta_lua_3d_math

https://forum.mtasa.com/topic/122576-software-rendering-in-mtasa-lua/

There is a topic on the MTA forums if you want to learn more about this project. Maybe we will get to write a really good C++ implementation ?

- Martin

This topic is closed to new replies.

Advertisement