From 8cc8805a439c7b59cbdf13f35f9a4d4c59eb8f95 Mon Sep 17 00:00:00 2001 From: Christian Forfang Date: Wed, 7 Mar 2018 14:50:14 +0100 Subject: [PATCH] Parallax: fix texture() in non-uniform control-flow --- data/shaders/parallax/parallax.frag | 22 +++++++++++----------- data/shaders/parallax/parallax.frag.spv | Bin 8336 -> 8392 bytes 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/shaders/parallax/parallax.frag b/data/shaders/parallax/parallax.frag index 4787bbf2..8460331c 100644 --- a/data/shaders/parallax/parallax.frag +++ b/data/shaders/parallax/parallax.frag @@ -22,7 +22,7 @@ vec2 parallax_uv(vec2 uv, vec3 view_dir, int type) { if (type == 2) { // Parallax mapping - float depth = 1.0 - texture(sNormalHeightMap, uv).a; + float depth = 1.0 - textureLod(sNormalHeightMap, uv, 0.0).a; vec2 p = view_dir.xy * (depth * (ubo.heightScale * 0.5) + ubo.parallaxBias) / view_dir.z; return uv - p; } else { @@ -31,12 +31,12 @@ vec2 parallax_uv(vec2 uv, vec3 view_dir, int type) vec2 delta_uv = view_dir.xy * ubo.heightScale / (view_dir.z * ubo.numLayers); vec2 cur_uv = uv; - float depth_from_tex = 1.0 - texture(sNormalHeightMap, cur_uv).a; + float depth_from_tex = 1.0 - textureLod(sNormalHeightMap, cur_uv, 0.0).a; for (int i = 0; i < 32; i++) { cur_layer_depth += layer_depth; cur_uv -= delta_uv; - depth_from_tex = 1.0 - texture(sNormalHeightMap, cur_uv).a; + depth_from_tex = 1.0 - textureLod(sNormalHeightMap, cur_uv, 0.0).a; if (depth_from_tex < cur_layer_depth) { break; } @@ -49,7 +49,7 @@ vec2 parallax_uv(vec2 uv, vec3 view_dir, int type) // Parallax occlusion mapping vec2 prev_uv = cur_uv + delta_uv; float next = depth_from_tex - cur_layer_depth; - float prev = 1.0 - texture(sNormalHeightMap, prev_uv).a - cur_layer_depth + layer_depth; + float prev = 1.0 - textureLod(sNormalHeightMap, prev_uv, 0.0).a - cur_layer_depth + layer_depth; float weight = next / (next - prev); return mix(cur_uv, prev_uv, weight); } @@ -58,7 +58,7 @@ vec2 parallax_uv(vec2 uv, vec3 view_dir, int type) vec2 parallaxMapping(vec2 uv, vec3 viewDir) { - float height = 1.0 - texture(sNormalHeightMap, uv).a; + float height = 1.0 - textureLod(sNormalHeightMap, uv, 0.0).a; vec2 p = viewDir.xy * (height * (ubo.heightScale * 0.5) + ubo.parallaxBias) / viewDir.z; return uv - p; } @@ -69,11 +69,11 @@ vec2 steepParallaxMapping(vec2 uv, vec3 viewDir) float currLayerDepth = 0.0; vec2 deltaUV = viewDir.xy * ubo.heightScale / (viewDir.z * ubo.numLayers); vec2 currUV = uv; - float height = 1.0 - texture(sNormalHeightMap, currUV).a; + float height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a; for (int i = 0; i < ubo.numLayers; i++) { currLayerDepth += layerDepth; currUV -= deltaUV; - height = 1.0 - texture(sNormalHeightMap, currUV).a; + height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a; if (height < currLayerDepth) { break; } @@ -87,18 +87,18 @@ vec2 parallaxOcclusionMapping(vec2 uv, vec3 viewDir) float currLayerDepth = 0.0; vec2 deltaUV = viewDir.xy * ubo.heightScale / (viewDir.z * ubo.numLayers); vec2 currUV = uv; - float height = 1.0 - texture(sNormalHeightMap, currUV).a; + float height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a; for (int i = 0; i < ubo.numLayers; i++) { currLayerDepth += layerDepth; currUV -= deltaUV; - height = 1.0 - texture(sNormalHeightMap, currUV).a; + height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a; if (height < currLayerDepth) { break; } } vec2 prevUV = currUV + deltaUV; float nextDepth = height - currLayerDepth; - float prevDepth = 1.0 - texture(sNormalHeightMap, prevUV).a - currLayerDepth + layerDepth; + float prevDepth = 1.0 - textureLod(sNormalHeightMap, prevUV, 0.0).a - currLayerDepth + layerDepth; return mix(currUV, prevUV, nextDepth / (nextDepth - prevDepth)); } @@ -128,7 +128,7 @@ void main(void) discard; } - vec3 N = normalize(texture(sNormalHeightMap, uv).rgb * 2.0 - 1.0); + vec3 N = normalize(textureLod(sNormalHeightMap, uv, 0.0).rgb * 2.0 - 1.0); vec3 L = normalize(inTangentLightPos - inTangentFragPos); vec3 R = reflect(-L, N); vec3 H = normalize(L + V); diff --git a/data/shaders/parallax/parallax.frag.spv b/data/shaders/parallax/parallax.frag.spv index ccad474ef5d1b2e6df8ba61620db5446395c26fa..84624bfe978f7d905d4a9d1ec2b56c23b99a0b6d 100644 GIT binary patch delta 1702 zcmY*ZOHWfl7@cV;1wvIsEPWufh{#K+h*c2*F%+x@5jB$d2$%*mAgIN}g%(4IniwCM z7^6many^y53xmeE^0hK9j7#G}SGw>AU_58;or=?(&i9?~Ju~gij`tn;ZdavO2r1li z`O`ACRtPZxc!XOtU_Y>1=cGX)GHYZ(CPwCO^)pzJfAvq z7P5{~zokF29@^y4IC6SK7vxd8>`YChM_4CUB-JgK-)eWIU9F}}CEU2W;XqCT2q zEJ!ZTaO!tXahYi)0bdr50$f_RBA#P1QwLKnsE9TQ;fGE)ax74S@735V051AduL9fv z?e*9z05-M?ku1x21KXY>)`4TAw6`D*dPes}l8Ncq2yj(Ek71{ciA|~egAZ9QMKT$F5>istcazH zTFrS&T|S;KleBUU)mIRbjcTkQDWht>ApXDAS}1raWyG2xN68jfVS2mQ@`2ac&Ucl1ev*LGr2ZHW-eZ~$+ZPC`Ac@LjMxf=!8BY4$%b11HccCo zm11uNI22!sNw(eL_d0QH(8&>39IhQQ^Vv4H;NJr|=J0Z~4k(3LLWmuZ>BQ4!Go1i^ z$p69pbSh6tXHge4yVV@sUQ!K|Bzt&*-2kUf0H)C%hi6kf(Om#jm_EsD_pCs>Q?i!?F)Br@i0tOsK0X?*z=-ItunMa0JkAOU3+cc;u)3aapfs z{pGsK$!zRre^Sq8Iv&)J12Y>Vr~`f-U%Yd<)tmUvv0I6$$-6@=aK70A}P{*$fv#|3e+BR|f@eh7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