1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qnormaldiffusemapalphamaterial.h" |
41 | #include "qnormaldiffusemapalphamaterial_p.h" |
42 | |
43 | #include <Qt3DRender/qeffect.h> |
44 | #include <Qt3DRender/qtexture.h> |
45 | #include <Qt3DRender/qtechnique.h> |
46 | #include <Qt3DRender/qparameter.h> |
47 | #include <Qt3DRender/qshaderprogram.h> |
48 | #include <Qt3DRender/qshaderprogrambuilder.h> |
49 | #include <Qt3DRender/qrenderpass.h> |
50 | #include <Qt3DRender/qgraphicsapifilter.h> |
51 | #include <Qt3DRender/qalphacoverage.h> |
52 | #include <Qt3DRender/qdepthtest.h> |
53 | #include <QtCore/QUrl> |
54 | #include <QtGui/QVector3D> |
55 | #include <QtGui/QVector4D> |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | using namespace Qt3DRender; |
60 | |
61 | namespace Qt3DExtras { |
62 | |
63 | |
64 | QNormalDiffuseMapAlphaMaterialPrivate::() |
65 | : QNormalDiffuseMapMaterialPrivate() |
66 | , m_alphaCoverage(new QAlphaCoverage()) |
67 | , m_depthTest(new QDepthTest()) |
68 | { |
69 | } |
70 | |
71 | void QNormalDiffuseMapAlphaMaterialPrivate::() |
72 | { |
73 | Q_Q(QNormalDiffuseMapMaterial); |
74 | |
75 | connect(sender: m_ambientParameter, signal: &Qt3DRender::QParameter::valueChanged, |
76 | receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleAmbientChanged); |
77 | connect(sender: m_diffuseParameter, signal: &Qt3DRender::QParameter::valueChanged, |
78 | receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleDiffuseChanged); |
79 | connect(sender: m_normalParameter, signal: &Qt3DRender::QParameter::valueChanged, |
80 | receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleNormalChanged); |
81 | connect(sender: m_specularParameter, signal: &Qt3DRender::QParameter::valueChanged, |
82 | receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleSpecularChanged); |
83 | connect(sender: m_shininessParameter, signal: &Qt3DRender::QParameter::valueChanged, |
84 | receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleShininessChanged); |
85 | connect(sender: m_textureScaleParameter, signal: &Qt3DRender::QParameter::valueChanged, |
86 | receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleTextureScaleChanged); |
87 | |
88 | m_normalDiffuseGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert" )))); |
89 | m_normalDiffuseGL3ShaderBuilder->setParent(q); |
90 | m_normalDiffuseGL3ShaderBuilder->setShaderProgram(m_normalDiffuseGL3Shader); |
91 | m_normalDiffuseGL3ShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json" ))); |
92 | m_normalDiffuseGL3ShaderBuilder->setEnabledLayers({QStringLiteral("diffuseTexture" ), |
93 | QStringLiteral("specular" ), |
94 | QStringLiteral("normalTexture" )}); |
95 | |
96 | m_normalDiffuseGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/es2/default.vert" )))); |
97 | m_normalDiffuseGL2ES2ShaderBuilder->setParent(q); |
98 | m_normalDiffuseGL2ES2ShaderBuilder->setShaderProgram(m_normalDiffuseGL2ES2Shader); |
99 | m_normalDiffuseGL2ES2ShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json" ))); |
100 | m_normalDiffuseGL2ES2ShaderBuilder->setEnabledLayers({QStringLiteral("diffuseTexture" ), |
101 | QStringLiteral("specular" ), |
102 | QStringLiteral("normalTexture" )}); |
103 | |
104 | m_normalDiffuseRHIShader->setVertexShaderCode(QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/rhi/default.vert" )))); |
105 | m_normalDiffuseRHIShaderBuilder->setParent(q); |
106 | m_normalDiffuseRHIShaderBuilder->setShaderProgram(m_normalDiffuseRHIShader); |
107 | m_normalDiffuseRHIShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json" ))); |
108 | m_normalDiffuseRHIShaderBuilder->setEnabledLayers({QStringLiteral("diffuseTexture" ), |
109 | QStringLiteral("specular" ), |
110 | QStringLiteral("normalTexture" )}); |
111 | |
112 | m_normalDiffuseGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL); |
113 | m_normalDiffuseGL3Technique->graphicsApiFilter()->setMajorVersion(3); |
114 | m_normalDiffuseGL3Technique->graphicsApiFilter()->setMinorVersion(1); |
115 | m_normalDiffuseGL3Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::CoreProfile); |
116 | |
117 | m_normalDiffuseGL2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL); |
118 | m_normalDiffuseGL2Technique->graphicsApiFilter()->setMajorVersion(2); |
119 | m_normalDiffuseGL2Technique->graphicsApiFilter()->setMinorVersion(0); |
120 | m_normalDiffuseGL2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile); |
121 | |
122 | m_normalDiffuseES2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGLES); |
123 | m_normalDiffuseES2Technique->graphicsApiFilter()->setMajorVersion(2); |
124 | m_normalDiffuseES2Technique->graphicsApiFilter()->setMinorVersion(0); |
125 | m_normalDiffuseES2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile); |
126 | |
127 | m_normalDiffuseRHITechnique->graphicsApiFilter()->setApi(QGraphicsApiFilter::RHI); |
128 | m_normalDiffuseRHITechnique->graphicsApiFilter()->setMajorVersion(1); |
129 | m_normalDiffuseRHITechnique->graphicsApiFilter()->setMinorVersion(0); |
130 | |
131 | m_filterKey->setParent(q); |
132 | m_filterKey->setName(QStringLiteral("renderingStyle" )); |
133 | m_filterKey->setValue(QStringLiteral("forward" )); |
134 | |
135 | m_normalDiffuseGL3Technique->addFilterKey(filterKey: m_filterKey); |
136 | m_normalDiffuseGL2Technique->addFilterKey(filterKey: m_filterKey); |
137 | m_normalDiffuseES2Technique->addFilterKey(filterKey: m_filterKey); |
138 | m_normalDiffuseRHITechnique->addFilterKey(filterKey: m_filterKey); |
139 | |
140 | m_depthTest->setDepthFunction(QDepthTest::Less); |
141 | |
142 | m_normalDiffuseGL3RenderPass->setShaderProgram(m_normalDiffuseGL3Shader); |
143 | m_normalDiffuseGL3RenderPass->addRenderState(state: m_alphaCoverage); |
144 | m_normalDiffuseGL3RenderPass->addRenderState(state: m_depthTest); |
145 | |
146 | m_normalDiffuseGL2RenderPass->setShaderProgram(m_normalDiffuseGL2ES2Shader); |
147 | m_normalDiffuseGL2RenderPass->addRenderState(state: m_alphaCoverage); |
148 | m_normalDiffuseGL2RenderPass->addRenderState(state: m_depthTest); |
149 | |
150 | m_normalDiffuseES2RenderPass->setShaderProgram(m_normalDiffuseGL2ES2Shader); |
151 | m_normalDiffuseES2RenderPass->addRenderState(state: m_alphaCoverage); |
152 | m_normalDiffuseES2RenderPass->addRenderState(state: m_depthTest); |
153 | |
154 | m_normalDiffuseRHIRenderPass->setShaderProgram(m_normalDiffuseRHIShader); |
155 | m_normalDiffuseRHIRenderPass->addRenderState(state: m_alphaCoverage); |
156 | m_normalDiffuseRHIRenderPass->addRenderState(state: m_depthTest); |
157 | |
158 | m_normalDiffuseGL3Technique->addRenderPass(pass: m_normalDiffuseGL3RenderPass); |
159 | m_normalDiffuseGL2Technique->addRenderPass(pass: m_normalDiffuseGL2RenderPass); |
160 | m_normalDiffuseES2Technique->addRenderPass(pass: m_normalDiffuseES2RenderPass); |
161 | m_normalDiffuseRHITechnique->addRenderPass(pass: m_normalDiffuseRHIRenderPass); |
162 | |
163 | m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseGL3Technique); |
164 | m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseGL2Technique); |
165 | m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseES2Technique); |
166 | m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseRHITechnique); |
167 | |
168 | m_normalDiffuseEffect->addParameter(parameter: m_ambientParameter); |
169 | m_normalDiffuseEffect->addParameter(parameter: m_diffuseParameter); |
170 | m_normalDiffuseEffect->addParameter(parameter: m_normalParameter); |
171 | m_normalDiffuseEffect->addParameter(parameter: m_specularParameter); |
172 | m_normalDiffuseEffect->addParameter(parameter: m_shininessParameter); |
173 | m_normalDiffuseEffect->addParameter(parameter: m_textureScaleParameter); |
174 | |
175 | q->setEffect(m_normalDiffuseEffect); |
176 | } |
177 | |
178 | |
179 | /*! |
180 | \class Qt3DExtras::QNormalDiffuseMapAlphaMaterial |
181 | \brief The QNormalDiffuseMapAlphaMaterial provides a specialization of QNormalDiffuseMapMaterial |
182 | with alpha coverage and a depth test performed in the rendering pass. |
183 | \inmodule Qt3DExtras |
184 | \since 5.7 |
185 | \inherits Qt3DExtras::QNormalDiffuseMapMaterial |
186 | |
187 | \deprecated |
188 | This class is deprecated; use Qt3DExtras::QDiffuseSpecularMaterial instead. |
189 | |
190 | The specular lighting effect is based on the combination of 3 lighting components ambient, |
191 | diffuse and specular. The relative strengths of these components are controlled by means of |
192 | their reflectivity coefficients which are modelled as RGB triplets: |
193 | |
194 | \list |
195 | \li Ambient is the color that is emitted by an object without any other light source. |
196 | \li Diffuse is the color that is emitted for rought surface reflections with the lights. |
197 | \li Specular is the color emitted for shiny surface reflections with the lights. |
198 | \li The shininess of a surface is controlled by a float property. |
199 | \endlist |
200 | |
201 | This material uses an effect with a single render pass approach and performs per fragment |
202 | lighting. Techniques are provided for OpenGL 2, OpenGL 3 or above as well as OpenGL ES 2. |
203 | */ |
204 | /*! |
205 | Constructs a new QNormalDiffuseMapAlphaMaterial instance with parent object \a parent. |
206 | */ |
207 | QNormalDiffuseMapAlphaMaterial::(QNode *parent) |
208 | : QNormalDiffuseMapMaterial(*new QNormalDiffuseMapAlphaMaterialPrivate, parent) |
209 | { |
210 | } |
211 | |
212 | /*! |
213 | Destroys the QNormalDiffuseMapAlphaMaterial instance. |
214 | */ |
215 | QNormalDiffuseMapAlphaMaterial::() |
216 | { |
217 | } |
218 | |
219 | } // namespace Qt3DRender |
220 | |
221 | QT_END_NAMESPACE |
222 | |