Skip to content

v0.7.0

Compare
Choose a tag to compare
@da1nerd da1nerd released this 23 Apr 14:14
· 106 commits to master since this release

Shaders

This release was all about shaders and I ended up completely changing how shaders work. I think it's for the better. I almost didn't tag this release because the rendering engine is only using the first light it finds and it's using a hardcoded shader. But I'm about to completely re-write the rendering engine soon anyway.

Shader::Program

There is now a Prism::Core::Shader::Program which is the heart of the new shader abstraction. This makes it very easy to create a new shader.

Step 1 Create a glsl shader program. Right now the shader only supports the vertex and fragment shaders. This is just regular glsl code that contains some uniform declarations inside.

shader.vs
shader.fs

Step 2 Create your Shader::Program

class MyShader < Shader::Program
    uniform view_matrix, Matrix4f
    uniform light, Core::Light
    # etc.

    def initialize
      super("shader") # loads shader.vs and shader.fs
    end
  end

Step 3 use your shader!

my_shader.start
shader.view_matrix = TheMatrix.new
shader.light = TheLight.new
# draw stuff
my_shader.stop

You'll notice we used a Core::Light as a uniform. To use complex objects as uniforms you must serialize them.
For example

class Light
  include Shader::Serializable
  @[Core::Shader::Field]
  @color : Vector3f
end

There are a few other things to keep in mind, but this at least shows you how simple using shaders are.

Uniform Annotations

  • The class annotation was removed
  • The instance variable/method annotation was updated. Use @[Shader::Field(name: "uniform_name")] instead of @[Shader::Field(key: "uniform_name")]

Other changes

  • Prism::VMath was changed to Prism::Maths
  • Renamed GameObject to Entity. This actually isn't a proper entity. An entity system will come later. See #52
  • There are some other new objects floating around that aren't fully designed or implemented. These will become part of the new rendering/entity system or be removed.
  • Deprecated specialized ambient lighting class. Ambient lighting will instead be part of other lights.
  • Lights are no longer shaders. They are simply objects with light values.