8 layout(color) uniform vec3 surfaceColor;
9 uniform int doLinearLighting;
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));
19 vec3 n = normal_at(p);
20 vec3 l = normalize(vec3(-1, -1, 0.5));
21 vec3 C = surfaceColor;
23 if (doLinearLighting != 0) { C = toLinearSrgb(C); }
24 C *= saturate(dot(n, l));
25 if (doLinearLighting != 0) { C = fromLinearSrgb(C); }
30 builder.uniform("surfaceColor") =
SkV3{0.8, 0.8, 0.8};
35 builder.uniform(
"doLinearLighting") = 0;
41 builder.uniform(
"doLinearLighting") = 1;
REG_FIDDLE(SkSL_LinearSRGB, 256, 128, false, 0)
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