17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 14:29:20 +02:00
Files
maszyna/betterRenderer/renderer/source/environment.h
maj00r 26501b0fd7 hoist standard includes above everything else
Ordering them before the imports in the same file was not enough: a
project header on line 1 can import a module several levels down whose
global module fragment already pulled in the same standard header, and
that include guard does not cross the module boundary. Putting them
first means the guard is set before anything can import.

Skips vendored single-header libraries and anything inside an #if.
2026-09-10 01:02:17 +02:00

149 lines
4.5 KiB
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include "fullscreenpass.h"
#include "nvrenderer/resource_registry.h"
#include "nvrhi/nvrhi.h"
struct MaEnvironment : public MaResourceRegistry {
nvrhi::TextureHandle m_skybox;
nvrhi::TextureHandle m_dynamic_skybox[2];
nvrhi::TextureHandle m_envmap_specular;
nvrhi::TextureHandle m_dynamic_envmap_specular[2];
nvrhi::TextureHandle m_envmap_diffuse;
nvrhi::TextureHandle m_dynamic_envmap_diffuse[2];
nvrhi::TextureHandle m_hdri;
nvrhi::TextureHandle m_brdf_lut;
nvrhi::TextureHandle m_sky_texture;
nvrhi::TextureHandle m_aerial_lut;
nvrhi::TextureHandle m_clouds_texture;
nvrhi::TextureHandle m_high_clouds_texture;
nvrhi::SamplerHandle m_sampler_linear_clamp_v_repeat_h;
nvrhi::SamplerHandle m_sampler_linear_clamp;
nvrhi::SamplerHandle m_sampler_point_clamp;
nvrhi::ShaderHandle m_cs_sample_equirectangular;
nvrhi::ComputePipelineHandle m_pso_sample_equirectangular;
nvrhi::BindingLayoutHandle m_bl_sample_equirectangular;
nvrhi::ShaderHandle m_cs_gbuffer_lighting;
nvrhi::ComputePipelineHandle m_pso_gbuffer_lighting;
nvrhi::BindingLayoutHandle m_bl_gbuffer_lighting;
nvrhi::ShaderHandle m_cs_diffuse_ibl;
nvrhi::ComputePipelineHandle m_pso_diffuse_ibl;
nvrhi::BindingLayoutHandle m_bl_diffuse_ibl;
nvrhi::ShaderHandle m_cs_specular_ibl;
nvrhi::ComputePipelineHandle m_pso_specular_ibl;
nvrhi::ShaderHandle m_cs_generate_mip;
nvrhi::ComputePipelineHandle m_pso_generate_mip;
nvrhi::ShaderHandle m_cs_integrate_brdf;
nvrhi::ComputePipelineHandle m_pso_integrate_brdf;
nvrhi::BindingLayoutHandle m_bl_integrate_brdf;
nvrhi::EventQueryHandle m_ready_handle;
nvrhi::BufferHandle m_face_inverse_projection_buffer;
class NvRenderer* m_renderer;
class NvRendererBackend* m_backend;
struct NvGbuffer* m_gbuffer;
struct Sky* m_sky;
int filter_step = 0;
int mip = 0;
int x = 0;
int y = 0;
int m_current_set_index = 0;
int m_locked_set_index = 0;
int GetCurrentSetIndex();
std::shared_ptr<struct EnvironmentRenderPass> m_environment_pass;
const int m_pixels_per_pass = 256;
nvrhi::BindingSetHandle GetBindingSet(int pass, int mip, int set,
NvGbuffer* gbuffer_cube);
struct EnvironmentFilterConstants {
EnvironmentFilterConstants() {
m_pre_exposure_mul = 1.f;
m_roughness = 0.f;
m_sample_count = 32.f;
m_source_width = 2048.f;
m_mip_bias = 0.f;
m_offset_x = 0;
m_offset_y = 0;
m_offset_z = 0;
}
float m_pre_exposure_mul;
float m_roughness;
float m_sample_count;
float m_source_width;
float m_mip_bias;
uint32_t m_offset_x;
uint32_t m_offset_y;
uint32_t m_offset_z;
};
struct CubeLightingConstants {
uint32_t m_offset_x;
uint32_t m_offset_y;
uint32_t m_offset_z;
uint32_t m_unused;
glm::vec3 m_light_direction;
float m_height;
glm::vec3 m_light_color;
};
MaEnvironment(class NvRenderer* renderer);
void Init(const std::string& texture, float pre_exposure);
void Render(nvrhi::ICommandList* command_list, glm::dmat4 const& jitter,
glm::dmat4 const& projection, glm::dmat4 const& view,
glm::dmat4 const& previous_view_projection);
void Filter(uint64_t sky_instance_id, NvGbuffer* gbuffer_cube);
bool IsReady() const;
};
struct EnvironmentRenderPass : public FullScreenPass {
EnvironmentRenderPass(MaEnvironment* environment);
size_t m_texture_handle_clouds;
struct EnvironmentConstants {
glm::mat4 m_inverse_view_projection;
glm::mat4 m_reproject_matrix;
glm::vec3 m_sun_direction;
float m_height;
glm::vec3 m_moon_direction;
};
virtual void Init() override;
virtual void CreatePipelineDesc(
nvrhi::GraphicsPipelineDesc& pipeline_desc) override;
void UpdateConstants(nvrhi::ICommandList* command_list,
glm::dmat4 const& jitter, glm::dmat4 const& projection,
glm::dmat4 const& view,
glm::dmat4 const& previous_view_projection);
virtual void Render(nvrhi::ICommandList* command_list) override;
virtual nvrhi::IFramebuffer* GetFramebuffer() override;
struct NvGbuffer* m_gbuffer;
MaEnvironment* m_environment;
nvrhi::BufferHandle m_environment_constants;
nvrhi::TextureHandle m_skybox_texture;
nvrhi::BindingLayoutHandle m_binding_layout;
nvrhi::BindingSetHandle m_binding_set[2];
nvrhi::ShaderHandle m_pixel_shader;
nvrhi::FramebufferHandle m_framebuffer;
};