PurpleKingdomGames / indigo

An FP game engine for Scala.
https://indigoengine.io/
MIT License
648 stars 60 forks source link

Fixed #788: Encode/derive case classes as UniformBlocks #789

Closed davesmith00000 closed 1 week ago

davesmith00000 commented 1 week ago

The main goal of this PR is to drastically improve how easy it is to send data to shaders. We've gone from having to know about all of this:

ShaderData(
  Shaders.externalId,
  UniformBlock(
    UniformBlockName("CustomData"),
    Batch(
      Uniform("ALPHA")        -> float(0.75),
      Uniform("BORDER_COLOR") -> vec3(1.0, 1.0, 0.0)
    )
  )
)

...to a very familiar this:

ShaderData(Shaders.externalId)
  .addUniformData(CustomData(0.75, RGB(1.0, 1.0, 0.0)))

final case class CustomData(ALPHA: Float, BORDER_COLOR: RGB) derives ToUniformBlock

The conversion process supports all the same types we used to support, but now we don't need any specialised syntax - WHICH MEANS - all the old imports for shaders have gone - WHICH MEANS - no more term/import collisions with Ultraviolet!! 🎉

Additional clean up work done in this PR: