Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Gl lighting

edited October 2013 in Shaders Posts: 20

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?

Tagged:

Comments

  • Posts: 2,820

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

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

  • Posts: 2,820

    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.

  • IgnatzIgnatz Mod
    edited October 2013 Posts: 5,396

    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!

Sign In or Register to comment.