From c79c403a52ac6e86b19b0210042d1edf715717bd Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 8 Nov 2018 10:47:24 +0100 Subject: [PATCH] More android shader compilation fixes --- libraries/render-utils/src/ssao.slh | 38 ++++++++++--------- .../render-utils/src/ssao_bilateralBlur.slf | 4 +- .../render-utils/src/ssao_buildNormals.slf | 2 +- .../render-utils/src/ssao_makeOcclusion.slf | 3 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/libraries/render-utils/src/ssao.slh b/libraries/render-utils/src/ssao.slh index bd2e29d04d..248a9f930e 100644 --- a/libraries/render-utils/src/ssao.slh +++ b/libraries/render-utils/src/ssao.slh @@ -253,6 +253,14 @@ vec3 getTapLocationClampedSSAO(int sampleNumber, float spinAngle, float outerRad LAYOUT(binding=RENDER_UTILS_TEXTURE_SSAO_DEPTH) uniform sampler2D depthPyramidTex; LAYOUT(binding=RENDER_UTILS_TEXTURE_SSAO_NORMAL) uniform sampler2D normalTex; +vec2 getFramebufferUVFromSideUV(ivec4 side, vec2 uv) { + return isStereo() ? vec2((uv.x + float(getStereoSide(side))) * 0.5, uv.y) : uv; +} + +vec2 getSideUVFromFramebufferUV(ivec4 side, vec2 uv) { + return isStereo() ? vec2(uv.x * 2.0 - float(getStereoSide(side)), uv.y) : uv; +} + ivec2 getDepthTextureSize(int level) { return textureSize(depthPyramidTex, level); } @@ -286,7 +294,7 @@ float getZEyeAtUV(vec2 texCoord, float level) { <@endfunc@> float getZEyeAtUV(ivec4 side, vec2 texCoord, float level) { - texCoord.x = mix(texCoord.x, (texCoord.x + getStereoSide(side)) * 0.5, isStereo()); + texCoord = getFramebufferUVFromSideUV(side, texCoord); return getZEyeAtUV(texCoord, level); } @@ -304,7 +312,7 @@ vec3 getNormalEyeAtUV(vec2 texCoord, float level) { } vec3 getNormalEyeAtUV(ivec4 side, vec2 texCoord, float level) { - texCoord.x = mix(texCoord.x, (texCoord.x + getStereoSide(side)) * 0.5, isStereo()); + texCoord = getFramebufferUVFromSideUV(side, texCoord); return getNormalEyeAtUV(texCoord, level); } @@ -322,7 +330,7 @@ vec2 fetchTap(ivec4 side, vec2 tapUV, float tapRadius) { int mipLevel = evalMipFromRadius(tapRadius * float(doFetchMips())); vec2 fetchUV = clamp(tapUV, vec2(0), vec2(1)); - fetchUV = isStereo() ? vec2((fetchUV.x + getStereoSide(side)) * 0.5, fetchUV.y) : fetchUV; + fetchUV = getFramebufferUVFromSideUV(side, fetchUV); vec2 P; P.x = float(mipLevel); @@ -357,19 +365,17 @@ const ivec2 UV_TOP = ivec2(0,1); const ivec2 UV_BOTTOM = ivec2(0,-1); vec3 buildNormal(ivec4 side, vec2 fragUVPos, vec3 fragPosition, vec2 deltaDepthUV) { - vec2 sideUVPos = fragUVPos; - - sideUVPos.x = mix(sideUVPos.x, (sideUVPos.x + getStereoSide(side)) * 0.5, isStereo()); + vec2 fullUVPos = getFramebufferUVFromSideUV(side, fragUVPos); vec3 fragPositionDxPos; vec3 fragPositionDxNeg; vec3 fragPositionDyPos; vec3 fragPositionDyNeg; - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_RIGHT, deltaDepthUV, fragPositionDxPos)$> - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_LEFT, deltaDepthUV, fragPositionDxNeg)$> - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_TOP, deltaDepthUV, fragPositionDyPos)$> - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_BOTTOM, deltaDepthUV, fragPositionDyNeg)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_RIGHT, deltaDepthUV, fragPositionDxPos)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_LEFT, deltaDepthUV, fragPositionDxNeg)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_TOP, deltaDepthUV, fragPositionDyPos)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_BOTTOM, deltaDepthUV, fragPositionDyNeg)$> vec3 fragDeltaDx = getMinDelta(fragPosition, fragPositionDxPos, fragPositionDxNeg); vec3 fragDeltaDy = getMinDelta(fragPosition, fragPositionDyPos, fragPositionDyNeg); @@ -379,19 +385,17 @@ vec3 buildNormal(ivec4 side, vec2 fragUVPos, vec3 fragPosition, vec2 deltaDepthU void buildTangentBinormal(ivec4 side, vec2 fragUVPos, vec3 fragPosition, vec3 fragNormal, vec2 deltaDepthUV, out vec3 fragTangent, out vec3 fragBinormal) { - vec2 sideUVPos = fragUVPos; - - sideUVPos.x = mix(sideUVPos.x, (sideUVPos.x + getStereoSide(side)) * 0.5, isStereo()); + vec2 fullUVPos = getFramebufferUVFromSideUV(side, fragUVPos); vec3 fragPositionDxPos; vec3 fragPositionDxNeg; vec3 fragPositionDyPos; vec3 fragPositionDyNeg; - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_RIGHT, deltaDepthUV, fragPositionDxPos)$> - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_LEFT, deltaDepthUV, fragPositionDxNeg)$> - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_TOP, deltaDepthUV, fragPositionDyPos)$> - <$buildPositionOffset(side, fragUVPos, sideUVPos, UV_BOTTOM, deltaDepthUV, fragPositionDyNeg)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_RIGHT, deltaDepthUV, fragPositionDxPos)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_LEFT, deltaDepthUV, fragPositionDxNeg)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_TOP, deltaDepthUV, fragPositionDyPos)$> + <$buildPositionOffset(side, fragUVPos, fullUVPos, UV_BOTTOM, deltaDepthUV, fragPositionDyNeg)$> vec3 fragDeltaDx = getMinDelta(fragPosition, fragPositionDxPos, fragPositionDxNeg); vec3 fragDeltaDy = getMinDelta(fragPosition, fragPositionDyPos, fragPositionDyNeg); diff --git a/libraries/render-utils/src/ssao_bilateralBlur.slf b/libraries/render-utils/src/ssao_bilateralBlur.slf index cf13065555..c392f79322 100644 --- a/libraries/render-utils/src/ssao_bilateralBlur.slf +++ b/libraries/render-utils/src/ssao_bilateralBlur.slf @@ -43,7 +43,7 @@ int getBlurRadius() { } vec4 fetchOcclusionPacked(ivec4 side, vec2 texCoord) { - texCoord.x = mix(texCoord.x, (texCoord.x + getStereoSide(side) * getBlurOcclusionUVLimit().x) * 0.5, isStereo()); + texCoord.x = isStereo() ? (texCoord.x + float(getStereoSide(side)) * getBlurOcclusionUVLimit().x) * 0.5 : texCoord.x; return textureLod(occlusionMap, texCoord, 0.0); } @@ -96,7 +96,7 @@ vec4 getBlurredOcclusion(ivec2 destPixelCoord, vec2 occlusionTexCoord, vec2 dept int r; // From now on, occlusionTexCoord is the UV pos in the side - float sideTexCoord = occlusionTexCoord.x * 2.0 - getStereoSide(side) * getBlurOcclusionUVLimit().x; + float sideTexCoord = occlusionTexCoord.x * 2.0 - float(getStereoSide(side)) * getBlurOcclusionUVLimit().x; occlusionTexCoord.x = mix(occlusionTexCoord.x, sideTexCoord, isStereo()); occlusionTexCoord -= getBlurOcclusionAxis() * blurRadius; diff --git a/libraries/render-utils/src/ssao_buildNormals.slf b/libraries/render-utils/src/ssao_buildNormals.slf index 0dea63ae14..2f205119d9 100644 --- a/libraries/render-utils/src/ssao_buildNormals.slf +++ b/libraries/render-utils/src/ssao_buildNormals.slf @@ -32,7 +32,7 @@ void main(void) { vec2 deltaDepthUV = vec2(1.0) / vec2(getDepthTextureSideSize(0)); // From now on, fragUVPos is the UV pos in the side - fragUVPos.x = mix(fragUVPos.x, fragUVPos.x * 2.0 - getStereoSide(side), isStereo()); + fragUVPos = getSideUVFromFramebufferUV(side, fragUVPos); // The position and normal of the pixel fragment in Eye space vec3 fragPositionES = buildPosition(side, fragUVPos); diff --git a/libraries/render-utils/src/ssao_makeOcclusion.slf b/libraries/render-utils/src/ssao_makeOcclusion.slf index cc161d7323..5dfa879c69 100644 --- a/libraries/render-utils/src/ssao_makeOcclusion.slf +++ b/libraries/render-utils/src/ssao_makeOcclusion.slf @@ -45,8 +45,7 @@ void main(void) { } ivec4 side = getStereoSideInfoFromWidth(fragPixelPos.x, sideOcclusionSize.x); // From now on, fragUVPos is the UV pos in the side - fragUVPos.x = mix(fragUVPos.x, fragUVPos.x * 2.0 - getStereoSide(side), isStereo()); - + fragUVPos = getSideUVFromFramebufferUV(side, fragUVPos); fragUVPos = snapToTexel(fragUVPos, sideDepthSize); // The position and normal of the pixel fragment in Eye space