1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qnormaldiffusemapalphamaterial.h"
5#include "qnormaldiffusemapalphamaterial_p.h"
6
7#include <Qt3DRender/qeffect.h>
8#include <Qt3DRender/qtexture.h>
9#include <Qt3DRender/qtechnique.h>
10#include <Qt3DRender/qparameter.h>
11#include <Qt3DRender/qshaderprogram.h>
12#include <Qt3DRender/qshaderprogrambuilder.h>
13#include <Qt3DRender/qrenderpass.h>
14#include <Qt3DRender/qgraphicsapifilter.h>
15#include <Qt3DRender/qalphacoverage.h>
16#include <Qt3DRender/qdepthtest.h>
17#include <QtCore/QUrl>
18#include <QtGui/QVector3D>
19#include <QtGui/QVector4D>
20
21QT_BEGIN_NAMESPACE
22
23using namespace Qt3DRender;
24
25namespace Qt3DExtras {
26
27
28QNormalDiffuseMapAlphaMaterialPrivate::QNormalDiffuseMapAlphaMaterialPrivate()
29 : QNormalDiffuseMapMaterialPrivate()
30 , m_alphaCoverage(new QAlphaCoverage())
31 , m_depthTest(new QDepthTest())
32{
33}
34
35void QNormalDiffuseMapAlphaMaterialPrivate::init()
36{
37 Q_Q(QNormalDiffuseMapMaterial);
38
39 connect(sender: m_ambientParameter, signal: &Qt3DRender::QParameter::valueChanged,
40 receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleAmbientChanged);
41 connect(sender: m_diffuseParameter, signal: &Qt3DRender::QParameter::valueChanged,
42 receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleDiffuseChanged);
43 connect(sender: m_normalParameter, signal: &Qt3DRender::QParameter::valueChanged,
44 receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleNormalChanged);
45 connect(sender: m_specularParameter, signal: &Qt3DRender::QParameter::valueChanged,
46 receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleSpecularChanged);
47 connect(sender: m_shininessParameter, signal: &Qt3DRender::QParameter::valueChanged,
48 receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleShininessChanged);
49 connect(sender: m_textureScaleParameter, signal: &Qt3DRender::QParameter::valueChanged,
50 receiverPrivate: this, slot: &QNormalDiffuseMapMaterialPrivate::handleTextureScaleChanged);
51
52 m_normalDiffuseGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
53 m_normalDiffuseGL3ShaderBuilder->setParent(q);
54 m_normalDiffuseGL3ShaderBuilder->setShaderProgram(m_normalDiffuseGL3Shader);
55 m_normalDiffuseGL3ShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json")));
56 m_normalDiffuseGL3ShaderBuilder->setEnabledLayers({QStringLiteral("diffuseTexture"),
57 QStringLiteral("specular"),
58 QStringLiteral("normalTexture")});
59
60 m_normalDiffuseGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
61 m_normalDiffuseGL2ES2ShaderBuilder->setParent(q);
62 m_normalDiffuseGL2ES2ShaderBuilder->setShaderProgram(m_normalDiffuseGL2ES2Shader);
63 m_normalDiffuseGL2ES2ShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json")));
64 m_normalDiffuseGL2ES2ShaderBuilder->setEnabledLayers({QStringLiteral("diffuseTexture"),
65 QStringLiteral("specular"),
66 QStringLiteral("normalTexture")});
67
68 m_normalDiffuseRHIShader->setVertexShaderCode(QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/rhi/default_pos_norm_tex_tan.vert"))));
69 m_normalDiffuseRHIShaderBuilder->setParent(q);
70 m_normalDiffuseRHIShaderBuilder->setShaderProgram(m_normalDiffuseRHIShader);
71 m_normalDiffuseRHIShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json")));
72 m_normalDiffuseRHIShaderBuilder->setEnabledLayers({QStringLiteral("diffuseTexture"),
73 QStringLiteral("specular"),
74 QStringLiteral("normalTexture")});
75
76 m_normalDiffuseGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
77 m_normalDiffuseGL3Technique->graphicsApiFilter()->setMajorVersion(3);
78 m_normalDiffuseGL3Technique->graphicsApiFilter()->setMinorVersion(1);
79 m_normalDiffuseGL3Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::CoreProfile);
80
81 m_normalDiffuseGL2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
82 m_normalDiffuseGL2Technique->graphicsApiFilter()->setMajorVersion(2);
83 m_normalDiffuseGL2Technique->graphicsApiFilter()->setMinorVersion(0);
84 m_normalDiffuseGL2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile);
85
86 m_normalDiffuseES2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGLES);
87 m_normalDiffuseES2Technique->graphicsApiFilter()->setMajorVersion(2);
88 m_normalDiffuseES2Technique->graphicsApiFilter()->setMinorVersion(0);
89 m_normalDiffuseES2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile);
90
91 m_normalDiffuseRHITechnique->graphicsApiFilter()->setApi(QGraphicsApiFilter::RHI);
92 m_normalDiffuseRHITechnique->graphicsApiFilter()->setMajorVersion(1);
93 m_normalDiffuseRHITechnique->graphicsApiFilter()->setMinorVersion(0);
94
95 m_filterKey->setParent(q);
96 m_filterKey->setName(QStringLiteral("renderingStyle"));
97 m_filterKey->setValue(QStringLiteral("forward"));
98
99 m_normalDiffuseGL3Technique->addFilterKey(filterKey: m_filterKey);
100 m_normalDiffuseGL2Technique->addFilterKey(filterKey: m_filterKey);
101 m_normalDiffuseES2Technique->addFilterKey(filterKey: m_filterKey);
102 m_normalDiffuseRHITechnique->addFilterKey(filterKey: m_filterKey);
103
104 m_depthTest->setDepthFunction(QDepthTest::Less);
105
106 m_normalDiffuseGL3RenderPass->setShaderProgram(m_normalDiffuseGL3Shader);
107 m_normalDiffuseGL3RenderPass->addRenderState(state: m_alphaCoverage);
108 m_normalDiffuseGL3RenderPass->addRenderState(state: m_depthTest);
109
110 m_normalDiffuseGL2RenderPass->setShaderProgram(m_normalDiffuseGL2ES2Shader);
111 m_normalDiffuseGL2RenderPass->addRenderState(state: m_alphaCoverage);
112 m_normalDiffuseGL2RenderPass->addRenderState(state: m_depthTest);
113
114 m_normalDiffuseES2RenderPass->setShaderProgram(m_normalDiffuseGL2ES2Shader);
115 m_normalDiffuseES2RenderPass->addRenderState(state: m_alphaCoverage);
116 m_normalDiffuseES2RenderPass->addRenderState(state: m_depthTest);
117
118 m_normalDiffuseRHIRenderPass->setShaderProgram(m_normalDiffuseRHIShader);
119 m_normalDiffuseRHIRenderPass->addRenderState(state: m_alphaCoverage);
120 m_normalDiffuseRHIRenderPass->addRenderState(state: m_depthTest);
121
122 m_normalDiffuseGL3Technique->addRenderPass(pass: m_normalDiffuseGL3RenderPass);
123 m_normalDiffuseGL2Technique->addRenderPass(pass: m_normalDiffuseGL2RenderPass);
124 m_normalDiffuseES2Technique->addRenderPass(pass: m_normalDiffuseES2RenderPass);
125 m_normalDiffuseRHITechnique->addRenderPass(pass: m_normalDiffuseRHIRenderPass);
126
127 m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseGL3Technique);
128 m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseGL2Technique);
129 m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseES2Technique);
130 m_normalDiffuseEffect->addTechnique(t: m_normalDiffuseRHITechnique);
131
132 m_normalDiffuseEffect->addParameter(parameter: m_ambientParameter);
133 m_normalDiffuseEffect->addParameter(parameter: m_diffuseParameter);
134 m_normalDiffuseEffect->addParameter(parameter: m_normalParameter);
135 m_normalDiffuseEffect->addParameter(parameter: m_specularParameter);
136 m_normalDiffuseEffect->addParameter(parameter: m_shininessParameter);
137 m_normalDiffuseEffect->addParameter(parameter: m_textureScaleParameter);
138
139 q->setEffect(m_normalDiffuseEffect);
140}
141
142
143/*!
144 \class Qt3DExtras::QNormalDiffuseMapAlphaMaterial
145 \brief The QNormalDiffuseMapAlphaMaterial provides a specialization of QNormalDiffuseMapMaterial
146 with alpha coverage and a depth test performed in the rendering pass.
147 \inmodule Qt3DExtras
148 \since 5.7
149 \inherits Qt3DExtras::QNormalDiffuseMapMaterial
150
151 \deprecated
152 This class is deprecated; use Qt3DExtras::QDiffuseSpecularMaterial instead.
153
154 The specular lighting effect is based on the combination of 3 lighting components ambient,
155 diffuse and specular. The relative strengths of these components are controlled by means of
156 their reflectivity coefficients which are modelled as RGB triplets:
157
158 \list
159 \li Ambient is the color that is emitted by an object without any other light source.
160 \li Diffuse is the color that is emitted for rought surface reflections with the lights.
161 \li Specular is the color emitted for shiny surface reflections with the lights.
162 \li The shininess of a surface is controlled by a float property.
163 \endlist
164
165 This material uses an effect with a single render pass approach and performs per fragment
166 lighting. Techniques are provided for OpenGL 2, OpenGL 3 or above as well as OpenGL ES 2.
167*/
168/*!
169 Constructs a new QNormalDiffuseMapAlphaMaterial instance with parent object \a parent.
170*/
171QNormalDiffuseMapAlphaMaterial::QNormalDiffuseMapAlphaMaterial(QNode *parent)
172 : QNormalDiffuseMapMaterial(*new QNormalDiffuseMapAlphaMaterialPrivate, parent)
173{
174}
175
176/*!
177 Destroys the QNormalDiffuseMapAlphaMaterial instance.
178*/
179QNormalDiffuseMapAlphaMaterial::~QNormalDiffuseMapAlphaMaterial()
180{
181}
182
183} // namespace Qt3DRender
184
185QT_END_NAMESPACE
186
187#include "moc_qnormaldiffusemapalphamaterial.cpp"
188

source code of qt3d/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp