mischief-render-0.1.0.0: examples/postprocess/Material.hs
module Material where
import Mischief.Materials
import Mischief.Materials.Fullscreen (FullscreenMaterial)
import Mischief.Materials.Fullscreen qualified as Fullscreen
import Mischief.Render.Camera (cameraSwapView)
import Mischief.Render.Core
import Prelude ()
data PostprocessMaterial
data Bindings f = Bindings
{ texture :: Binding f Texture,
sampler :: Binding f Sampler
}
deriving (Generic, Bindable)
instance Material PostprocessMaterial where
type VI PostprocessMaterial = Fullscreen.VertexInput
type VO PostprocessMaterial = Fullscreen.VertexOutput
type B PostprocessMaterial = Bindings
type Extends PostprocessMaterial = '[FullscreenMaterial]
vertex = liftExt . vertex @FullscreenMaterial
fragment vo = do
Bindings {texture, sampler} <- bindings
pure $ sample texture sampler vo.uv * vec4 1 0 0 1
fetch =
FetchBindings
( \camera -> do
(DefaultSampler sampler) <- qres @DefaultSampler
texture <- cameraSwapView camera
pure (sampler, texture)
)
(const $ pure ())
(\(sampler, texture) _ -> Bindings texture sampler)