From 80a51b60c2f501a726b98e20eaba7f9551bee720 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Mon, 16 Jul 2018 14:32:08 +0100 Subject: Add support for loading specific animations from glTF 2 files Can now specify source urls to QAnimationClipLoader with query parameters for animationIndex or animationName. Add a new manual test to demonstrate/test this by loading the 2nd animation from the Rigged-Simple.gltf file. Will followup with the same support for Qt 3D native json animation files. Change-Id: Icb66073f29b8471fe06e2e2e9c43720567dc9ee5 Reviewed-by: Paul Lemire --- tests/manual/manual.pro | 1 + tests/manual/rigged-simple/DefaultSceneEntity.qml | 116 ++++++++++++++++++++++ tests/manual/rigged-simple/SkinnedEntity.qml | 91 +++++++++++++++++ tests/manual/rigged-simple/SkinnedPbrEffect.qml | 89 +++++++++++++++++ tests/manual/rigged-simple/main.cpp | 65 ++++++++++++ tests/manual/rigged-simple/main.qml | 98 ++++++++++++++++++ tests/manual/rigged-simple/rigged-simple.pro | 23 +++++ tests/manual/rigged-simple/rigged-simple.qrc | 9 ++ tests/manual/rigged-simple/skinnedPbr.vert | 94 ++++++++++++++++++ 9 files changed, 586 insertions(+) create mode 100644 tests/manual/rigged-simple/DefaultSceneEntity.qml create mode 100644 tests/manual/rigged-simple/SkinnedEntity.qml create mode 100644 tests/manual/rigged-simple/SkinnedPbrEffect.qml create mode 100644 tests/manual/rigged-simple/main.cpp create mode 100644 tests/manual/rigged-simple/main.qml create mode 100644 tests/manual/rigged-simple/rigged-simple.pro create mode 100644 tests/manual/rigged-simple/rigged-simple.qrc create mode 100644 tests/manual/rigged-simple/skinnedPbr.vert (limited to 'tests') diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 3dcdae8a0..f5f60f6cb 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -53,6 +53,7 @@ SUBDIRS += \ animation-keyframe-programmatic \ layerfilter-qml \ skinned-mesh \ + rigged-simple \ proximityfilter \ rendercapture-qml-fbo \ blitframebuffer-qml \ diff --git a/tests/manual/rigged-simple/DefaultSceneEntity.qml b/tests/manual/rigged-simple/DefaultSceneEntity.qml new file mode 100644 index 000000000..e3820fd0a --- /dev/null +++ b/tests/manual/rigged-simple/DefaultSceneEntity.qml @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.10 +import Qt3D.Render 2.10 +import Qt3D.Input 2.0 +import Qt3D.Extras 2.10 + +Entity { + id: root + + components: [ + RenderSettings { + activeFrameGraph: ForwardRenderer { + camera: mainCamera + } + }, + // Event Source will be set by the Qt3DQuickWindow + InputSettings { } + ] + + Camera { + id: mainCamera + position: Qt.vector3d(1, 0.15, 0) + viewCenter: Qt.vector3d(0, 0.15, 0) + fieldOfView: 60 + } + + OrbitCameraController { + camera: mainCamera + linearSpeed: 10 + lookSpeed: 180 + } + + Entity { + components: [ + PointLight { + enabled: parent.enabled + color: "black" + intensity: 0 + }, + EnvironmentLight { + enabled: parent.enabled + + irradiance: TextureLoader { + source: "qrc:/assets/envmaps/cedar-bridge/cedar_bridge_irradiance.dds" + wrapMode { + x: WrapMode.ClampToEdge + y: WrapMode.ClampToEdge + } + generateMipMaps: false + } + specular: TextureLoader { + source: "qrc:/assets/envmaps/cedar-bridge/cedar_bridge_specular.dds" + wrapMode { + x: WrapMode.ClampToEdge + y: WrapMode.ClampToEdge + } + generateMipMaps: false + } + } + ] + + SkyboxEntity { + baseName: "qrc:/assets/envmaps/cedar-bridge/cedar_bridge_irradiance" + extension: ".dds" + } + } +} diff --git a/tests/manual/rigged-simple/SkinnedEntity.qml b/tests/manual/rigged-simple/SkinnedEntity.qml new file mode 100644 index 000000000..9707673e0 --- /dev/null +++ b/tests/manual/rigged-simple/SkinnedEntity.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.10 +import Qt3D.Render 2.10 +import Qt3D.Input 2.0 +import Qt3D.Extras 2.10 + +Entity { + id: root + + property Effect effect: skinnedPbrEffect + property url source: "" + property alias createJointsEnabled: skeleton.createJointsEnabled + property alias transform: transform + property color baseColor: "red" + property alias rootJoint: skeleton.rootJoint + property alias skeleton: skeleton + + components: [ + Transform { + id: transform + rotationX: -90 + }, + Mesh { + source: root.source + }, + Armature { + skeleton: SkeletonLoader { + id: skeleton + source: root.source + onStatusChanged: console.log("skeleton loader status: " + status) + onJointCountChanged: console.log("skeleton has " + jointCount + " joints") + } + }, + Material { + effect: root.effect + + parameters: [ + Parameter { name: "baseColor"; value: root.baseColor } + ] + } + ] +} diff --git a/tests/manual/rigged-simple/SkinnedPbrEffect.qml b/tests/manual/rigged-simple/SkinnedPbrEffect.qml new file mode 100644 index 000000000..235b45849 --- /dev/null +++ b/tests/manual/rigged-simple/SkinnedPbrEffect.qml @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.10 +import Qt3D.Render 2.10 +import Qt3D.Input 2.0 +import Qt3D.Extras 2.10 + +Effect { + id: skinnedPbrEffect + parameters: [ + Parameter { name: "baseColor"; value: "red" }, + Parameter { name: "metalness"; value: 0.1 }, + Parameter { name: "roughness"; value: 0.2 } + ] + + techniques: [ + Technique { + filterKeys: FilterKey { name: "renderingStyle"; value: "forward" } + + graphicsApiFilter { + api: GraphicsApiFilter.OpenGL + majorVersion: 3 + minorVersion: 1 + profile: GraphicsApiFilter.CoreProfile + } + + renderPasses: RenderPass { + shaderProgram: ShaderProgram { + id: prog + vertexShaderCode: loadSource("qrc:/skinnedPbr.vert") + } + + ShaderProgramBuilder { + shaderProgram: prog + fragmentShaderGraph: "qrc:/shaders/graphs/metalrough.frag.json" + enabledLayers: ["baseColor", "metalness", "roughness", "ambientOcclusion", "normal"] + } + } + } + ] +} diff --git a/tests/manual/rigged-simple/main.cpp b/tests/manual/rigged-simple/main.cpp new file mode 100644 index 000000000..8e2ebcbfb --- /dev/null +++ b/tests/manual/rigged-simple/main.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + Qt3DExtras::Quick::Qt3DQuickWindow view; + view.registerAspect(new Qt3DAnimation::QAnimationAspect()); + + view.setSource(QUrl("qrc:/main.qml")); + view.show(); + + return app.exec(); +} diff --git a/tests/manual/rigged-simple/main.qml b/tests/manual/rigged-simple/main.qml new file mode 100644 index 000000000..d905e57a5 --- /dev/null +++ b/tests/manual/rigged-simple/main.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.10 +import Qt3D.Render 2.10 +import Qt3D.Input 2.0 +import Qt3D.Animation 2.10 +import Qt3D.Extras 2.10 +import QtQuick 2.9 + +DefaultSceneEntity { + id: scene + + SkinnedPbrEffect { + id: skinnedPbrEffect + } + + Timer { + interval: 2000 + running: true + repeat: false + onTriggered: { + animator.running = true + } + } + + SkinnedEntity { + id: riggedSimple + effect: skinnedPbrEffect + source: "qrc:/assets/gltf/2.0/RiggedSimple/RiggedSimple.gltf" + baseColor: "blue" + transform.scale: 0.05 + + components: [ + ClipAnimator { + id: animator + running: true + loops: Animation.Infinite + clip: AnimationClipLoader { + source: "qrc:/assets/gltf/2.0/RiggedSimple/RiggedSimple.gltf?animationIndex=1" + } + channelMapper: ChannelMapper { + mappings: [ + SkeletonMapping{ skeleton: riggedSimple.skeleton } + ] + } + } + + ] + } +} diff --git a/tests/manual/rigged-simple/rigged-simple.pro b/tests/manual/rigged-simple/rigged-simple.pro new file mode 100644 index 000000000..f8cd5fbe1 --- /dev/null +++ b/tests/manual/rigged-simple/rigged-simple.pro @@ -0,0 +1,23 @@ +!include( ../manual.pri ) { + error( "Couldn't find the manual.pri file!" ) +} + +QT += 3dcore 3drender 3dinput 3dquick qml quick 3dquickextras 3danimation + +SOURCES += \ + main.cpp + +OTHER_FILES += \ + main.qml \ + DefaultSceneEntity.qml \ + SkinnedEntity.qml \ + SkinnedPbrEffect.qml + +RESOURCES += \ + rigged-simple.qrc \ + ../../../examples/qt3d/exampleresources/cubemaps.qrc \ + ../../../examples/qt3d/exampleresources/envmaps.qrc \ + ../../../examples/qt3d/exampleresources/gltf.qrc + +DISTFILES += \ + skinnedPbr.vert diff --git a/tests/manual/rigged-simple/rigged-simple.qrc b/tests/manual/rigged-simple/rigged-simple.qrc new file mode 100644 index 000000000..e062e6be4 --- /dev/null +++ b/tests/manual/rigged-simple/rigged-simple.qrc @@ -0,0 +1,9 @@ + + + main.qml + DefaultSceneEntity.qml + skinnedPbr.vert + SkinnedEntity.qml + SkinnedPbrEffect.qml + + diff --git a/tests/manual/rigged-simple/skinnedPbr.vert b/tests/manual/rigged-simple/skinnedPbr.vert new file mode 100644 index 000000000..94cb3417c --- /dev/null +++ b/tests/manual/rigged-simple/skinnedPbr.vert @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec4 vertexTangent; +in vec2 vertexTexCoord; +in ivec4 vertexJointIndices; +in vec4 vertexJointWeights; + +out vec3 worldPosition; +out vec3 worldNormal; +out vec4 worldTangent; +out vec2 texCoord; + +uniform mat4 modelMatrix; +uniform mat3 modelNormalMatrix; +uniform mat4 mvp; + +const int maxJoints = 100; +uniform mat4 skinningPalette[maxJoints]; + +void main() +{ + // Pass the texture coordinates through + texCoord = vertexTexCoord; + + // Perform the skinning + mat4 skinningMatrix = skinningPalette[vertexJointIndices[0]] * vertexJointWeights[0]; + skinningMatrix += skinningPalette[vertexJointIndices[1]] * vertexJointWeights[1]; + skinningMatrix += skinningPalette[vertexJointIndices[2]] * vertexJointWeights[2]; + skinningMatrix += skinningPalette[vertexJointIndices[3]] * vertexJointWeights[3]; + + vec4 skinnedPosition = skinningMatrix * vec4(vertexPosition, 1.0); + vec3 skinnedNormal = vec3(skinningMatrix * vec4(vertexNormal, 0.0)); + vec3 skinnedTangent = vec3(skinningMatrix * vec4(vertexTangent.xyz, 0.0)); + + // Transform position, normal, and tangent to world space + worldPosition = vec3(modelMatrix * skinnedPosition); + worldNormal = normalize(modelNormalMatrix * skinnedNormal); + worldTangent.xyz = normalize(vec3(modelMatrix * vec4(skinnedTangent, 0.0))); + worldTangent.w = vertexTangent.w; + + gl_Position = mvp * skinnedPosition; +} -- cgit v1.2.3