Skip to content

Commit

Permalink
Merge pull request #46 from shader-slang/lsp
Browse files Browse the repository at this point in the history
Update demo code.
  • Loading branch information
csyonghe authored Nov 9, 2024
2 parents b4f0d03 + 94ed295 commit 9ebf03d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
10 changes: 6 additions & 4 deletions demos/generic.slang
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ void printMain()
// all vector<float ,N> types conform to IMyHashable and thus valid to use in the call.
printHash(v);

// The following line will result in a compile error because `int` does not
// conform to `IMyHashable`.
// printHash(1);
// The following lines will result in a compile error because `NonHashable` does not
// conform to `IMyHashable`:
//
// struct NonHashable{int data;}
// NonHashable obj = {0};
// printHash(obj);
}

21 changes: 4 additions & 17 deletions demos/image-from-url.slang
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,16 @@ 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 scaled = (uint2)floor(float2(dispatchThreadID.xy) / screenSize.y * 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);
float4 imageColor = myImage[flipped];
return imageColor;
}

0 comments on commit 9ebf03d

Please sign in to comment.