Fix shader error on Raspberry PI 3 Model B+
parent
ab5e53fb54
commit
c73277a4aa
|
@ -52,9 +52,9 @@
|
||||||
// https://github.com/qt/qt3d/blob/5.11/src/extras/shaders/gl3/metalrough.inc.frag
|
// https://github.com/qt/qt3d/blob/5.11/src/extras/shaders/gl3/metalrough.inc.frag
|
||||||
|
|
||||||
// Exposure correction
|
// Exposure correction
|
||||||
float exposure;
|
highp float exposure;
|
||||||
// Gamma correction
|
// Gamma correction
|
||||||
float gamma;
|
highp float gamma;
|
||||||
|
|
||||||
varying highp vec3 vert;
|
varying highp vec3 vert;
|
||||||
varying highp vec3 vertNormal;
|
varying highp vec3 vertNormal;
|
||||||
|
@ -63,9 +63,9 @@ varying highp vec2 vertTexCoord;
|
||||||
varying highp float vertMetalness;
|
varying highp float vertMetalness;
|
||||||
varying highp float vertRoughness;
|
varying highp float vertRoughness;
|
||||||
varying highp vec3 cameraPos;
|
varying highp vec3 cameraPos;
|
||||||
varying vec3 firstLightPos;
|
varying highp vec3 firstLightPos;
|
||||||
varying vec3 secondLightPos;
|
varying highp vec3 secondLightPos;
|
||||||
varying vec3 thirdLightPos;
|
varying highp vec3 thirdLightPos;
|
||||||
uniform highp vec3 lightPos;
|
uniform highp vec3 lightPos;
|
||||||
uniform highp sampler2D textureId;
|
uniform highp sampler2D textureId;
|
||||||
uniform highp int textureEnabled;
|
uniform highp int textureEnabled;
|
||||||
|
@ -94,39 +94,39 @@ struct Light {
|
||||||
int lightCount;
|
int lightCount;
|
||||||
Light lights[MAX_LIGHTS];
|
Light lights[MAX_LIGHTS];
|
||||||
|
|
||||||
float remapRoughness(const in float roughness)
|
highp float remapRoughness(const in highp float roughness)
|
||||||
{
|
{
|
||||||
// As per page 14 of
|
// As per page 14 of
|
||||||
// http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
|
// http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
|
||||||
// we remap the roughness to give a more perceptually linear response
|
// we remap the roughness to give a more perceptually linear response
|
||||||
// of "bluriness" as a function of the roughness specified by the user.
|
// of "bluriness" as a function of the roughness specified by the user.
|
||||||
// r = roughness^2
|
// r = roughness^2
|
||||||
float maxSpecPower;
|
highp float maxSpecPower;
|
||||||
float minRoughness;
|
highp float minRoughness;
|
||||||
maxSpecPower = 999999.0;
|
maxSpecPower = 999999.0;
|
||||||
minRoughness = sqrt(2.0 / (maxSpecPower + 2.0));
|
minRoughness = sqrt(2.0 / (maxSpecPower + 2.0));
|
||||||
return max(roughness * roughness, minRoughness);
|
return max(roughness * roughness, minRoughness);
|
||||||
}
|
}
|
||||||
|
|
||||||
float normalDistribution(const in vec3 n, const in vec3 h, const in float alpha)
|
highp float normalDistribution(const in highp vec3 n, const in highp vec3 h, const in highp float alpha)
|
||||||
{
|
{
|
||||||
// Blinn-Phong approximation - see
|
// Blinn-Phong approximation - see
|
||||||
// http://graphicrants.blogspot.co.uk/2013/08/specular-brdf-reference.html
|
// http://graphicrants.blogspot.co.uk/2013/08/specular-brdf-reference.html
|
||||||
float specPower = 2.0 / (alpha * alpha) - 2.0;
|
highp float specPower = 2.0 / (alpha * alpha) - 2.0;
|
||||||
return (specPower + 2.0) / (2.0 * 3.14159) * pow(max(dot(n, h), 0.0), specPower);
|
return (specPower + 2.0) / (2.0 * 3.14159) * pow(max(dot(n, h), 0.0), specPower);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 fresnelFactor(const in vec3 color, const in float cosineFactor)
|
highp vec3 fresnelFactor(const in highp vec3 color, const in highp float cosineFactor)
|
||||||
{
|
{
|
||||||
// Calculate the Fresnel effect value
|
// Calculate the Fresnel effect value
|
||||||
vec3 f = color;
|
highp vec3 f = color;
|
||||||
vec3 F = f + (1.0 - f) * pow(1.0 - cosineFactor, 5.0);
|
highp vec3 F = f + (1.0 - f) * pow(1.0 - cosineFactor, 5.0);
|
||||||
return clamp(F, f, vec3(1.0));
|
return clamp(F, f, vec3(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
float geometricModel(const in float lDotN,
|
highp float geometricModel(const in highp float lDotN,
|
||||||
const in float vDotN,
|
const in highp float vDotN,
|
||||||
const in vec3 h)
|
const in highp vec3 h)
|
||||||
{
|
{
|
||||||
// Implicit geometric model (equal to denominator in specular model).
|
// Implicit geometric model (equal to denominator in specular model).
|
||||||
// This currently assumes that there is no attenuation by geometric shadowing or
|
// This currently assumes that there is no attenuation by geometric shadowing or
|
||||||
|
@ -134,50 +134,50 @@ float geometricModel(const in float lDotN,
|
||||||
return lDotN * vDotN;
|
return lDotN * vDotN;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 specularModel(const in vec3 F0,
|
highp vec3 specularModel(const in highp vec3 F0,
|
||||||
const in float sDotH,
|
const in highp float sDotH,
|
||||||
const in float sDotN,
|
const in highp float sDotN,
|
||||||
const in float vDotN,
|
const in highp float vDotN,
|
||||||
const in vec3 n,
|
const in highp vec3 n,
|
||||||
const in vec3 h)
|
const in highp vec3 h)
|
||||||
{
|
{
|
||||||
// Clamp sDotN and vDotN to small positive value to prevent the
|
// Clamp sDotN and vDotN to small positive value to prevent the
|
||||||
// denominator in the reflection equation going to infinity. Balance this
|
// denominator in the reflection equation going to infinity. Balance this
|
||||||
// by using the clamped values in the geometric factor function to
|
// by using the clamped values in the geometric factor function to
|
||||||
// avoid ugly seams in the specular lighting.
|
// avoid ugly seams in the specular lighting.
|
||||||
float sDotNPrime = max(sDotN, 0.001);
|
highp float sDotNPrime = max(sDotN, 0.001);
|
||||||
float vDotNPrime = max(vDotN, 0.001);
|
highp float vDotNPrime = max(vDotN, 0.001);
|
||||||
|
|
||||||
vec3 F = fresnelFactor(F0, sDotH);
|
highp vec3 F = fresnelFactor(F0, sDotH);
|
||||||
float G = geometricModel(sDotNPrime, vDotNPrime, h);
|
highp float G = geometricModel(sDotNPrime, vDotNPrime, h);
|
||||||
|
|
||||||
vec3 cSpec = F * G / (4.0 * sDotNPrime * vDotNPrime);
|
highp vec3 cSpec = F * G / (4.0 * sDotNPrime * vDotNPrime);
|
||||||
return clamp(cSpec, vec3(0.0), vec3(1.0));
|
return clamp(cSpec, vec3(0.0), vec3(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 pbrModel(const in int lightIndex,
|
highp vec3 pbrModel(const in int lightIndex,
|
||||||
const in vec3 wPosition,
|
const in highp vec3 wPosition,
|
||||||
const in vec3 wNormal,
|
const in highp vec3 wNormal,
|
||||||
const in vec3 wView,
|
const in highp vec3 wView,
|
||||||
const in vec3 baseColor,
|
const in highp vec3 baseColor,
|
||||||
const in float metalness,
|
const in highp float metalness,
|
||||||
const in float alpha,
|
const in highp float alpha,
|
||||||
const in float ambientOcclusion)
|
const in highp float ambientOcclusion)
|
||||||
{
|
{
|
||||||
// Calculate some useful quantities
|
// Calculate some useful quantities
|
||||||
vec3 n = wNormal;
|
highp vec3 n = wNormal;
|
||||||
vec3 s = vec3(0.0);
|
highp vec3 s = vec3(0.0);
|
||||||
vec3 v = wView;
|
highp vec3 v = wView;
|
||||||
vec3 h = vec3(0.0);
|
highp vec3 h = vec3(0.0);
|
||||||
|
|
||||||
float vDotN = dot(v, n);
|
highp float vDotN = dot(v, n);
|
||||||
float sDotN = 0.0;
|
highp float sDotN = 0.0;
|
||||||
float sDotH = 0.0;
|
highp float sDotH = 0.0;
|
||||||
float att = 1.0;
|
highp float att = 1.0;
|
||||||
|
|
||||||
if (lights[lightIndex].type != TYPE_DIRECTIONAL) {
|
if (lights[lightIndex].type != TYPE_DIRECTIONAL) {
|
||||||
// Point and Spot lights
|
// Point and Spot lights
|
||||||
vec3 sUnnormalized = vec3(lights[lightIndex].position) - wPosition;
|
highp vec3 sUnnormalized = vec3(lights[lightIndex].position) - wPosition;
|
||||||
s = normalize(sUnnormalized);
|
s = normalize(sUnnormalized);
|
||||||
|
|
||||||
// Calculate the attenuation factor
|
// Calculate the attenuation factor
|
||||||
|
@ -186,7 +186,7 @@ vec3 pbrModel(const in int lightIndex,
|
||||||
if (lights[lightIndex].constantAttenuation != 0.0
|
if (lights[lightIndex].constantAttenuation != 0.0
|
||||||
|| lights[lightIndex].linearAttenuation != 0.0
|
|| lights[lightIndex].linearAttenuation != 0.0
|
||||||
|| lights[lightIndex].quadraticAttenuation != 0.0) {
|
|| lights[lightIndex].quadraticAttenuation != 0.0) {
|
||||||
float dist = length(sUnnormalized);
|
highp float dist = length(sUnnormalized);
|
||||||
att = 1.0 / (lights[lightIndex].constantAttenuation +
|
att = 1.0 / (lights[lightIndex].constantAttenuation +
|
||||||
lights[lightIndex].linearAttenuation * dist +
|
lights[lightIndex].linearAttenuation * dist +
|
||||||
lights[lightIndex].quadraticAttenuation * dist * dist);
|
lights[lightIndex].quadraticAttenuation * dist * dist);
|
||||||
|
@ -210,22 +210,22 @@ vec3 pbrModel(const in int lightIndex,
|
||||||
sDotH = dot(s, h);
|
sDotH = dot(s, h);
|
||||||
|
|
||||||
// Calculate diffuse component
|
// Calculate diffuse component
|
||||||
vec3 diffuseColor = (1.0 - metalness) * baseColor * lights[lightIndex].color;
|
highp vec3 diffuseColor = (1.0 - metalness) * baseColor * lights[lightIndex].color;
|
||||||
vec3 diffuse = diffuseColor * max(sDotN, 0.0) / 3.14159;
|
highp vec3 diffuse = diffuseColor * max(sDotN, 0.0) / 3.14159;
|
||||||
|
|
||||||
// Calculate specular component
|
// Calculate specular component
|
||||||
vec3 dielectricColor = vec3(0.04);
|
highp vec3 dielectricColor = vec3(0.04);
|
||||||
vec3 F0 = mix(dielectricColor, baseColor, metalness);
|
highp vec3 F0 = mix(dielectricColor, baseColor, metalness);
|
||||||
vec3 specularFactor = vec3(0.0);
|
highp vec3 specularFactor = vec3(0.0);
|
||||||
if (sDotN > 0.0) {
|
if (sDotN > 0.0) {
|
||||||
specularFactor = specularModel(F0, sDotH, sDotN, vDotN, n, h);
|
specularFactor = specularModel(F0, sDotH, sDotN, vDotN, n, h);
|
||||||
specularFactor *= normalDistribution(n, h, alpha);
|
specularFactor *= normalDistribution(n, h, alpha);
|
||||||
}
|
}
|
||||||
vec3 specularColor = lights[lightIndex].color;
|
highp vec3 specularColor = lights[lightIndex].color;
|
||||||
vec3 specular = specularColor * specularFactor;
|
highp vec3 specular = specularColor * specularFactor;
|
||||||
|
|
||||||
// Blend between diffuse and specular to conserver energy
|
// Blend between diffuse and specular to conserver energy
|
||||||
vec3 color = att * lights[lightIndex].intensity * (specular + diffuse * (vec3(1.0) - specular));
|
highp vec3 color = att * lights[lightIndex].intensity * (specular + diffuse * (vec3(1.0) - specular));
|
||||||
|
|
||||||
// Reduce by ambient occlusion amount
|
// Reduce by ambient occlusion amount
|
||||||
color *= ambientOcclusion;
|
color *= ambientOcclusion;
|
||||||
|
@ -233,28 +233,28 @@ vec3 pbrModel(const in int lightIndex,
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 toneMap(const in vec3 c)
|
highp vec3 toneMap(const in highp vec3 c)
|
||||||
{
|
{
|
||||||
return c / (c + vec3(1.0));
|
return c / (c + vec3(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 gammaCorrect(const in vec3 color)
|
highp vec3 gammaCorrect(const in highp vec3 color)
|
||||||
{
|
{
|
||||||
return pow(color, vec3(1.0 / gamma));
|
return pow(color, vec3(1.0 / gamma));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 metalRoughFunction(const in vec4 baseColor,
|
highp vec4 metalRoughFunction(const in highp vec4 baseColor,
|
||||||
const in float metalness,
|
const in highp float metalness,
|
||||||
const in float roughness,
|
const in highp float roughness,
|
||||||
const in float ambientOcclusion,
|
const in highp float ambientOcclusion,
|
||||||
const in vec3 worldPosition,
|
const in highp vec3 worldPosition,
|
||||||
const in vec3 worldView,
|
const in highp vec3 worldView,
|
||||||
const in vec3 worldNormal)
|
const in highp vec3 worldNormal)
|
||||||
{
|
{
|
||||||
vec3 cLinear = vec3(0.0);
|
highp vec3 cLinear = vec3(0.0);
|
||||||
|
|
||||||
// Remap roughness for a perceptually more linear correspondence
|
// Remap roughness for a perceptually more linear correspondence
|
||||||
float alpha = remapRoughness(roughness);
|
highp float alpha = remapRoughness(roughness);
|
||||||
|
|
||||||
for (int i = 0; i < lightCount; ++i) {
|
for (int i = 0; i < lightCount; ++i) {
|
||||||
cLinear += pbrModel(i,
|
cLinear += pbrModel(i,
|
||||||
|
@ -271,10 +271,10 @@ vec4 metalRoughFunction(const in vec4 baseColor,
|
||||||
cLinear *= pow(2.0, exposure);
|
cLinear *= pow(2.0, exposure);
|
||||||
|
|
||||||
// Apply simple (Reinhard) tonemap transform to get into LDR range [0, 1]
|
// Apply simple (Reinhard) tonemap transform to get into LDR range [0, 1]
|
||||||
vec3 cToneMapped = toneMap(cLinear);
|
highp vec3 cToneMapped = toneMap(cLinear);
|
||||||
|
|
||||||
// Apply gamma correction prior to display
|
// Apply gamma correction prior to display
|
||||||
vec3 cGamma = gammaCorrect(cToneMapped);
|
highp vec3 cGamma = gammaCorrect(cToneMapped);
|
||||||
|
|
||||||
return vec4(cGamma, 1.0);
|
return vec4(cGamma, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -332,17 +332,17 @@ void main()
|
||||||
// Green: Roughness
|
// Green: Roughness
|
||||||
// Blue: Metallic
|
// Blue: Metallic
|
||||||
|
|
||||||
float metalness = vertMetalness;
|
highp float metalness = vertMetalness;
|
||||||
if (metalnessMapEnabled == 1) {
|
if (metalnessMapEnabled == 1) {
|
||||||
metalness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).b;
|
metalness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).b;
|
||||||
}
|
}
|
||||||
|
|
||||||
float roughness = vertRoughness;
|
highp float roughness = vertRoughness;
|
||||||
if (roughnessMapEnabled == 1) {
|
if (roughnessMapEnabled == 1) {
|
||||||
roughness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).g;
|
roughness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).g;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ambientOcclusion = 1.0;
|
highp float ambientOcclusion = 1.0;
|
||||||
if (ambientOcclusionMapEnabled == 1) {
|
if (ambientOcclusionMapEnabled == 1) {
|
||||||
ambientOcclusion = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).r;
|
ambientOcclusion = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).r;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue