Quake II RTX doxygen  1.0 dev
physical_sky.c File Reference
#include "physical_sky.h"
#include "precomputed_sky.h"
#include "system/system.h"
#include "../../client/client.h"
#include <time.h>
#include <SDL_joystick.h>
#include <SDL_gamecontroller.h>

Go to the source code of this file.

Macros

#define BARRIER_COMPUTE(cmd_buf, img)
 

Enumerations

enum  sun_preset_t {
  SUN_PRESET_NONE = 0, SUN_PRESET_CURRENT_TIME = 1, SUN_PRESET_FAST_TIME = 2, SUN_PRESET_NIGHT = 3,
  SUN_PRESET_DAWN = 4, SUN_PRESET_MORNING = 5, SUN_PRESET_NOON = 6, SUN_PRESET_EVENING = 7,
  SUN_PRESET_DUSK = 8, SUN_PRESET_COUNT
}
 

Functions

void vkpt_physical_sky_latch_local_time ()
 
static int active_sun_preset ()
 
static void change_image_layouts (VkImage image, const VkImageSubresourceRange *subresource_range)
 
static void destroyEnvTexture (void)
 
static VkResult initializeEnvTexture (int width, int height)
 
VkResult vkpt_physical_sky_initialize ()
 
VkResult vkpt_physical_sky_destroy ()
 
VkResult vkpt_physical_sky_beginRegistration ()
 
VkResult vkpt_physical_sky_endRegistration ()
 
VkResult vkpt_physical_sky_create_pipelines ()
 
VkResult vkpt_physical_sky_destroy_pipelines ()
 
static void reset_sun_color_buffer (VkCommandBuffer cmd_buf)
 
qboolean vkpt_physical_sky_needs_update ()
 
VkResult vkpt_physical_sky_record_cmd_buffer (VkCommandBuffer cmd_buf)
 
static void process_gamepad_input ()
 
void vkpt_next_sun_preset ()
 
void vkpt_evaluate_sun_light (sun_light_t *light, const vec3_t sky_matrix[3], float time)
 
VkResult vkpt_physical_sky_update_ubo (QVKUniformBuffer_t *ubo, const sun_light_t *light, qboolean render_world)
 
void physical_sky_cvar_changed (cvar_t *self)
 
void InitialiseSkyCVars ()
 
void UpdatePhysicalSkyCVars ()
 
const PhysicalSkyDesc_tGetSkyPreset (uint16_t index)
 
static void rotationQuat (vec3_t const axis, float radians, vec4_t result)
 
static float dotQuat (vec4_t const q0, vec4_t const q1)
 
static void normalizeQuat (vec4_t q)
 
static void conjugateQuat (vec4_t q)
 
static void inverseQuat (vec4_t q)
 
static void quatMult (vec4_t const a, vec4_t const b, vec4_t result)
 
void CalculateDirectionToSun (float DayOfYear, float TimeOfDay, float LatitudeDegrees, vec3_t result)
 

Variables

static VkImage img_envmap = 0
 
static VkImageView imv_envmap = 0
 
static VkDeviceMemory mem_envmap = 0
 
static VkPipeline pipeline_physical_sky
 
static VkPipeline pipeline_physical_sky_space
 
static VkPipelineLayout pipeline_layout_physical_sky
 
static VkPipeline pipeline_resolve
 
static VkPipelineLayout pipeline_layout_resolve
 
static int width = 1024
 
static int height = 1024
 
static int skyNeedsUpdate = VK_TRUE
 
cvar_t * sun_color [3]
 
cvar_t * sun_elevation
 
cvar_t * sun_azimuth
 
cvar_t * sun_angle
 
cvar_t * sun_brightness
 
cvar_t * sun_bounce
 
cvar_t * sun_animate
 
cvar_t * sun_gamepad
 
cvar_t * sun_preset
 
cvar_t * sun_latitude
 
cvar_t * physical_sky
 
cvar_t * physical_sky_draw_clouds
 
cvar_t * physical_sky_space
 
cvar_t * physical_sky_brightness
 
cvar_t * sky_scattering
 
cvar_t * sky_transmittance
 
cvar_t * sky_phase_g
 
cvar_t * sky_amb_phase_g
 
static uint32_t physical_sky_planet_albedo_map = 0
 
static uint32_t physical_sky_planet_normal_map = 0
 
static time_t latched_local_time
 
static int current_preset = 0
 
static qboolean sdl_initialized = qfalse
 
static SDL_GameController * game_controller = 0
 
float terrain_shadowmap_viewproj [16]
 
static PhysicalSkyDesc_t skyPresets [3]
 

Macro Definition Documentation

◆ BARRIER_COMPUTE

#define BARRIER_COMPUTE (   cmd_buf,
  img 
)
Value:
do { \
VkImageSubresourceRange subresource_range = { \
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
.baseMipLevel = 0, \
.levelCount = 1, \
.baseArrayLayer = 0, \
.layerCount = 1 \
}; \
IMAGE_BARRIER(cmd_buf, \
.image = img, \
.subresourceRange = subresource_range, \
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, \
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT, \
.oldLayout = VK_IMAGE_LAYOUT_GENERAL, \
.newLayout = VK_IMAGE_LAYOUT_GENERAL, \
); \
} while(0)

Definition at line 416 of file physical_sky.c.

Enumeration Type Documentation

◆ sun_preset_t

Enumerator
SUN_PRESET_NONE 
SUN_PRESET_CURRENT_TIME 
SUN_PRESET_FAST_TIME 
SUN_PRESET_NIGHT 
SUN_PRESET_DAWN 
SUN_PRESET_MORNING 
SUN_PRESET_NOON 
SUN_PRESET_EVENING 
SUN_PRESET_DUSK 
SUN_PRESET_COUNT 

Definition at line 80 of file physical_sky.c.

Function Documentation

◆ active_sun_preset()

static int active_sun_preset ( )
static

Definition at line 94 of file physical_sky.c.

95 {
96  qboolean multiplayer = cl.maxclients > 1;
97 
98  if (multiplayer)
99  {
100  int preset = sun_preset->integer;
101  if (preset == SUN_PRESET_CURRENT_TIME)
102  return SUN_PRESET_FAST_TIME;
103  return preset;
104  }
105 
106  return sun_preset->integer;
107 }

Referenced by process_gamepad_input(), and vkpt_evaluate_sun_light().

◆ CalculateDirectionToSun()

void CalculateDirectionToSun ( float  DayOfYear,
float  TimeOfDay,
float  LatitudeDegrees,
vec3_t  result 
)

Definition at line 1041 of file physical_sky.c.

1042 {
1043  const float AxialTilt = 23.439f;
1044  const float DaysInYear = 365.25f;
1045  const float SpringEquinoxDay = 79.0f; // Mar 20
1046 
1047  float altitudeAtNoon = 90 - LatitudeDegrees + AxialTilt * sinf((DayOfYear - SpringEquinoxDay) / DaysInYear * 2.0f * M_PI);
1048  altitudeAtNoon = altitudeAtNoon * M_PI / 180.f;
1049 
1050  float altitudeOfEarthAxis = 180 - LatitudeDegrees;
1051  altitudeOfEarthAxis = altitudeOfEarthAxis * M_PI / 180.f;
1052 
1053  // X -> North
1054  // Y -> Zenith
1055  // Z -> East
1056 
1057  vec3_t noonVector = { cosf(altitudeAtNoon), sinf(altitudeAtNoon), 0.0f };
1058  vec3_t earthAxis = { cosf(altitudeOfEarthAxis), sinf(altitudeOfEarthAxis), 0.0f };
1059 
1060  float angleFromNoon = (TimeOfDay - 12.0f) / 24.0f * 2.f * M_PI;
1061 
1062  vec4_t dayRotation;
1063  rotationQuat(earthAxis, -angleFromNoon, dayRotation);
1064 
1065  vec4_t dayRotationInv = { dayRotation[0], dayRotation[1], dayRotation[2], dayRotation[3] };
1066  inverseQuat(dayRotationInv);
1067 
1068 
1069  // = normalize(dayRotationInv * makequat(0.f, noonVector) * dayRotation);
1070  vec4_t sunDirection = { 0.0f, 0.0f, 0.0f, 0.0f };
1071  vec4_t noonQuat = { 0.0f, noonVector[0], noonVector[1], noonVector[2] };
1072  quatMult(dayRotationInv, noonQuat, sunDirection);
1073  quatMult(sunDirection, dayRotation, sunDirection);
1074  normalizeQuat(sunDirection);
1075 
1076  result[0] = sunDirection[1];
1077  result[1] = sunDirection[3];
1078  result[2] = sunDirection[2];
1079 }

Referenced by vkpt_evaluate_sun_light().

◆ change_image_layouts()

static void change_image_layouts ( VkImage  image,
const VkImageSubresourceRange *  subresource_range 
)
static

Definition at line 534 of file physical_sky.c.

535 {
536  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
537 
538  IMAGE_BARRIER(cmd_buf,
539  .image = img_envmap,
540  .subresourceRange = *subresource_range,
541  .srcAccessMask = 0,
542  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
543  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
544  .newLayout = VK_IMAGE_LAYOUT_GENERAL,
545  );
546 
549 }

Referenced by initializeEnvTexture().

◆ conjugateQuat()

static void conjugateQuat ( vec4_t  q)
static

Definition at line 1017 of file physical_sky.c.

1018 {
1019  q[0] = q[0];
1020  q[1] = -q[1];
1021  q[2] = -q[2];
1022  q[3] = -q[3];
1023 }

Referenced by inverseQuat().

◆ destroyEnvTexture()

static void destroyEnvTexture ( void  )
static

Definition at line 112 of file physical_sky.c.

113 {
114  if (imv_envmap != VK_NULL_HANDLE) {
115  vkDestroyImageView(qvk.device, imv_envmap, NULL);
116  imv_envmap = NULL;
117  }
118  if (img_envmap != VK_NULL_HANDLE) {
119  vkDestroyImage(qvk.device, img_envmap, NULL);
120  img_envmap = NULL;
121  }
122  if (mem_envmap != VK_NULL_HANDLE) {
123  vkFreeMemory(qvk.device, mem_envmap, NULL);
124  mem_envmap = VK_NULL_HANDLE;
125  }
126 }

Referenced by initializeEnvTexture(), and vkpt_physical_sky_destroy().

◆ dotQuat()

static float dotQuat ( vec4_t const  q0,
vec4_t const  q1 
)
static

Definition at line 1005 of file physical_sky.c.

1006 {
1007  return q0[0]*q1[0] + q0[1]*q1[1] + q0[2]*q1[2] + q0[3]*q1[3];
1008 }

Referenced by inverseQuat(), and normalizeQuat().

◆ GetSkyPreset()

const PhysicalSkyDesc_t* GetSkyPreset ( uint16_t  index)

Definition at line 986 of file physical_sky.c.

987 {
988  if (index >= 0 && index < q_countof(skyPresets))
989  return &skyPresets[index];
990 
991  return &skyPresets[0];
992 }

Referenced by UpdatePhysicalSkyCVars(), vkpt_evaluate_sun_light(), and vkpt_physical_sky_update_ubo().

◆ InitialiseSkyCVars()

void InitialiseSkyCVars ( )

Definition at line 881 of file physical_sky.c.

882 {
883  static char _rgb[3] = {'r', 'g', 'b'};
884 
885  // sun
886  for (int i = 0; i < 3; ++i)
887  {
888  char buff[32];
889  snprintf(buff, 32, "sun_color_%c", _rgb[i]);
890  sun_color[i] = Cvar_Get(buff, "1.0", 0);
891  sun_color[i]->changed = physical_sky_cvar_changed;
892  }
893 
894  sun_elevation = Cvar_Get("sun_elevation", "45", 0);
896 
897  sun_azimuth = Cvar_Get("sun_azimuth", "345", 0);
899 
900  sun_angle = Cvar_Get("sun_angle", "1.0", 0);
902 
903  sun_brightness = Cvar_Get("sun_brightness", "10", 0);
905 
906  sky_scattering = Cvar_Get("sky_scattering", "5.0", 0);
908 
909  sky_transmittance = Cvar_Get("sky_transmittance", "10.0", 0);
911 
912  sky_phase_g = Cvar_Get("sky_phase_g", "0.9", 0);
914 
915  sky_amb_phase_g = Cvar_Get("sky_amb_phase_g", "0.3", 0);
917 
918  sun_bounce = Cvar_Get("sun_bounce", "1.0", 0);
920 
921  sun_animate = Cvar_Get("sun_animate", "0", 0);
923 
924  sun_preset = Cvar_Get("sun_preset", va("%d", SUN_PRESET_MORNING), CVAR_ARCHIVE);
926 
927  sun_latitude = Cvar_Get("sun_latitude", "32.9", CVAR_ARCHIVE); // latitude of former HQ of id Software in Richardson, TX
929 
930  sun_gamepad = Cvar_Get("sun_gamepad", "0", 0);
931 
932  // sky
933 
934  physical_sky = Cvar_Get("physical_sky", "2", 0);
936 
937  physical_sky_draw_clouds = Cvar_Get("physical_sky_draw_clouds", "1", 0);
939 
940  physical_sky_space = Cvar_Get("physical_sky_space", "0", 0);
942 
943  physical_sky_brightness = Cvar_Get("physical_sky_brightness", "0", 0);
945 }

Referenced by R_Init_RTX().

◆ initializeEnvTexture()

static VkResult initializeEnvTexture ( int  width,
int  height 
)
static

Definition at line 129 of file physical_sky.c.

130 {
131  vkDeviceWaitIdle(qvk.device);
133 
134  const int num_images = 6;
135 
136  // cube image
137 
138  VkImageCreateInfo img_info = {
139  .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
140  .extent = {
141  .width = width,
142  .height = height,
143  .depth = 1,
144  },
145  .imageType = VK_IMAGE_TYPE_2D,
146  .format = VK_FORMAT_R16G16B16A16_SFLOAT,
147  .mipLevels = 1,
148  .arrayLayers = num_images,
149  .samples = VK_SAMPLE_COUNT_1_BIT,
150  .tiling = VK_IMAGE_TILING_OPTIMAL,
151  .usage = VK_IMAGE_USAGE_STORAGE_BIT
152  | VK_IMAGE_USAGE_TRANSFER_DST_BIT
153  | VK_IMAGE_USAGE_SAMPLED_BIT,
154  .flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT,
155  .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
156  .queueFamilyIndexCount = qvk.queue_idx_graphics,
157  .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
158  };
159 
160  _VK(vkCreateImage(qvk.device, &img_info, NULL, &img_envmap));
162 
163  VkMemoryRequirements mem_req;
164  vkGetImageMemoryRequirements(qvk.device, img_envmap, &mem_req);
165  //assert(mem_req.size >= (img_size * num_images));
166 
167  _VK(allocate_gpu_memory(mem_req, &mem_envmap));
168 
169  _VK(vkBindImageMemory(qvk.device, img_envmap, mem_envmap, 0));
170 
171  const VkImageSubresourceRange subresource_range = {
172  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
173  .baseMipLevel = 0,
174  .levelCount = 1,
175  .baseArrayLayer = 0,
176  .layerCount = num_images,
177  };
178 
179  change_image_layouts(img_envmap, &subresource_range);
180 
181  // image view
182 
183  VkImageViewCreateInfo img_view_info = {
184  .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
185  .viewType = VK_IMAGE_VIEW_TYPE_CUBE,
186  .format = VK_FORMAT_R16G16B16A16_SFLOAT,
187  .image = img_envmap,
188  .subresourceRange = subresource_range,
189  .components = {
190  VK_COMPONENT_SWIZZLE_R,
191  VK_COMPONENT_SWIZZLE_G,
192  VK_COMPONENT_SWIZZLE_B,
193  VK_COMPONENT_SWIZZLE_A,
194  },
195  };
196  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_envmap));
197  ATTACH_LABEL_VARIABLE(imv_envmap, IMAGE_VIEW);
198 
199  // cube descriptor layout
200  {
201  VkDescriptorImageInfo desc_img_info = {
202  .imageLayout = VK_IMAGE_LAYOUT_GENERAL,
203  .imageView = imv_envmap,
204  .sampler = qvk.tex_sampler,
205  };
206 
207  VkWriteDescriptorSet s = {
208  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
209  .dstSet = qvk.desc_set_textures_even,
210  .dstBinding = BINDING_OFFSET_PHYSICAL_SKY,
211  .dstArrayElement = 0,
212  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
213  .descriptorCount = 1,
214  .pImageInfo = &desc_img_info,
215  };
216 
217  vkUpdateDescriptorSets(qvk.device, 1, &s, 0, NULL);
218 
219  s.dstSet = qvk.desc_set_textures_odd;
220  vkUpdateDescriptorSets(qvk.device, 1, &s, 0, NULL);
221  }
222 
223  // image descriptor
224  {
225  VkDescriptorImageInfo desc_img_info = {
226  .imageLayout = VK_IMAGE_LAYOUT_GENERAL,
227  .imageView = imv_envmap,
228  };
229 
230  VkWriteDescriptorSet s = {
231  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
232  .dstSet = qvk.desc_set_textures_even,
233  .dstBinding = BINDING_OFFSET_PHYSICAL_SKY_IMG,
234  .dstArrayElement = 0,
235  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
236  .descriptorCount = 1,
237  .pImageInfo = &desc_img_info,
238  };
239 
240  vkUpdateDescriptorSets(qvk.device, 1, &s, 0, NULL);
241 
242  s.dstSet = qvk.desc_set_textures_odd;
243  vkUpdateDescriptorSets(qvk.device, 1, &s, 0, NULL);
244  }
245  return VK_SUCCESS;
246 }

Referenced by vkpt_physical_sky_initialize().

◆ inverseQuat()

static void inverseQuat ( vec4_t  q)
static

Definition at line 1025 of file physical_sky.c.

1026 {
1027  float l2 = dotQuat(q, q);
1028  conjugateQuat(q);
1029  for (int i = 0; i < 4; ++i)
1030  q[i] /= l2;
1031 }

Referenced by CalculateDirectionToSun().

◆ normalizeQuat()

static void normalizeQuat ( vec4_t  q)
static

Definition at line 1010 of file physical_sky.c.

1011 {
1012  float l = sqrtf(dotQuat(q, q));
1013  for (int i = 0; i < 4; ++i)
1014  q[i] /= l;
1015 }

Referenced by CalculateDirectionToSun().

◆ physical_sky_cvar_changed()

void physical_sky_cvar_changed ( cvar_t *  self)

Definition at line 875 of file physical_sky.c.

876 { // cvar callback to trigger a re-render of skybox
877  skyNeedsUpdate = VK_TRUE;
879 }

Referenced by InitialiseSkyCVars().

◆ process_gamepad_input()

static void process_gamepad_input ( )
static

Definition at line 552 of file physical_sky.c.

553 {
554  static int prev_milliseconds = 0;
555  int curr_milliseconds = Sys_Milliseconds();
556  if (!prev_milliseconds)
557  {
558  prev_milliseconds = curr_milliseconds;
559  return;
560  }
561 
562  int frame_time = curr_milliseconds - prev_milliseconds;
563  prev_milliseconds = curr_milliseconds;
564 
565  if (frame_time > 1000)
566  return;
567 
569  {
570  float dx = SDL_GameControllerGetAxis(game_controller, sun_gamepad->integer == 1 ? SDL_CONTROLLER_AXIS_LEFTX : SDL_CONTROLLER_AXIS_RIGHTX);
571  float dy = SDL_GameControllerGetAxis(game_controller, sun_gamepad->integer == 1 ? SDL_CONTROLLER_AXIS_LEFTY : SDL_CONTROLLER_AXIS_RIGHTY);
572 
573  const float deadzone = 8000.f;
574  const float limit = 32768.f - deadzone;
575  dx = powf(max(fabsf(dx) - deadzone, 0.f) / limit, 2.f) * (dx < 0 ? -1.f : 1.f);
576  dy = powf(max(fabsf(dy) - deadzone, 0.f) / limit, 2.f) * (dy < 0 ? -1.f : 1.f);
577 
578  dx *= frame_time * 0.05f;
579  dy *= frame_time * 0.05f;
580 
581  if (dx)
582  {
583  float azimuth = sun_azimuth->value;
584  azimuth -= dx;
585  while (azimuth > 360.f) azimuth -= 360.f;
586  while (azimuth < 0.f) azimuth += 360.f;
587  sun_azimuth->value = azimuth;
588  sun_azimuth->changed(sun_azimuth);
589  }
590 
591  if (dy)
592  {
593  float elevation = sun_elevation->value;
594  elevation -= dy;
595  if (elevation > 90.f) elevation = 90.f;
596  if (elevation < -90.f) elevation = -90.f;
597  sun_elevation->value = elevation;
598  sun_elevation->changed(sun_elevation);
599  }
600  }
601 }

Referenced by vkpt_evaluate_sun_light().

◆ quatMult()

static void quatMult ( vec4_t const  a,
vec4_t const  b,
vec4_t  result 
)
static

Definition at line 1033 of file physical_sky.c.

1034 {
1035  result[0] = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
1036  result[1] = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
1037  result[2] = a[0] * b[2] + a[2] * b[0] + a[3] * b[1] - a[1] * b[3];
1038  result[3] = a[0] * b[3] + a[3] * b[0] + a[1] * b[2] - a[2] * b[1];
1039 }

Referenced by CalculateDirectionToSun().

◆ reset_sun_color_buffer()

static void reset_sun_color_buffer ( VkCommandBuffer  cmd_buf)
static

Definition at line 437 of file physical_sky.c.

438 {
439  BUFFER_BARRIER(cmd_buf,
440  .buffer = qvk.buf_sun_color.buffer,
441  .offset = 0,
442  .size = VK_WHOLE_SIZE,
443  .srcAccessMask = VK_ACCESS_UNIFORM_READ_BIT,
444  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT
445  );
446 
447  vkCmdFillBuffer(cmd_buf, qvk.buf_sun_color.buffer,
448  0, VK_WHOLE_SIZE, 0);
449 
450  BUFFER_BARRIER(cmd_buf,
451  .buffer = qvk.buf_sun_color.buffer,
452  .offset = 0,
453  .size = VK_WHOLE_SIZE,
454  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
455  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT
456  );
457 }

Referenced by vkpt_physical_sky_record_cmd_buffer().

◆ rotationQuat()

static void rotationQuat ( vec3_t const  axis,
float  radians,
vec4_t  result 
)
static

Definition at line 994 of file physical_sky.c.

995 {
996  // Note: assumes axis is normalized
997  float sinHalfTheta = sinf(0.5f * radians);
998  float cosHalfTheta = cosf(0.5f * radians);
999  result[0] = cosHalfTheta;
1000  result[1] = axis[0] * sinHalfTheta;
1001  result[2] = axis[1] * sinHalfTheta;
1002  result[3] = axis[2] * sinHalfTheta;
1003 }

Referenced by CalculateDirectionToSun().

◆ UpdatePhysicalSkyCVars()

void UpdatePhysicalSkyCVars ( )

Definition at line 947 of file physical_sky.c.

948 {
949  PhysicalSkyDesc_t const * sky = GetSkyPreset(physical_sky->integer);
950 
951  // sun
952  for (int i = 0; i < 3; ++i)
953  Cvar_SetValue(sun_color[i], sky->sunColor[i], FROM_CODE);
954 
955  Cvar_SetValue(sun_angle, sky->sunAngularDiameter, FROM_CODE);
956 
957  skyNeedsUpdate = VK_TRUE;
958 }

Referenced by R_BeginRegistration_RTX(), and vkpt_evaluate_sun_light().

◆ vkpt_evaluate_sun_light()

void vkpt_evaluate_sun_light ( sun_light_t light,
const vec3_t  sky_matrix[3],
float  time 
)

Definition at line 620 of file physical_sky.c.

621 {
622  static uint16_t skyIndex = -1;
623  if (physical_sky->integer != skyIndex)
624  { // update cvars with presets if the user changed the sky
626  skyIndex = physical_sky->integer;
627  }
628 
629  PhysicalSkyDesc_t const * skyDesc = GetSkyPreset(skyIndex);
630 
631  if ((skyDesc->flags & PHYSICAL_SKY_FLAG_USE_SKYBOX) != 0)
632  {
633  // physical sky is disabled - no direct sun light in this mode
634  memset(light, 0, sizeof(*light));
635  return;
636  }
637 
638  if (skyIndex != current_preset)
639  {
640  vkQueueWaitIdle(qvk.queue_graphics);
642  current_preset = skyIndex;
643  }
644 
646 
647  float azimuth, elevation;
648 
649  static float start_time = 0.0f, sun_animate_changed = 0.0f;
650  if (sun_animate->value != sun_animate_changed)
651  {
652  start_time = time;
653  sun_animate_changed = sun_animate->value;
654  }
655 
656  const int preset = active_sun_preset();
657 
658  if ((preset == SUN_PRESET_CURRENT_TIME) || (preset == SUN_PRESET_FAST_TIME))
659  {
660  qboolean fast_time = (preset == SUN_PRESET_FAST_TIME);
661 
662  struct tm* local_time;
663 
664  if (fast_time)
665  local_time = gmtime(&latched_local_time);
666  else
667  local_time = localtime(&latched_local_time);
668 
669  float time_of_day = local_time->tm_hour + local_time->tm_min / 60.f;
670  if (fast_time)
671  time_of_day *= 12.f;
672  else if (local_time->tm_isdst)
673  time_of_day -= 1.f;
674 
675  CalculateDirectionToSun(local_time->tm_yday, time_of_day, sun_latitude->value, light->direction_envmap);
676  }
677  else
678  {
679  switch (preset)
680  {
681  case SUN_PRESET_NIGHT:
682  elevation = -90.f;
683  azimuth = 0.f;
684  break;
685 
686  case SUN_PRESET_DAWN:
687  elevation = -3.f;
688  azimuth = 0.f;
689  break;
690 
691  case SUN_PRESET_MORNING:
692  elevation = 25.f;
693  azimuth = -15.f;
694  break;
695 
696  case SUN_PRESET_NOON:
697  elevation = 80.f;
698  azimuth = -75.f;
699  break;
700 
701  case SUN_PRESET_EVENING:
702  elevation = 15.f;
703  azimuth = 190.f;
704  break;
705 
706  case SUN_PRESET_DUSK:
707  elevation = -6.f;
708  azimuth = 205.f;
709  break;
710 
711  default:
712  if (sun_animate->value > 0.0f)
713  {
714  float elapsed = (time - start_time) * 1000.f * sun_animate->value;
715 
716  azimuth = fmod(sun_azimuth->value + elapsed / (24.f * 60.f * 60.f), 360.0f);
717 
718  float e = fmod(sun_elevation->value + elapsed / (60.f * 60.f), 360.0f);
719  if (e > 270.f)
720  elevation = -(360.f - e);
721  else if (e > 180.0f)
722  {
723  elevation = -(e - 180.0f);
724  azimuth = fmod(azimuth + 180.f, 360.f);
725  }
726  else if (e > 90.0f)
727  {
728  elevation = 180.0f - e;
729  azimuth = fmod(azimuth + 180.f, 360.f);
730  }
731  else
732  elevation = e;
733  elevation = max(-90, min(90, elevation));
734 
735  skyNeedsUpdate = VK_TRUE;
736  }
737  else
738  {
739  azimuth = sun_azimuth->value;
740  elevation = sun_elevation->value;
741  }
742  break;
743  }
744 
745  float elevation_rad = elevation * M_PI / 180.0f; //max(-20.f, min(90.f, elevation)) * M_PI / 180.f;
746  float azimuth_rad = azimuth * M_PI / 180.f;
747  light->direction_envmap[0] = cosf(azimuth_rad) * cosf(elevation_rad);
748  light->direction_envmap[1] = sinf(azimuth_rad) * cosf(elevation_rad);
749  light->direction_envmap[2] = sinf(elevation_rad);
750  }
751 
752  light->angular_size_rad = max(1.f, min(10.f, sun_angle->value)) * M_PI / 180.f;
753 
754  light->use_physical_sky = qtrue;
755 
756  // color before occlusion
757  vec3_t sunColor = { sun_color[0]->value, sun_color[1]->value, sun_color[2]->value };
758  VectorScale(sunColor, sun_brightness->value, light->color);
759 
760  // potentially visible - can be overridden if readback data says it's occluded
761  if (physical_sky_space->integer)
762  light->visible = qtrue;
763  else
764  light->visible = (light->direction_envmap[2] >= -sinf(light->angular_size_rad * 0.5f));
765 
766  vec3_t sun_direction_world = { 0.f };
767  sun_direction_world[0] = light->direction_envmap[0] * sky_matrix[0][0] + light->direction_envmap[1] * sky_matrix[0][1] + light->direction_envmap[2] * sky_matrix[0][2];
768  sun_direction_world[1] = light->direction_envmap[0] * sky_matrix[1][0] + light->direction_envmap[1] * sky_matrix[1][1] + light->direction_envmap[2] * sky_matrix[1][2];
769  sun_direction_world[2] = light->direction_envmap[0] * sky_matrix[2][0] + light->direction_envmap[1] * sky_matrix[2][1] + light->direction_envmap[2] * sky_matrix[2][2];
770  VectorCopy(sun_direction_world, light->direction);
771 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_next_sun_preset()

void vkpt_next_sun_preset ( )

Definition at line 603 of file physical_sky.c.

604 {
605  int preset;
606 
607  if (sun_preset->integer < SUN_PRESET_NIGHT || sun_preset->integer > SUN_PRESET_DUSK)
608  preset = SUN_PRESET_MORNING;
609  else
610  {
611  preset = sun_preset->integer + 1;
612  if (preset > SUN_PRESET_DUSK)
613  preset = SUN_PRESET_NIGHT;
614  }
615 
616  Cvar_SetByVar(sun_preset, va("%d", preset), FROM_CONSOLE);
617 }

Referenced by R_Init_RTX().

◆ vkpt_physical_sky_beginRegistration()

VkResult vkpt_physical_sky_beginRegistration ( )

Definition at line 338 of file physical_sky.c.

339 {
342  return VK_SUCCESS;
343 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_physical_sky_create_pipelines()

VkResult vkpt_physical_sky_create_pipelines ( )

Definition at line 364 of file physical_sky.c.

365 {
366  {
367  VkComputePipelineCreateInfo pipeline_info = {
368  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
369  .stage = SHADER_STAGE(QVK_MOD_PHYSICAL_SKY_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
371  };
372 
373  _VK(vkCreateComputePipelines(qvk.device, 0, 1, &pipeline_info, 0, &pipeline_physical_sky));
374  }
375 
376  {
377  VkComputePipelineCreateInfo pipeline_info = {
378  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
379  .stage = SHADER_STAGE(QVK_MOD_PHYSICAL_SKY_SPACE_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
381  };
382 
383  _VK(vkCreateComputePipelines(qvk.device, 0, 1, &pipeline_info, 0, &pipeline_physical_sky_space));
384  }
385 
386  {
387  VkComputePipelineCreateInfo pipeline_info = {
388  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
389  .stage = SHADER_STAGE(QVK_MOD_SKY_BUFFER_RESOLVE_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
390  .layout = pipeline_layout_resolve
391  };
392 
393  _VK(vkCreateComputePipelines(qvk.device, 0, 1, &pipeline_info, 0, &pipeline_resolve));
394  }
395 
396  skyNeedsUpdate = VK_TRUE;
397 
398  return VK_SUCCESS;
399 }

◆ vkpt_physical_sky_destroy()

VkResult vkpt_physical_sky_destroy ( )

Definition at line 315 of file physical_sky.c.

316 {
317  current_preset = 0;
318 
321 
322  vkDestroyPipelineLayout(qvk.device, pipeline_layout_physical_sky, NULL);
323  pipeline_layout_physical_sky = VK_NULL_HANDLE;
324  vkDestroyPipelineLayout(qvk.device, pipeline_layout_resolve, NULL);
325  pipeline_layout_resolve = VK_NULL_HANDLE;
327 
328  if (game_controller)
329  {
330  SDL_GameControllerClose(game_controller);
331  game_controller = 0;
332  }
333 
334  return VK_SUCCESS;
335 }

◆ vkpt_physical_sky_destroy_pipelines()

VkResult vkpt_physical_sky_destroy_pipelines ( )

Definition at line 402 of file physical_sky.c.

403 {
404  vkDestroyPipeline(qvk.device, pipeline_physical_sky, NULL);
405  pipeline_physical_sky = VK_NULL_HANDLE;
406 
407  vkDestroyPipeline(qvk.device, pipeline_physical_sky_space, NULL);
408  pipeline_physical_sky_space = VK_NULL_HANDLE;
409 
410  vkDestroyPipeline(qvk.device, pipeline_resolve, NULL);
411  pipeline_resolve = VK_NULL_HANDLE;
412 
413  return VK_SUCCESS;
414 }

◆ vkpt_physical_sky_endRegistration()

VkResult vkpt_physical_sky_endRegistration ( )

Definition at line 346 of file physical_sky.c.

347 {
348  if (physical_sky_space->integer > 0)
349  {
350  image_t const * albedo_map = IMG_Find("env/planet_albedo.tga", IT_SKIN, IF_SRGB);
351  if (albedo_map != R_NOTEXTURE) {
353  }
354 
355  image_t const * normal_map = IMG_Find("env/planet_normal.tga", IT_SKIN, IF_SRGB);
356  if (normal_map != R_NOTEXTURE) {
358  }
359  }
360  return VK_SUCCESS;
361 }

Referenced by R_EndRegistration_RTX().

◆ vkpt_physical_sky_initialize()

VkResult vkpt_physical_sky_initialize ( )

Definition at line 249 of file physical_sky.c.

250 {
251  current_preset = 0;
252 
254 
256 
257  {
258  VkDescriptorSetLayout desc_set_layouts[] = {
263  };
264 
265  VkPushConstantRange push_constant_range = {
266  .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
267  .offset = 0,
268  .size = sizeof(float) * 16,
269  };
270 
272  .setLayoutCount = LENGTH(desc_set_layouts),
273  .pSetLayouts = desc_set_layouts,
274  .pushConstantRangeCount = 1,
275  .pPushConstantRanges = &push_constant_range,
276  );
277 
279  }
280 
281  {
282  VkDescriptorSetLayout desc_set_layouts[] = {
285  };
286 
288  .setLayoutCount = LENGTH(desc_set_layouts),
289  .pSetLayouts = desc_set_layouts,
290  );
292  }
293 
294  if (!sdl_initialized)
295  {
296  SDL_InitSubSystem(SDL_INIT_JOYSTICK);
297  sdl_initialized = qtrue;
298  }
299 
300  for (int i = 0; i < SDL_NumJoysticks(); i++)
301  {
302  if (SDL_IsGameController(i))
303  {
304  game_controller = SDL_GameControllerOpen(i);
305  break;
306  }
307  }
308 
309 
310 
312 }

◆ vkpt_physical_sky_latch_local_time()

void vkpt_physical_sky_latch_local_time ( )

Definition at line 75 of file physical_sky.c.

76 {
77  time(&latched_local_time);
78 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_physical_sky_needs_update()

qboolean vkpt_physical_sky_needs_update ( )

Definition at line 459 of file physical_sky.c.

460 {
461  return skyNeedsUpdate;
462 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_physical_sky_record_cmd_buffer()

VkResult vkpt_physical_sky_record_cmd_buffer ( VkCommandBuffer  cmd_buf)

Definition at line 467 of file physical_sky.c.

468 {
469  if (!skyNeedsUpdate)
470  return VK_SUCCESS;
471 
473 
474  reset_sun_color_buffer(cmd_buf);
475 
476  {
477  VkDescriptorSet desc_sets[] = {
482  };
483 
484  if (physical_sky_space->integer > 0) {
485  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_physical_sky_space);
486  } else {
487  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_physical_sky);
488  }
489 
490  vkCmdPushConstants(cmd_buf, pipeline_layout_physical_sky, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(float) * 16, terrain_shadowmap_viewproj);
491 
492  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
493  pipeline_layout_physical_sky, 0, LENGTH(desc_sets), desc_sets, 0, 0);
494  const int group_size = 16;
495  vkCmdDispatch(cmd_buf, width / group_size, height / group_size, 6);
496  }
497 
498  BARRIER_COMPUTE(cmd_buf, img_envmap);
499 
500  BUFFER_BARRIER(cmd_buf,
501  .buffer = qvk.buf_sun_color.buffer,
502  .offset = 0,
503  .size = VK_WHOLE_SIZE,
504  .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
505  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT
506  );
507 
508  {
509  VkDescriptorSet desc_sets[] = {
512  };
513 
514  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_resolve);
515  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
516  pipeline_layout_resolve, 0, LENGTH(desc_sets), desc_sets, 0, 0);
517 
518  vkCmdDispatch(cmd_buf, 1, 1, 1);
519  }
520 
521  BUFFER_BARRIER(cmd_buf,
522  .buffer = qvk.buf_sun_color.buffer,
523  .offset = 0,
524  .size = VK_WHOLE_SIZE,
525  .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
526  .dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT
527  );
528 
529  skyNeedsUpdate = VK_FALSE;
530 
531  return VK_SUCCESS;
532 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_physical_sky_update_ubo()

VkResult vkpt_physical_sky_update_ubo ( QVKUniformBuffer_t ubo,
const sun_light_t light,
qboolean  render_world 
)

Definition at line 774 of file physical_sky.c.

775 {
776  PhysicalSkyDesc_t const * skyDesc = GetSkyPreset(physical_sky->integer);
777 
778  if(physical_sky_space->integer)
779  ubo->pt_env_scale = 0.3f;
780  else
781  {
782  const float min_brightness = -10.f;
783  const float max_brightness = 2.f;
784 
785  float brightness = max(min_brightness, min(max_brightness, physical_sky_brightness->value));
786  ubo->pt_env_scale = exp2f(brightness - 2.f);
787  }
788 
789  // sun
790 
791  ubo->sun_bounce_scale = sun_bounce->value;
792  ubo->sun_tan_half_angle = tanf(light->angular_size_rad * 0.5f);
793  ubo->sun_cos_half_angle = cosf(light->angular_size_rad * 0.5f);
794  ubo->sun_solid_angle = 2 * M_PI * (float)(1.0 - cos(light->angular_size_rad * 0.5)); // use double for precision
795  //ubo->sun_solid_angle = max(ubo->sun_solid_angle, 1e-3f);
796 
797  VectorCopy(light->color, ubo->sun_color);
798  VectorCopy(light->direction_envmap, ubo->sun_direction_envmap);
799  VectorCopy(light->direction, ubo->sun_direction);
800 
801  if (light->direction[2] >= 0.99f)
802  {
803  VectorSet(ubo->sun_tangent, 1.f, 0.f, 0.f);
804  VectorSet(ubo->sun_bitangent, 0.f, 1.f, 0.f);
805  }
806  else
807  {
808  vec3_t up;
809  VectorSet(up, 0.f, 0.f, 1.f);
810  CrossProduct(light->direction, up, ubo->sun_tangent);
811  VectorNormalize(ubo->sun_tangent);
812  CrossProduct(light->direction, ubo->sun_tangent, ubo->sun_bitangent);
813  VectorNormalize(ubo->sun_bitangent);
814  }
815  // clouds
816 
817  ubo->sky_transmittance = sky_transmittance->value;
818  ubo->sky_phase_g = sky_phase_g->value;
819  ubo->sky_amb_phase_g = sky_amb_phase_g->value;
820  ubo->sky_scattering = sky_scattering->value;
821 
822  // atmosphere
823 
824  if (!render_world)
825  ubo->environment_type = ENVIRONMENT_NONE;
826  else if (light->use_physical_sky)
827  ubo->environment_type = ENVIRONMENT_DYNAMIC;
828  else
829  ubo->environment_type = ENVIRONMENT_STATIC;
830 
831  if (light->use_physical_sky)
832  {
833  uint32_t flags = skyDesc->flags;
834  // adjust flags from cvars here
835 
836  if (physical_sky_draw_clouds->value > 0.0f)
837  flags = flags | PHYSICAL_SKY_FLAG_DRAW_CLOUDS;
838  else
839  flags = flags & (~PHYSICAL_SKY_FLAG_DRAW_CLOUDS);
840 
841  ubo->physical_sky_flags = flags;
842 
843  // compute approximation of reflected radiance from ground
844  vec3_t ground_radiance;
845  VectorCopy(skyDesc->groundAlbedo, ground_radiance);
846  VectorScale(ground_radiance, max(0.f, light->direction_envmap[2]), ground_radiance); // N.L
847  VectorVectorScale(ground_radiance, light->color, ground_radiance);
848 
849  VectorCopy(ground_radiance, ubo->physical_sky_ground_radiance);
850  }
851  else
852  skyNeedsUpdate = VK_FALSE;
853 
854  // planet
855 
856  ubo->planet_albedo_map = physical_sky_planet_albedo_map;
857  ubo->planet_normal_map = physical_sky_planet_normal_map;
858 
859  ubo->sun_visible = light->visible;
860 
861  if (render_world && !(skyDesc->flags & PHYSICAL_SKY_FLAG_USE_SKYBOX))
862  {
863  vec3_t forward;
864  VectorScale(light->direction_envmap, -1.0f, forward);
866  }
867 
868  return VK_SUCCESS;
869 }

Referenced by R_RenderFrame_RTX().

Variable Documentation

◆ current_preset

int current_preset = 0
static

◆ game_controller

SDL_GameController* game_controller = 0
static

◆ height

◆ img_envmap

VkImage img_envmap = 0
static

◆ imv_envmap

VkImageView imv_envmap = 0
static

Definition at line 29 of file physical_sky.c.

Referenced by destroyEnvTexture(), and initializeEnvTexture().

◆ latched_local_time

time_t latched_local_time
static

Definition at line 68 of file physical_sky.c.

Referenced by vkpt_evaluate_sun_light(), and vkpt_physical_sky_latch_local_time().

◆ mem_envmap

VkDeviceMemory mem_envmap = 0
static

Definition at line 30 of file physical_sky.c.

Referenced by destroyEnvTexture(), and initializeEnvTexture().

◆ physical_sky

cvar_t* physical_sky

◆ physical_sky_brightness

cvar_t* physical_sky_brightness

Definition at line 58 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_physical_sky_update_ubo().

◆ physical_sky_draw_clouds

cvar_t* physical_sky_draw_clouds

Definition at line 56 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_physical_sky_update_ubo().

◆ physical_sky_planet_albedo_map

uint32_t physical_sky_planet_albedo_map = 0
static

◆ physical_sky_planet_normal_map

uint32_t physical_sky_planet_normal_map = 0
static

◆ physical_sky_space

◆ pipeline_layout_physical_sky

VkPipelineLayout pipeline_layout_physical_sky
static

◆ pipeline_layout_resolve

VkPipelineLayout pipeline_layout_resolve
static

◆ pipeline_physical_sky

VkPipeline pipeline_physical_sky
static

◆ pipeline_physical_sky_space

VkPipeline pipeline_physical_sky_space
static

◆ pipeline_resolve

VkPipeline pipeline_resolve
static

◆ sdl_initialized

qboolean sdl_initialized = qfalse
static

Definition at line 72 of file physical_sky.c.

Referenced by vkpt_physical_sky_initialize().

◆ sky_amb_phase_g

cvar_t* sky_amb_phase_g

Definition at line 63 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_physical_sky_update_ubo().

◆ sky_phase_g

cvar_t* sky_phase_g

Definition at line 62 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_physical_sky_update_ubo().

◆ sky_scattering

cvar_t* sky_scattering

Definition at line 60 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_physical_sky_update_ubo().

◆ sky_transmittance

cvar_t* sky_transmittance

Definition at line 61 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_physical_sky_update_ubo().

◆ skyNeedsUpdate

◆ skyPresets

PhysicalSkyDesc_t skyPresets[3]
static
Initial value:
= {
{
.preset = SKY_NONE,
},
{
.sunColor = {1.45f, 1.29f, 1.27f},
.sunAngularDiameter = 1.f,
.groundAlbedo = {0.3f, 0.15f, 0.14f},
.preset = SKY_EARTH,
},
{
.sunColor = {0.315f, 0.137f, 0.033f},
.sunAngularDiameter = 5.f,
.groundAlbedo = {0.133, 0.101, 0.047},
.preset = SKY_STROGGOS,
},
}

Definition at line 965 of file physical_sky.c.

Referenced by GetSkyPreset().

◆ sun_angle

cvar_t* sun_angle

◆ sun_animate

cvar_t* sun_animate

◆ sun_azimuth

cvar_t* sun_azimuth

◆ sun_bounce

cvar_t* sun_bounce

Definition at line 48 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_physical_sky_update_ubo().

◆ sun_brightness

cvar_t* sun_brightness

Definition at line 47 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_evaluate_sun_light().

◆ sun_color

cvar_t* sun_color[3]

◆ sun_elevation

cvar_t* sun_elevation

◆ sun_gamepad

cvar_t* sun_gamepad

Definition at line 50 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and process_gamepad_input().

◆ sun_latitude

cvar_t* sun_latitude

Definition at line 53 of file physical_sky.c.

Referenced by InitialiseSkyCVars(), and vkpt_evaluate_sun_light().

◆ sun_preset

cvar_t* sun_preset

Definition at line 52 of file physical_sky.c.

Referenced by active_sun_preset(), InitialiseSkyCVars(), and vkpt_next_sun_preset().

◆ terrain_shadowmap_viewproj

float terrain_shadowmap_viewproj[16]

◆ width

QVK_s::desc_set_ubo
VkDescriptorSet desc_set_ubo
Definition: vkpt.h:226
BUFFER_BARRIER
#define BUFFER_BARRIER(cmd_buf,...)
Definition: vk_util.h:68
SUN_PRESET_MORNING
@ SUN_PRESET_MORNING
Definition: physical_sky.c:87
sdl_initialized
static qboolean sdl_initialized
Definition: physical_sky.c:72
PhysicalSkyDesc
Definition: physical_sky.h:51
change_image_layouts
static void change_image_layouts(VkImage image, const VkImageSubresourceRange *subresource_range)
Definition: physical_sky.c:534
CREATE_PIPELINE_LAYOUT
#define CREATE_PIPELINE_LAYOUT(dev, layout,...)
Definition: vk_util.h:82
ReleaseShadowmapResources
void ReleaseShadowmapResources()
Definition: precomputed_sky.c:981
current_preset
static int current_preset
Definition: physical_sky.c:70
ENVIRONMENT_NONE
#define ENVIRONMENT_NONE
Definition: constants.h:98
SUN_PRESET_NIGHT
@ SUN_PRESET_NIGHT
Definition: physical_sky.c:85
reset_sun_color_buffer
static void reset_sun_color_buffer(VkCommandBuffer cmd_buf)
Definition: physical_sky.c:437
height
static int height
Definition: physical_sky.c:39
allocate_gpu_memory
VkResult allocate_gpu_memory(VkMemoryRequirements mem_req, VkDeviceMemory *pMemory)
Definition: vk_util.c:402
SUN_PRESET_FAST_TIME
@ SUN_PRESET_FAST_TIME
Definition: physical_sky.c:84
image_t
struct image_s image_t
Definition: material.h:27
sun_light_s::use_physical_sky
qboolean use_physical_sky
Definition: vkpt.h:419
sky_phase_g
cvar_t * sky_phase_g
Definition: physical_sky.c:62
physical_sky
cvar_t * physical_sky
Definition: physical_sky.c:55
QVK_s::device
VkDevice device
Definition: vkpt.h:172
normalizeQuat
static void normalizeQuat(vec4_t q)
Definition: physical_sky.c:1010
sun_latitude
cvar_t * sun_latitude
Definition: physical_sky.c:53
Cvar_Get
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
Definition: cvar.c:257
GetSkyPreset
const PhysicalSkyDesc_t * GetSkyPreset(uint16_t index)
Definition: physical_sky.c:986
SUN_PRESET_COUNT
@ SUN_PRESET_COUNT
Definition: physical_sky.c:91
PHYSICAL_SKY_FLAG_DRAW_CLOUDS
#define PHYSICAL_SKY_FLAG_DRAW_CLOUDS
Definition: sky.h:26
pipeline_physical_sky_space
static VkPipeline pipeline_physical_sky_space
Definition: physical_sky.c:33
sun_preset_t
sun_preset_t
Definition: physical_sky.c:80
PhysicalSkyDesc::sunAngularDiameter
float sunAngularDiameter
Definition: physical_sky.h:53
QVK_s::current_frame_index
uint32_t current_frame_index
Definition: vkpt.h:219
sun_brightness
cvar_t * sun_brightness
Definition: physical_sky.c:47
QVK_s::tex_sampler
VkSampler tex_sampler
Definition: vkpt.h:255
latched_local_time
static time_t latched_local_time
Definition: physical_sky.c:68
game_controller
static SDL_GameController * game_controller
Definition: physical_sky.c:73
img_envmap
static VkImage img_envmap
Definition: physical_sky.c:28
rotationQuat
static void rotationQuat(vec3_t const axis, float radians, vec4_t result)
Definition: physical_sky.c:994
dotQuat
static float dotQuat(vec4_t const q0, vec4_t const q1)
Definition: physical_sky.c:1005
QVK_s::cmd_buffers_graphics
cmd_buf_group_t cmd_buffers_graphics
Definition: vkpt.h:193
sun_gamepad
cvar_t * sun_gamepad
Definition: physical_sky.c:50
sky_scattering
cvar_t * sky_scattering
Definition: physical_sky.c:60
Sys_Milliseconds
unsigned Sys_Milliseconds(void)
Definition: system.c:644
sun_light_s::direction_envmap
vec3_t direction_envmap
Definition: vkpt.h:416
physical_sky_planet_albedo_map
static uint32_t physical_sky_planet_albedo_map
Definition: physical_sky.c:65
imv_envmap
static VkImageView imv_envmap
Definition: physical_sky.c:29
sun_angle
cvar_t * sun_angle
Definition: physical_sky.c:46
QVK_s::desc_set_textures_even
VkDescriptorSet desc_set_textures_even
Definition: vkpt.h:229
sun_light_s::visible
qboolean visible
Definition: vkpt.h:420
sky_amb_phase_g
cvar_t * sky_amb_phase_g
Definition: physical_sky.c:63
width
static int width
Definition: physical_sky.c:38
SkyLoadScatterParameters
VkResult SkyLoadScatterParameters(SkyPreset preset)
Definition: precomputed_sky.c:565
PHYSICAL_SKY_FLAG_USE_SKYBOX
#define PHYSICAL_SKY_FLAG_USE_SKYBOX
Definition: sky.h:24
SUN_PRESET_CURRENT_TIME
@ SUN_PRESET_CURRENT_TIME
Definition: physical_sky.c:83
_VK
#define _VK(...)
Definition: vkpt.h:65
SKY_NONE
@ SKY_NONE
Definition: precomputed_sky.h:30
skyPresets
static PhysicalSkyDesc_t skyPresets[3]
Definition: physical_sky.c:965
PHYSICAL_SKY_FLAG_DRAW_MOUNTAINS
#define PHYSICAL_SKY_FLAG_DRAW_MOUNTAINS
Definition: sky.h:25
terrain_shadowmap_viewproj
float terrain_shadowmap_viewproj[16]
Definition: precomputed_sky.c:99
QVK_s::queue_idx_graphics
int32_t queue_idx_graphics
Definition: vkpt.h:176
conjugateQuat
static void conjugateQuat(vec4_t q)
Definition: physical_sky.c:1017
QVK_s::desc_set_vertex_buffer
VkDescriptorSet desc_set_vertex_buffer
Definition: vkpt.h:241
physical_sky_cvar_changed
void physical_sky_cvar_changed(cvar_t *self)
Definition: physical_sky.c:875
forward
static vec3_t forward
Definition: p_view.c:27
quatMult
static void quatMult(vec4_t const a, vec4_t const b, vec4_t result)
Definition: physical_sky.c:1033
SkyReleaseDataGPU
void SkyReleaseDataGPU()
Definition: precomputed_sky.c:610
process_gamepad_input
static void process_gamepad_input()
Definition: physical_sky.c:552
physical_sky_planet_normal_map
static uint32_t physical_sky_planet_normal_map
Definition: physical_sky.c:66
Cvar_SetValue
void Cvar_SetValue(cvar_t *var, float value, from_t from)
Definition: cvar.c:487
QVK_s::buf_sun_color
BufferResource_t buf_sun_color
Definition: vkpt.h:253
va
char * va(const char *format,...)
Definition: shared.c:429
RecordCommandBufferShadowmap
void RecordCommandBufferShadowmap(VkCommandBuffer cmd_buf)
Definition: precomputed_sky.c:991
BufferResource_s::buffer
VkBuffer buffer
Definition: vk_util.h:34
physical_sky_brightness
cvar_t * physical_sky_brightness
Definition: physical_sky.c:58
SkyGetDescriptorSet
VkDescriptorSet SkyGetDescriptorSet()
Definition: precomputed_sky.c:361
ENVIRONMENT_DYNAMIC
#define ENVIRONMENT_DYNAMIC
Definition: constants.h:100
sun_bounce
cvar_t * sun_bounce
Definition: physical_sky.c:48
r_images
image_t r_images[MAX_RIMAGES]
Definition: images.c:651
UpdateTerrainShadowMapView
void UpdateTerrainShadowMapView(vec3_t forward)
Definition: precomputed_sky.c:550
UpdatePhysicalSkyCVars
void UpdatePhysicalSkyCVars()
Definition: physical_sky.c:947
sun_elevation
cvar_t * sun_elevation
Definition: physical_sky.c:44
sun_preset
cvar_t * sun_preset
Definition: physical_sky.c:52
Cvar_SetByVar
void Cvar_SetByVar(cvar_t *var, const char *value, from_t from)
Definition: cvar.c:345
pipeline_layout_resolve
static VkPipelineLayout pipeline_layout_resolve
Definition: physical_sky.c:36
vkpt_wait_idle
void vkpt_wait_idle(VkQueue queue, cmd_buf_group_t *group)
Definition: main.c:3405
active_sun_preset
static int active_sun_preset()
Definition: physical_sky.c:94
LENGTH
#define LENGTH(a)
Definition: tent.c:228
sun_light_s::angular_size_rad
float angular_size_rad
Definition: vkpt.h:418
sun_color
cvar_t * sun_color[3]
Definition: physical_sky.c:43
SkyInitializeDataGPU
VkResult SkyInitializeDataGPU()
Definition: precomputed_sky.c:597
sun_animate
cvar_t * sun_animate
Definition: physical_sky.c:49
sun_light_s::color
vec3_t color
Definition: vkpt.h:417
BINDING_OFFSET_PHYSICAL_SKY_IMG
#define BINDING_OFFSET_PHYSICAL_SKY_IMG
Definition: global_textures.h:130
CalculateDirectionToSun
void CalculateDirectionToSun(float DayOfYear, float TimeOfDay, float LatitudeDegrees, vec3_t result)
Definition: physical_sky.c:1041
ENVIRONMENT_STATIC
#define ENVIRONMENT_STATIC
Definition: constants.h:99
cl
client_state_t cl
Definition: main.c:99
QVK_s::desc_set_textures_odd
VkDescriptorSet desc_set_textures_odd
Definition: vkpt.h:230
IMG_Find
image_t * IMG_Find(const char *name, imagetype_t type, imageflags_t flags)
Definition: images.c:1122
pipeline_resolve
static VkPipeline pipeline_resolve
Definition: physical_sky.c:35
sun_light_s::direction
vec3_t direction
Definition: vkpt.h:415
BINDING_OFFSET_PHYSICAL_SKY
#define BINDING_OFFSET_PHYSICAL_SKY
Definition: global_textures.h:129
SUN_PRESET_DUSK
@ SUN_PRESET_DUSK
Definition: physical_sky.c:90
qvk
QVK_t qvk
Definition: main.c:377
SUN_PRESET_NOON
@ SUN_PRESET_NOON
Definition: physical_sky.c:88
SkyGetDescriptorLayout
VkDescriptorSetLayout * SkyGetDescriptorLayout()
Definition: precomputed_sky.c:356
SKY_EARTH
@ SKY_EARTH
Definition: precomputed_sky.h:31
vkpt_submit_command_buffer_simple
void vkpt_submit_command_buffer_simple(VkCommandBuffer cmd_buf, VkQueue queue, qboolean all_gpus)
Definition: main.c:3473
PhysicalSkyDesc::flags
uint32_t flags
Definition: physical_sky.h:55
skyNeedsUpdate
static int skyNeedsUpdate
Definition: physical_sky.c:41
physical_sky_space
cvar_t * physical_sky_space
Definition: physical_sky.c:57
PhysicalSkyDesc::preset
int preset
Definition: physical_sky.h:56
up
static vec3_t up
Definition: p_view.c:27
SHADER_STAGE
#define SHADER_STAGE(_module, _stage)
Definition: vkpt.h:116
initializeEnvTexture
static VkResult initializeEnvTexture(int width, int height)
Definition: physical_sky.c:129
vkpt_reset_accumulation
void vkpt_reset_accumulation()
Definition: main.c:219
InitializeShadowmapResources
void InitializeShadowmapResources()
Definition: precomputed_sky.c:975
SUN_PRESET_EVENING
@ SUN_PRESET_EVENING
Definition: physical_sky.c:89
IMAGE_BARRIER
#define IMAGE_BARRIER(cmd_buf,...)
Definition: vk_util.h:55
PhysicalSkyDesc::groundAlbedo
vec3_t groundAlbedo
Definition: physical_sky.h:54
ATTACH_LABEL_VARIABLE
#define ATTACH_LABEL_VARIABLE(a, type)
Definition: vk_util.h:137
vkpt_begin_command_buffer
VkCommandBuffer vkpt_begin_command_buffer(cmd_buf_group_t *group)
Definition: main.c:3301
QVK_s::desc_set_layout_textures
VkDescriptorSetLayout desc_set_layout_textures
Definition: vkpt.h:228
BARRIER_COMPUTE
#define BARRIER_COMPUTE(cmd_buf, img)
Definition: physical_sky.c:416
QVK_s::desc_set_layout_ubo
VkDescriptorSetLayout desc_set_layout_ubo
Definition: vkpt.h:225
mem_envmap
static VkDeviceMemory mem_envmap
Definition: physical_sky.c:30
SUN_PRESET_DAWN
@ SUN_PRESET_DAWN
Definition: physical_sky.c:86
client_state_s::maxclients
int maxclients
Definition: client.h:279
SKY_STROGGOS
@ SKY_STROGGOS
Definition: precomputed_sky.h:32
sun_azimuth
cvar_t * sun_azimuth
Definition: physical_sky.c:45
pipeline_physical_sky
static VkPipeline pipeline_physical_sky
Definition: physical_sky.c:32
inverseQuat
static void inverseQuat(vec4_t q)
Definition: physical_sky.c:1025
destroyEnvTexture
static void destroyEnvTexture(void)
Definition: physical_sky.c:112
VectorNormalize
vec_t VectorNormalize(vec3_t v)
Definition: shared.c:55
qvk_get_current_desc_set_textures
VkDescriptorSet qvk_get_current_desc_set_textures()
Definition: main.c:1847
SUN_PRESET_NONE
@ SUN_PRESET_NONE
Definition: physical_sky.c:82
physical_sky_draw_clouds
cvar_t * physical_sky_draw_clouds
Definition: physical_sky.c:56
QVK_s::queue_graphics
VkQueue queue_graphics
Definition: vkpt.h:173
PhysicalSkyDesc::sunColor
vec3_t sunColor
Definition: physical_sky.h:52
sky_transmittance
cvar_t * sky_transmittance
Definition: physical_sky.c:61
QVK_s::desc_set_layout_vertex_buffer
VkDescriptorSetLayout desc_set_layout_vertex_buffer
Definition: vkpt.h:240
pipeline_layout_physical_sky
static VkPipelineLayout pipeline_layout_physical_sky
Definition: physical_sky.c:34