diff options
author | Nikita Krupitskas <nkrupitskas@luxoft.com> | 2018-03-06 18:34:38 +0300 |
---|---|---|
committer | Daniel d'Andrada <daniel.dandrada@luxoft.com> | 2018-03-23 09:18:57 +0000 |
commit | 473b6b42b121b518cbff13d8a2a6b602f8dafdc3 (patch) | |
tree | 477a108e2429494f55f5048417d837bd7ffd9add | |
parent | 59c4d448def5d1964366158e19709990767a1ac1 (diff) |
[vehicle] Move from ADS materials to PBR
Change-Id: I065f37abcdb2bc50ef5a7128f5984f85a3f2a62d
Reviewed-by: Daniel d'Andrada <daniel.dandrada@luxoft.com>
8 files changed, 373 insertions, 71 deletions
diff --git a/apps/com.luxoft.vehicle/Vehicle3DView.qml b/apps/com.luxoft.vehicle/Vehicle3DView.qml index 7fd3211f..fc533d99 100644 --- a/apps/com.luxoft.vehicle/Vehicle3DView.qml +++ b/apps/com.luxoft.vehicle/Vehicle3DView.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 Pelagicore AB +** Copyright (C) 2017-2018 Pelagicore AB ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Neptune 3 IVI UI. @@ -38,6 +38,7 @@ import QtQuick.Scene3D 2.0 import QtQuick.Controls 2.3 import "paths" +import "materials" Item { id: vehicle3DView @@ -80,21 +81,6 @@ Item { id: inputSettings } - Entity { - components: [ - DirectionalLight { - worldDirection: Qt.vector3d(1, -1, -1).normalized() - color: "white" - intensity: 0.3 - }, - DirectionalLight { - worldDirection: Qt.vector3d(-1, -1, 1).normalized() - color: "white" - intensity: 0.3 - } - ] - } - components: [inputSettings, renderSettings] // Uncomment this camera and use it for from up to down renderer to take a screenshot @@ -120,59 +106,59 @@ Item { upVector: Qt.vector3d(0.0, 1.0, 0.0) } - PhongMaterial { + VehicleCameraController { + camera: camera + } + + CookTorranceMaterial { id: blackMaterial - diffuse: "#000000" - specular: "#121212" - shininess: 10 + albedo: "black" + metalness: 0.5 + roughness: 0.8 } - PhongMaterial { + CookTorranceMaterial { id: whiteHood - diffuse: "#FFFFFF" - specular: "#FFFFFF" - shininess: 1 + albedo: "white" + metalness: 0.1 + roughness: 0.35 } - PhongMaterial { + CookTorranceMaterial { id: chromeMaterial - ambient: "#000000" - diffuse: "#858687" - specular: "#858687" - shininess: 8 + albedo: "black" + metalness: 0.1 + roughness: 0.2 } - PhongAlphaMaterial { + CookTorranceMaterial { id: taillightsMaterial - diffuse: "red" - specular: "#d14545" - alpha: 0.85 - shininess: 512 + albedo: "red" + metalness: 0.1 + roughness: 0.2 + alpha: 0.5 } - PhongMaterial { + CookTorranceMaterial { id: interiorMaterial - diffuse: "#927B51" + albedo: "gray" + metalness: 1.0 + roughness: 0.1 } - PhongMaterial { + CookTorranceMaterial { id: whiteMaterial - ambient: "#606060" - diffuse: "white" - specular: "white" - shininess: 128 + albedo: "white" + metalness: 0.5 + roughness: 0.5 } - PhongAlphaMaterial { + CookTorranceMaterial { id: glassMaterial - ambient: "black" - diffuse: "black" - specular: "black" - alpha: 0.9 - } - - VehicleCameraController { - camera: camera + albedo: "black" + metalness: 0.1 + roughness: 0.1 + alpha: 0.8 } VehicleShadow {} diff --git a/apps/com.luxoft.vehicle/VehicleBody.qml b/apps/com.luxoft.vehicle/VehicleBody.qml index fe46b295..da2e5b0c 100644 --- a/apps/com.luxoft.vehicle/VehicleBody.qml +++ b/apps/com.luxoft.vehicle/VehicleBody.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 Pelagicore AB +** Copyright (C) 2017-2018 Pelagicore AB ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Neptune 3 IVI UI. @@ -36,6 +36,7 @@ import Qt3D.Input 2.0 import QtQuick.Scene3D 2.0 import "paths" +import "materials" Entity { id: root @@ -96,11 +97,11 @@ Entity { id: frontLights source: Paths.model("front_ights.obj") } - PhongAlphaMaterial { + CookTorranceMaterial { id: frontLightsMaterial - diffuse: "gray" - specular: "gray" - shininess: 512 + albedo: "black" + metalness: 1.0 + roughness: 0.1 alpha: 0.7 } components: [frontLights, frontLightsMaterial] diff --git a/apps/com.luxoft.vehicle/VehicleFrameGraph.qml b/apps/com.luxoft.vehicle/VehicleFrameGraph.qml index d5de4738..101e7164 100644 --- a/apps/com.luxoft.vehicle/VehicleFrameGraph.qml +++ b/apps/com.luxoft.vehicle/VehicleFrameGraph.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 Pelagicore AB +** Copyright (C) 2018 Pelagicore AB ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Neptune 3 IVI UI. @@ -44,25 +44,33 @@ RenderSurfaceSelector { depthFunction: DepthTest.Less } - renderStates: [depth] + BlendEquation { + id: blendEq + blendFunction: BlendEquation.Add + } + + BlendEquationArguments { + id: blendEqArgs + sourceRgb: BlendEquationArguments.SourceAlpha; + destinationRgb: BlendEquationArguments.OneMinusSourceAlpha + } + + renderStates: [depth, blendEq, blendEqArgs] Viewport { id: viewport normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0) - - // Use the specified camera - CameraSelector { - id: cameraSelector - ClearBuffers { - id: clearBuffer - clearColor: "white" - buffers: ClearBuffers.ColorDepthBuffer - } - SortPolicy { - sortTypes: [ - SortPolicy.StateChangeCost, - SortPolicy.Material - ] + SortPolicy { + sortTypes: [ + SortPolicy.BackToFront // For alpha blending + ] + } + ClearBuffers { + id: clearBuffer + clearColor: "transparent" + buffers: ClearBuffers.ColorDepthBuffer + CameraSelector { + id: cameraSelector } } } diff --git a/apps/com.luxoft.vehicle/assets/images/cedar-bridge/cedar_bridge_irradiance.dds b/apps/com.luxoft.vehicle/assets/images/cedar-bridge/cedar_bridge_irradiance.dds new file mode 100644 index 00000000..242b9ce4 --- /dev/null +++ b/apps/com.luxoft.vehicle/assets/images/cedar-bridge/cedar_bridge_irradiance.dds @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5dc9c4c1ef4cbfb6fa5ef2725a40bb9c956fd7127ce94ff9365704fa3dc1e7bb +size 262276 diff --git a/apps/com.luxoft.vehicle/assets/images/cedar-bridge/cedar_bridge_specular.dds b/apps/com.luxoft.vehicle/assets/images/cedar-bridge/cedar_bridge_specular.dds new file mode 100644 index 00000000..7174dbab --- /dev/null +++ b/apps/com.luxoft.vehicle/assets/images/cedar-bridge/cedar_bridge_specular.dds @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b6e42e4baa90422cfdff488e381b7eae069a2d9fdcbdbc98ffcfc0ac0632e74 +size 1048708 diff --git a/apps/com.luxoft.vehicle/assets/shaders/pbr_shader.frag b/apps/com.luxoft.vehicle/assets/shaders/pbr_shader.frag new file mode 100644 index 00000000..c0ddc3c2 --- /dev/null +++ b/apps/com.luxoft.vehicle/assets/shaders/pbr_shader.frag @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AB +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Triton IVI UI. +** +** $QT_BEGIN_LICENSE:GPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +** SPDX-License-Identifier: GPL-3.0 +** +****************************************************************************/ + +#define FP highp +#define PI 3.1415926535897932384626433832795 + +uniform FP vec3 eyePosition; + +varying FP vec3 worldPosition; +varying FP vec3 worldNormal; +varying FP vec4 worldTangent; + +// PBR material +uniform FP float metalness; +uniform FP float roughness; +uniform FP vec3 albedo; +uniform FP float ao; +uniform FP float alpha; + +FP float DistributionGGX(FP vec3 N, FP vec3 H, FP float roughness) +{ + FP float a = roughness * roughness; + FP float a2 = a * a; + FP float NdotH = max(dot(N, H), 0.0); + FP float NdotH2 = NdotH * NdotH; + + FP float nom = a2; + FP float denom = (NdotH2 * (a2 - 1.0) + 1.0); + denom = PI * denom * denom; + + return nom / denom; +} + +FP float GeometrySchlickGGX(FP float NdotV, FP float roughness) +{ + FP float r = (roughness + 1.0); + FP float k = (r*r) / 8.0; + + FP float nom = NdotV; + FP float denom = NdotV * (1.0 - k) + k; + + return nom / denom; +} + +FP float GeometrySmith(FP vec3 N, FP vec3 V, FP vec3 L, FP float roughness) +{ + FP float NdotV = max(dot(N, V), 0.0); + FP float NdotL = max(dot(N, L), 0.0); + FP float ggx2 = GeometrySchlickGGX(NdotV, roughness); + FP float ggx1 = GeometrySchlickGGX(NdotL, roughness); + + return ggx1 * ggx2; +} + +FP vec3 FresnelSchlick(FP float cosTheta, FP vec3 F0) +{ + return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); +} + +void main() +{ + FP vec3 V = normalize(eyePosition - worldPosition); + FP vec3 F0 = vec3(0.04); + + F0 = mix(F0, albedo, metalness); + + const int lightsCount = 3; + + FP vec3 lightPositions[lightsCount]; + + // 2000.0 is radiant flux + const FP vec3 lightColor = vec3(300.0, 300.0, 300.0); + + const FP float dist = 8.0; + + lightPositions[0] = vec3(0, dist, 0); // Top light + lightPositions[1] = vec3(-dist, dist, dist); // Left back + lightPositions[2] = vec3(dist, dist, -dist); // Right front + + // reflectance equation + FP vec3 Lo = vec3(0.0); + for(int i = 0; i < lightsCount; ++i) + { + // calculate per-light radiance + FP vec3 L = normalize(lightPositions[i] - worldPosition); + FP vec3 H = normalize(V + L); + + FP float distance = length(lightPositions[i] - worldPosition); + FP float attenuation = 1.0 / (distance * distance); + FP vec3 radiance = lightColor * attenuation; + + // cook-torrance brdf + FP float NDF = DistributionGGX(worldNormal, H, roughness); + FP float G = GeometrySmith(worldNormal, V, L, roughness); + FP vec3 F = FresnelSchlick(max(dot(H, V), 0.0), F0); + + FP vec3 kS = F; + FP vec3 kD = vec3(1.0) - kS; + kD *= 1.0 - metalness; + + FP vec3 nominator = NDF * G * F; + FP float denominator = 4.0 * max(dot(worldNormal, V), 0.0) + * max(dot(worldNormal, L), 0.0); + FP vec3 specular = nominator / max(denominator, 0.001); + + // add to outgoing radiance Lo + FP float NdotL = max(dot(worldNormal, L), 0.0); + Lo += (kD * albedo / PI + specular) * radiance * NdotL; + } + + FP vec3 ambient = vec3(0.03) * albedo * ao; + FP vec3 color = ambient + Lo; + + // Gamma correction + color = color / (color + vec3(1.0)); + color = pow(color, vec3(1.0/2.2)); + + gl_FragColor = vec4(color, alpha); +} diff --git a/apps/com.luxoft.vehicle/assets/shaders/pbr_shader.vert b/apps/com.luxoft.vehicle/assets/shaders/pbr_shader.vert new file mode 100644 index 00000000..2d26b92f --- /dev/null +++ b/apps/com.luxoft.vehicle/assets/shaders/pbr_shader.vert @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AB +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Triton IVI UI. +** +** $QT_BEGIN_LICENSE:GPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +** SPDX-License-Identifier: GPL-3.0 +** +****************************************************************************/ + +#define FP highp + +attribute vec3 vertexPosition; +attribute vec3 vertexNormal; +attribute vec4 vertexTangent; +attribute vec2 vertexTexCoord; + +varying FP vec3 worldPosition; +varying FP vec3 worldNormal; +varying FP vec4 worldTangent; +varying FP vec2 texCoord; + +uniform FP mat4 modelMatrix; +uniform FP mat3 modelNormalMatrix; +uniform FP mat4 modelViewProjection; + +void main() +{ + texCoord = vertexTexCoord; + + // Transform position, normal, and tangent to world space + worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0)); + worldNormal = normalize(modelNormalMatrix * vertexNormal); + worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0))); + worldTangent.w = vertexTangent.w; + + gl_Position = modelViewProjection * vec4(vertexPosition, 1.0); +} diff --git a/apps/com.luxoft.vehicle/materials/CookTorranceMaterial.qml b/apps/com.luxoft.vehicle/materials/CookTorranceMaterial.qml new file mode 100644 index 00000000..055377d3 --- /dev/null +++ b/apps/com.luxoft.vehicle/materials/CookTorranceMaterial.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AB +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Neptune 3 IVI UI. +** +** $QT_BEGIN_LICENSE:GPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +** SPDX-License-Identifier: GPL-3.0 +** +****************************************************************************/ + +import QtQuick 2.2 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 + +import "../paths" + +Material { + id: root + + property color albedo: "red" + property real metalness: 1.0 + property real roughness: 1.0 + property real ao: 1.0 + property real alpha: 1.0 + + parameters: [ + Parameter { + name: "albedo" + value: albedo + }, + Parameter { + name: "metalness" + value: metalness + }, + Parameter { + name: "roughness" + value: roughness + }, + Parameter { + name: "ao" + value: ao + }, + Parameter { + name: "alpha" + value: alpha + } + ] + + effect : Effect { + property string vertex: "file:assets/shaders/pbr_shader.vert" + property string fragment: "file:assets/shaders/pbr_shader.frag" + + ShaderProgram { + id: es2Shader + vertexShaderCode: loadSource(parent.vertex) + fragmentShaderCode: loadSource(parent.fragment) + } + techniques: [ + Technique { + graphicsApiFilter { + api: GraphicsApiFilter.OpenGLES + profile: GraphicsApiFilter.CoreProfile + majorVersion: 2 + minorVersion: 0 + } + renderPasses: RenderPass { + shaderProgram: es2Shader + } + } + ] + } + +} + |