Split distance vector into direction and magnitude components

The vector was split because the vector's users need it split, and we were creating it from the split components in the first place, so it made sense to skip that step.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2223053002

Review-Url: https://codereview.chromium.org/2223053002
This commit is contained in:
dvonbeck 2016-08-08 11:47:12 -07:00 committed by Commit bot
parent 397a517d1a
commit 84bca78ab4
3 changed files with 7 additions and 7 deletions

View File

@ -86,10 +86,9 @@ public:
}
// Here we are splitting the distance vector into length and normalized direction
// TODO: Output these values from the geometry processor frag code instead of the vector
fragBuilder->codeAppendf("float dv_length = length(%s);",
fragBuilder->codeAppendf("float dv_length = %s.z;",
fragBuilder->distanceVectorName());
fragBuilder->codeAppendf("vec2 dv_norm = normalize(%s);",
fragBuilder->codeAppendf("vec2 dv_norm = %s.xy;",
fragBuilder->distanceVectorName());
// Asserting presence of necessary uniforms

View File

@ -139,10 +139,10 @@ public:
if (args.fDistanceVectorName) {
fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center of the circle
fragBuilder->codeAppendf(" %s = vec2(distanceToEdge, 0.0);", // avoid normalizing
fragBuilder->codeAppendf(" %s = vec3(1.0, 0.0, distanceToEdge);", // no normalize
args.fDistanceVectorName);
fragBuilder->codeAppend ("} else {");
fragBuilder->codeAppendf(" %s = normalize(%s.xy) * distanceToEdge;",
fragBuilder->codeAppendf(" %s = vec3(normalize(%s.xy), distanceToEdge);",
args.fDistanceVectorName, v.fsIn());
fragBuilder->codeAppend ("}");
}

View File

@ -90,8 +90,9 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
const char* distanceVectorName = nullptr;
if (this->fPipeline.usesDistanceVectorField() && proc.implementsDistanceVector()) {
distanceVectorName = fFS.distanceVectorName();
fFS.codeAppend( "// Un-normalized vector to the closed geometric edge (in source space)\n");
fFS.codeAppendf("vec2 %s;", distanceVectorName);
fFS.codeAppend( "// Normalized vector to the closest geometric edge (in source space)\n");
fFS.codeAppend( "// Distance to the edge encoded in the z-component\n");
fFS.codeAppendf("vec3 %s;", distanceVectorName);
}
// Enclose custom code in a block to avoid namespace conflicts