@@ -11,6 +11,46 @@ open Nu
1111[<RequireQualifiedAccess>]
1212module LightMap =
1313
14+ let CreateIrradianceMap ( mapId , cb , resolution , cubeMapSurface : CubeMap.CubeMapSurface , colorFormat , irradiancePipeline , vkc ) =
15+
16+ // create irradiance cube map
17+ let metadata = Texture.TextureMetadata.make resolution resolution
18+ let cubeMapInternal =
19+ Texture.TextureInternal.create
20+ VkSamplerAddressMode.ClampToEdge VkFilter.Linear VkFilter.Linear false
21+ Texture.MipmapNone ( Texture.AttachmentColor false ) Texture.TextureCubeMap [| VkImageUsageFlags.Sampled|]
22+ colorFormat Hl.Rgba metadata vkc
23+ let cubeMap = Texture.EagerTexture { TextureMetadata = Texture.TextureMetadata.empty; TextureInternal = cubeMapInternal }
24+
25+ // compute views and projection
26+ let views =
27+ [| Matrix4x4.CreateLookAt ( v3Zero, v3Right, v3Down)
28+ Matrix4x4.CreateLookAt ( v3Zero, v3Left, v3Down)
29+ Matrix4x4.CreateLookAt ( v3Zero, v3Up, v3Back)
30+ Matrix4x4.CreateLookAt ( v3Zero, v3Down, v3Forward)
31+ Matrix4x4.CreateLookAt ( v3Zero, v3Back, v3Down)
32+ Matrix4x4.CreateLookAt ( v3Zero, v3Forward, v3Down)|]
33+ let projection = Matrix4x4.CreatePerspectiveFieldOfView ( MathF.PI_ OVER_ 2, 1.0 f, 0.1 f, 10.0 f)
34+
35+ // render faces to irradiance cube map
36+ for i in 0 .. dec 6 do
37+
38+ // render face
39+ let view = views.[ i]
40+ let viewProjection = view * projection
41+ CubeMap.DrawCubeMap
42+ ( mapId * 6 + i, cb, view, projection, viewProjection, cubeMapSurface.CubeMap, cubeMapSurface.CubeMapGeometry, resolution, cubeMap, irradiancePipeline, vkc)
43+
44+ // take a snapshot for testing
45+ // TODO: DJL: implement.
46+ //Hl.SaveFramebufferRgbaToBitmap (resolution, resolution, "Irradiance." + string cubeMapId + "." + string i + ".bmp")
47+
48+ // transition cubemap layout
49+ // TODO: DJL: implement once multi-layered transition is sorted out!
50+
51+ // fin
52+ cubeMap
53+
1454 /// A collection of maps consisting a light map.
1555 type [<Struct>] LightMap =
1656 { Enabled : bool
0 commit comments