packages feed

mischief-render-0.1.0.0: examples/start/MyMaterial.hs

module MyMaterial where

import Mischief.Materials
import Mischief.Materials.Sprite qualified as Sprite
import Prelude ()

newtype MyColor f = MyColor (Field f (Vec3 Float)) deriving (Generic, Bufferable)

instance Component (MyColor CPU)

newtype Bindings f = Bindings (Uniform f (MyColor f)) deriving (Generic, Bindable)

data MyMaterial

instance Material MyMaterial where
  type VI MyMaterial = Sprite.VertexInput
  type VO MyMaterial = Sprite.VertexOutput

  type B MyMaterial = Bindings

  type Extends MyMaterial = '[Sprite.SpriteMaterial]

  vertex = liftExt . (vertex @Sprite.SpriteMaterial)

  fragment vo = do
    color <- liftExt $ Sprite.sampleSprite vo.uv
    Bindings (MyColor myColor) <- bindings
    pure $ (myColor * color.rgb) +: color.a

  fetch =
    FetchBindings
      { camera = \_ -> pure (),
        mesh = \sprite -> qget sprite [qd|(Buffer MyColor)|],
        result = \_ color -> Bindings color
      }