summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/deferred-renderer-cpp/deferred-renderer-cpp.pro6
-rw-r--r--examples/deferred-renderer-cpp/final_gl3.frag8
-rw-r--r--examples/deferred-renderer-cpp/main.cpp7
-rw-r--r--examples/deferred-renderer-cpp/pointlightblock.cpp64
-rw-r--r--examples/deferred-renderer-cpp/pointlightblock.h65
5 files changed, 145 insertions, 5 deletions
diff --git a/examples/deferred-renderer-cpp/deferred-renderer-cpp.pro b/examples/deferred-renderer-cpp/deferred-renderer-cpp.pro
index 28e42cb3e..8fc5d682c 100644
--- a/examples/deferred-renderer-cpp/deferred-renderer-cpp.pro
+++ b/examples/deferred-renderer-cpp/deferred-renderer-cpp.pro
@@ -8,14 +8,16 @@ HEADERS += \
gbuffer.h \
deferredrenderer.h \
finaleffect.h \
- sceneeffect.h
+ sceneeffect.h \
+ pointlightblock.h
SOURCES += \
main.cpp \
gbuffer.cpp \
deferredrenderer.cpp \
finaleffect.cpp \
- sceneeffect.cpp
+ sceneeffect.cpp \
+ pointlightblock.cpp
RESOURCES += \
deferred-renderer-cpp.qrc
diff --git a/examples/deferred-renderer-cpp/final_gl3.frag b/examples/deferred-renderer-cpp/final_gl3.frag
index bf8e9978c..fe4854f2d 100644
--- a/examples/deferred-renderer-cpp/final_gl3.frag
+++ b/examples/deferred-renderer-cpp/final_gl3.frag
@@ -16,7 +16,9 @@ struct PointLight
};
const int lightCount = 3;
-uniform PointLight pointLights[lightCount];
+uniform PointLightBlock {
+ PointLight lights[lightCount];
+} pointLights;
void main()
{
@@ -27,8 +29,8 @@ void main()
vec4 lightColor;
for (int i = 0; i < 3; i++) {
- vec3 s = normalize(pointLights[i].position - pos);
- lightColor += pointLights[i].color * (pointLights[i].intensity * max(dot(s, norm), 0.0));
+ vec3 s = normalize(pointLights.lights[i].position - pos);
+ lightColor += pointLights.lights[i].color * (pointLights.lights[i].intensity * max(dot(s, norm), 0.0));
}
lightColor /= float(lightCount);
fragColor = col * lightColor;
diff --git a/examples/deferred-renderer-cpp/main.cpp b/examples/deferred-renderer-cpp/main.cpp
index bc446ae8f..be8a48add 100644
--- a/examples/deferred-renderer-cpp/main.cpp
+++ b/examples/deferred-renderer-cpp/main.cpp
@@ -63,6 +63,7 @@
#include "deferredrenderer.h"
#include "finaleffect.h"
#include "sceneeffect.h"
+#include "pointlightblock.h"
int main(int ac, char **av)
{
@@ -180,6 +181,12 @@ int main(int ac, char **av)
screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("normal"), gBuffer->normalTexture()));
screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("color"), gBuffer->colorTexture()));
screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("winSize"), QSize(1024, 1024)));
+ PointLightBlock *lightsData = new PointLightBlock(screenQuadMaterial);
+ lightsData->addLight(light1);
+ lightsData->addLight(light2);
+ lightsData->addLight(light3);
+
+ screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("PointLightBlock"), QVariant::fromValue(lightsData)));
screenQuadMaterial->setEffect(finalEffect);
Qt3D::QRotateTransform *screenPlaneRotation = new Qt3D::QRotateTransform();
diff --git a/examples/deferred-renderer-cpp/pointlightblock.cpp b/examples/deferred-renderer-cpp/pointlightblock.cpp
new file mode 100644
index 000000000..1d78a4746
--- /dev/null
+++ b/examples/deferred-renderer-cpp/pointlightblock.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pointlightblock.h"
+
+PointLightBlock::PointLightBlock(Qt3D::QNode *parent)
+ : Qt3D::QShaderData(parent)
+{
+
+}
+
+PointLightBlock::~PointLightBlock()
+{
+}
+
+QList<Qt3D::QShaderData *> PointLightBlock::lights() const
+{
+ return m_lights;
+}
+
+void PointLightBlock::addLight(Qt3D::QShaderData *light)
+{
+ m_lights.append(light);
+ emit lightsChanged();
+}
+
diff --git a/examples/deferred-renderer-cpp/pointlightblock.h b/examples/deferred-renderer-cpp/pointlightblock.h
new file mode 100644
index 000000000..07c1ef171
--- /dev/null
+++ b/examples/deferred-renderer-cpp/pointlightblock.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef POINTLIGHTBLOCK_H
+#define POINTLIGHTBLOCK_H
+
+#include <Qt3DRenderer/QShaderData>
+
+class PointLightBlock : public Qt3D::QShaderData
+{
+ Q_OBJECT
+ Q_PROPERTY(QList<QShaderData *> lights READ lights NOTIFY lightsChanged)
+public:
+ explicit PointLightBlock(Qt3D::QNode *parent = 0);
+ ~PointLightBlock();
+
+ QList<QShaderData *> lights() const;
+ void addLight(QShaderData *light);
+
+Q_SIGNALS:
+ void lightsChanged();
+
+private:
+ QList<Qt3D::QShaderData *> m_lights;
+};
+
+#endif // POINTLIGHTBLOCK_H