forked from shader-slang/slang-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_demo.js
33 lines (25 loc) · 889 Bytes
/
image_demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const imageDemoCode =
`
import playground;
//! @myImage: URL("static/jeep.jpg")
Texture2D<float4> myImage;
float4 imageMain(uint2 dispatchThreadID, int2 screenSize)
{
float2 size = float2(screenSize.x, screenSize.y);
float2 center = size / 2.0;
float2 pos = float2(dispatchThreadID.xy);
float stripSize = screenSize.x / 40;
float dist = distance(pos, center) + getTime() * 3;
float strip = dist / stripSize % 2.0;
uint imageW;
uint imageH;
myImage.GetDimensions(imageW, imageH);
uint2 scaled = (uint2)floor(float2(dispatchThreadID.xy) / float2(screenSize) * float2(imageW, imageH));
uint2 flipped = uint2(scaled.x, imageH - scaled.y);
float4 imageColor = myImage[flipped] * 0.8;
if (strip < 1.0f)
return imageColor;
else
return float4(0.8f - imageColor.x, 0.8f - imageColor.y, 0.8f - imageColor.z, 1.0f);
}
`;