diff --git a/src/graphics/program-lib/phong.js b/src/graphics/program-lib/phong.js index 3adfa7c2e23..4add6dfcfc3 100644 --- a/src/graphics/program-lib/phong.js +++ b/src/graphics/program-lib/phong.js @@ -267,6 +267,8 @@ pc.programlib.phong = { } } + if (options.forceUv1) useUv[1] = true; + for (i = 0; i < maxUvSets; i++) { if (useUv[i]) { attributes["vertex_texCoord" + i] = pc["SEMANTIC_TEXCOORD" + i]; @@ -575,14 +577,18 @@ pc.programlib.phong = { // FRAGMENT SHADER BODY code += chunks.startPS; + var opacityParallax = false; if (options.blendType===pc.BLEND_NONE && !options.alphaTest) { code += " data.alpha = 1.0;\n"; } else { - code += " getOpacity(data);\n"; - } - - if (options.alphaTest) { - code += " if (data.alpha < alpha_ref) discard;\n"; + if (options.heightMap && options.opacityMap) { + opacityParallax = true; + } else { + code += " getOpacity(data);\n"; // calculate opacity first if there's no parallax+opacityMap, to allow early out + if (options.alphaTest) { + code += " if (data.alpha < alpha_ref) discard;\n"; + } + } } if (needsNormal) { @@ -593,6 +599,14 @@ pc.programlib.phong = { if (options.heightMap) { code += " getParallax(data);\n"; } + + if (opacityParallax) { + code += " getOpacity(data);\n"; // if there's parallax, calculate opacity after it, to properly distort + if (options.alphaTest) { + code += " if (data.alpha < alpha_ref) discard;\n"; + } + } + code += " getNormal(data);\n"; if (options.useSpecular) code += " getReflDir(data);\n"; }