Skip to content

Commit

Permalink
fix parallax + opacityMap
Browse files Browse the repository at this point in the history
  • Loading branch information
guycalledfrank committed Jan 14, 2016
1 parent e59cdad commit 2dbe896
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/graphics/program-lib/phong.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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";
}
Expand Down

0 comments on commit 2dbe896

Please sign in to comment.