Quake II RTX doxygen  1.0 dev
physical_sky.h File Reference
#include "vkpt.h"
#include "shader/sky.h"

Go to the source code of this file.

Classes

struct  PhysicalSkyDesc
 

Typedefs

typedef struct PhysicalSkyDesc PhysicalSkyDesc_t
 

Functions

void vkpt_evaluate_sun_light (sun_light_t *light, const vec3_t sky_matrix[3], float time)
 
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 ()
 
VkResult vkpt_physical_sky_record_cmd_buffer (VkCommandBuffer cmd_buf)
 
VkResult vkpt_physical_sky_update_ubo (QVKUniformBuffer_t *ubo, const sun_light_t *light, qboolean render_world)
 
void vkpt_physical_sky_latch_local_time ()
 
qboolean vkpt_physical_sky_needs_update ()
 
void vkpt_next_sun_preset ()
 
void InitialiseSkyCVars ()
 
void UpdatePhysicalSkyCVars ()
 
const PhysicalSkyDesc_tGetSkyPreset (uint16_t index)
 
void CalculateDirectionToSun (float DayOfYear, float TimeOfDay, float LatitudeDegrees, vec3_t result)
 

Typedef Documentation

◆ PhysicalSkyDesc_t

Function Documentation

◆ 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().

◆ 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().

◆ 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().

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
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
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
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
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
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
sun_gamepad
cvar_t * sun_gamepad
Definition: physical_sky.c:50
sky_scattering
cvar_t * sky_scattering
Definition: physical_sky.c:60
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
sun_angle
cvar_t * sun_angle
Definition: physical_sky.c:46
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
skyPresets
static PhysicalSkyDesc_t skyPresets[3]
Definition: physical_sky.c:965
terrain_shadowmap_viewproj
float terrain_shadowmap_viewproj[16]
Definition: precomputed_sky.c:99
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
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
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
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
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
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
InitializeShadowmapResources
void InitializeShadowmapResources()
Definition: precomputed_sky.c:975
SUN_PRESET_EVENING
@ SUN_PRESET_EVENING
Definition: physical_sky.c:89
PhysicalSkyDesc::groundAlbedo
vec3_t groundAlbedo
Definition: physical_sky.h:54
ATTACH_LABEL_VARIABLE
#define ATTACH_LABEL_VARIABLE(a, type)
Definition: vk_util.h:137
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
SUN_PRESET_DAWN
@ SUN_PRESET_DAWN
Definition: physical_sky.c:86
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
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