From 85eaba320ed26b811af6df72c8e151a45d9a3f92 Mon Sep 17 00:00:00 2001 From: andromeda Date: Thu, 20 Aug 2026 03:52:49 +0200 Subject: draw, nothing on screen --- Shaders.hs | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'Shaders.hs') diff --git a/Shaders.hs b/Shaders.hs index f94bc43..19a9cd8 100644 --- a/Shaders.hs +++ b/Shaders.hs @@ -1,5 +1,6 @@ {-# LANGUAGE BlockArguments #-} {-# LANGUAGE DataKinds #-} +{-# LANGUAGE PartialTypeSignatures #-} {-# LANGUAGE RebindableSyntax #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} @@ -10,14 +11,34 @@ module Shaders where import FIR import Math.Linear -type FragmentDefs = '[ "in_pos" ':-> Input '[ Location 0 ] (V 2 Float) - , "out_col" ':-> Output '[ Location 0 ] (V 4 Float) - , "image" ':-> Texture2D '[ DescriptorSet 0, Binding 0 ] (RGBA8 UNorm) - , "main" ':-> EntryPoint '[ OriginLowerLeft ] Fragment - ] - -fragment :: Module FragmentDefs -fragment = Module $ entryPoint @"main" @Fragment do - pos <- get @"in_pos" - col <- use @(ImageTexel "image") NilOps pos - put @"out_col" col \ No newline at end of file +vertices = Vec3 (Vec2 0 (-0.5)) + (Vec2 0.5 0.5) + (Vec2 (-0.5) 0.5) + +vertPath = "assets/shaders/vert.spv" +fragPath = "assets/shaders/frag.spv" + +type VertexDefs = + '[ "main" ':-> EntryPoint '[] Vertex ] + +vertex :: ShaderModule "main" VertexShader VertexDefs _ +vertex = shader do + i <- get @"gl_VertexIndex" + let (Vec2 x y) = atv3v2f vertices i (Vec2 0 0) + put @"gl_Position" (Vec4 x y 0.0 1.0) + +type FragmentDefs = + '[ "main" ':-> EntryPoint '[ OriginUpperLeft ] Fragment + , "out_color" ':-> Output '[ Location 0 ] (V 4 Float) + ] + +fragment :: ShaderModule "main" FragmentShader FragmentDefs _ +fragment = shader do + put @"out_color" (Vec4 1.0 1.0 0.0 1.0) + +atv3v2f :: Code (V 3 (V 2 Float)) -> Code Word32 -> Code (V 2 Float) -> Code (V 2 Float) +atv3v2f (Vec3 x y z) i d = + if i == 0 then x + else if i == 1 then y + else if i == 2 then z + else d \ No newline at end of file -- cgit v1.3.1