Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
MaterialStore.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
23#pragma once
24
25#include "../../core/Types.hpp"
28#include "../draw/BlendMode.hpp"
29#include "../rhi/GfxEnums.hpp"
30
31#include <glm/vec4.hpp>
32
33#include <algorithm>
34#include <cstring>
35#include <string>
36#include <unordered_map>
37#include <unordered_set>
38#include <vector>
39
40namespace esengine {
41namespace resource { struct ParsedShader; }
42
43namespace resource { class ResourceManager; }
44
45
46class GfxDevice;
47
49enum class CullMode : u8 {
50 None = 0,
51 Back = 1,
52 Front = 2,
53};
54
57 std::string name;
58 u32 offset = 0;
59 u32 arity = 1;
60 f32 defaults[4] = {0, 0, 0, 0};
62};
63
66
68inline MaterialDefaultTexture materialDefaultByName(const std::string& name) {
69 if (name == "black") return MaterialDefaultTexture::Black;
70 if (name == "flatnormal" || name == "normal") return MaterialDefaultTexture::FlatNormal;
71 if (name == "ripples") return MaterialDefaultTexture::Ripples;
72 return MaterialDefaultTexture::White; // "white" / empty / unknown
73}
74
87
96
102 std::string coverageParam;
104 std::string tipParam;
106 std::string hairShadowParam;
108 bool usesGBuffer = false;
110 bool usesLights = false;
112 bool highPrecision = false;
114 std::string name;
118 float vertexBounds = 0.0f;
119 bool vertexHook = false;
121 std::vector<MaterialParamSlot> params;
122 std::vector<MaterialTextureSlot> textures;
123
126 struct Named {
128 i32 transmission = -1, blendDistance = -1; // params
129 i32 coverage = -1, tip = -1, hairShadow = -1; // params
130 bool coverageIsCutoff = false;
132
135 const auto param = [this](const std::string& n) -> i32 {
136 if (n.empty()) return -1;
137 for (usize i = 0; i < params.size(); ++i) if (params[i].name == n) return static_cast<i32>(i);
138 return -1;
139 };
140 const auto texture = [this](const char* n) -> i32 {
141 for (usize i = 0; i < textures.size(); ++i) if (textures[i].name == n) return static_cast<i32>(i);
142 return -1;
143 };
144 named.sceneColor = texture("u_sceneColor");
145 named.sceneDepth = texture("u_sceneDepthMap");
146 named.screenColor = texture("u_screenColor");
147 named.transmission = param("u_transmission");
148 named.blendDistance = param("u_blendDistance");
149 named.coverage = param(coverageParam);
150 named.tip = param(tipParam);
151 named.hairShadow = param(hairShadowParam);
152 named.coverageIsCutoff = coverageParam == "u_alphaCutoff";
153 }
154
155 const MaterialParamSlot* find(const std::string& name) const {
156 for (const auto& p : params) {
157 if (p.name == name) return &p;
158 }
159 return nullptr;
160 }
161 const MaterialTextureSlot* findTexture(const std::string& name) const {
162 for (const auto& t : textures) {
163 if (t.name == name) return &t;
164 }
165 return nullptr;
166 }
167};
168
198
204public:
205 MaterialStore() = default;
207 MaterialStore(const MaterialStore&) = delete;
210 void setDevice(GfxDevice* device) { device_ = device; }
211
215
218 defaultWhite_ = white;
219 defaultBlack_ = black;
220 defaultFlatNormal_ = flatNormal;
221 defaultRipples_ = ripples;
222 }
223
229 defaultWhiteArray_ = white;
230 defaultBlackArray_ = black;
231 defaultFlatNormalArray_ = flatNormal;
232 }
233
235 if (!slot.layered) return builtinDefault(slot.defaultTexture);
236 if (slot.defaultTexture == MaterialDefaultTexture::Black) return defaultBlackArray_;
237 if (slot.defaultTexture == MaterialDefaultTexture::FlatNormal) return defaultFlatNormalArray_;
238 return defaultWhiteArray_;
239 }
240
247 static void seedSamplers(Shader& shader, const resource::ParsedShader& parsed);
248
253
257 void rememberSource(resource::ShaderHandle shader, std::string source, std::string features) {
258 if (shader.isValid()) {
259 const bool mentionsGbuffer = source.find("ES_GBUFFER") != std::string::npos;
260 const bool writesAlbedo = mentionsGbuffer && source.find("fragAlbedo") != std::string::npos;
261 const bool takesLight = source.find("applyLighting") != std::string::npos;
262 const bool mentionsOpaque = source.find("ES_OPAQUE") != std::string::npos;
263 sources_[shader.id()] = { std::move(source), std::move(features), mentionsGbuffer, writesAlbedo, takesLight, mentionsOpaque };
264 }
265 }
266
270 u32 meshProgram(u32 materialId, resource::ResourceManager& resources,
271 bool withNormals = false, bool skinned = false,
272 bool envMapped = false, bool lightmapped = false, bool gbuffer = false,
273 bool tangents = false, bool tipPass = false, bool opaque = false) const;
274
275 void setLightingDirect(bool on) { lighting_direct_ = on; }
276 bool lightingDirect() const { return lighting_direct_; }
277
281 bool programWritesGBuffer(u32 programId) const {
282 return gbuffer_programs_.count(programId) != 0;
283 }
284
285 bool programWritesAlbedo(u32 programId) const {
286 return albedo_programs_.count(programId) != 0;
287 }
288
289 void markGBufferProgram(u32 programId, bool albedo) const {
290 gbuffer_programs_.insert(programId);
291 if (albedo) albedo_programs_.insert(programId);
292 }
293
295 const std::string& shaderLabel(u32 materialId) const {
296 static const std::string fallback = "default";
297 const MaterialRecord* m = find(materialId);
298 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
299 return layout && !layout->name.empty() ? layout->name : fallback;
300 }
301
304 float vertexBounds(u32 materialId) const {
305 const MaterialRecord* m = find(materialId);
306 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
307 return layout ? layout->vertexBounds : 0.0f;
308 }
309
311 bool hasVertexHook(u32 materialId) const {
312 const MaterialRecord* m = find(materialId);
313 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
314 return layout && layout->vertexHook;
315 }
316
319 bool hasUntrackedDepthHook(u32 materialId) const {
320 const auto* material = find(materialId);
321 const auto* layout = material ? layoutFor(material->shaderRef) : nullptr;
322 return layout && layout->vertexHook && layout->depthInputUnit < 0;
323 }
324
327 bool castsCutoutShadow(u32 materialId) const {
328 const MaterialRecord* m = find(materialId);
329 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
330 return layout && layout->named.coverageIsCutoff && alphaIsCoverage(materialId);
331 }
332
337 u32 shadowProgram(u32 materialId, resource::ResourceManager& resources,
338 bool withNormals, bool skinned, bool tangents = false) const;
339
344 bool withNormals, bool skinned, bool tangents = false) const;
345
349 u32 particleProgram(u32 materialId, resource::ResourceManager& resources) const;
350
357 if (!shader.isValid()) return;
358 layout.resolveNamed();
359 layouts_[shader.id()] = std::move(layout);
360 // Every material on it now reads its params through another layout.
361 reviseMaterialsOf(shader);
362 }
363
368 u64 revisionOf(u32 materialId) const {
369 const MaterialRecord* m = find(materialId);
370 return m ? m->revision : 0;
371 }
372
378 u64 revision() const { return store_revision_; }
379
383 void define(u32 materialId, const MaterialRecord& record) {
384 if (materialId == 0) return;
385 auto it = materials_.find(materialId);
386 if (it == materials_.end()) {
387 MaterialRecord& added = materials_[materialId];
388 added = record;
389 added.revision = revise();
390 return;
391 }
392 MaterialRecord& rec = it->second;
393 const bool shaderChanged = rec.shaderRef != record.shaderRef;
394 const BufferHandle ubo = rec.ubo;
395 std::vector<u8> bytes = std::move(rec.uboBytes);
396 std::vector<MaterialTextureBinding> texs = std::move(rec.textures);
397 rec = record; // render state
398 rec.ubo = ubo; // keep the GPU buffer
399 if (shaderChanged) {
400 rec.uboBytes.clear(); // old layout invalid; re-packed on next set
401 rec.textures.clear();
402 } else {
403 rec.uboBytes = std::move(bytes);
404 rec.textures = std::move(texs);
405 }
406 rec.uboDirty = true; // re-upload on next bind
407 rec.revision = revise();
408 }
409
412 void setUniform(u32 materialId, const std::string& name, const f32* values, u32 arity) {
413 auto it = materials_.find(materialId);
414 if (it == materials_.end()) return;
415 MaterialRecord& rec = it->second;
416 auto lit = layouts_.find(rec.shaderRef.id());
417 if (lit == layouts_.end()) return;
418 const MaterialParamSlot* slot = lit->second.find(name);
419 if (!slot) return;
420 ensureDefaults(rec, lit->second);
421 const u32 n = std::min(arity, slot->arity);
422 std::memcpy(rec.uboBytes.data() + slot->offset, values, n * sizeof(f32));
423 rec.uboDirty = true;
424 rec.revision = revise();
425 }
426
429 void setTexture(u32 materialId, const std::string& name, resource::TextureHandle texture) {
430 auto it = materials_.find(materialId);
431 if (it == materials_.end()) return;
432 auto lit = layouts_.find(it->second.shaderRef.id());
433 if (lit == layouts_.end()) return;
434 const MaterialTextureSlot* slot = lit->second.findTexture(name);
435 if (!slot) return;
436 it->second.revision = revise();
437 for (auto& b : it->second.textures) {
438 if (b.unit == slot->unit) { b.texture = texture; return; }
439 }
440 it->second.textures.push_back({ slot->unit, texture });
441 }
442
443 void undefine(u32 materialId);
444
446 const MaterialRecord* find(u32 materialId) const {
447 if (materialId == 0) return nullptr;
448 // Every question about a draw's material asks for it again: the last answer is kept, as layoutFor keeps its own.
449 if (materialId == last_material_id_ && last_material_) return last_material_;
450 auto it = materials_.find(materialId);
451 last_material_id_ = materialId;
452 last_material_ = it != materials_.end() ? &it->second : nullptr;
453 return last_material_;
454 }
455
457 static f32 paramValue(const MaterialRecord& m, const MaterialUniformLayout& layout, i32 index) {
458 if (index < 0) return 0.0f;
459 const MaterialParamSlot& slot = layout.params[static_cast<usize>(index)];
460 if (slot.offset + sizeof(f32) > m.uboBytes.size()) return 0.0f;
461 f32 value = 0.0f;
462 std::memcpy(&value, m.uboBytes.data() + slot.offset, sizeof(f32));
463 return value;
464 }
465
468 bool usesSceneColor(u32 materialId) const {
469 const MaterialRecord* m = find(materialId);
470 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
471 if (!layout || layout->named.sceneColor < 0) return false;
472 // A shader that has a `u_transmission` (the Model shader, whose material is mostly opaque) asks for the copy only while
473 // the material holds it above zero; one that has none always does.
474 if (layout->named.transmission < 0) return true;
475 return paramValue(*m, *layout, layout->named.transmission) > 0.0f;
476 }
477
479 void setSceneColor(TextureHandle texture) { sceneColor_ = texture; }
480
481 bool usesScreenColor(u32 materialId) const {
482 const MaterialRecord* m = find(materialId);
483 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
484 return layout && layout->named.screenColor >= 0;
485 }
486 void setScreenColor(TextureHandle texture) { screenColor_ = texture; }
488 const MaterialRecord* m = find(materialId);
489 return m ? m->shaderRef : resource::ShaderHandle{};
490 }
491
494 bool usesSceneDepth(u32 materialId) const {
495 const MaterialRecord* m = find(materialId);
496 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
497 return layout && layout->named.sceneDepth >= 0;
498 }
499
501 bool needsScenePicture(u32 materialId) const {
502 const MaterialRecord* m = find(materialId);
503 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
504 return layout && layout->named.blendDistance >= 0;
505 }
506
507 void setSceneDepth(TextureHandle texture) { sceneDepth_ = texture; }
508
511 bool alphaIsCoverage(u32 materialId) const {
512 const MaterialRecord* m = find(materialId);
513 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
514 if (!layout) return false;
515 return paramValue(*m, *layout, layout->named.coverage) > 0.0f;
516 }
517
520 bool hasTipPass(u32 materialId) const {
521 const MaterialRecord* m = find(materialId);
522 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
523 if (!layout) return false;
524 return paramValue(*m, *layout, layout->named.tip) > 0.0f;
525 }
526
528 f32 hairShadowDensity(u32 materialId) const {
529 const MaterialRecord* m = find(materialId);
530 const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
531 if (!layout) return 0.0f;
532 const f32 value = paramValue(*m, *layout, layout->named.hairShadow);
533 return value > 0.0f ? value : 0.0f;
534 }
535
540 // Asked for the same shader by every mesh on it, several times each: the last answer is kept. Node-based, so an answer
541 // stays where it is while others are added; only an erase moves it, and forgets it (forgetLookups).
542 const u32 id = shader.id();
543 if (id == last_layout_id_ && last_layout_) return last_layout_;
544 auto it = layouts_.find(id);
545 last_layout_id_ = id;
546 last_layout_ = it != layouts_.end() ? &it->second : nullptr;
547 return last_layout_;
548 }
549
552
553 void bindForDraw(u32 materialId, u32 samplerUnits = 0xFFFFFFFFu);
554
563 bool bindThrough(u32 materialId, resource::ShaderHandle shader,
564 const std::vector<std::pair<std::string, glm::vec4>>& overrides, u32 scratch);
565
568 void setWorldUnitsPerMeter(f32 unitsPerMeter);
569
572 void clear();
573
574private:
577 void ensureDefaults(MaterialRecord& rec, const MaterialUniformLayout& layout) const {
578 if (layout.blockSize == 0 || rec.uboBytes.size() >= layout.blockSize) return;
579 rec.uboBytes.resize(layout.blockSize, 0);
580 for (const auto& p : layout.params) {
581 f32 value[4];
582 defaultInUnits(p, world_unit_scale_, value);
583 std::memcpy(rec.uboBytes.data() + p.offset, value, p.arity * sizeof(f32));
584 }
585 rec.uboDirty = true;
586 }
587
589 static void defaultInUnits(const MaterialParamSlot& p, f32 scale, f32* out) {
590 const f32 k = p.worldUnits > 0 ? scale : p.worldUnits < 0 ? 1.0f / scale : 1.0f;
591 for (u32 i = 0; i < 4; ++i) out[i] = p.defaults[i] * k;
592 }
593
595 f32 world_unit_scale_ = 1.0f;
596
597 std::unordered_map<u32, MaterialRecord> materials_;
598 std::unordered_map<u32, MaterialUniformLayout> layouts_;
600 std::vector<std::pair<BufferHandle, u32>> through_ubos_;
602 mutable u32 last_material_id_ = 0;
603 mutable const MaterialRecord* last_material_ = nullptr;
604 mutable u32 last_layout_id_ = 0;
605 mutable const MaterialUniformLayout* last_layout_ = nullptr;
606 void forgetLookups() {
607 last_material_ = nullptr; last_material_id_ = 0; last_layout_ = nullptr; last_layout_id_ = 0;
608 // A record went: a pointer anyone kept to one may be to it.
609 store_revision_ = nextRevision();
610 }
612 u64 revise() { return store_revision_ = nextRevision(); }
613 u64 store_revision_ = nextRevision();
615 void reviseMaterialsOf(resource::ShaderHandle shader) {
616 for (auto& [id, rec] : materials_) if (rec.shaderRef == shader) rec.revision = revise();
617 }
618
621 struct ShaderSource {
622 std::string source;
623 std::string features;
626 bool mentionsGbuffer = false;
629 bool writesAlbedo = false;
630 bool takesLight = false;
632 bool mentionsOpaque = false;
633 };
634 std::unordered_map<u32, ShaderSource> sources_;
635 bool lighting_direct_ = false;
639 // Indexed first by source shader: retirement touches only its own variants.
640 // Handles resolve to the current device program, including after recovery.
641 mutable std::unordered_map<u32, std::unordered_map<u64, resource::ShaderHandle>> mesh_programs_;
642 mutable std::unordered_map<u32, std::unordered_map<u64, resource::ShaderHandle>> variant_sources_;
643 void releaseVariants(const std::unordered_map<u64, resource::ShaderHandle>& variants);
644 static u64 sourceDigest(const std::string& vertex, const std::string& fragment);
646 mutable std::unordered_set<u32> gbuffer_programs_;
648 mutable std::unordered_set<u32> albedo_programs_;
652
653public:
657 u32 count = 0;
658 for (const auto& [shader, variants] : mesh_programs_) count += static_cast<u32>(variants.size());
659 return count;
660 }
661
662private:
663
666 u32 variantProgram(u32 materialId, resource::ResourceManager& resources,
667 u64 shape, std::vector<std::string> extraFeatures,
668 const char* what) const;
669 GfxDevice* device_ = nullptr;
670 resource::ResourceManager* resources_ = nullptr;
673 TextureHandle defaultFlatNormal_ = TextureHandle::Invalid;
674 TextureHandle defaultRipples_ = TextureHandle::Invalid;
675 TextureHandle defaultWhiteArray_ = TextureHandle::Invalid;
676 TextureHandle defaultBlackArray_ = TextureHandle::Invalid;
677 TextureHandle defaultFlatNormalArray_ = TextureHandle::Invalid;
678};
679
680} // namespace esengine
Blend mode enumeration for custom rendering.
Backend-agnostic graphics enumerations.
Type-safe resource handle system.
What a resource's content is, as a number that changes whenever it does.
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
bool programWritesAlbedo(u32 programId) const
Of those, the ones that also write the surface's diffuse colour (location 2, fragAlbedo).
MaterialStore & operator=(const MaterialStore &)=delete
MaterialStore(const MaterialStore &)=delete
void setScreenColor(TextureHandle texture)
void registerLayout(resource::ShaderHandle shader, MaterialUniformLayout layout)
void markGBufferProgram(u32 programId, bool albedo) const
A program that is not a material's — the engine's own mesh shader — says it writes the record.
void bindForDraw(u32 materialId, u32 samplerUnits=0xFFFFFFFFu)
bool bindThrough(u32 materialId, resource::ShaderHandle shader, const std::vector< std::pair< std::string, glm::vec4 > > &overrides, u32 scratch)
Binds a material's values for a draw through another shader (a bake into a texture,...
const MaterialRecord * find(u32 materialId) const
The record for materialId, or nullptr if the handle is 0 / unregistered.
bool hasUntrackedDepthHook(u32 materialId) const
void setSceneColor(TextureHandle texture)
resource::ShaderHandle shaderOf(u32 materialId) const
void setBuiltinDefaults(TextureHandle white, TextureHandle black, TextureHandle flatNormal, TextureHandle ripples)
The context's built-in fallbacks.
static f32 paramValue(const MaterialRecord &m, const MaterialUniformLayout &layout, i32 index)
bool usesSceneColor(u32 materialId) const
u32 meshProgram(u32 materialId, resource::ResourceManager &resources, bool withNormals=false, bool skinned=false, bool envMapped=false, bool lightmapped=false, bool gbuffer=false, bool tangents=false, bool tipPass=false, bool opaque=false) const
u64 revision() const
Changes whenever any material does (revisionOf), or one is added or removed.
void setBuiltinDefaultArrays(TextureHandle white, TextureHandle black, TextureHandle flatNormal)
The context's layers of white, black and a flat normal: what an unset textureArray param binds.
void setWorldUnitsPerMeter(f32 unitsPerMeter)
void forgetShader(resource::ShaderHandle shader)
void rememberSource(resource::ShaderHandle shader, std::string source, std::string features)
float vertexBounds(u32 materialId) const
const std::string & shaderLabel(u32 materialId) const
The name of the shader materialId draws with, or "default" for the path's own batch shader.
TextureHandle builtinDefault(MaterialDefaultTexture which) const
const MaterialUniformLayout * layoutFor(resource::ShaderHandle shader) const
u32 shadowProgram(u32 materialId, resource::ResourceManager &resources, bool withNormals, bool skinned, bool tangents=false) const
void setDevice(GfxDevice *device)
The render path uses this device to create/upload/delete per-material UBOs.
void setTexture(u32 materialId, const std::string &name, resource::TextureHandle texture)
TextureHandle builtinDefault(const MaterialTextureSlot &slot) const
What an unset param of slot binds: its declared default, as layers for an array (ripples are white th...
bool usesSceneDepth(u32 materialId) const
u32 prepassCoverageProgram(u32 materialId, resource::ResourceManager &resources, bool withNormals, bool skinned, bool tangents=false) const
u64 revisionOf(u32 materialId) const
What materialId is, as a number that changes whenever it does: its state, a param,...
u32 builtVariantCount() const
How many material program variants have been built. A prewarm counts what it caused by the difference...
bool hasTipPass(u32 materialId) const
void undefine(u32 materialId)
bool usesScreenColor(u32 materialId) const
u32 particleProgram(u32 materialId, resource::ResourceManager &resources) const
bool alphaIsCoverage(u32 materialId) const
bool programWritesGBuffer(u32 programId) const
bool castsCutoutShadow(u32 materialId) const
static MaterialUniformLayout layoutOf(const resource::ParsedShader &parsed)
void setUniform(u32 materialId, const std::string &name, const f32 *values, u32 arity)
bool needsScenePicture(u32 materialId) const
static void seedSamplers(Shader &shader, const resource::ParsedShader &parsed)
Point each of shader's texture params at its unit.
void setLightingDirect(bool on)
f32 hairShadowDensity(u32 materialId) const
The hair shadow density materialId holds (see ParsedShader::hairShadowParam), 0 when its shader has n...
void define(u32 materialId, const MaterialRecord &record)
void setResourceManager(resource::ResourceManager *resources)
Resolves texture handles at bind time; without one, texture params bind nothing.
bool hasVertexHook(u32 materialId) const
Whether materialId bends its vertices (so its shadow has to bend too).
void setSceneDepth(TextureHandle texture)
The copy of the opaque scene's distances the frame took, or invalid when it took none....
GPU shader program for rendering.
Definition Shader.hpp:86
bool isValid() const
Checks if the handle references a valid resource.
Definition Handle.hpp:82
IdType id() const
Gets the packed identifier (index + generation).
Definition Handle.hpp:85
Central manager for GPU resources.
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
Definition Handle.hpp:214
Handle< esengine::Texture > TextureHandle
Handle to a texture resource.
Definition Handle.hpp:217
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
std::uint64_t u64
Unsigned 64-bit integer.
Definition Types.hpp:47
std::size_t usize
Size type for indexing and sizes.
Definition Types.hpp:64
std::int16_t i16
Signed 16-bit integer.
Definition Types.hpp:52
MaterialDefaultTexture
Which built-in texture a param falls back to when a material leaves it unset.
std::int8_t i8
Signed 8-bit integer.
Definition Types.hpp:50
MaterialDefaultTexture materialDefaultByName(const std::string &name)
Maps a shader's declared default(<name>) to the built-in it names.
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
BlendMode
Predefined blend modes for rendering.
Definition BlendMode.hpp:22
std::uint8_t u8
Unsigned 8-bit integer.
Definition Types.hpp:41
CullMode
Triangle culling mode baked into a material's pipeline.
u64 nextRevision()
A revision no content has had before. Never 0, which reads as "none".
Definition Revision.hpp:24
float f32
32-bit floating point
Definition Types.hpp:59
One scalar/vector param's slot in a shader's std140 MaterialConstants block.
i8 worldUnits
1 a length, -1 a rate per length: the default is at 100 units a metre (ShaderProperty::worldUnits).
u32 arity
Float component count (1..4); textures are not slots.
u32 offset
std140 byte offset within the block.
f32 defaults[4]
Shader-declared default(...); the block's initial value.
A material's resolved render state (P0) plus its packed std140 constants (P1).
resource::ShaderHandle shaderRef
std::vector< MaterialTextureBinding > textures
Texture params bound to sampler units, by handle (see MaterialTextureBinding).
u32 shader
Program id; 0 means "use the path's default batch shader".
u64 revision
Changes whenever anything above does, or its shader's layout: see core/Revision.hpp and MaterialStore...
std::vector< u8 > uboBytes
A material's bound texture at a sampler unit.
resource::TextureHandle texture
A texture param's sampler unit (>= MATERIAL_TEXTURE_UNIT_BASE, above the batch's 0....
MaterialDefaultTexture defaultTexture
A shader's layout: std140 block (scalar/vector params) + texture sampler slots.
const MaterialParamSlot * find(const std::string &name) const
bool highPrecision
The shader writes a measurement and wants a float target (ParsedShader::highPrecision).
std::vector< MaterialTextureSlot > textures
std::vector< MaterialParamSlot > params
struct esengine::MaterialUniformLayout::Named named
std::string tipParam
The float param that turns the shader's blended tip pass on (see ParsedShader::tipParam).
std::string hairShadowParam
The float param that makes the shader's meshes hair for shadows (see ParsedShader::hairShadowParam).
i32 depthInputUnit
The tracked sampler of a deterministic vertex hook.
const MaterialTextureSlot * findTexture(const std::string &name) const
bool usesLights
The shader reads the frame's light block and shadow atlas (ParsedShader::usesLights).
bool usesGBuffer
The shader reads the scene's surface record (ParsedShader::usesGBuffer).
std::string name
The shader's own name (#pragma shader "<name>"), for what a profiler calls a draw by.
Result of parsing an .esshader file.