From 834d9c07103cf3448e5cdef2146895a69ac1b4a0 Mon Sep 17 00:00:00 2001 From: Gabriel Calero Date: Tue, 11 Oct 2016 12:15:49 -0300 Subject: [PATCH] Adapt shader for GL ES support which requires operators of the same datatype --- libraries/gpu/src/gpu/PackedNormal.slh | 2 +- libraries/model/src/model/Light.slh | 4 ++-- libraries/render-utils/src/DeferredBufferRead.slh | 6 +++--- libraries/render-utils/src/DeferredBufferWrite.slh | 4 ++-- libraries/render-utils/src/DeferredGlobalLight.slh | 6 +++--- libraries/render-utils/src/LightAmbient.slh | 6 +++--- libraries/render-utils/src/LightPoint.slh | 2 +- libraries/render-utils/src/LightSpot.slh | 2 +- libraries/render-utils/src/LightingModel.slh | 6 +++--- libraries/render-utils/src/SubsurfaceScattering.slh | 6 +++--- libraries/render-utils/src/deferred_light.slv | 2 +- libraries/render-utils/src/deferred_light_limited.slv | 2 +- libraries/render-utils/src/deferred_light_spot.slv | 2 +- libraries/render-utils/src/directional_ambient_light.slf | 2 +- libraries/render-utils/src/directional_skybox_light.slf | 2 +- 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libraries/gpu/src/gpu/PackedNormal.slh b/libraries/gpu/src/gpu/PackedNormal.slh index ecb383fc30..1d834b620e 100644 --- a/libraries/gpu/src/gpu/PackedNormal.slh +++ b/libraries/gpu/src/gpu/PackedNormal.slh @@ -23,7 +23,7 @@ vec2 float32x3_to_oct(in vec3 v) { vec3 oct_to_float32x3(in vec2 e) { vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y)); - if (v.z < 0) { + if (v.z < 0.0) { v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy); } return normalize(v); diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index 5e9d3d30c0..c9cfa1ad80 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -108,7 +108,7 @@ float evalLightAttenuation(Light l, float d) { // "Fade" the edges of light sources to make things look a bit more attractive. // Note: this tends to look a bit odd at lower exponents. - attenuation *= min(1, max(0, -(d - cutoff))); + attenuation *= min(1.0, max(0.0, -(d - cutoff))); return attenuation; } @@ -118,7 +118,7 @@ SphericalHarmonics getLightAmbientSphere(Light l) { } bool getLightHasAmbientMap(Light l) { - return l._control.x > 0; + return l._control.x > 0.0; } float getLightAmbientMapNumMips(Light l) { diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index 6b5060cc5f..7cba2007cc 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -51,7 +51,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { vec4 specularVal; DeferredFragment frag; - frag.depthVal = -1; + frag.depthVal = -1.0; normalVal = texture(normalMap, texcoord); diffuseVal = texture(albedoMap, texcoord); specularVal = texture(specularMap, texcoord); @@ -138,8 +138,8 @@ void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out lowNormalCurvature = fetchDiffusedCurvature(texcoord); midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f); lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f); - midNormalCurvature.w = (midNormalCurvature.w * 2 - 1); - lowNormalCurvature.w = (lowNormalCurvature.w * 2 - 1); + midNormalCurvature.w = (midNormalCurvature.w * 2.0 - 1.0); + lowNormalCurvature.w = (lowNormalCurvature.w * 2.0 - 1.0); } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index aa79781c25..2f6bfaeb61 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -27,8 +27,8 @@ float evalOpaqueFinalAlpha(float alpha, float mapAlpha) { } const float DEFAULT_ROUGHNESS = 0.9; -const float DEFAULT_SHININESS = 10; -const float DEFAULT_METALLIC = 0; +const float DEFAULT_SHININESS = 10.0; +const float DEFAULT_METALLIC = 0.0; const vec3 DEFAULT_SPECULAR = vec3(0.1); const vec3 DEFAULT_EMISSIVE = vec3(0.0); const float DEFAULT_OCCLUSION = 1.0; diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 16cdab535c..799ad53b58 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -23,7 +23,7 @@ // prepareGlobalLight // Transform directions to worldspace vec3 fragNormal = vec3((normal)); - vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0)); + vec3 fragEyeVector = vec3(invViewMat * vec4(-1.0*position, 0.0)); vec3 fragEyeDir = normalize(fragEyeVector); // Get light @@ -143,13 +143,13 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); // Reevaluate the shadow attenuation for light facing fragments - float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; + float lightAttenuation = (1.0 - facingLight) + facingLight * shadowAttenuation; // Diffuse light is the lightmap dimmed by shadow vec3 diffuseLight = lightAttenuation * lightmap; // Ambient light is the lightmap when in shadow - vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(light); + vec3 ambientLight = (1.0 - lightAttenuation) * lightmap * getLightAmbientIntensity(light); return isLightmapEnabled() * obscurance * albedo * (diffuseLight + ambientLight); } diff --git a/libraries/render-utils/src/LightAmbient.slh b/libraries/render-utils/src/LightAmbient.slh index ec665e6deb..b1b36ad2d4 100644 --- a/libraries/render-utils/src/LightAmbient.slh +++ b/libraries/render-utils/src/LightAmbient.slh @@ -23,7 +23,7 @@ vec4 evalSkyboxLight(vec3 direction, float lod) { <@func declareEvalAmbientSpecularIrradiance(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere)@> vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float gloss) { - return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5); + return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5.0); } <@if supportAmbientMap@> @@ -32,7 +32,7 @@ vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float vec3 evalAmbientSpecularIrradiance(Light light, vec3 fragEyeDir, vec3 fragNormal, float roughness, vec3 fresnel) { vec3 direction = -reflect(fragEyeDir, fragNormal); - vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness); + vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1.0 - roughness); vec3 specularLight; <@if supportIfAmbientMapElseAmbientSphere@> if (getLightHasAmbientMap(light)) @@ -76,7 +76,7 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 // Diffuse from ambient - diffuse = (1 - metallic) * evalSphericalLight(getLightAmbientSphere(light), normal).xyz; + diffuse = (1.0 - metallic) * evalSphericalLight(getLightAmbientSphere(light), normal).xyz; // Specular highlight from ambient specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light); diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index 5c9e66dd24..f4d20aa58e 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -40,7 +40,7 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, if (isShowLightContour() > 0.0) { // Show edge float edge = abs(2.0 * ((getLightRadius(light) - fragLightDistance) / (0.1)) - 1.0); - if (edge < 1) { + if (edge < 1.0) { float edgeCoord = exp2(-8.0*edge*edge); diffuse = vec3(edgeCoord * edgeCoord * getLightShowContour(light) * getLightColor(light)); } diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 8a17a5ef4d..7f39a1e5f9 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -44,7 +44,7 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light)); float edgeDist = min(edgeDistR, edgeDistS); float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); - if (edge < 1) { + if (edge < 1.0) { float edgeCoord = exp2(-8.0*edge*edge); diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); } diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index f36b2d8131..3bc05fc54f 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -118,8 +118,8 @@ vec3 fresnelSchlickColor(vec3 fresnelColor, vec3 lightDir, vec3 halfDir) { float specularDistribution(float roughness, vec3 normal, vec3 halfDir) { float ndoth = clamp(dot(halfDir, normal), 0.0, 1.0); - float gloss2 = pow(0.001 + roughness, 4); - float denom = (ndoth * ndoth*(gloss2 - 1) + 1); + float gloss2 = pow(0.001 + roughness, 4.0); + float denom = (ndoth * ndoth*(gloss2 - 1.0) + 1.0); float power = gloss2 / (3.14159 * denom * denom); return power; } @@ -142,7 +142,7 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float m float power = specularDistribution(roughness, fragNormal, halfDir); vec3 specular = power * fresnelColor * diffuse; - return vec4(specular, (1.0 - metallic) * diffuse * (1 - fresnelColor.x)); + return vec4(specular, (1.0 - metallic) * diffuse * (1.0 - fresnelColor.x)); } <@endfunc@> diff --git a/libraries/render-utils/src/SubsurfaceScattering.slh b/libraries/render-utils/src/SubsurfaceScattering.slh index 6d5dd01d8f..42ffafd9ff 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.slh +++ b/libraries/render-utils/src/SubsurfaceScattering.slh @@ -137,7 +137,7 @@ vec3 integrate(float cosTheta, float skinRadius) { uniform sampler2D scatteringLUT; vec3 fetchBRDF(float LdotN, float curvature) { - return texture(scatteringLUT, vec2( clamp(LdotN * 0.5 + 0.5, 0.0, 1.0), clamp(2 * curvature, 0.0, 1.0))).xyz; + return texture(scatteringLUT, vec2( clamp(LdotN * 0.5 + 0.5, 0.0, 1.0), clamp(2.0 * curvature, 0.0, 1.0))).xyz; } vec3 fetchBRDFSpectrum(vec3 LdotNSpectrum, float curvature) { @@ -183,7 +183,7 @@ float tuneCurvatureUnsigned(float curvature) { } float unpackCurvature(float packedCurvature) { - return (packedCurvature * 2 - 1); + return (packedCurvature * 2.0 - 1.0); } vec3 evalScatteringBentNdotL(vec3 normal, vec3 midNormal, vec3 lowNormal, vec3 lightDir) { @@ -210,7 +210,7 @@ vec3 evalSkinBRDF(vec3 lightDir, vec3 normal, vec3 midNormal, vec3 lowNormal, fl return lowNormal * 0.5 + vec3(0.5); } if (showCurvature()) { - return (curvature > 0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature)); + return (curvature > 0.0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature)); } vec3 bentNdotL = evalScatteringBentNdotL(normal, midNormal, lowNormal, lightDir); diff --git a/libraries/render-utils/src/deferred_light.slv b/libraries/render-utils/src/deferred_light.slv index 27845bf6a2..74b3749181 100644 --- a/libraries/render-utils/src/deferred_light.slv +++ b/libraries/render-utils/src/deferred_light.slv @@ -26,7 +26,7 @@ void main(void) { ); vec4 pos = UNIT_QUAD[gl_VertexID]; - _texCoord0 = (pos.xy + 1) * 0.5; + _texCoord0 = (pos.xy + 1.0) * 0.5; _texCoord0 *= texcoordFrameTransform.zw; _texCoord0 += texcoordFrameTransform.xy; diff --git a/libraries/render-utils/src/deferred_light_limited.slv b/libraries/render-utils/src/deferred_light_limited.slv index 81ec882bdf..0525509f0b 100644 --- a/libraries/render-utils/src/deferred_light_limited.slv +++ b/libraries/render-utils/src/deferred_light_limited.slv @@ -47,7 +47,7 @@ void main(void) { ); vec4 pos = UNIT_QUAD[gl_VertexID]; - _texCoord0 = vec4((pos.xy + 1) * 0.5, 0.0, 1.0); + _texCoord0 = vec4((pos.xy + 1.0) * 0.5, 0.0, 1.0); if (cam_isStereo()) { _texCoord0.x = 0.5 * (_texCoord0.x + cam_getStereoSide()); diff --git a/libraries/render-utils/src/deferred_light_spot.slv b/libraries/render-utils/src/deferred_light_spot.slv index 6ae133b7a5..4a1a0472aa 100755 --- a/libraries/render-utils/src/deferred_light_spot.slv +++ b/libraries/render-utils/src/deferred_light_spot.slv @@ -60,7 +60,7 @@ void main(void) { ); vec4 pos = UNIT_QUAD[gl_VertexID]; - _texCoord0 = vec4((pos.xy + 1) * 0.5, 0.0, 1.0); + _texCoord0 = vec4((pos.xy + 1.0) * 0.5, 0.0, 1.0); if (cam_isStereo()) { _texCoord0.x = 0.5 * (_texCoord0.x + cam_getStereoSide()); } diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 5b591cb01f..6c99d44c5f 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// directional_light.frag +// directional_ambient_light.frag // fragment shader // // Created by Andrzej Kapolka on 9/3/14. diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 6130c8ac8e..d8a2f44042 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// directional_light.frag +// directional_skybox_light.frag // fragment shader // // Created by Sam Gateau on 5/8/2015.