{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
 - Module
 - Description : declarative shaders for Haskengl
 - Copyright   : Andromeda 2025
 - License     : WTFPL
 - Maintainer  : Matrix @Andromeda:tchncs.de
 - Stability   : Experimental
 -}
module Haskengl.Internal.IO.Shaders.Shaders where

import Relude

import Language.GLSL

-- | fragment shader
-- inputs:
-- - vec4 float fragColorOut
-- - vec2 float uv
-- outputs:
-- - vec4 float fragColor
-- uniform:
-- - sampler2D tex
fragShader :: Program
fragShader =
  [ VersionDeclaration 450 Core
  , VariableDeclaration Nothing In fragColorOut
  , VariableDeclaration Nothing In uv
  , VariableDeclaration Nothing Out fragColor
  , DangerousExpression "uniform sampler2D tex;"
  , MainStart
  , DangerousExpression "fragColor = texture(tex, uv);"
  ]

-- | vert shader
-- inputs:
-- - Location 0 vec3 float vertexPosition
-- - Location 1 vec4 float vertexColor
-- - Location 2 vec2 float uvCoords
-- outputs:
-- - vec4 float fragColorout
-- - vec2 float uv
-- uniform:
-- - mat4 float projection
vertShader :: Program
vertShader =
  [ VersionDeclaration 450 Core
  , VariableDeclaration (Just $ Location 0) In vertexPosition
  , VariableDeclaration (Just $ Location 1) In vertexColor
  , VariableDeclaration (Just $ Location 2) In uvCoords
  , VariableDeclaration Nothing Out fragColorOut
  , VariableDeclaration Nothing Out uv
  , VariableDeclaration Nothing Uniform projection
  , MainStart
  , DangerousExpression "gl_Position = projection * vec4(vertexPosition, 1.0);"
  , VariableAssignment fragColorOut vertexColor
  , VariableAssignment uv uvCoords
  ]

fragColor = Variable "fragColor" $ GLSLVec4 GLSLFloat
fragColorOut = Variable "fragColorOut" $ GLSLVec4 GLSLFloat
vertexPosition = Variable "vertexPosition" $ GLSLVec3 GLSLFloat
vertexColor = Variable "vertexColor" $ GLSLVec4 GLSLFloat
projection = Variable "projection" $ GLSLMat4 GLSLFloat
uvCoords = Variable "uvCoords" $ GLSLVec2 GLSLFloat
uv = Variable "uv" $ GLSLVec2 GLSLFloat
