Skip to content

Commit

Permalink
Clarify normalized coordinates in SKGL
Browse files Browse the repository at this point in the history
fixes #341
  • Loading branch information
wcandillon committed Apr 4, 2022
1 parent 4e886ba commit c0f8548
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/docs/shaders/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {Skia} from "@shopify/react-native-skia";

const source = Skia.RuntimeEffect.Make(`
vec4 main(vec2 pos) {
vec2 normalized = pos/vec2(256.0, 256.0);
// The canvas is 256x256
vec2 canvas = vec2(256);
// normalized x,y values go from 0 to 1
vec2 normalized = pos/canvas;
return vec4(normalized.x, normalized.y, 0.5, 1);
}`);

Expand All @@ -43,6 +46,7 @@ import {Skia, Canvas, Paint, Shader, Fill} from "@shopify/react-native-skia";

const source = Skia.RuntimeEffect.Make(`
vec4 main(vec2 pos) {
// normalized x,y values go from 0 to 1, the canvas is 256x256
vec2 normalized = pos/vec2(256);
return vec4(normalized.x, normalized.y, 0.5, 1);
}`)!;
Expand Down

0 comments on commit c0f8548

Please sign in to comment.