Gl lighting

Hi there,

I’ve started playing with the glsl shaders in a Codea but I’m trying to create a simple light, I’ve tried a few tutorials and a few copy and paste solutions out of desperation but none of them seem to work (at all)

Could one of you kind souls help me out with just a simple ambient light to give my cube a little more life please?

This is funny. I was literally just looking for the exact same thing.

Haha :slight_smile: I have an idea for a game which would really help my understanding of 3d games dev.

Here’s a VERY simple cube shader:

function shadeCube(oC)
    local sA = 100
    local c = {}
    -- Far
    for i = 1,6 do
        table.insert(c,color(oC.r-sA,oC.g-sA,oC.b-sA))
    end
    -- Left
    for i = 1,6 do
        table.insert(c,color(oC.r-sA,oC.g-sA,oC.b-sA))
    end
    -- Close
    for i = 1,6 do
        table.insert(c,color(oC.r-sA/2,oC.g-sA/2,oC.b-sA/2))
    end
    -- Right
    for i = 1,6 do
        table.insert(c,oC)
    end
    -- Top
    for i = 1,6 do
        table.insert(c,oC)
    end
    -- Bottom
    for i = 1,6 do
        table.insert(c,color(oC.r-sA,oC.g-sA,oC.b-sA))
    end
    return c
end

The ordre of the cube faces are in the code. “sA” is the shadow amount.

I’m in the middle of a series of posts on lighting, starting here

http://coolcodea.wordpress.com/2013/09/24/112-lighting-in-3d-introduction/

Here is a more recent post on ambient light

http://coolcodea.wordpress.com/2013/10/05/118-lighting-in-3d-coding-ambient-and-diffuse-light/

I’ll be covering all sorts of lights in the next few posts, including point lights (lights that are in your scene, like streetlights), spotlights (lights focussed in one direction, like torches), flickering, maybe more.

Shader lighting is not for complete beginners, though, be warned!