LightingShader and NormalSource comment and style fixes

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

Review-Url: https://codereview.chromium.org/2237963002
This commit is contained in:
dvonbeck 2016-08-11 14:17:59 -07:00 committed by Commit bot
parent 5bf60adaaf
commit ee92063f9e
6 changed files with 23 additions and 24 deletions

View File

@ -20,9 +20,6 @@ public:
/** Returns a shader that lights the shape, colored by the diffuseShader, using the /** Returns a shader that lights the shape, colored by the diffuseShader, using the
normals from normalSource, with the set of lights provided. normals from normalSource, with the set of lights provided.
It returns a shader with a reference count of 1.
The caller should decrement the shader's reference count when done with the shader.
It is an error for count to be < 2.
@param diffuseShader the shader that provides the colors. If nullptr, uses the paint's @param diffuseShader the shader that provides the colors. If nullptr, uses the paint's
color. color.
@param normalSource the source for the shape's normals. If nullptr, assumes straight @param normalSource the source for the shape's normals. If nullptr, assumes straight
@ -30,7 +27,7 @@ public:
@param lights the lights applied to the normals @param lights the lights applied to the normals
The lighting equation is currently: The lighting equation is currently:
result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientColor result = (LightColor * dot(Normal, LightDir) + AmbientColor) * DiffuseColor
*/ */
static sk_sp<SkShader> Make(sk_sp<SkShader> diffuseShader, sk_sp<SkNormalSource> normalSource, static sk_sp<SkShader> Make(sk_sp<SkShader> diffuseShader, sk_sp<SkNormalSource> normalSource,

View File

@ -245,6 +245,7 @@ private:
sk_sp<GrFragmentProcessor> SkNormalBevelSourceImpl::asFragmentProcessor( sk_sp<GrFragmentProcessor> SkNormalBevelSourceImpl::asFragmentProcessor(
const SkShader::AsFPArgs& args) const { const SkShader::AsFPArgs& args) const {
// This assumes a uniform scale. Anisotropic scaling might not be handled gracefully.
SkScalar maxScale = args.fViewMatrix->getMaxScale(); SkScalar maxScale = args.fViewMatrix->getMaxScale();
// Providing device-space width and height // Providing device-space width and height
@ -268,6 +269,7 @@ size_t SkNormalBevelSourceImpl::providerSize(const SkShader::ContextRec&) const
return sizeof(Provider); return sizeof(Provider);
} }
// TODO Implement feature for the CPU pipeline
void SkNormalBevelSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[], void SkNormalBevelSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[],
int count) const { int count) const {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -297,7 +299,7 @@ void SkNormalBevelSourceImpl::flatten(SkWriteBuffer& buf) const {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) { sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) {
/* TODO make sure this checks are tolerant enough to account for loss of conversion when GPUs /* TODO make sure these checks are tolerant enough to account for loss of conversion when GPUs
use 16-bit float types. We don't want to assume stuff is non-zero on the GPU and be wrong.*/ use 16-bit float types. We don't want to assume stuff is non-zero on the GPU and be wrong.*/
SkASSERT(width > 0.0f && !SkScalarNearlyZero(width)); SkASSERT(width > 0.0f && !SkScalarNearlyZero(width));
if (SkScalarNearlyZero(height)) { if (SkScalarNearlyZero(height)) {

View File

@ -57,9 +57,7 @@ public:
private: private:
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalFlatFP; } GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalFlatFP; }
bool onIsEqual(const GrFragmentProcessor& proc) const override { bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
return true;
}
}; };
sk_sp<GrFragmentProcessor> SkNormalFlatSourceImpl::asFragmentProcessor( sk_sp<GrFragmentProcessor> SkNormalFlatSourceImpl::asFragmentProcessor(

View File

@ -73,8 +73,7 @@ public:
fragBuilder->codeAppend( "}"); fragBuilder->codeAppend( "}");
} }
static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
GrProcessorKeyBuilder* b) {
b->add32(0x0); b->add32(0x0);
} }
@ -92,6 +91,7 @@ public:
} }
private: private:
// Upper-right 2x2 corner of the inverse of the CTM in column-major form
float fColumnMajorInvCTM22[4]; float fColumnMajorInvCTM22[4];
GrGLSLProgramDataManager::UniformHandle fXformUni; GrGLSLProgramDataManager::UniformHandle fXformUni;
}; };
@ -145,8 +145,8 @@ SkNormalMapSourceImpl::Provider::~Provider() {
fOverridePaint->~SkPaint(); fOverridePaint->~SkPaint();
} }
SkNormalSource::Provider* SkNormalMapSourceImpl::asProvider( SkNormalSource::Provider* SkNormalMapSourceImpl::asProvider(const SkShader::ContextRec &rec,
const SkShader::ContextRec &rec, void *storage) const { void *storage) const {
SkMatrix normTotalInv; SkMatrix normTotalInv;
if (!this->computeNormTotalInverse(rec, &normTotalInv)) { if (!this->computeNormTotalInverse(rec, &normTotalInv)) {
return nullptr; return nullptr;

View File

@ -68,7 +68,7 @@ public:
*/ */
static sk_sp<SkNormalSource> MakeFromNormalMap(sk_sp<SkShader> map, const SkMatrix& ctm); static sk_sp<SkNormalSource> MakeFromNormalMap(sk_sp<SkShader> map, const SkMatrix& ctm);
/** Returns a normal source that provides straight-up normals only (0, 0, 1). /** Returns a normal source that provides straight-up normals only <0, 0, 1>.
*/ */
static sk_sp<SkNormalSource> MakeFlat(); static sk_sp<SkNormalSource> MakeFlat();
@ -108,8 +108,10 @@ public:
*/ */
kRoundedIn kRoundedIn
}; };
/** Returns a normal source that generates a bevel for the given shape. UNIMPLEMENTED: Will
return straight-up normals only. /** Returns a normal source that generates a bevel for the shape being drawn. Currently this is
not implemented on CPU rendering. On GPU this currently only works for anti-aliased circles
and rectangles.
@param type the type of bevel to add. @param type the type of bevel to add.
@param width the width of the bevel, in source space. Must be positive. @param width the width of the bevel, in source space. Must be positive.

View File

@ -90,7 +90,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
const char* distanceVectorName = nullptr; const char* distanceVectorName = nullptr;
if (this->fPipeline.usesDistanceVectorField() && proc.implementsDistanceVector()) { if (this->fPipeline.usesDistanceVectorField() && proc.implementsDistanceVector()) {
distanceVectorName = fFS.distanceVectorName(); distanceVectorName = fFS.distanceVectorName();
fFS.codeAppend( "// Normalized vector to the closest geometric edge (in source space)\n"); fFS.codeAppend( "// Normalized vector to the closest geometric edge (in device space)\n");
fFS.codeAppend( "// Distance to the edge encoded in the z-component\n"); fFS.codeAppend( "// Distance to the edge encoded in the z-component\n");
fFS.codeAppendf("vec3 %s;", distanceVectorName); fFS.codeAppendf("vec3 %s;", distanceVectorName);
} }