Skip to content

Commit

Permalink
planet material, tweaks...
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Oct 11, 2023
1 parent d0fba1a commit 44010d8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
3 changes: 2 additions & 1 deletion ghengin-core/ghengin-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ cabal-version: 3.4

name: ghengin-core
version: 0.1.0.0
tested-with: GHC ==9.4.4 || ==9.6.1
-- tested-with: GHC ==9.4.4 || ==9.6.1
tested-with: GHC ==9.8.1
license: BSD-3-Clause
license-file: ../LICENSE
author: romes
Expand Down
3 changes: 1 addition & 2 deletions ghengin-core/ghengin-core/Ghengin/Core/Material.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ instance HasProperties Material where
-- | All materials for a given pipeline share the same Descriptor Set #1
-- Layout. If we know the pipeline we're creating a material for, we can simply
-- allocate a descriptor set with the known layout for this material.
material :: α π β. (CompatibleMaterial α π)
material :: α π β. CompatibleMaterial α π
=> PropertyBindings α RenderPipeline π β Renderer (Material α, RenderPipeline π β)
material props0 (RenderProperty pr rps) = material props0 rps >>= \case (m, rp) -> pure (m, RenderProperty pr rp)
material props0 (RenderPipeline gpip rpass (rdset, rres, dpool0) shaders) = Linear.do
Expand Down Expand Up @@ -140,7 +140,6 @@ material props0 (RenderPipeline gpip rpass (rdset, rres, dpool0) shaders) = Line
( mkMat (Done (dset2, resources2, Ur uniq)) props1
, RenderPipeline gpip rpass (rdset, rres, dpool3) shaders
)
-- TODO: Apecs.newEntity (SomeMaterial mat)?
where
mkMat :: b. Material '[] PropertyBindings b Material b
mkMat x GHNil = x
Expand Down
5 changes: 5 additions & 0 deletions ghengin-core/ghengin-core/Ghengin/Core/Renderer.hsig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ signature Ghengin.Core.Renderer
, module Ghengin.Core.Renderer.Buffer
, module Ghengin.Core.Renderer.Command
, module Ghengin.Core.Renderer.Kernel
, module Ghengin.Core.Renderer.Texture
, module Ghengin.Core.Renderer.Sampler
, module Ghengin.Core.Renderer
)
where
Expand All @@ -20,6 +22,9 @@ import Ghengin.Core.Renderer.Buffer
import Ghengin.Core.Renderer.Kernel
import Ghengin.Core.Renderer.DescriptorSet
import Ghengin.Core.Renderer.Command
import Ghengin.Core.Renderer.Texture
import Ghengin.Core.Renderer.Sampler


import qualified Data.Linear.Alias as Alias

Expand Down
36 changes: 21 additions & 15 deletions ghengin-games/planets-core/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,38 @@ which in turn are made up of multiple things, as represented in the following pi
│Planet (RenderPacket) │
└──────────────────────────────────┘
The function `newPlanet` handles the creation of planet render packets.
The main function
The function `newPlanet` handles the creation of planet render packets...
-}
module Main where

import qualified Prelude
import Data.Time
import Data.Coerce
import Data.Time
import Foreign.Storable
import Geomancy.Mat4
import Geomancy.Transform
import Geomancy.Vec3
import Geomancy.Vec4
import Geomancy.Vulkan.Projection (perspective)
import Ghengin.Core
import Ghengin.Core.Log
import Ghengin.Core.Mesh
import Ghengin.Core.Material
import Ghengin.Core.Prelude as Linear
import Ghengin.Core.Render
import Ghengin.Core.Render.Packet
import Ghengin.Core.Render.Pipeline
import Ghengin.Core.Render.Property
import Ghengin.Core.Render.Queue
import Ghengin.Core.Render
import Ghengin.Core.Shader (StructVec3(..), StructMat4(..))
import Ghengin.Core.Log
import Ghengin.Core
import Geomancy.Mat4
import Geomancy.Vec4
import Geomancy.Vec3
import Geomancy.Transform
import Geomancy.Vulkan.Projection (perspective)
import Vulkan.Core10.FundamentalTypes (Extent2D(..))
import qualified Data.Monoid.Linear as LMon
import qualified FIR
import qualified Math.Linear as FIR
import qualified Data.Monoid.Linear as LMon
import qualified Prelude

import Shaders -- planet shaders
import Planet

newtype ProjectionM = ProjectionM Transform
deriving Storable -- use GlBlock instead...
Expand Down Expand Up @@ -116,10 +117,15 @@ main = do
currTime <- getCurrentTime
withLinearIO $
runCore Linear.do
pipeline <- (makeMainPipeline )

pipeline <- (makeMainPipeline )
(p1mesh, Ur minmax) <- newPlanetMesh defaultPlanetSettings
(pmat, pipeline) <- newPlanetMaterial minmax undefined pipeline

rq <- gameLoop currTime LMon.mempty

(freeMaterial pmat )
(freeMesh p1mesh )
(freeRenderQueue rq )
(destroyRenderPipeline pipeline )

Expand Down
25 changes: 24 additions & 1 deletion ghengin-games/planets-core/Planet.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedLists #-}
module Planet where

import qualified Prelude as P
import Ghengin.Core.Prelude as Linear hiding (All, foldl')
import Ghengin.Core.Render
import Ghengin.Core.Render.Pipeline
import Ghengin.Core.Render.Property
import Ghengin.Core.Material
import Ghengin.Core.Type.Compatible
import Data.List (foldl')
import Ghengin.Core.Log

Expand All @@ -15,6 +22,7 @@ import Ghengin.Core.Mesh
import Geomancy.Vec3

import Game.Geometry.Sphere
import Foreign.Storable.Generic

--------------------------------------------------------------------------------
-- * Planet
Expand All @@ -32,7 +40,7 @@ data PlanetSettings = PlanetSettings { resolution :: !Int
data DisplayFace = All | FaceUp | FaceRight deriving Show

data MinMax = MinMax !Float !Float
deriving (P.Eq, Generic, Show)
deriving (P.Eq, Generic, Show, GStorable)

newPlanetMesh :: PlanetSettings -> Core (Mesh '[Vec3, Vec3, Vec3], Ur MinMax)
newPlanetMesh (PlanetSettings re ra co enableMask nss df) = enterD "newPlanetMesh" $ Linear.do
Expand Down Expand Up @@ -64,6 +72,14 @@ newPlanetMesh (PlanetSettings re ra co enableMask nss df) = enterD "newPlanetMes
minmax = MinMax (P.minimum elevations) (P.maximum elevations)
in (,Ur minmax) <$> (createMeshWithIxs vs'' is )

newPlanetMaterial :: forall π p
. CompatibleMaterial '[MinMax,Texture2D] π
=> MinMax
-> Alias Texture2D
RenderPipeline π p
Core (Material '[MinMax,Texture2D], RenderPipeline π p)
newPlanetMaterial mm t pl = ( material @_ @π (StaticBinding (Ur mm) :## Texture2DBinding t :## GHNil) pl )

--------------------------------------------------------------------------------
-- * Noise
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -115,3 +131,10 @@ evalNoise (NoiseSettings nl st ro br ps ce mv en nt) p =

noiseValue' (WithVec3 x y z) = coherentNoise 2 (float2Double x, float2Double y, float2Double z)

defaultPlanetSettings :: PlanetSettings
defaultPlanetSettings
= PlanetSettings 5 1 (vec3 1 0 0) False
[ NoiseSettings 1 1 1 2 0.5 (vec3 0 0 0) 0 True SimpleNoise
, NoiseSettings 1 1 1 2 0.5 (vec3 0 0 0) 0 True SimpleNoise
]
All
5 changes: 5 additions & 0 deletions ghengin-vulkan/ghengin-vulkan/Ghengin/Vulkan/Renderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ module Ghengin.Vulkan.Renderer
, module Ghengin.Vulkan.Renderer.Buffer
, module Ghengin.Vulkan.Renderer.Command
, module Ghengin.Vulkan.Renderer.Kernel
, module Ghengin.Vulkan.Renderer.Texture
, module Ghengin.Vulkan.Renderer.Sampler
, module Ghengin.Vulkan.Renderer
)
where

-- For re-exports
import Ghengin.Vulkan.Renderer.Texture
import Ghengin.Vulkan.Renderer.Sampler

import GHC.TypeLits
import qualified Prelude
Expand Down

0 comments on commit 44010d8

Please sign in to comment.