diff options
Diffstat (limited to 'tests/manual/planets-qml/shaders/gl3')
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetD.frag | 63 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetD.vert | 29 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetDB.frag | 66 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetDB.vert | 54 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetDS.frag | 62 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetDSB.frag | 67 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetDShadow.frag | 70 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/planetDShadow.vert | 38 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/shadowmap.frag | 8 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/shadowmap.vert | 13 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/sun.frag | 30 | ||||
-rw-r--r-- | tests/manual/planets-qml/shaders/gl3/sun.vert | 23 |
12 files changed, 523 insertions, 0 deletions
diff --git a/tests/manual/planets-qml/shaders/gl3/planetD.frag b/tests/manual/planets-qml/shaders/gl3/planetD.frag new file mode 100644 index 000000000..72f4a030a --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetD.frag @@ -0,0 +1,63 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; + +in vec3 position; +in vec3 normal; +in vec2 texCoord; + +out vec4 fragColor; + +vec3 dModel(const in vec2 flipYTexCoord) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize(-position); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect(-s, normal); + + // Calculate the diffuse component + float diffuse = max(dot(s, normal), 0.0); + + // Calculate the specular component + float specular = 0.0; + if (dot(s, normal) > 0.0) + specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess); + + // Lookup diffuse and specular factors + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ((ka + diffuse) * diffuseColor + specular * ks); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + result += dModel(flipYTexCoord); + + float alpha = opacity * texture(diffuseTexture, flipYTexCoord).a; + + fragColor = vec4(result, alpha); +} diff --git a/tests/manual/planets-qml/shaders/gl3/planetD.vert b/tests/manual/planets-qml/shaders/gl3/planetD.vert new file mode 100644 index 000000000..9f1b6331a --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetD.vert @@ -0,0 +1,29 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec2 vertexTexCoord; + +out vec3 position; +out vec3 normal; +out vec2 texCoord; + +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +uniform float texCoordScale; + +void main() +{ + texCoord = vertexTexCoord * texCoordScale; + normal = normalize(modelViewNormal * vertexNormal); + position = vec3(modelView * vec4(vertexPosition, 1.0)); + + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/tests/manual/planets-qml/shaders/gl3/planetDB.frag b/tests/manual/planets-qml/shaders/gl3/planetDB.frag new file mode 100644 index 000000000..e8bd7296f --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetDB.frag @@ -0,0 +1,66 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D normalTexture; + +in vec3 lightDir; +in vec3 viewDir; +in vec2 texCoord; + +out vec4 fragColor; + +void dbModel(const in vec3 norm, const in vec2 flipYTexCoord, out vec3 ambientAndDiff, out vec3 spec) +{ + // Reflection of light direction about normal + vec3 r = reflect(-lightDir, norm); + + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + + // Calculate the ambient contribution + vec3 ambient = lightIntensity * ka * diffuseColor; + + // Calculate the diffuse contribution + float sDotN = max(dot(lightDir, norm), 0.0); + vec3 diffuse = lightIntensity * diffuseColor * sDotN; + + // Sum the ambient and diffuse contributions + ambientAndDiff = ambient + diffuse; + + // Calculate the specular highlight contribution + spec = vec3(0.0); + if (sDotN > 0.0) + spec = (lightIntensity * ks) * pow(max(dot(r, viewDir), 0.0), shininess); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + // Sample the textures at the interpolated texCoords + vec4 normal = 2.0 * texture(normalTexture, flipYTexCoord) - vec4(1.0); + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + + // Calculate the lighting model, keeping the specular component separate + vec3 ambientAndDiff, spec; + dbModel(normalize(normal.xyz), flipYTexCoord, ambientAndDiff, spec); + result = ambientAndDiff + spec; + + // Combine spec with ambient+diffuse for final fragment color + fragColor = vec4(result, opacity); +} diff --git a/tests/manual/planets-qml/shaders/gl3/planetDB.vert b/tests/manual/planets-qml/shaders/gl3/planetDB.vert new file mode 100644 index 000000000..b6a72058c --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetDB.vert @@ -0,0 +1,54 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec2 vertexTexCoord; +in vec4 vertexTangent; + +out vec3 lightDir; +out vec3 viewDir; +out vec2 texCoord; + +uniform mat4 viewMatrix; +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +uniform float texCoordScale; + +uniform vec3 lightPosition; + +void main() +{ + // Pass through texture coordinates + texCoord = vertexTexCoord * texCoordScale; + + // Transform position, normal, and tangent to eye coords + vec3 normal = normalize(modelViewNormal * vertexNormal); + vec3 tangent = normalize(modelViewNormal * vertexTangent.xyz); + vec3 position = vec3(modelView * vec4(vertexPosition, 1.0)); + + // Calculate binormal vector + vec3 binormal = normalize(cross(normal, tangent)); + + // Construct matrix to transform from eye coords to tangent space + mat3 tangentMatrix = mat3 ( + tangent.x, binormal.x, normal.x, + tangent.y, binormal.y, normal.y, + tangent.z, binormal.z, normal.z); + + // Transform light direction and view direction to tangent space + vec3 s = lightPosition - position; + lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0))); + + vec3 v = -position; + viewDir = normalize(tangentMatrix * v); + + // Calculate vertex position in clip coordinates + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/tests/manual/planets-qml/shaders/gl3/planetDS.frag b/tests/manual/planets-qml/shaders/gl3/planetDS.frag new file mode 100644 index 000000000..ccf48d6cb --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetDS.frag @@ -0,0 +1,62 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; + +in vec3 position; +in vec3 normal; +in vec2 texCoord; + +out vec4 fragColor; + +vec3 dsModel(const in vec2 flipYTexCoord) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize(-position); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect(-s, normal); + + // Calculate the diffuse component + float diffuse = max(dot(s, normal), 0.0); + + // Calculate the specular component + float specular = 0.0; + if (dot(s, normal) > 0.0) + specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess); + + // Lookup diffuse and specular factors + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + vec3 specularColor = texture(specularTexture, flipYTexCoord).rgb; + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ((ka + diffuse) * diffuseColor + specular * specularColor); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + result += dsModel(flipYTexCoord); + + fragColor = vec4(result, opacity * texture(diffuseTexture, flipYTexCoord).a); +} diff --git a/tests/manual/planets-qml/shaders/gl3/planetDSB.frag b/tests/manual/planets-qml/shaders/gl3/planetDSB.frag new file mode 100644 index 000000000..c7206e559 --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetDSB.frag @@ -0,0 +1,67 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; +uniform sampler2D normalTexture; + +in vec3 lightDir; +in vec3 viewDir; +in vec2 texCoord; + +out vec4 fragColor; + +void dsbModel(const in vec3 norm, const in vec2 flipXTexCoord, out vec3 ambientAndDiff, out vec3 spec) +{ + // Reflection of light direction about normal + vec3 r = reflect(-lightDir, norm); + + vec3 diffuseColor = texture(diffuseTexture, flipXTexCoord).rgb; + vec3 specularColor = texture(specularTexture, flipXTexCoord).rgb; + + // Calculate the ambient contribution + vec3 ambient = lightIntensity * ka * diffuseColor; + + // Calculate the diffuse contribution + float sDotN = max(dot(lightDir, norm), 0.0); + vec3 diffuse = lightIntensity * diffuseColor * sDotN; + + // Sum the ambient and diffuse contributions + ambientAndDiff = ambient + diffuse; + + // Calculate the specular highlight contribution + spec = vec3(0.0); + if (sDotN > 0.0) + spec = (lightIntensity * (shininess / (8.0 * 3.14))) * pow(max(dot(r, viewDir), 0.0), shininess); + + spec *= specularColor; +} + +void main() +{ + vec2 flipXTexCoord = texCoord; + flipXTexCoord.x = 1.0 - texCoord.x; + + // Sample the textures at the interpolated texCoords + vec4 normal = 2.0 * texture(normalTexture, flipXTexCoord) - vec4(1.0); + + // Calculate the lighting model, keeping the specular component separate + vec3 ambientAndDiff, spec; + dsbModel(normalize(normal.xyz), flipXTexCoord, ambientAndDiff, spec); + vec3 result = ambientAndDiff + spec; + + // Combine spec with ambient+diffuse for final fragment color + fragColor = vec4(result, opacity); +} diff --git a/tests/manual/planets-qml/shaders/gl3/planetDShadow.frag b/tests/manual/planets-qml/shaders/gl3/planetDShadow.frag new file mode 100644 index 000000000..02eea673e --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetDShadow.frag @@ -0,0 +1,70 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; + +uniform sampler2DShadow shadowMapTexture; + +in vec4 positionInLightSpace; + +in vec3 position; +in vec3 normal; +in vec2 texCoord; + +out vec4 fragColor; + +vec3 dModel(const in vec2 flipYTexCoord) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize(-position); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect(-s, normal); + + // Calculate the diffuse component + float diffuse = max(dot(s, normal), 0.0); + + // Calculate the specular component + float specular = 0.0; + if (dot(s, normal) > 0.0) + specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess); + + // Lookup diffuse and specular factors + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ((ka + diffuse) * diffuseColor + specular * ks); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace); + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + if (shadowMapSample > 0) + result += dModel(flipYTexCoord); + + float alpha = opacity * texture(diffuseTexture, flipYTexCoord).a; + + fragColor = vec4(result, alpha); +} diff --git a/tests/manual/planets-qml/shaders/gl3/planetDShadow.vert b/tests/manual/planets-qml/shaders/gl3/planetDShadow.vert new file mode 100644 index 000000000..e2dbaa0df --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/planetDShadow.vert @@ -0,0 +1,38 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec2 vertexTexCoord; + +out vec4 positionInLightSpace; +out vec3 position; +out vec3 normal; +out vec2 texCoord; + +uniform mat4 lightViewProjection; +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +uniform float texCoordScale; + +void main() +{ + const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + + positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0); + + texCoord = vertexTexCoord * texCoordScale; + normal = normalize(modelViewNormal * vertexNormal); + position = vec3(modelView * vec4(vertexPosition, 1.0)); + + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/tests/manual/planets-qml/shaders/gl3/shadowmap.frag b/tests/manual/planets-qml/shaders/gl3/shadowmap.frag new file mode 100644 index 000000000..31b39e148 --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/shadowmap.frag @@ -0,0 +1,8 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +void main() +{ +} diff --git a/tests/manual/planets-qml/shaders/gl3/shadowmap.vert b/tests/manual/planets-qml/shaders/gl3/shadowmap.vert new file mode 100644 index 000000000..d245cd127 --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/shadowmap.vert @@ -0,0 +1,13 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +in vec3 vertexPosition; + +uniform mat4 mvp; + +void main() +{ + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/tests/manual/planets-qml/shaders/gl3/sun.frag b/tests/manual/planets-qml/shaders/gl3/sun.frag new file mode 100644 index 000000000..d62e87954 --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/sun.frag @@ -0,0 +1,30 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +uniform sampler2D diffuseTexture; + +in vec3 position; +in vec2 texCoord; + +out vec4 fragColor; + +vec4 dModel(const in vec2 flipYTexCoord) +{ + // Lookup diffuse + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + + return vec4(diffuseColor, 1.0); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + vec4 result = dModel(flipYTexCoord); + + fragColor = result; +} diff --git a/tests/manual/planets-qml/shaders/gl3/sun.vert b/tests/manual/planets-qml/shaders/gl3/sun.vert new file mode 100644 index 000000000..0734c1c1a --- /dev/null +++ b/tests/manual/planets-qml/shaders/gl3/sun.vert @@ -0,0 +1,23 @@ +// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 150 core + +in vec3 vertexPosition; +in vec2 vertexTexCoord; + +out vec3 position; +out vec2 texCoord; + +uniform mat4 modelView; +uniform mat4 mvp; + +uniform float texCoordScale; + +void main() +{ + texCoord = vertexTexCoord * texCoordScale; + position = vec3(modelView * vec4(vertexPosition, 1.0)); + gl_Position = mvp * vec4(vertexPosition, 1.0); +} |