Skip to content

Commit 6743055

Browse files
committed
Working on irradiance map creation.
1 parent 8c9a255 commit 6743055

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

Nu/Nu/Render/Renderer3d.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6063,7 +6063,8 @@ type [<ReferenceEquality>] VulkanRenderer3d =
60636063
let skyBoxPipeline = SkyBox.CreateSkyBoxPipeline compositionAttachment.Format compositionDepthAttachment.Format vkc
60646064

60656065
// create irradiance pipeline
6066-
let irradiancePipeline = CubeMap.CreateCubeMapPipeline (Constants.Paths.IrradianceShaderFilePath, compositionAttachment.Format, compositionDepthAttachment.Format, vkc)
6066+
let irradianceFormat = Hl.Rgba16f
6067+
let irradiancePipeline = CubeMap.CreateCubeMapPipeline (Constants.Paths.IrradianceShaderFilePath, irradianceFormat.VkFormat, vkc)
60676068

60686069
// create physically-based pipelines
60696070
let physicallyBasedPipelines = PhysicallyBased.CreatePhysicallyBasedPipelines (Constants.Render.LightMapsMaxDeferred, Constants.Render.LightsMaxDeferred, compositionAttachment.Format, compositionDepthAttachment.Format, vkc)

Nu/Nu/Vulkan/Vulkan.CubeMap.fs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ module CubeMap =
234234
Pipeline : Pipeline.Pipeline }
235235

236236
/// Create a CubeMapPipeline.
237-
let CreateCubeMapPipeline (shaderPath, colorAttachmentFormat, depthAttachmentFormat, vkc : Hl.VulkanContext) =
237+
let CreateCubeMapPipeline (shaderPath, colorAttachmentFormat, vkc : Hl.VulkanContext) =
238238

239239
// create pipeline
240240
let pipeline =
@@ -248,7 +248,7 @@ module CubeMap =
248248
Pipeline.descriptor 1 Hl.CombinedImageSampler Hl.FragmentStage 1|]|]
249249
[|Pipeline.pushConstant 0 sizeof<int> Hl.VertexFragmentStage|]
250250
colorAttachmentFormat
251-
(Some (Pipeline.depthTest depthAttachmentFormat))
251+
None // NOTE: DJL: not porting currently meaningless depth test as it imposes complexity cost in vulkan.
252252
vkc
253253

254254
// create uniform buffer
@@ -273,7 +273,6 @@ module CubeMap =
273273
geometry : CubeMapGeometry,
274274
resolution : int,
275275
colorAttachment : Texture.Texture,
276-
depthAttachment : Texture.Texture,
277276
pipeline : CubeMapPipeline,
278277
vkc : Hl.VulkanContext) =
279278

@@ -299,7 +298,7 @@ module CubeMap =
299298
if Hl.validateRect scissor then
300299

301300
// init render
302-
let mutable rendering = Hl.makeRenderingInfo colorAttachment.ImageView (Some depthAttachment.ImageView) renderArea None
301+
let mutable rendering = Hl.makeRenderingInfo colorAttachment.ImageView None renderArea None
303302
Vulkan.vkCmdBeginRendering (cb, asPointer &rendering)
304303

305304
// bind pipeline
@@ -310,10 +309,6 @@ module CubeMap =
310309
Vulkan.vkCmdSetViewport (cb, 0u, 1u, asPointer &vkViewport)
311310
Vulkan.vkCmdSetScissor (cb, 0u, 1u, asPointer &scissor)
312311

313-
// set depth test state
314-
Vulkan.vkCmdSetDepthTestEnable (cb, true)
315-
Vulkan.vkCmdSetDepthCompareOp (cb, VkCompareOp.LessOrEqual)
316-
317312
// bind vertex and index buffer
318313
let mutable vertexBuffer = geometry.VertexBuffer.VkBuffer
319314
let mutable vertexOffset = 0UL

Nu/Nu/Vulkan/Vulkan.LightMap.fs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,46 @@ open Nu
1111
[<RequireQualifiedAccess>]
1212
module 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.0f, 0.1f, 10.0f)
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

Comments
 (0)