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 
38  // NetworkMaterial
39  bool isMissingTexture() override;
40  bool checkResetOpacityMap() override;
41 
42  // ProceduralMaterial
43  bool isProcedural() const override;
44  bool isEnabled() const override;
45  bool isReady() const override;
46  QString getProceduralString() const override;
47 
48  glm::vec4 getColor(const glm::vec4& color) const override;
49  bool isFading() const override;
50  uint64_t getFadeStartTime() const override;
51  bool hasVertexShader() const override;
52  void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation,
53  const uint64_t& created, const ProceduralProgramKey key = ProceduralProgramKey()) override;
54  void initializeProcedural() override;
55 
56  // MToonMaterial
57  bool isMToon() const override;
58  glm::vec3 getShade(bool SRGB = true) const override;
59  float getShadingShift() const override;
60  float getShadingToony() const override;
61  glm::vec3 getMatcap(bool SRGB = true) const override;
62  glm::vec3 getParametricRim(bool SRGB = true) const override;
63  float getParametricRimFresnelPower() const override;
64  float getParametricRimLift() const override;
65  float getRimLightingMix() const override;
66  float getUVAnimationScrollXSpeed() const override;
67  float getUVAnimationScrollYSpeed() const override;
68  float getUVAnimationRotationSpeed() const override;
69  uint8_t getOutlineWidthMode() override;
70  float getOutlineWidth() override;
71  glm::vec3 getOutline(bool SRGB = true) const override;
72 
73  bool isReference() const override { return true; }
74  std::function<graphics::MaterialPointer()> getReferenceOperator() const { return _materialForUUIDOperator; }
75 
76  static void setMaterialForUUIDOperator(std::function<graphics::MaterialPointer(QUuid)> materialForUUIDOperator);
77 
78 private:
79  static std::function<graphics::MaterialPointer(QUuid)> _unboundMaterialForUUIDOperator;
80  std::function<graphics::MaterialPointer()> _materialForUUIDOperator;
81  mutable bool _locked { false };
82 
83  graphics::MaterialPointer getMaterial() const;
84  std::shared_ptr<NetworkMaterial> getNetworkMaterial() const;
85  graphics::ProceduralMaterialPointer getProceduralMaterial() const;
86  std::shared_ptr<NetworkMToonMaterial> getMToonMaterial() const;
87 
88  template <typename T, typename F>
89  T resultWithLock(F&& f) const;
90 
91  template <typename F>
92  void withLock(F&& f) const;
93 };