Quick Links
  • Homepage
        - Overview
        - Download
        - Screenshots
        - Community
  • Code Sample Pack
  • Reference Guide
  • Changelog
  • Overview of GLSL Hacker
  • Live Coding
  • Hack your first GLSL Code
  • Moon3D

  • GLSL Hacker Articles

    > Compute shaders on Radeon
    > Distance functions in GLSL
    > GLSL Interpolation Qualifiers
    > Tessellation Spacing Modes
    > Normal Visualizer with GS
    > 3D Surface Plots
    > Normal Mapping
    > Circle and Disc in GLSL
    > PhysX 3 Flag Demo
    > GLSL Hacker on Raspberry Pi
    GLSL Hacker

    1 - Moon3D Overview

    Moon3D is a high level library for GLSL Hacker (available with GLSL Hacker AT the time of writing, Moon3D is a Lua only library but it can be ported to Python without too much problem. Moon3D is library designed to quickly code a GLSL Hacker demo. Moon3D try to follow the spirit of Love2D at the level of function names. For example, to create a quad with Love2D, you have to call:

    quad = love.graphics.newQuad(...)

    With Moon3D, you will call something very similar:

    quad = moon3d.graphics.newQuad(...)

    Moon3D has two main goals: 1/ being a tool to quickly code a GLSL Hacker demo and 2/ being a tool to learn GLSL Hacker programming.

    2 - Moon3D Example

    Moon3D includes many functions that are commonly used by most of the demos. For instance, here is a complete demo that renders a wireframe sphere:

    INIT script:
    app_dir = gh_utils.get_scripting_libs_dir() 		
    dofile(app_dir .. "lua/Moon3D_v2.lua")
    moon3d.init(2, 1) -- OpenGL 2.1
    sphere = moon3d.graphics.newSphere(5, 20, 20)
    moon3d.object.setPosition(sphere, 0, 5, 0)
    camera = moon3d.camera.getDefaultPersp()
    moon3d.camera.setPosition(camera, 0, 15, 50)
    FRAME script:
    moon3d.startFrame(0.1, 0.3, 0.3, 1.0)
    local elapsed_time = moon3d.getTime()
    moon3d.graphics.drawWithColor(sphere, 1, 1, 1, 1)
    moon3d.print(10, 20, "GLSL Hacker - Moon3D Test, time=" .. elapsed_time)
    SIZE script:

    Looking at this code, you can easily see the creation of a sphere and its rendering in wireframe mode. Once this scene is clear in you mind, you can go deeper by editing the moon3d source code and, for example, looking at what is hidden by moon3d.graphics.drawWithColor().

    Moon3D is a high level API over GLSL Hacker low level API (the host API). Then you can mix Moon3D and host API without problem:

    gh_object.set_euler_angles(mesh, -90, 0, 0)
    moon3d.graphics.drawWithTexturing(mesh, 1, 1, 1, 1, 1, 1)

    The source code of Moon3D (Moon3D_v2.lua) is located in the GLSLHacker/libs/lua/ folder. The function gh_utils.get_scripting_libs_dir() returns the path to the libs folder.

    All moon3D based code samples can be found in the moon3d/ folder of the Code sample pack.

    (C)2012-2014 Geeks3D