46 ZValue(
float z) : fZ(z) {}
47 operator float()
const {
return fZ; }
60 float val()
const {
return fData.fZ; }
96 float fFalloffExponent;
97 float fCosCutoffAngle;
100 return {Type::kPoint,
111 return {Type::kDistant,
122 float falloffExponent,
float cosCutoffAngle) {
150 static Material Diffuse(
float k,
float surfaceDepth) {
154 static Material Specular(
float k,
float shininess,
float surfaceDepth) {
164 , fMaterial(material) {}
196 return requiredInput;
212 builder.child(
"alphaMap") = std::move(alphaMap);
214 builder.uniform(
"negSurfaceDepth") = -surfaceDepth.
val();
220 Light::Type lightType,
226 float falloffExponent,
227 float cosCutoffAngle,
228 Material::Type matType,
237 builder.child(
"normalMap") = std::move(normalMap);
239 builder.uniform(
"materialAndLightType") =
242 matType == Material::Type::kDiffuse ? 0.f : 1.f,
243 lightType == Light::Type::kPoint ?
244 0.f : (lightType == Light::Type::kDistant ? -1.f : 1.f)};
245 builder.uniform(
"lightPosAndSpotFalloff") =
246 SkV4{locationXY.
x(), locationXY.
y(), locationZ.
val(), falloffExponent};
251 SkV3 dir{directionXY.x(), directionXY.y(), directionZ.
val()};
252 float invDirLen =
dir.length();
253 invDirLen = invDirLen ? 1.0f / invDirLen : 0.f;
254 builder.uniform(
"lightDirAndSpotCutoff") =
255 SkV4{invDirLen*
dir.x, invDirLen*
dir.y, invDirLen*
dir.z, cosCutoffAngle};
271 const float colorScale = k / 255.f;
280 const Material& material,
285 if (!
SkIsFinite(material.fK, material.fShininess, ZValue(material.fSurfaceDepth)) ||
292 !
SkIsFinite(light.fFalloffExponent, light.fCosCutoffAngle,
293 ZValue(light.fLocationZ), ZValue(light.fDirectionZ)) ||
294 light.fCosCutoffAngle < -1.f || light.fCosCutoffAngle > 1.f) {
305 new SkLightingImageFilter(light, material, std::move(filter)));
317 return make_lighting(Light::Distant(lightColor, direction),
318 Material::Diffuse(kd, surfaceScale),
319 std::move(input), cropRect);
325 return make_lighting(
Light::Point(lightColor, location),
326 Material::Diffuse(kd, surfaceScale),
327 std::move(input), cropRect);
336 return make_lighting(Light::Spot(lightColor, location,
dir, falloffExponent, cosCutoffAngle),
337 Material::Diffuse(kd, surfaceScale),
338 std::move(input), cropRect);
344 return make_lighting(Light::Distant(lightColor, direction),
345 Material::Specular(ks, shininess, surfaceScale),
346 std::move(input), cropRect);
352 return make_lighting(
Light::Point(lightColor, location),
353 Material::Specular(ks, shininess, surfaceScale),
354 std::move(input), cropRect);
363 return make_lighting(Light::Spot(lightColor, location,
dir, falloffExponent, cosCutoffAngle),
364 Material::Specular(ks, shininess, surfaceScale),
365 std::move(input), cropRect);
372 SkLightingImageFilter::LegacyDiffuseCreateProc);
374 SkLightingImageFilter::LegacySpecularCreateProc);
383 light.fType =
buffer.read32LE(Light::Type::kLast);
384 light.fLightColor =
buffer.readColor();
387 buffer.readPoint3(&lightPos);
391 buffer.readPoint3(&lightDir);
395 light.fFalloffExponent =
buffer.readScalar();
396 light.fCosCutoffAngle =
buffer.readScalar();
399 material.fType =
buffer.read32LE(Material::Type::kLast);
401 material.fK =
buffer.readScalar();
402 material.fShininess =
buffer.readScalar();
408 return make_lighting(light, material,
common.getInput(0),
common.cropRect());
413 Light::Type lightType =
buffer.read32LE(Light::Type::kLast);
425 case Light::Type::kDistant: {
427 return Light::Distant(lightColor,
dir);
429 case Light::Type::kPoint: {
433 case Light::Type::kSpot: {
436 float falloffExponent =
buffer.readScalar();
437 float cosOuterConeAngle =
buffer.readScalar();
443 return Light::Spot(lightColor, loc,
target - loc, falloffExponent, cosOuterConeAngle);
453 Light light = LegacyDeserializeLight(
buffer);
457 float surfaceScale =
buffer.readScalar();
458 float kd =
buffer.readScalar();
459 Material material = Material::Diffuse(kd, surfaceScale);
461 return make_lighting(light, material,
common.getInput(0),
common.cropRect());
467 Light light = LegacyDeserializeLight(
buffer);
471 float surfaceScale =
buffer.readScalar();
472 float ks =
buffer.readScalar();
473 float shininess =
buffer.readScalar();
474 Material material = Material::Specular(ks, shininess, surfaceScale);
476 return make_lighting(light, material,
common.getInput(0),
common.cropRect());
483 buffer.writeInt((
int) fLight.fType);
484 buffer.writeColor(fLight.fLightColor);
487 buffer.writeScalar(ZValue(fLight.fLocationZ));
491 buffer.writeScalar(ZValue(fLight.fDirectionZ));
493 buffer.writeScalar(fLight.fFalloffExponent);
494 buffer.writeScalar(fLight.fCosCutoffAngle);
497 buffer.writeInt((
int) fMaterial.fType);
498 buffer.writeScalar(ZValue(fMaterial.fSurfaceDepth));
499 buffer.writeScalar(fMaterial.fK);
500 buffer.writeScalar(fMaterial.fShininess);
542 auto edgeClamp = [](
int actualEdgeValue,
int requestedEdgeValue,
int outputEdge) {
543 return actualEdgeValue == outputEdge ? outputEdge : requestedEdgeValue;
548 edgeClamp(inputRect.left(), requiredInput.
left(), clampTo.left()),
549 edgeClamp(inputRect.top(), requiredInput.
top(), clampTo.top()),
550 edgeClamp(inputRect.right(), requiredInput.
right(), clampTo.right()),
551 edgeClamp(inputRect.bottom(), requiredInput.
bottom(), clampTo.bottom())});
555 builder.add(childOutput, clampRect, ShaderFlags::kSampledRepeatedly);
564 return make_lighting_shader(std::move(
normals),
572 fLight.fFalloffExponent,
573 fLight.fCosCutoffAngle,
578 fMaterial.fShininess);
587 return this->getChildInputLayerBounds(0, mapping, requiredInput, contentBounds);
590std::optional<skif::LayerSpace<SkIRect>> SkLightingImageFilter::onGetOutputLayerBounds(
599SkRect SkLightingImageFilter::computeFastBounds(
const SkRect&
src)
const {
static SkM44 normals(SkM44 m)
#define SkColorGetR(color)
#define SkColorGetG(color)
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#define SkColorGetB(color)
#define SK_FLATTENABLE_HOOKS(type)
#define SK_REGISTER_FLATTENABLE(type)
static bool SkIsFinite(T x, Pack... values)
#define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount)
void SkRegisterLightingImageFilterFlattenables()
sk_sp< T > sk_ref_sp(T *obj)
#define SkDegreesToRadians(degrees)
#define SkScalarAve(a, b)
#define SkScalarCos(radians)
static void Register(const char name[], Factory)
virtual skif::LayerSpace< SkIRect > onGetInputLayerBounds(const skif::Mapping &mapping, const skif::LayerSpace< SkIRect > &desiredOutput, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const =0
virtual bool onAffectsTransparentBlack() const
void flatten(SkWriteBuffer &) const override
virtual std::optional< skif::LayerSpace< SkIRect > > onGetOutputLayerBounds(const skif::Mapping &mapping, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const =0
virtual skif::FilterResult onFilterImage(const skif::Context &context) const =0
virtual SkRect computeFastBounds(const SkRect &bounds) const
static sk_sp< SkImageFilter > PointLitDiffuse(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitSpecular(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitDiffuse(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Crop(const SkRect &rect, SkTileMode tileMode, sk_sp< SkImageFilter > input)
static sk_sp< SkImageFilter > PointLitSpecular(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitDiffuse(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitSpecular(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static SkRect MakeLargeS32()
const LayerSpace< SkIRect > & desiredOutput() const
Context withNewDesiredOutput(const LayerSpace< SkIRect > &desiredOutput) const
const Mapping & mapping() const
LayerSpace< SkIRect > layerBounds() const
void outset(const LayerSpace< SkISize > &delta)
bool contains(const LayerSpace< SkIRect > &r) const
static LayerSpace< ZValue > Map(const Mapping &mapping, ParameterSpace< ZValue > z)
LayerSpace< T > paramToLayer(const ParameterSpace< T > ¶mGeometry) const
@ kNormal
Default priority level.
const SkRuntimeEffect * GetKnownRuntimeEffect(StableKey stableKey)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
@ kPoint
Draws a point at each input vertex.
static SkRect Make(const SkISize &size)
SkRect makeInset(float dx, float dy) const