4 {
6
8 layout(color) uniform vec3 surfaceColor;
9 uniform int doLinearLighting;
10
11 vec3 normal_at(vec2 p) {
12 p = (p / 128) * 2 - 1;
13 float len2 = dot(p, p);
14 vec3 n = (len2 > 1) ? vec3(0, 0, 1) : vec3(p, sqrt(1 - len2));
15 return normalize(n);
16 }
17
18 vec4 main(vec2 p) {
19 vec3 n = normal_at(p);
20 vec3 l = normalize(vec3(-1, -1, 0.5));
21 vec3 C = surfaceColor;
22
23 if (doLinearLighting != 0) { C = toLinearSrgb(C); }
24 C *= saturate(dot(n, l));
25 if (doLinearLighting != 0) { C = fromLinearSrgb(C); }
26
27 return C.rgb1;
30 builder.uniform("surfaceColor") =
SkV3{0.8, 0.8, 0.8};
32
33
34
35 builder.uniform(
"doLinearLighting") = 0;
38
39
40
41 builder.uniform(
"doLinearLighting") = 1;
45}}
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
void drawRect(const SkRect &rect, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
static Result MakeForShader(SkString sksl, const Options &)
sk_sp< SkRuntimeEffect > effect