1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2008-2012 NVIDIA Corporation. 4 ** Copyright (C) 2019 The Qt Company Ltd. 5 ** Contact: https://www.qt.io/licensing/ 6 ** 7 ** This file is part of Qt Quick 3D. 8 ** 9 ** $QT_BEGIN_LICENSE:GPL$ 10 ** Commercial License Usage 11 ** Licensees holding valid commercial Qt licenses may use this file in 12 ** accordance with the commercial license agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and The Qt Company. For licensing terms 15 ** and conditions see https://www.qt.io/terms-conditions. For further 16 ** information use the contact form at https://www.qt.io/contact-us. 17 ** 18 ** GNU General Public License Usage 19 ** Alternatively, this file may be used under the terms of the GNU 20 ** General Public License version 3 or (at your option) any later version 21 ** approved by the KDE Free Qt Foundation. The licenses are as published by 22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3 23 ** included in the packaging of this file. Please review the following 24 ** information to ensure the GNU General Public License requirements will 25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 26 ** 27 ** $QT_END_LICENSE$ 28 ** 29 ****************************************************************************/ 30 31 #ifndef QSSG_RENDER_DEFAULT_MATERIAL_H 32 #define QSSG_RENDER_DEFAULT_MATERIAL_H 33 34 // 35 // W A R N I N G 36 // ------------- 37 // 38 // This file is not part of the Qt API. It exists purely as an 39 // implementation detail. This header file may change from version to 40 // version without notice, or even be removed. 41 // 42 // We mean it. 43 // 44 45 #include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h> 46 #include <QtQuick3DRuntimeRender/private/qssgrendermaterialdirty_p.h> 47 #include <QtQuick3DRuntimeRender/private/qssgrenderlightmaps_p.h> 48 49 #include <QtGui/QVector3D> 50 51 QT_BEGIN_NAMESPACE 52 53 struct QSSGRenderImage; 54 55 struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderDefaultMaterial : QSSGRenderGraphObject 56 { 57 enum class MaterialLighting : quint8 58 { 59 NoLighting = 0, 60 FragmentLighting 61 }; 62 enum class MaterialBlendMode : quint8 63 { 64 SourceOver = 0, 65 Screen, 66 Multiply, 67 Overlay, 68 ColorBurn, 69 ColorDodge 70 }; 71 enum class MaterialSpecularModel : quint8 72 { 73 Default = 0, 74 KGGX, 75 KWard 76 }; 77 enum MaterialAlphaMode : quint8 78 { 79 Opaque = 0, 80 Mask, 81 Blend, 82 Default 83 }; 84 enum TextureChannelMapping : quint8 85 { 86 R = 0, 87 G, 88 B, 89 A 90 }; 91 92 // Materials are stored as a linked list on models. 93 QSSGRenderGraphObject *nextSibling = nullptr; 94 QSSGRenderModel *parent = nullptr; 95 QSSGRenderImage *colorMap = nullptr; 96 // material section 97 QSSGRenderImage *iblProbe = nullptr; 98 QSSGRenderImage *emissiveMap = nullptr; 99 QSSGRenderImage *specularReflection = nullptr; 100 QSSGRenderImage *specularMap = nullptr; 101 QSSGRenderImage *roughnessMap = nullptr; 102 QSSGRenderImage *opacityMap = nullptr; 103 QSSGRenderImage *bumpMap = nullptr; 104 QSSGRenderImage *normalMap = nullptr; 105 QSSGRenderImage *displacementMap = nullptr; 106 QSSGRenderImage *translucencyMap = nullptr; 107 QSSGRenderImage *metalnessMap = nullptr; 108 QSSGRenderImage *occlusionMap = nullptr; 109 // lightmap section 110 QSSGRenderLightmaps lightmaps; 111 112 QVector3D specularTint{ 1.0f, 1.0f, 1.0f }; 113 float ior = 0.2f; 114 QVector3D emissiveColor = { 1.0f, 1.0f, 1.0f }; 115 QVector4D color{ 1.0f, 1.0f, 1.0f, 1.0f }; // colors are 0-1 normalized 116 float diffuseLightWrap = 0.0f; // 0 - 1 117 float fresnelPower = 0.0f; 118 float specularAmount = 0.0f; // 0-??, defaults to 0 119 float specularRoughness = 50.0f; // 0-??, defaults to 50 120 float metalnessAmount = 0.0f; 121 float opacity = 1.0f; // 0-1 122 float bumpAmount = 0.0f; // 0-?? 123 float displaceAmount = 0.0f; // 0-?? 124 float translucentFalloff = 0.0f; // 0 - ?? 125 float occlusionAmount = 1.0f; // 0 - 1 126 float alphaCutoff = 0.5f; // 0 - 1 127 128 QSSGMaterialDirty dirty; 129 MaterialLighting lighting = MaterialLighting::FragmentLighting; 130 QSSGRenderDefaultMaterial::MaterialBlendMode blendMode = QSSGRenderDefaultMaterial::MaterialBlendMode::SourceOver; 131 QSSGRenderDefaultMaterial::MaterialSpecularModel specularModel = QSSGRenderDefaultMaterial::MaterialSpecularModel::Default; 132 QSSGRenderDefaultMaterial::MaterialAlphaMode alphaMode = QSSGRenderDefaultMaterial::Default; 133 QSSGCullFaceMode cullMode = QSSGCullFaceMode::Back; 134 bool vertexColorsEnabled = false; 135 TextureChannelMapping roughnessChannel = TextureChannelMapping::R; 136 TextureChannelMapping opacityChannel = TextureChannelMapping::A; 137 TextureChannelMapping translucencyChannel = TextureChannelMapping::A; 138 TextureChannelMapping metalnessChannel = TextureChannelMapping::R; 139 TextureChannelMapping occlusionChannel = TextureChannelMapping::R; 140 141 QSSGRenderDefaultMaterial(Type type = Type::DefaultMaterial); 142 isSpecularEnabledQSSGRenderDefaultMaterial143 bool isSpecularEnabled() const { return specularAmount > .01f; } isMetalnessEnabledQSSGRenderDefaultMaterial144 bool isMetalnessEnabled() const { return metalnessAmount > 0.01f; } isFresnelEnabledQSSGRenderDefaultMaterial145 bool isFresnelEnabled() const { return fresnelPower > 0.0f; } isVertexColorsEnabledQSSGRenderDefaultMaterial146 bool isVertexColorsEnabled() const { return vertexColorsEnabled; } hasLightingQSSGRenderDefaultMaterial147 bool hasLighting() const { return lighting != MaterialLighting::NoLighting; } 148 }; 149 150 QT_END_NAMESPACE 151 152 #endif 153