3#ifdef ES_ENABLE_POSTPROCESS
25#define g_device (ctx().tryGet<GfxDevice>())
26#define g_initialized (ctx().state().initialized)
27#define g_renderContext (ctx().tryGet<RenderContext>())
28#define g_resourceManager (ctx().tryGet<resource::ResourceManager>())
29#define g_postProcessPipeline (ctx().tryGet<PostProcessPipeline>())
34 if (!g_postProcessPipeline) {
39 g_postProcessPipeline->init(width, height);
42 return g_postProcessPipeline->isInitialized();
46 if (g_postProcessPipeline) {
56 g_postProcessPipeline->shutdown();
61 if (g_postProcessPipeline) {
62 g_postProcessPipeline->resize(width, height);
67 if (!g_postProcessPipeline)
return 0;
72 u32 workgroupX,
u32 workgroupY) {
73 if (!g_postProcessPipeline)
return 0;
74 std::vector<std::string> names;
76 while (start <= params.size() && !params.empty()) {
77 const usize comma = params.find(
',', start);
78 const usize end = comma == std::string::npos ? params.size() : comma;
79 if (end > start) names.push_back(params.substr(start, end - start));
80 if (comma == std::string::npos)
break;
83 return g_postProcessPipeline->addComputePass(name, wgsl, names, workgroupX, workgroupY);
87 if (!g_postProcessPipeline)
return 0;
88 return g_postProcessPipeline->addNativePass(name, kind);
92 uintptr_t pixelsPtr,
u32 pixelCount) {
95 const f32* instances =
boundarySpan<f32>(instancesPtr, instanceCount,
"postprocess_setGIScene.instances");
97 if (!header || !sdf || !instances || !pixels || headerCount < 22)
return false;
99 scene.header.assign(header, header + headerCount);
100 scene.sdf.assign(sdf, sdf + sdfCount);
101 scene.instances.assign(instances, instances + instanceCount);
102 scene.pixels.assign(pixels, pixels + pixelCount);
110 if (scene.sdf.empty() || scene.header.size() < 22 || headerCount != scene.header.size() ||
static_cast<u64>(sdfOffset) + sdfCount > scene.sdf.size())
return false;
111 const f32* header =
boundarySpan<f32>(headerPtr, headerCount,
"postprocess_updateGIField.header");
113 if (!header || !sdf)
return false;
114 std::copy(header, header + headerCount, scene.header.begin());
115 std::copy(sdf, sdf + sdfCount, scene.sdf.begin() + sdfOffset);
117 scene.dirtyBegin = scene.dirtyEnd == scene.dirtyBegin ? sdfOffset : std::min(scene.dirtyBegin, sdfOffset);
118 scene.dirtyEnd = std::max(scene.dirtyEnd, sdfOffset + sdfCount);
125 return g_postProcessPipeline ? g_postProcessPipeline->supportsCompute() : (
g_device &&
g_device->supportsCompute());
129 if (g_postProcessPipeline) g_postProcessPipeline->setRequestedSamples(samples);
133 return g_postProcessPipeline ? g_postProcessPipeline->sceneSamples() : 0u;
143 for (
u32 i = 0; i < 4; ++i) out[i] = 0.0f;
144 if (!g_postProcessPipeline)
return 0;
146 out[0] =
static_cast<f32>(
static_cast<u8>(d.requested));
147 out[1] =
static_cast<f32>(
static_cast<u8>(d.effective));
148 out[2] =
static_cast<f32>(
static_cast<u8>(d.refusal));
149 out[3] = d.linear ? 1.0f : 0.0f;
154 if (!g_postProcessPipeline)
return {};
161 if (g_postProcessPipeline) {
162 g_postProcessPipeline->setPassScale(passName, scale);
167 if (g_postProcessPipeline) g_postProcessPipeline->requestSkyCapture(passName, width, height);
171 return g_postProcessPipeline ? g_postProcessPipeline->pollSkyCapture() : 2;
179 const f32 v[
kDynamicGIStatFloats] = {s.width, s.height, s.probeSpacing, s.probes, s.probeRays, s.cardPixels, s.cardPixelsRelit, s.cardRays,
180 s.applyPixels, s.applyLoadsPerPixel, s.forcedAttachmentBytes, s.residentBytes, s.levels, s.lights, s.instances, s.frame};
181 std::memcpy(out, v,
sizeof(v));
186 if (!g_postProcessPipeline || dst == 0)
return false;
187 const std::vector<u8>& px = g_postProcessPipeline->skyCapturePixels();
188 if (px.empty() || px.size() > bytes)
return false;
189 std::memcpy(
reinterpret_cast<void*
>(dst), px.data(), px.size());
194 if (g_postProcessPipeline) {
195 g_postProcessPipeline->setPassContinuesEffect(passName);
200 const std::string& uniform,
f32 value) {
201 if (g_postProcessPipeline) {
202 g_postProcessPipeline->setPassUniformFloat(passName, uniform, value);
207 const std::string& uniform,
u32 textureHandle) {
208 if (!g_postProcessPipeline)
return;
210 if (textureHandle != 0) {
211 if (
auto* rm =
ctx().tryGet<resource::ResourceManager>()) {
217 g_postProcessPipeline->setPassTexture(passName, uniform, glId);
221 const std::string& uniform,
223 if (g_postProcessPipeline) {
224 g_postProcessPipeline->setPassUniformVec4(passName, uniform, glm::vec4(x, y, z, w));
229 if (g_postProcessPipeline) {
230 g_postProcessPipeline->begin();
237 if (g_postProcessPipeline) {
238 g_postProcessPipeline->chainDone();
243 if (!g_postProcessPipeline)
return false;
244 return g_postProcessPipeline->isInitialized();
248 if (g_postProcessPipeline) {
249 g_postProcessPipeline->setBypass(bypass);
254 if (!g_postProcessPipeline)
return;
263 if (!g_postProcessPipeline)
return;
265 if (textureHandle != 0) {
266 if (
auto* rm =
ctx().tryGet<resource::ResourceManager>()) {
270 g_postProcessPipeline->setDisplayLut(glId, amount);
274 if (g_postProcessPipeline) g_postProcessPipeline->setViewExposure(ev);
278 if (g_postProcessPipeline) {
279 g_postProcessPipeline->clearPasses();
284 if (g_postProcessPipeline) {
285 g_postProcessPipeline->setOutputViewport(x, y, w, h);
290 if (g_postProcessPipeline) {
291 g_postProcessPipeline->setPresentRequired(required);
296 if (!g_postProcessPipeline)
return;
297 g_postProcessPipeline->beginScreenCapture();
301 if (!g_postProcessPipeline)
return;
302 g_postProcessPipeline->endScreenCapture();
306 if (!g_postProcessPipeline)
return;
307 g_postProcessPipeline->executeScreenPasses();
311 if (!g_postProcessPipeline)
return 0;
316 if (g_postProcessPipeline) {
317 g_postProcessPipeline->clearScreenPasses();
322 const std::string& uniform,
f32 value) {
323 if (g_postProcessPipeline) {
324 g_postProcessPipeline->setScreenPassUniformFloat(passName, uniform, value);
329 const std::string& uniform,
331 if (g_postProcessPipeline) {
332 g_postProcessPipeline->setScreenPassUniformVec4(passName, uniform, glm::vec4(x, y, z, w));
Always-on validation for JS-supplied pointer+length pairs at the WASM boundary.
Custom geometry for user-defined mesh rendering.
Diffuse global illumination from the scene's distance field and surface cache, run as compute passes ...
#define g_resourceManager
Abstract graphics device interface.
Post-processing effects pipeline.
Rendering context containing all renderer state.
Frame resources and the shared scene rendering contract.
Central resource management system.
ServiceRegistry & services()
Post-processing effects pipeline.
void registerOwned(Unique< T > service)
Registers an owned service.
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
Handle< esengine::Texture > TextureHandle
Handle to a texture resource.
const T * boundarySpan(uintptr_t ptr, u64 count, const char *what)
Validates a JS-supplied pointer to count elements of T and returns it typed.
constexpr Unique< T > makeUnique(Args &&... args)
Creates a Unique pointer with the given arguments.
std::int32_t i32
Signed 32-bit integer.
bool postprocess_init(u32 width, u32 height)
const char * pixelFormatName(GfxPixelFormat format)
A pixel format as a word.
void postprocess_setUniformVec4(const std::string &passName, const std::string &uniform, f32 x, f32 y, f32 z, f32 w)
void postprocess_clearScreenPasses()
u32 postprocess_maxMsaaSamples()
void postprocess_setBypass(bool bypass)
void postprocess_setMsaaSamples(u32 samples)
std::uint64_t u64
Unsigned 64-bit integer.
void postprocess_shutdown()
void postprocess_setPassTexture(const std::string &passName, const std::string &uniform, u32 textureHandle)
void postprocess_setUniformFloat(const std::string &passName, const std::string &uniform, f32 value)
std::size_t usize
Size type for indexing and sizes.
@ 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.
DynamicGIScene & dynamicGIScene()
void postprocess_setPresentRequired(bool required)
T * boundarySpanMut(uintptr_t ptr, u64 count, const char *what)
Mutable variant of boundarySpan, for entry points that WRITE into a JS buffer.
void postprocess_setPassScale(const std::string &passName, f32 scale)
u32 postprocess_giStats(uintptr_t dst, u32 capacity)
const DynamicGIStats & dynamicGIStats()
i32 postprocess_hdrFormat(uintptr_t outPtr)
The format decision the last frame COMMITTED to, into four floats at outPtr: requested,...
bool postprocess_takeSkyCapture(uintptr_t dst, u32 bytes)
void postprocess_resize(u32 width, u32 height)
void postprocess_setOutputTransform(u32 transform)
bool postprocess_updateGIField(uintptr_t headerPtr, u32 headerCount, uintptr_t sdfPtr, u32 sdfOffset, u32 sdfCount)
Updates the scene the dynamic GI traces after the camera moved: the header, and sdfCount floats of th...
void postprocess_setScreenUniformVec4(const std::string &passName, const std::string &uniform, f32 x, f32 y, f32 z, f32 w)
u32 postprocess_effectiveMsaaSamples()
i32 postprocess_pollSkyCapture()
std::string postprocess_hdrFormatNames()
The last committed decision as words: "requested|effective|reason". Empty before a frame has committe...
void postprocess_requestSkyCapture(const std::string &passName, u32 width, u32 height)
std::uint32_t u32
Unsigned 32-bit integer.
std::uint8_t u8
Unsigned 8-bit integer.
void postprocess_executeScreenPasses()
void postprocess_setOutputViewport(u32 x, u32 y, u32 w, u32 h)
const char * hdrRefusalName(HdrRefusal why)
The refusal as a word, for a log line and for a reader.
void postprocess_setDisplayLut(u32 textureHandle, f32 amount)
bool postprocess_setGIScene(uintptr_t headerPtr, u32 headerCount, uintptr_t sdfPtr, u32 sdfCount, uintptr_t instancesPtr, u32 instanceCount, uintptr_t pixelsPtr, u32 pixelCount)
Hands the dynamic GI the scene it traces: the header, the distance field, the instances and the card ...
void postprocess_beginScreenCapture()
void postprocess_setScreenUniformFloat(const std::string &passName, const std::string &uniform, f32 value)
void postprocess_clearPasses()
u32 postprocess_addPass(const std::string &name, u32 shaderHandle)
constexpr u32 kDynamicGIStatFloats
static EstellaContext & ctx()
EstellaContext & activeCtx()
The engine context every binding routes through — single source of truth.
u32 postprocess_addNativePass(const std::string &name, const std::string &kind)
Adds a pass the engine implements itself ("voxelGI"); its parameters are set by name like any pass's.
void postprocess_endScreenCapture()
void postprocess_setPassContinuesEffect(const std::string &passName)
bool postprocess_isInitialized()
void postprocess_setViewExposure(f32 ev)
u32 postprocess_addScreenPass(const std::string &name, u32 shaderHandle)
float f32
32-bit floating point
bool postprocess_supportsCompute()
Whether compute passes run on this device: WebGPU yes, WebGL2 no.
u32 postprocess_addComputePass(const std::string &name, const std::string &wgsl, const std::string ¶ms, u32 workgroupX, u32 workgroupY)
Adds a pass that is a WGSL compute shader over the picture (see PostProcessPipeline::addComputePass).