Quake II RTX doxygen
1.0 dev
|
|
#include "vkpt.h"
#include "shader/sky.h"
Go to the source code of this file.
◆ PhysicalSkyDesc_t
◆ CalculateDirectionToSun()
void CalculateDirectionToSun |
( |
float |
DayOfYear, |
|
|
float |
TimeOfDay, |
|
|
float |
LatitudeDegrees, |
|
|
vec3_t |
result |
|
) |
| |
Definition at line 1041 of file physical_sky.c.
1043 const float AxialTilt = 23.439f;
1044 const float DaysInYear = 365.25f;
1045 const float SpringEquinoxDay = 79.0f;
1047 float altitudeAtNoon = 90 - LatitudeDegrees + AxialTilt * sinf((DayOfYear - SpringEquinoxDay) / DaysInYear * 2.0f * M_PI);
1048 altitudeAtNoon = altitudeAtNoon * M_PI / 180.f;
1050 float altitudeOfEarthAxis = 180 - LatitudeDegrees;
1051 altitudeOfEarthAxis = altitudeOfEarthAxis * M_PI / 180.f;
1057 vec3_t noonVector = { cosf(altitudeAtNoon), sinf(altitudeAtNoon), 0.0f };
1058 vec3_t earthAxis = { cosf(altitudeOfEarthAxis), sinf(altitudeOfEarthAxis), 0.0f };
1060 float angleFromNoon = (TimeOfDay - 12.0f) / 24.0f * 2.f * M_PI;
1065 vec4_t dayRotationInv = { dayRotation[0], dayRotation[1], dayRotation[2], dayRotation[3] };
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);
1076 result[0] = sunDirection[1];
1077 result[1] = sunDirection[3];
1078 result[2] = sunDirection[2];
Referenced by vkpt_evaluate_sun_light().
◆ GetSkyPreset()
◆ InitialiseSkyCVars()
void InitialiseSkyCVars |
( |
| ) |
|
Definition at line 881 of file physical_sky.c.
883 static char _rgb[3] = {
'r',
'g',
'b'};
886 for (
int i = 0; i < 3; ++i)
889 snprintf(buff, 32,
"sun_color_%c", _rgb[i]);
Referenced by R_Init_RTX().
◆ UpdatePhysicalSkyCVars()
void UpdatePhysicalSkyCVars |
( |
| ) |
|
◆ 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.
622 static uint16_t skyIndex = -1;
634 memset(light, 0,
sizeof(*light));
647 float azimuth, elevation;
649 static float start_time = 0.0f, sun_animate_changed = 0.0f;
662 struct tm* local_time;
669 float time_of_day = local_time->tm_hour + local_time->tm_min / 60.f;
672 else if (local_time->tm_isdst)
714 float elapsed = (time - start_time) * 1000.f *
sun_animate->value;
716 azimuth = fmod(
sun_azimuth->value + elapsed / (24.f * 60.f * 60.f), 360.0f);
718 float e = fmod(
sun_elevation->value + elapsed / (60.f * 60.f), 360.0f);
720 elevation = -(360.f - e);
723 elevation = -(e - 180.0f);
724 azimuth = fmod(azimuth + 180.f, 360.f);
728 elevation = 180.0f - e;
729 azimuth = fmod(azimuth + 180.f, 360.f);
733 elevation = max(-90, min(90, elevation));
745 float elevation_rad = elevation * M_PI / 180.0f;
746 float azimuth_rad = azimuth * M_PI / 180.f;
766 vec3_t sun_direction_world = { 0.f };
770 VectorCopy(sun_direction_world, light->
direction);
Referenced by R_RenderFrame_RTX().
◆ vkpt_next_sun_preset()
void vkpt_next_sun_preset |
( |
| ) |
|
◆ vkpt_physical_sky_beginRegistration()
VkResult vkpt_physical_sky_beginRegistration |
( |
| ) |
|
◆ vkpt_physical_sky_create_pipelines()
VkResult vkpt_physical_sky_create_pipelines |
( |
| ) |
|
Definition at line 364 of file physical_sky.c.
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),
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),
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),
◆ vkpt_physical_sky_destroy()
VkResult vkpt_physical_sky_destroy |
( |
| ) |
|
◆ vkpt_physical_sky_destroy_pipelines()
VkResult vkpt_physical_sky_destroy_pipelines |
( |
| ) |
|
◆ vkpt_physical_sky_endRegistration()
VkResult vkpt_physical_sky_endRegistration |
( |
| ) |
|
◆ vkpt_physical_sky_initialize()
VkResult vkpt_physical_sky_initialize |
( |
| ) |
|
Definition at line 249 of file physical_sky.c.
258 VkDescriptorSetLayout desc_set_layouts[] = {
265 VkPushConstantRange push_constant_range = {
266 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
268 .size =
sizeof(float) * 16,
272 .setLayoutCount =
LENGTH(desc_set_layouts),
273 .pSetLayouts = desc_set_layouts,
274 .pushConstantRangeCount = 1,
275 .pPushConstantRanges = &push_constant_range,
282 VkDescriptorSetLayout desc_set_layouts[] = {
288 .setLayoutCount =
LENGTH(desc_set_layouts),
289 .pSetLayouts = desc_set_layouts,
296 SDL_InitSubSystem(SDL_INIT_JOYSTICK);
300 for (
int i = 0; i < SDL_NumJoysticks(); i++)
302 if (SDL_IsGameController(i))
◆ vkpt_physical_sky_latch_local_time()
void vkpt_physical_sky_latch_local_time |
( |
| ) |
|
◆ vkpt_physical_sky_needs_update()
qboolean vkpt_physical_sky_needs_update |
( |
| ) |
|
◆ 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.
477 VkDescriptorSet desc_sets[] = {
492 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
494 const int group_size = 16;
495 vkCmdDispatch(cmd_buf,
width / group_size,
height / group_size, 6);
503 .size = VK_WHOLE_SIZE,
504 .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
505 .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT
509 VkDescriptorSet desc_sets[] = {
514 vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
pipeline_resolve);
515 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
518 vkCmdDispatch(cmd_buf, 1, 1, 1);
524 .size = VK_WHOLE_SIZE,
525 .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
526 .dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT
Referenced by R_RenderFrame_RTX().
◆ vkpt_physical_sky_update_ubo()
Definition at line 774 of file physical_sky.c.
779 ubo->pt_env_scale = 0.3f;
782 const float min_brightness = -10.f;
783 const float max_brightness = 2.f;
786 ubo->pt_env_scale = exp2f(brightness - 2.f);
794 ubo->sun_solid_angle = 2 * M_PI * (float)(1.0 - cos(light->
angular_size_rad * 0.5));
797 VectorCopy(light->
color, ubo->sun_color);
799 VectorCopy(light->
direction, ubo->sun_direction);
803 VectorSet(ubo->sun_tangent, 1.f, 0.f, 0.f);
804 VectorSet(ubo->sun_bitangent, 0.f, 1.f, 0.f);
809 VectorSet(
up, 0.f, 0.f, 1.f);
810 CrossProduct(light->
direction,
up, ubo->sun_tangent);
812 CrossProduct(light->
direction, ubo->sun_tangent, ubo->sun_bitangent);
833 uint32_t flags = skyDesc->
flags;
841 ubo->physical_sky_flags = flags;
844 vec3_t ground_radiance;
846 VectorScale(ground_radiance, max(0.f, light->
direction_envmap[2]), ground_radiance);
847 VectorVectorScale(ground_radiance, light->
color, ground_radiance);
849 VectorCopy(ground_radiance, ubo->physical_sky_ground_radiance);
859 ubo->sun_visible = light->
visible;
Referenced by R_RenderFrame_RTX().
VkDescriptorSet desc_set_ubo
#define BUFFER_BARRIER(cmd_buf,...)
static qboolean sdl_initialized
#define CREATE_PIPELINE_LAYOUT(dev, layout,...)
void ReleaseShadowmapResources()
static int current_preset
static void reset_sun_color_buffer(VkCommandBuffer cmd_buf)
qboolean use_physical_sky
static void normalizeQuat(vec4_t q)
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
const PhysicalSkyDesc_t * GetSkyPreset(uint16_t index)
#define PHYSICAL_SKY_FLAG_DRAW_CLOUDS
static VkPipeline pipeline_physical_sky_space
uint32_t current_frame_index
static time_t latched_local_time
static SDL_GameController * game_controller
static VkImage img_envmap
static void rotationQuat(vec3_t const axis, float radians, vec4_t result)
static uint32_t physical_sky_planet_albedo_map
VkResult SkyLoadScatterParameters(SkyPreset preset)
#define PHYSICAL_SKY_FLAG_USE_SKYBOX
@ SUN_PRESET_CURRENT_TIME
static PhysicalSkyDesc_t skyPresets[3]
float terrain_shadowmap_viewproj[16]
VkDescriptorSet desc_set_vertex_buffer
void physical_sky_cvar_changed(cvar_t *self)
static void quatMult(vec4_t const a, vec4_t const b, vec4_t result)
static void process_gamepad_input()
static uint32_t physical_sky_planet_normal_map
void Cvar_SetValue(cvar_t *var, float value, from_t from)
BufferResource_t buf_sun_color
char * va(const char *format,...)
void RecordCommandBufferShadowmap(VkCommandBuffer cmd_buf)
cvar_t * physical_sky_brightness
VkDescriptorSet SkyGetDescriptorSet()
#define ENVIRONMENT_DYNAMIC
image_t r_images[MAX_RIMAGES]
void UpdateTerrainShadowMapView(vec3_t forward)
void UpdatePhysicalSkyCVars()
void Cvar_SetByVar(cvar_t *var, const char *value, from_t from)
static VkPipelineLayout pipeline_layout_resolve
static int active_sun_preset()
VkResult SkyInitializeDataGPU()
void CalculateDirectionToSun(float DayOfYear, float TimeOfDay, float LatitudeDegrees, vec3_t result)
#define ENVIRONMENT_STATIC
image_t * IMG_Find(const char *name, imagetype_t type, imageflags_t flags)
static VkPipeline pipeline_resolve
VkDescriptorSetLayout * SkyGetDescriptorLayout()
static int skyNeedsUpdate
cvar_t * physical_sky_space
#define SHADER_STAGE(_module, _stage)
static VkResult initializeEnvTexture(int width, int height)
void InitializeShadowmapResources()
#define ATTACH_LABEL_VARIABLE(a, type)
VkDescriptorSetLayout desc_set_layout_textures
#define BARRIER_COMPUTE(cmd_buf, img)
VkDescriptorSetLayout desc_set_layout_ubo
static VkPipeline pipeline_physical_sky
static void inverseQuat(vec4_t q)
static void destroyEnvTexture(void)
vec_t VectorNormalize(vec3_t v)
VkDescriptorSet qvk_get_current_desc_set_textures()
cvar_t * physical_sky_draw_clouds
cvar_t * sky_transmittance
VkDescriptorSetLayout desc_set_layout_vertex_buffer
static VkPipelineLayout pipeline_layout_physical_sky