Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
MicrosurfaceInfo.h
Go to the documentation of this file.
1#pragma once
2
4#include "SDL/sdl_interface.h"
5
6#include <Common/assertion.h>
7#include <Common/primitive_type.h>
8
9#include <memory>
10#include <optional>
11#include <utility>
12
13namespace ph
14{
15
16class Microfacet;
17
19{
20public:
25 std::unique_ptr<Microfacet> genMicrofacet(
27
28 bool isIsotropic() const;
29 real getIsotropicRoughness() const;
30 std::pair<real, real> getAnisotropicUVRoughnesses() const;
31
32private:
33 EInterfaceMicrosurface m_microsurface;
34 real m_roughness;
35 std::optional<real> m_roughnessV;
36 ERoughnessToAlpha m_roughnessToAlpha;
37 EMaskingShadowing m_maskingShadowing;
38
39public:
41 {
42 StructType ztruct("microsurface");
43 ztruct.description("Describing microsurface structure of the material.");
44
45 TSdlEnumField<OwnerType, EInterfaceMicrosurface> microsurface("microsurface", &OwnerType::m_microsurface);
46 microsurface.description("Type of the microsurface of the material.");
47 microsurface.optional();
49 ztruct.addField(microsurface);
50
51 TSdlReal<OwnerType> roughness("roughness", &OwnerType::m_roughness);
52 roughness.description(
53 "Isotropic surface roughness in [0, 1], the material will appear "
54 "to be smoother with smaller roughness value.");
55 roughness.optional();
56 roughness.defaultTo(0.5_r);
57 ztruct.addField(roughness);
58
59 TSdlOptionalReal<OwnerType> roughnessV("roughness-v", &OwnerType::m_roughnessV);
60 roughnessV.description(
61 "Similar to the `roughness` parameter, but is used for anisotropic "
62 "surface appearances. This value controls the V component of "
63 "surface roughness. If this value is provided, the `roughness` "
64 "parameter is interpreted as the U component of surface roughness.");
65 ztruct.addField(roughnessV);
66
67 TSdlEnumField<OwnerType, ERoughnessToAlpha> roughnessToAlpha("roughness-to-alpha", &OwnerType::m_roughnessToAlpha);
68 roughnessToAlpha.description("Type of the mapping to transform roughness into alpha value.");
69 roughnessToAlpha.optional();
70 roughnessToAlpha.defaultTo(ERoughnessToAlpha::Squared);
71 ztruct.addField(roughnessToAlpha);
72
73 TSdlEnumField<OwnerType, EMaskingShadowing> maskingShadowing("masking-shadowing", &OwnerType::m_maskingShadowing);
74 maskingShadowing.description("Type of the masking and shadowing for a microsurface.");
75 maskingShadowing.optional();
77 ztruct.addField(maskingShadowing);
78
79 return ztruct;
80 }
81};
82
83// In-header Implementations:
84
86{
87 return !m_roughnessV.has_value() ||
88 (m_roughnessV.has_value() && m_roughness == *m_roughnessV);
89}
90
92{
93 PH_ASSERT(isIsotropic());
94
95 return m_roughness;
96}
97
98inline std::pair<real, real> MicrosurfaceInfo::getAnisotropicUVRoughnesses() const
99{
100 PH_ASSERT(!isIsotropic());
101 PH_ASSERT(m_roughnessV.has_value());
102
103 return {m_roughness, *m_roughnessV};
104}
105
106}// end namespace ph
Definition MicrosurfaceInfo.h:19
bool isIsotropic() const
Definition MicrosurfaceInfo.h:85
real getIsotropicRoughness() const
Definition MicrosurfaceInfo.h:91
std::pair< real, real > getAnisotropicUVRoughnesses() const
Definition MicrosurfaceInfo.h:98
PH_DEFINE_SDL_STRUCT(TSdlOwnerStruct< MicrosurfaceInfo >)
Definition MicrosurfaceInfo.h:40
std::unique_ptr< Microfacet > genMicrofacet(EInterfaceMicrosurface defaultType=EInterfaceMicrosurface::TrowbridgeReitz) const
Definition MicrosurfaceInfo.cpp:14
Definition TSdlEnumField.h:23
SDL binding type for a typical C++ struct.
Definition TSdlOwnerStruct.h:18
A field class that binds a floating point member variable.
Definition TSdlReal.h:21
TSdlValue & description(std::string descriptionStr)
Definition TSdlValue.ipp:95
TSdlValue & optional()
Definition TSdlValue.ipp:103
TSdlValue & defaultTo(T defaultValue)
Definition TSdlValue.ipp:71
The root for all renderer implementations.
Definition EEngineProject.h:6
EMaskingShadowing
Different types of masking and shadowing terms for microfacet distributions. Eric Heitz has published...
Definition enums.h:11
ERoughnessToAlpha
Definition sdl_component_enums.h:26
EInterfaceMicrosurface
Definition sdl_component_enums.h:18