@@ -30,11 +30,11 @@ if (!source) {
3030Creates a shader from source.
3131Shaders can be nested with one another.
3232
33- | Name | Type | Description |
34- | :---------| :----------------| :------------------------------|
35- | source | ` RuntimeEffect ` | Compiled shaders |
36- | uniforms | ` number ` | uniform values |
37- | children | ` Shader ` | Shaders to be used as uniform |
33+ | Name | Type | Description |
34+ | :---------| :--------------------------------------------------------------------- | :------------------------------|
35+ | source | ` RuntimeEffect ` | Compiled shaders |
36+ | uniforms | < code >{ [ name: string ] : number &# 124 ; Vector &# 124 ; number [ ] }</ code > | uniform values |
37+ | children | ` Shader ` | Shaders to be used as uniform |
3838
3939### Simple Shader
4040
@@ -63,25 +63,30 @@ const SimpleShader = () => {
6363
6464### Using Uniforms
6565
66+ Uniforms are variables used to parametrize shaders.
67+ The following uniform types are supported: ` float ` , ` float2 ` , ` float3 ` , ` float4 ` , ` float2x2 ` , ` float3x3 ` , ` float4x4 ` , ` int ` , ` int2 ` , ` int3 ` and, ` int4 ` .
68+
6669``` tsx twoslash
67- import {Canvas , Skia , Paint , Shader , Fill } from " @shopify/react-native-skia" ;
70+ import {Canvas , Skia , Paint , Shader , Fill , vec } from " @shopify/react-native-skia" ;
6871
6972const source = Skia .RuntimeEffect .Make (`
70- uniform float blue ;
73+ uniform vec2 c ;
7174uniform float r;
75+ uniform float blue;
7276
7377vec4 main(vec2 pos) {
7478 vec2 normalized = pos/vec2(2 * r);
75- return distance(pos, vec2(r)) > r ? vec4(1) : vec4(normalized.x, normalized.y , blue, 1);
79+ return distance(pos, c) > r ? vec4(1) : vec4(normalized, blue, 1);
7680} ` )! ;
7781
7882const UniformShader = () => {
79- const blue = 1.0 ;
8083 const r = 128 ;
84+ const c = vec (2 * r , r );
85+ const blue = 1.0 ;
8186 return (
8287 <Canvas style = { { flex: 1 }} >
8388 <Paint >
84- <Shader source = { source } uniforms = { [ blue , r ] } />
89+ <Shader source = { source } uniforms = { { c , r , blue } } />
8590 </Paint >
8691 <Fill />
8792 </Canvas >
@@ -122,4 +127,4 @@ const NestedShader = () => {
122127};
123128```
124129
125- ![ Simple Shader] ( assets/nested.png )
130+ ![ Simple Shader] ( assets/nested.png )
0 commit comments