27#include <unordered_map>
183 u32 addComputePass(
const std::string& name,
const std::string& wgsl,
const std::vector<std::string>& params,
184 u32 workgroupX,
u32 workgroupY);
217 void setPassTexture(
const std::string& passName,
const std::string& uniform,
u32 glTextureId);
222 void setPassUniformVec4(
const std::string& passName,
const std::string& uniform,
const glm::vec4& value);
245 void begin(
const f32* clearColor =
nullptr);
314 void trackView(
const glm::mat4& viewProjection,
u64 key);
358 void setCoverMatrix(
const glm::mat4& viewProjection) { cover_matrix_ = viewProjection; }
387 shadow_texture_ = glTextureId;
415 return initialized_ && ((!bypass_ && !passes_.empty()) || linear_output_
418 || view_exposure_ != 0.0f
419 ||
presentScales() || present_required_ || compute_needs_depth_ || selection_wanted_);
431 return output_vp_w_ > 0 && output_vp_h_ > 0
432 && (output_vp_w_ != width_ || output_vp_h_ != height_);
473 && (output_vp_w_ > width_ || output_vp_h_ > height_);
477 if (!
presentScales() || width_ == 0 || height_ == 0)
return false;
478 if (output_vp_w_ % width_ || output_vp_h_ % height_)
return false;
479 return output_vp_w_ / width_ == output_vp_h_ / height_;
538 display_lut_texture_ = glTexture;
539 display_lut_amount_ = std::isfinite(amount) ? std::clamp(amount, 0.0f, 1.0f) : 0.0f;
541 bool displayLutActive()
const {
return display_lut_texture_ != 0 && display_lut_amount_ > 0.0f; }
668 void ensureScreenQuad();
669 void drawScreenQuad();
671 void applyPassPipeline(
const Shader& shader,
bool over =
false,
bool additive =
false);
682 std::unordered_map<std::string, ComputeHandle> compute_cache_;
685 std::unordered_map<u64, Unique<VoxelGI>> voxel_gis_;
686 std::unordered_map<u64, Unique<DynamicGI>> dynamic_gis_;
691 void runChain(std::vector<PostProcessPass>& passes,
rg::ResourceId scene);
714 void dropSpareParamUbos();
716 std::vector<SpareParamUbo> spare_param_ubos_;
719 RenderContext& context_;
720 resource::ResourceManager& resourceManager_;
723 rg::RenderGraph* graph_ =
nullptr;
725 rg::RenderGraph* frameGraph_ =
nullptr;
733 std::unordered_map<u32, resource::ShaderHandle> blitVariants_;
734 u32 display_lut_texture_ = 0;
735 f32 display_lut_amount_ = 0.0f;
738 f32 blitParamAmount_ = -1.0f;
748 std::vector<PostProcessPass> passes_;
751 bool initialized_ =
false;
752 bool inFrame_ =
false;
753 bool bypass_ =
false;
754 bool linear_output_ =
false;
756 HdrFormatDecision frame_format_{};
759 bool scene_needs_depth_ =
false;
762 u32 requested_samples_ = 4;
765 u32 scene_samples_ = 1;
766 void applySampleRequest();
768 f32 view_exposure_ = 0.0f;
774 u32 output_vp_x_ = 0;
775 u32 output_vp_y_ = 0;
776 bool present_required_ =
false;
777 bool present_over_ =
false;
778 bool background_sky_ =
false;
779 bool compute_needs_depth_ =
false;
780 bool selection_wanted_ =
false;
781 u32 output_vp_w_ = 0;
782 u32 output_vp_h_ = 0;
785 struct TemporalState {
786 glm::mat4 current{1.0f};
787 glm::mat4 previous{1.0f};
789 glm::dvec3 origin{0.0};
791 glm::vec2 jitter{0.0f};
795 u32 writtenFrame = 0;
803 std::unordered_map<u64, TemporalState> temporal_;
804 u64 temporalKey_ = 0;
805 bool passIsTemporal(
const PostProcessPass& pass);
806 bool passUsesLights(
const PostProcessPass& pass);
808 bool passesWantGBuffer();
809 bool scene_gbuffer_ =
false;
810 u32 environment_texture_ = 0;
811 u32 shadow_texture_ = 0;
815 u32 cover_serial_ = 0;
819 enum class State :
u8 { Idle, Requested, Drawn, Reading };
820 State state = State::Idle;
825 PostProcessPass copy;
827 std::vector<u8> pixels;
829 SkyCapture sky_capture_;
831 PostProcessPass cloud_shadow_copy_;
833 bool drawing_cloud_shadow_ =
false;
835 bool cover_active_ =
false;
836 glm::mat4 cover_matrix_{1.0f};
839 bool velocity_active_ =
false;
840 bool passHasTexture(
const PostProcessPass& pass,
const char* name);
842 bool passDrawsCover(
const PostProcessPass& pass);
846 bool passIsHighPrecision(
const PostProcessPass& pass);
848 std::unordered_map<u64, TemporalState> feedback_;
849 u64 feedbackKey(
const std::string& passName)
const;
852 bool screenFBOCreated_ =
false;
853 bool screenCaptureActive_ =
false;
854 std::vector<PostProcessPass> screenPasses_;
856 PostProcessPass* findScreenPass(
const std::string& name);
857 void ensureScreenFBO();
GPU framebuffer abstraction for render-to-texture.
Type-safe resource handle system.
Math utilities and GLM configuration for ESEngine.
Full-screen passes as a declared graph: what each one reads, what it writes, and at what size — the g...
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
PostProcessPipeline(const PostProcessPipeline &)=delete
void setPassContinuesEffect(const std::string &passName)
Mark passName as a later pass of the effect the pass before it began.
void setOutputTransform(OutputTransform transform)
The curve the final pass applies to scene values.
void setPassUniformVec4(const std::string &passName, const std::string &uniform, const glm::vec4 &value)
Sets a vec4 uniform for a pass.
bool displayLutActive() const
void setPresentOver(bool over)
This camera keeps the colour under it: its present composites over the target by coverage.
void executeScreenPasses()
Executes screen-level post-process passes on captured output.
u32 coverTargetId() const
PostProcessPipeline & operator=(const PostProcessPipeline &)=delete
bool velocityWanted()
Whether an enabled pass reads how far each moving surface travelled (u_velocity).
void resize(u32 width, u32 height)
Resizes the framebuffers.
bool isScreenCaptureActive() const
Checks if screen capture is active.
void clearScreenPasses()
Clears all screen-level passes.
bool drawMaterialOver(u32 material)
void setShadowAtlas(u32 glTextureId, rg::ResourceId resource)
The frame's shadow atlas, for an effect that asks whether a point of air is in the sun (#pragma light...
f32 coverRange()
How far from the camera, in world units, that map reaches each way (the effect's u_shelterRange).
void setBackgroundSky(bool drawn)
PostProcessPipeline(GfxDevice &device, RenderContext &context, resource::ResourceManager &resourceManager, rg::RenderGraph &graph)
Builds a pipeline that declares its chains onto the FRAME's graph.
void setComputeNeedsDepth(bool needs)
The caller has decided this frame needs a present.
u32 addComputePass(const std::string &name, const std::string &wgsl, const std::vector< std::string > ¶ms, u32 workgroupX, u32 workgroupY)
Adds a pass that is a compute shader over the picture instead of a draw.
void begin(const f32 *clearColor=nullptr)
Begins rendering to the pipeline.
u32 addNativePass(const std::string &name, const std::string &kind)
Adds a pass the engine implements itself: "voxelGI" (see VoxelGI). Its parameters are set like any pa...
const PostProcessPass * getPass(u32 index) const
Gets a pass by index.
bool isEngaged() const
Whether the scene goes through the graph or straight to the surface.
void setCoverMatrix(const glm::mat4 &viewProjection)
The matrix the map was drawn through, for the effect to put a world point in it.
void grabScene(bool marked=true)
void setViewExposure(f32 ev)
void drawCloudShadow(const glm::mat4 &inverse, const glm::vec4 &rect, const rg::PassContext &ctx)
Draws the caster's cloud shadow into the tile at rect of the bound target: what of the sun is left in...
const PostProcessPass * cloudShadowCaster(f32 &extentKm, f32 &unitsPerKm) const
The sky that casts the sun's cloud shadow this frame, how far its map reaches each way in kilometres,...
u32 getPassCount() const
Gets the pass count.
bool temporalActive()
Whether this frame's chain holds a temporal effect.
glm::vec2 beginTemporalView(const glm::mat4 &viewProjection, u64 key)
Starts a frame of the temporal view key, and answers how far to shift it.
void setScreenPassUniformFloat(const std::string &passName, const std::string &uniform, f32 value)
Sets a float uniform for a screen-level pass.
void setLinearOutput(bool linear)
Linear-light mode: sRGB-format intermediates (hardware linear blending) and an always-engaged capture...
bool coverWanted()
Whether an enabled pass reads what stands over each place (u_rainCover).
void setSelectionMask(rg::ResourceId mask)
The editor's selection mask for this chain (RenderFrame::declareSelectionMask): outlined after the la...
bool canDrawMaterialOver(u32 material)
u32 getScreenPassCount() const
Gets the screen pass count.
rg::ResourceId declareCover(u32 size)
The map's target for this frame, declared in the graph (kNoResource when it cannot be made).
void setScreenPassUniformVec4(const std::string &passName, const std::string &uniform, const glm::vec4 &value)
Sets a vec4 uniform for a screen-level pass.
void setEnvironmentTexture(u32 glTextureId)
The frame's environment atlas, for an effect that reflects it (u_environment).
bool drawProjectedMaterial(u32 material, u32 instances, u32 scratch, const glm::vec4 &sun, const glm::vec4 &receiverWindow, TextureHandle receiverDepth, TextureHandle movingDepth)
FramebufferHandle currentSceneFBO() const
The surface the scene is currently rendering into: the screen-capture FBO when the screen stack is li...
void setOutputTarget(FramebufferHandle target)
Sets the output target for the final blit (Default = screen).
void setSelectionWanted(bool wanted)
An editor selection is outlined this frame: a screen effect, so the scene is drawn where its depth ca...
void clearPasses()
Checks if bypass mode is enabled.
TemporalView peekTemporalView(const glm::mat4 &viewProjection, u64 key) const
bool presentScales() const
Whether the chain's own size differs from the rect it lands in.
void setPassUniformFloat(const std::string &passName, const std::string &uniform, f32 value)
Sets a float uniform for a pass.
const HdrFormatDecision & hdrFormat() const
What this frame's intermediates were asked to be and allowed to be.
const std::vector< u8 > & skyCapturePixels() const
The captured pixels, RGBA8, rows bottom-up as every readback lands. Valid after poll answered 1.
bool presentUpscales() const
Whether the present is a whole-multiple upscale of the chain.
void beginScreenCapture()
Begins screen-level capture (all camera output goes into screen FBO).
void drawSelectionOutline(TextureHandle mask)
The selection's outline over what the bound target holds, from its mask. Blended over; the caller set...
void setPresentRequired(bool required)
rg::ResourceId declareVelocity()
The motion pass's target for this frame, declared in the graph (kNoResource when it cannot be made).
void requestSkyCapture(const std::string &passName, u32 width, u32 height)
Draws pass passName once more, next frame, into a width x height RGBA8 target with its float param u_...
glm::vec4 bakeSun() const
void trackView(const glm::mat4 &viewProjection, u64 key)
Records this frame's camera as the view key's current one, and last frame's as its previous....
rg::TargetDesc grabTarget() const
The shape of the copy of the opaque scene a refractive surface reads: the chain's own,...
void setPassScale(const std::string &passName, f32 scale)
Draw passName at scale of the chain size (clamped to (0, 1]).
bool sceneHasGBuffer() const
Whether this frame's scene target carries a second attachment for the surface's material.
void shutdown()
Shuts down and releases resources.
u32 requestedSamples() const
What was asked for, before the ceiling.
bool drawMaterialThrough(u32 material, u32 shader, const std::vector< std::pair< std::string, glm::vec4 > > &overrides, u32 scratch)
rg::TargetDesc grabDepthTarget()
The shape of the copy of the opaque scene's depth: how far each pixel is from the eye,...
u32 addPass(const std::string &name, resource::ShaderHandle shader)
Adds a post-processing pass.
bool sceneCoverageWanted()
Whether the scene is to be cleared to nothing (all four channels zero) so that its alpha says how muc...
u32 addScreenPass(const std::string &name, resource::ShaderHandle shader)
Adds a screen-level post-process pass.
OutputTransform outputTransform() const
bool isInitialized() const
Checks if pipeline is initialized.
rg::ResourceId sceneResource() const
void encodeRgbm()
Draws the texture on unit 0 into the bound target as RGBM over 8 (alpha 0 kept for nothing drawn): a ...
bool cameraMotionWanted()
Whether an enabled pass that keeps no history reads the previous camera (u_prevViewProjection0).
i32 pollSkyCapture()
0 = not yet, 1 = the pixels are ready (skyCapturePixels), 2 = none was asked for or it failed....
void setRequestedSamples(u32 samples)
The project's multisampling request; 1 = off. Clamped by the device.
bool supportsCompute() const
Whether passes added with addComputePass run on this device.
void setPassTexture(const std::string &passName, const std::string &uniform, u32 glTextureId)
Binds a texture to a pass's sampler uniform (unit 2 upward, in registration order)....
void setDisplayLut(u32 glTexture, f32 amount)
A graded look the final pass applies to the picture as the display will show it.
bool presentIsWholeMultiple() const
f32 coverBias()
The bias the drawing effect reads the map with (its u_shelterBias), for a pass that only borrows the ...
bool linearOutput() const
void init(u32 width, u32 height)
Initializes the pipeline with given dimensions.
void setOutputViewport(u32 x, u32 y, u32 w, u32 h)
Sets the output viewport for the final blit.
void drawSelectionGround(TextureHandle depth)
The selection mask's ground, into the bound mask target: the scene's depth in g, nothing covered.
void endScreenCapture()
Ends screen-level capture.
void setSceneNeedsDepth(bool needs)
Whether the scene target needs a depth attachment.
void setBypass(bool bypass)
Skip the EFFECTS, not the chain.
void grabDepth()
Draws, into the target being drawn, the distance to the opaque scene at every pixel (the scene's dept...
GPU shader program for rendering.
Central manager for GPU resources.
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
constexpr ResourceId kNoResource
FramebufferHandle
Handle 0 is the default framebuffer (backbuffer); it cannot be created or deleted.
std::int32_t i32
Signed 32-bit integer.
std::uint64_t u64
Unsigned 64-bit integer.
OutputTransform
What the last pass of a chain does to scene values on the way out.
@ ACES
Narkowicz ACES filmic curve, for a scene that carries HDR radiance.
@ None
Encode only. Values above 1 clip, which is what LDR content means.
@ Neutral
Khronos PBR Neutral: hue and saturation survive, highlights roll off.
ComputeHandle
A compute program (GfxDevice::createCompute); only a device that supportsCompute() issues one.
std::unique_ptr< T > Unique
Unique ownership smart pointer.
std::uint32_t u32
Unsigned 32-bit integer.
std::uint8_t u8
Unsigned 8-bit integer.
static EstellaContext & ctx()
ReadbackHandle
An in-flight framebuffer readback (GfxDevice::requestReadback).
float f32
32-bit floating point
Post-processing pass configuration.
resource::ShaderHandle shader
std::unordered_map< std::string, f32 > floatUniforms
u32 paramUboBytes
The size paramUbo was made with: what lets the next chain's pass of the same size take it over.
std::vector< u8 > paramBytes
std::string nativeKind
A pass the engine implements itself, in compute passes of its own (see VoxelGI): its name,...
std::vector< std::pair< std::string, u32 > > textureUniforms
u64 historyKey
Which remembered state the pass uses, resolved when the chain is declared.
std::vector< std::pair< std::string, rg::ResourceId > > earlierInputs
std::vector< std::string > computeParams
std::unordered_map< std::string, glm::vec4 > vec4Uniforms
What a temporal view would be given by its NEXT begin: the sub-pixel shift and last frame's camera.
glm::vec2 previousJitter
The shift the previous frame was drawn with.
Shape of a target the graph allocates.