Overte C++ Documentation
ReferenceMaterial.h
1 //
2 // Created by HifiExperiments on 3/14/2021
3 // Copyright 2021 Vircadia contributors.
4 // Copyright 2024 Overte e.V.
5 //
6 // Distributed under the Apache License, Version 2.0.
7 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
8 //
9 
10 #pragma once
11 
12 #include "Procedural.h"
13 
14 class ReferenceMaterial : public graphics::ProceduralMaterial {
15 public:
16  using Parent = graphics::ProceduralMaterial;
17 
18  ReferenceMaterial() {}
19  ReferenceMaterial(QUuid uuid);
20 
21  // Material
22  graphics::MaterialKey getKey() const override;
23  glm::vec3 getEmissive(bool SRGB = true) const override;
24  float getOpacity() const override;
25  graphics::MaterialKey::OpacityMapMode getOpacityMapMode() const override;
26  float getOpacityCutoff() const override;
27  graphics::MaterialKey::CullFaceMode getCullFaceMode() const override;
28  bool isUnlit() const override;
29  glm::vec3 getAlbedo(bool SRGB = true) const override;
30  float getMetallic() const override;
31  float getRoughness() const override;
32  float getScattering() const override;
33  bool resetOpacityMap() const override;
34  graphics::Material::TextureMaps getTextureMaps() const override;
35  glm::vec2 getLightmapParams() const override;
36  bool getDefaultFallthrough() const override;
37  uint8_t getLayers() const override;
38 
39  // NetworkMaterial
40  bool isMissingTexture() override;
41  bool checkResetOpacityMap() override;
42 
43  // ProceduralMaterial
44  bool isProcedural() const override;
45  bool isEnabled() const override;
46  bool isReady() const override;
47  QString getProceduralString() const override;
48 
49  glm::vec4 getColor(const glm::vec4& color) const override;
50  bool hasVertexShader() const override;
51  void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation,
52  const uint64_t& created, const ProceduralProgramKey key = ProceduralProgramKey()) override;
53  void initializeProcedural() override;
54 
55  // MToonMaterial
56  bool isMToon() const override;
57  glm::vec3 getShade(bool SRGB = true) const override;
58  float getShadingShift() const override;
59  float getShadingToony() const override;
60  glm::vec3 getMatcap(bool SRGB = true) const override;
61  glm::vec3 getParametricRim(bool SRGB = true) const override;
62  float getParametricRimFresnelPower() const override;
63  float getParametricRimLift() const override;
64  float getRimLightingMix() const override;
65  float getUVAnimationScrollXSpeed() const override;
66  float getUVAnimationScrollYSpeed() const override;
67  float getUVAnimationRotationSpeed() const override;
68  uint8_t getOutlineWidthMode() override;
69  float getOutlineWidth() override;
70  glm::vec3 getOutline(bool SRGB = true) const override;
71 
72  bool isReference() const override { return true; }
73  std::function<graphics::MaterialPointer()> getReferenceOperator() const { return _materialForUUIDOperator; }
74 
75  static void setMaterialForUUIDOperator(std::function<graphics::MaterialPointer(QUuid)> materialForUUIDOperator);
76 
77 private:
78  static std::function<graphics::MaterialPointer(QUuid)> _unboundMaterialForUUIDOperator;
79  std::function<graphics::MaterialPointer()> _materialForUUIDOperator;
80  mutable bool _locked { false };
81 
82  graphics::MaterialPointer getMaterial() const;
83  std::shared_ptr<NetworkMaterial> getNetworkMaterial() const;
84  graphics::ProceduralMaterialPointer getProceduralMaterial() const;
85  std::shared_ptr<NetworkMToonMaterial> getMToonMaterial() const;
86 
87  template <typename T, typename F>
88  T resultWithLock(F&& f) const;
89 
90  template <typename F>
91  void withLock(F&& f) const;
92 };