OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrDistanceFieldGeoProc.h" | 8 #include "GrDistanceFieldGeoProc.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 fragBuilder->codeAppend(".r;"); | 354 fragBuilder->codeAppend(".r;"); |
355 fragBuilder->codeAppend("float distance = " | 355 fragBuilder->codeAppend("float distance = " |
356 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");"); | 356 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");"); |
357 | 357 |
358 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision); | 358 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision); |
359 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); | 359 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); |
360 fragBuilder->codeAppend("float afwidth;"); | 360 fragBuilder->codeAppend("float afwidth;"); |
361 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) == | 361 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) == |
362 kUniformScale_DistanceFieldEffectMask; | 362 kUniformScale_DistanceFieldEffectMask; |
363 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag); | 363 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag); |
364 bool srgbOutput = SkToBool(dfTexEffect.getFlags() & kSRGB_DistanceFieldE ffectFlag); | |
364 if (isUniformScale) { | 365 if (isUniformScale) { |
365 // For uniform scale, we adjust for the effect of the transformation on the distance | 366 // For uniform scale, we adjust for the effect of the transformation on the distance |
366 // by using the length of the gradient of the t coordinate in the y direction. | 367 // by using the length of the gradient of the t coordinate in the y direction. |
367 // We use st coordinates to ensure we're mapping 1:1 from texel spac e to pixel space. | 368 // We use st coordinates to ensure we're mapping 1:1 from texel spac e to pixel space. |
368 // We use the y gradient because there is a bug in the Mali 400 in t he x direction. | 369 // We use the y gradient because there is a bug in the Mali 400 in t he x direction. |
369 | 370 |
370 // this gives us a smooth step across approximately one fragment | 371 // this gives us a smooth step across approximately one fragment |
371 fragBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "* dFdy(st.y));"); | 372 fragBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "* dFdy(st.y));"); |
372 | 373 |
373 } else if (isSimilarity) { | 374 } else if (isSimilarity) { |
(...skipping 20 matching lines...) Expand all Loading... | |
394 fragBuilder->codeAppend("}"); | 395 fragBuilder->codeAppend("}"); |
395 | 396 |
396 fragBuilder->codeAppend("vec2 Jdx = dFdx(st);"); | 397 fragBuilder->codeAppend("vec2 Jdx = dFdx(st);"); |
397 fragBuilder->codeAppend("vec2 Jdy = dFdy(st);"); | 398 fragBuilder->codeAppend("vec2 Jdy = dFdy(st);"); |
398 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,"); | 399 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,"); |
399 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);"); | 400 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);"); |
400 | 401 |
401 // this gives us a smooth step across approximately one fragment | 402 // this gives us a smooth step across approximately one fragment |
402 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);"); | 403 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);"); |
403 } | 404 } |
404 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, dista nce);"); | 405 // The smoothstep falloff compensates for the non-linear sRGB response c urve. If we are |
406 // doing gamma-correct rendering (to an sRGB or F16 buffer), then we act ually want distance | |
Brian Osman
2016/04/13 13:55:17
This comment is actually incorrect at the moment -
| |
407 // mapped linearly to coverage, so use a linear step: | |
408 if (srgbOutput) { | |
409 fragBuilder->codeAppend( | |
410 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1. 0);"); | |
411 } else { | |
412 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d istance);"); | |
413 } | |
405 | 414 |
406 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 415 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
407 } | 416 } |
408 | 417 |
409 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override { | 418 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override { |
410 SkASSERT(fTextureSizeUni.isValid()); | 419 SkASSERT(fTextureSizeUni.isValid()); |
411 | 420 |
412 GrTexture* texture = proc.texture(0); | 421 GrTexture* texture = proc.texture(0); |
413 if (texture->width() != fTextureSize.width() || | 422 if (texture->width() != fTextureSize.width() || |
414 texture->height() != fTextureSize.height()) { | 423 texture->height() != fTextureSize.height()) { |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ; | 812 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ; |
804 } | 813 } |
805 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 814 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
806 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 815 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
807 GrTest::TestMatrix(d->fRandom), | 816 GrTest::TestMatrix(d->fRandom), |
808 d->fTextures[texIdx], params, | 817 d->fTextures[texIdx], params, |
809 wa, | 818 wa, |
810 flags, | 819 flags, |
811 d->fRandom->nextBool()); | 820 d->fRandom->nextBool()); |
812 } | 821 } |
OLD | NEW |