Quake II RTX doxygen  1.0 dev
precomputed_sky.h File Reference

Go to the source code of this file.

Classes

struct  AtmosphereParameters
 

Enumerations

enum  SkyPreset { SKY_NONE, SKY_EARTH, SKY_STROGGOS }
 

Functions

VkResult SkyInitializeDataGPU ()
 
void SkyReleaseDataGPU ()
 
void UpdateTerrainShadowMapView (vec3_t forward)
 
VkResult SkyLoadScatterParameters (SkyPreset preset)
 
VkDescriptorSetLayout * SkyGetDescriptorLayout ()
 
VkDescriptorSet SkyGetDescriptorSet ()
 
void RecordCommandBufferShadowmap (VkCommandBuffer cmd_buf)
 
void InitializeShadowmapResources ()
 
void ReleaseShadowmapResources ()
 

Variables

static const uint32_t ShadowmapSize = 2048
 
static const uint32_t ShadowmapHeightmapSize = 4096
 
static const uint32_t ShadowmapGridSize = 1024
 
static const float ShadowmapWorldSize = 30.0f
 
static const float ShadowmapWorldElevation = 3.0f
 

Enumeration Type Documentation

◆ SkyPreset

enum SkyPreset
Enumerator
SKY_NONE 
SKY_EARTH 
SKY_STROGGOS 

Definition at line 28 of file precomputed_sky.h.

29 {
30  SKY_NONE,
31  SKY_EARTH,
33 } SkyPreset;

Function Documentation

◆ InitializeShadowmapResources()

void InitializeShadowmapResources ( )

Definition at line 975 of file precomputed_sky.c.

976 {
979 }

Referenced by vkpt_physical_sky_initialize().

◆ RecordCommandBufferShadowmap()

void RecordCommandBufferShadowmap ( VkCommandBuffer  cmd_buf)

Definition at line 991 of file precomputed_sky.c.

992 {
993  IMAGE_BARRIER(cmd_buf,
994  .image = ShadowmapData.TargetTexture,
995  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT, .levelCount = 1, .layerCount = 1 },
996  .srcAccessMask = VK_ACCESS_SHADER_READ_BIT,
997  .dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
998  .oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
999  .newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1000  );
1001 
1002  VkClearValue clearValues;
1003  clearValues.depthStencil.depth = 1.0f;
1004  clearValues.depthStencil.stencil = 0;
1005 
1006  VkRenderPassBeginInfo renderPassBeginInfo =
1007  {
1008  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
1009  .renderPass = render_pass_smap,
1010  .framebuffer = ShadowmapData.FrameBuffer,
1011  .renderArea.extent.width = ShadowmapData.Width,
1012  .renderArea.extent.height = ShadowmapData.Height,
1013  .clearValueCount = 1,
1014  .pClearValues = &clearValues,
1015  };
1016 
1017  vkCmdBeginRenderPass(cmd_buf, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1018 
1019  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_smap);
1020 
1021  VkViewport viewport =
1022  {
1023  .width = ShadowmapData.Width,
1024  .height = ShadowmapData.Height,
1025  .minDepth = 0,
1026  .maxDepth = 1.0f,
1027  };
1028 
1029  vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
1030 
1031  VkRect2D rect2D =
1032  {
1033  .extent.width = ShadowmapData.Width,
1034  .extent.height = ShadowmapData.Height,
1035  .offset.x = 0,
1036  .offset.y = 0,
1037  };
1038 
1039  vkCmdSetScissor(cmd_buf, 0, 1, &rect2D);
1040  float depthBiasConstant = 0.f;
1041  float depthBiasSlope = 0.f;
1042 
1043  vkCmdPushConstants(cmd_buf, pipeline_layout_smap, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float) * 16, terrain_shadowmap_viewproj);
1044 
1045  VkDeviceSize offsets[1] = { 0 };
1046  vkCmdBindVertexBuffers(cmd_buf, 0, 1, &ShadowmapGrid.Vertexes.buffer, offsets);
1047  vkCmdBindIndexBuffer(cmd_buf, ShadowmapGrid.Indexes.buffer, 0, VK_INDEX_TYPE_UINT32);
1048  vkCmdDrawIndexed(cmd_buf, ShadowmapGrid.IndexCount, 1, 0, 0, 0);
1049  vkCmdEndRenderPass(cmd_buf);
1050 
1051  IMAGE_BARRIER(cmd_buf,
1052  .image = ShadowmapData.TargetTexture,
1053  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT,.levelCount = 1,.layerCount = 1 },
1054  .srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
1055  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
1056  .oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1057  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1058  );
1059 }

Referenced by vkpt_physical_sky_record_cmd_buffer().

◆ ReleaseShadowmapResources()

void ReleaseShadowmapResources ( )

Definition at line 981 of file precomputed_sky.c.

982 {
985  memset(&ShadowmapGrid, 0, sizeof(ShadowmapGrid));
986 
988 }

Referenced by vkpt_physical_sky_destroy().

◆ SkyGetDescriptorLayout()

VkDescriptorSetLayout* SkyGetDescriptorLayout ( )

Definition at line 356 of file precomputed_sky.c.

357 {
359 }

Referenced by vkpt_physical_sky_initialize().

◆ SkyGetDescriptorSet()

VkDescriptorSet SkyGetDescriptorSet ( )

Definition at line 361 of file precomputed_sky.c.

362 {
364 }

Referenced by vkpt_physical_sky_record_cmd_buffer().

◆ SkyInitializeDataGPU()

VkResult SkyInitializeDataGPU ( )

Definition at line 597 of file precomputed_sky.c.

598 {
599  LoadImageFromDDS("env/clouds.dds", BINDING_OFFSET_SKY_CLOUDS, &SkyClouds, "SkyClouds");
600 
601  LoadImageFromDDS("env/terrain_albedo.dds", BINDING_OFFSET_TERRAIN_ALBEDO, &TerrainAlbedo, "SkyGBufferAlbedo");
602  LoadImageFromDDS("env/terrain_normal.dds", BINDING_OFFSET_TERRAIN_NORMALS, &TerrainNormals, "SkyGBufferNormals");
603  LoadImageFromDDS("env/terrain_depth.dds", BINDING_OFFSET_TERRAIN_DEPTH, &TerrainDepth, "SkyGBufferDepth");
604 
606 
607  return VK_SUCCESS;
608 }

Referenced by vkpt_physical_sky_initialize().

◆ SkyLoadScatterParameters()

VkResult SkyLoadScatterParameters ( SkyPreset  preset)

Definition at line 565 of file precomputed_sky.c.

566 {
567  const char* Planet;
568 
569  if (preset == SKY_EARTH)
570  {
571  Planet = "earth";
573  }
574  else if (preset == SKY_STROGGOS)
575  {
576  Planet = "stroggos";
578  }
579 
583 
584  char FileBuf[MAX_QPATH];
585  Q_snprintf(FileBuf, sizeof(FileBuf), "env/transmittance_%s.dds", Planet);
587  Q_snprintf(FileBuf, sizeof(FileBuf), "env/inscatter_%s.dds", Planet);
588  LoadImageFromDDS(FileBuf, BINDING_OFFSET_SKY_SCATTERING, &SkyInscatter, "SkyInscatter");
589  Q_snprintf(FileBuf, sizeof(FileBuf), "env/irradiance_%s.dds", Planet);
590  LoadImageFromDDS(FileBuf, BINDING_OFFSET_SKY_IRRADIANCE, &SkyIrradiance, "SkyIrradiance");
591 
593 
594  return VK_SUCCESS;
595 }

Referenced by vkpt_evaluate_sun_light().

◆ SkyReleaseDataGPU()

void SkyReleaseDataGPU ( )

◆ UpdateTerrainShadowMapView()

void UpdateTerrainShadowMapView ( vec3_t  forward)

Definition at line 550 of file precomputed_sky.c.

551 {
552  float Proj[16];
553  float View[16];
554 
555  float BoundingOffset = ShadowmapWorldSize * 0.75f;
556  create_centered_orthographic_matrix(Proj, -BoundingOffset, BoundingOffset, -BoundingOffset, BoundingOffset, -ShadowmapWorldSize * 0.75f, ShadowmapWorldSize * 0.75f);
557  vec3_t up = { 0, 0, 1.0f };
558  vec3_t origin = { 0.f };
560 
562 }

Referenced by vkpt_physical_sky_update_ubo().

Variable Documentation

◆ ShadowmapGridSize

const uint32_t ShadowmapGridSize = 1024
static

Definition at line 24 of file precomputed_sky.h.

Referenced by InitializeShadowmapResources().

◆ ShadowmapHeightmapSize

const uint32_t ShadowmapHeightmapSize = 4096
static

Definition at line 23 of file precomputed_sky.h.

◆ ShadowmapSize

const uint32_t ShadowmapSize = 2048
static

Definition at line 22 of file precomputed_sky.h.

Referenced by CreateShadowMap().

◆ ShadowmapWorldElevation

const float ShadowmapWorldElevation = 3.0f
static

Definition at line 26 of file precomputed_sky.h.

◆ ShadowmapWorldSize

const float ShadowmapWorldSize = 30.0f
static

Definition at line 25 of file precomputed_sky.h.

Referenced by InitializeShadowmapResources(), and UpdateTerrainShadowMapView().

SkyTransmittance
struct ImageGPUInfo SkyTransmittance
Definition: precomputed_sky.c:81
Shadowmap::TargetTexture
VkImage TargetTexture
Definition: precomputed_sky.c:647
ShadowmapGeometry::Vertexes
BufferResource_t Vertexes
Definition: precomputed_sky.c:659
Q_snprintf
size_t Q_snprintf(char *dest, size_t size, const char *fmt,...)
Definition: shared.c:846
ShadowmapGrid
struct ShadowmapGeometry ShadowmapGrid
Definition: precomputed_sky.c:669
pipeline_smap
VkPipeline pipeline_smap
Definition: shadow_map.c:26
uniform_precomputed_descriptor_layout
VkDescriptorSetLayout uniform_precomputed_descriptor_layout
Definition: precomputed_sky.c:90
ReleaseShadowmap
void ReleaseShadowmap(struct Shadowmap *InOutShadowmap)
Definition: precomputed_sky.c:852
create_look_at_matrix
void create_look_at_matrix(float matrix[16], vec3_t EyePosition, vec3_t EyeDirection, vec3_t UpDirection)
Definition: precomputed_sky.c:483
Params_Earth
static struct AtmosphereParameters Params_Earth
Definition: precomputed_sky.c:38
BINDING_OFFSET_SKY_CLOUDS
#define BINDING_OFFSET_SKY_CLOUDS
Definition: global_textures.h:134
buffer_destroy
VkResult buffer_destroy(BufferResource_t *buf)
Definition: vk_util.c:132
BINDING_OFFSET_TERRAIN_ALBEDO
#define BINDING_OFFSET_TERRAIN_ALBEDO
Definition: global_textures.h:135
ShadowmapGeometry::Indexes
BufferResource_t Indexes
Definition: precomputed_sky.c:660
Shadowmap::Width
uint32_t Width
Definition: precomputed_sky.c:652
Params_Stroggos
static struct AtmosphereParameters Params_Stroggos
Definition: precomputed_sky.c:50
SkyInscatter
struct ImageGPUInfo SkyInscatter
Definition: precomputed_sky.c:82
ShadowmapData
struct Shadowmap ShadowmapData
Definition: precomputed_sky.c:668
FillVertexAndIndexBuffers
struct ShadowmapGeometry FillVertexAndIndexBuffers(const char *FileName, unsigned int SideSize, float size_km)
Definition: precomputed_sky.c:679
SKY_NONE
@ SKY_NONE
Definition: precomputed_sky.h:30
BINDING_OFFSET_SKY_SCATTERING
#define BINDING_OFFSET_SKY_SCATTERING
Definition: global_textures.h:132
Shadowmap::Height
uint32_t Height
Definition: precomputed_sky.c:653
forward
static vec3_t forward
Definition: p_view.c:27
BufferResource_s::buffer
VkBuffer buffer
Definition: vk_util.h:34
origin
static vec3_t origin
Definition: mesh.c:27
CreateShadowMap
void CreateShadowMap(struct Shadowmap *InOutShadowmap)
Definition: precomputed_sky.c:868
terrain_shadowmap_viewproj
float terrain_shadowmap_viewproj[16]
Definition: precomputed_sky.c:99
TerrainNormals
struct ImageGPUInfo TerrainNormals
Definition: precomputed_sky.c:87
ShadowmapGeometry::IndexCount
uint32_t IndexCount
Definition: precomputed_sky.c:661
BINDING_OFFSET_SKY_IRRADIANCE
#define BINDING_OFFSET_SKY_IRRADIANCE
Definition: global_textures.h:133
BINDING_OFFSET_TERRAIN_DEPTH
#define BINDING_OFFSET_TERRAIN_DEPTH
Definition: global_textures.h:137
SkyClouds
struct ImageGPUInfo SkyClouds
Definition: precomputed_sky.c:84
vkpt_uniform_precomputed_buffer_create
VkResult vkpt_uniform_precomputed_buffer_create()
Definition: precomputed_sky.c:367
BINDING_OFFSET_TERRAIN_NORMALS
#define BINDING_OFFSET_TERRAIN_NORMALS
Definition: global_textures.h:136
SKY_EARTH
@ SKY_EARTH
Definition: precomputed_sky.h:31
up
static vec3_t up
Definition: p_view.c:27
TerrainDepth
struct ImageGPUInfo TerrainDepth
Definition: precomputed_sky.c:88
render_pass_smap
VkRenderPass render_pass_smap
Definition: shadow_map.c:25
Constants
const struct AtmosphereParameters * Constants
Definition: precomputed_sky.c:30
vkpt_uniform_precomputed_buffer_destroy
VkResult vkpt_uniform_precomputed_buffer_destroy()
Definition: precomputed_sky.c:442
mult_matrix_matrix
void mult_matrix_matrix(float *p, const float *a, const float *b)
Definition: matrix.c:281
pipeline_layout_smap
VkPipelineLayout pipeline_layout_smap
Definition: shadow_map.c:24
ShadowmapGridSize
static const uint32_t ShadowmapGridSize
Definition: precomputed_sky.h:24
TerrainAlbedo
struct ImageGPUInfo TerrainAlbedo
Definition: precomputed_sky.c:86
IMAGE_BARRIER
#define IMAGE_BARRIER(cmd_buf,...)
Definition: vk_util.h:55
SkyIrradiance
struct ImageGPUInfo SkyIrradiance
Definition: precomputed_sky.c:83
ShadowmapWorldSize
static const float ShadowmapWorldSize
Definition: precomputed_sky.h:25
SKY_STROGGOS
@ SKY_STROGGOS
Definition: precomputed_sky.h:32
Shadowmap::FrameBuffer
VkFramebuffer FrameBuffer
Definition: precomputed_sky.c:651
vkpt_uniform_precomputed_buffer_update
VkResult vkpt_uniform_precomputed_buffer_update()
Definition: precomputed_sky.c:455
desc_set_precomputed_ubo
VkDescriptorSet desc_set_precomputed_ubo
Definition: precomputed_sky.c:91
create_centered_orthographic_matrix
void create_centered_orthographic_matrix(float matrix[16], float xmin, float xmax, float ymin, float ymax, float znear, float zfar)
Definition: precomputed_sky.c:519
SkyPreset
SkyPreset
Definition: precomputed_sky.h:28
ReleaseInfo
void ReleaseInfo(struct ImageGPUInfo *Info)
Definition: precomputed_sky.c:73
BINDING_OFFSET_SKY_TRANSMITTANCE
#define BINDING_OFFSET_SKY_TRANSMITTANCE
Definition: global_textures.h:131
LoadImageFromDDS
qboolean LoadImageFromDDS(const char *FileName, uint32_t Binding, struct ImageGPUInfo *Info, const char *DebugName)
Definition: precomputed_sky.c:286