Added slang shaders for additional compute samples
This commit is contained in:
parent
80ff4a41d2
commit
829118736f
8 changed files with 460 additions and 2 deletions
34
shaders/slang/computeshader/edgedetect.slang
Normal file
34
shaders/slang/computeshader/edgedetect.slang
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
import shared;
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(16, 16, 1)]
|
||||
void computeMain(uint3 GlobalInvocationID : SV_DispatchThreadID)
|
||||
{
|
||||
float imageData[9];
|
||||
// Fetch neighbouring texels
|
||||
int n = -1;
|
||||
for (int i=-1; i<2; ++i)
|
||||
{
|
||||
for(int j=-1; j<2; ++j)
|
||||
{
|
||||
n++;
|
||||
float3 rgb = inputImage[uint2(GlobalInvocationID.x + i, GlobalInvocationID.y + j)].rgb;
|
||||
imageData[n] = (rgb.r + rgb.g + rgb.b) / 3.0;
|
||||
}
|
||||
}
|
||||
|
||||
float kernel[9];
|
||||
kernel[0] = -1.0/8.0; kernel[1] = -1.0/8.0; kernel[2] = -1.0/8.0;
|
||||
kernel[3] = -1.0/8.0; kernel[4] = 1.0; kernel[5] = -1.0/8.0;
|
||||
kernel[6] = -1.0/8.0; kernel[7] = -1.0/8.0; kernel[8] = -1.0/8.0;
|
||||
|
||||
float4 res = float4(conv(kernel, imageData, 0.1, 0.0).xxx, 1.0);
|
||||
|
||||
resultImage[int2(GlobalInvocationID.xy)] = res;
|
||||
}
|
||||
34
shaders/slang/computeshader/emboss.slang
Normal file
34
shaders/slang/computeshader/emboss.slang
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
import shared;
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(16, 16, 1)]
|
||||
void computeMain(uint3 GlobalInvocationID : SV_DispatchThreadID)
|
||||
{
|
||||
float imageData[9];
|
||||
// Fetch neighbouring texels
|
||||
int n = -1;
|
||||
for (int i=-1; i<2; ++i)
|
||||
{
|
||||
for(int j=-1; j<2; ++j)
|
||||
{
|
||||
n++;
|
||||
float3 rgb = inputImage[uint2(GlobalInvocationID.x + i, GlobalInvocationID.y + j)].rgb;
|
||||
imageData[n] = (rgb.r + rgb.g + rgb.b) / 3.0;
|
||||
}
|
||||
}
|
||||
|
||||
float kernel[9];
|
||||
kernel[0] = -1.0; kernel[1] = 0.0; kernel[2] = 0.0;
|
||||
kernel[3] = 0.0; kernel[4] = -1.0; kernel[5] = 0.0;
|
||||
kernel[6] = 0.0; kernel[7] = 0.0; kernel[8] = 2.0;
|
||||
|
||||
float4 res = float4(conv(kernel, imageData, 1.0, 0.50).xxx, 1.0);
|
||||
|
||||
resultImage[int2(GlobalInvocationID.xy)] = res;
|
||||
}
|
||||
20
shaders/slang/computeshader/shared.slang
Normal file
20
shaders/slang/computeshader/shared.slang
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
module shared;
|
||||
|
||||
public Texture2D inputImage;
|
||||
public RWTexture2D<float4> resultImage;
|
||||
|
||||
public float conv(in float kernel[9], in float data[9], in float denom, in float offset)
|
||||
{
|
||||
float res = 0.0;
|
||||
for (int i=0; i<9; ++i)
|
||||
{
|
||||
res += kernel[i] * data[i];
|
||||
}
|
||||
return saturate(res/denom + offset);
|
||||
}
|
||||
43
shaders/slang/computeshader/sharpen.slang
Normal file
43
shaders/slang/computeshader/sharpen.slang
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
import shared;
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(16, 16, 1)]
|
||||
void computeMain(uint3 GlobalInvocationID : SV_DispatchThreadID)
|
||||
{
|
||||
float r[9];
|
||||
float g[9];
|
||||
float b[9];
|
||||
|
||||
// Fetch neighbouring texels
|
||||
int n = -1;
|
||||
for (int i=-1; i<2; ++i)
|
||||
{
|
||||
for(int j=-1; j<2; ++j)
|
||||
{
|
||||
n++;
|
||||
float3 rgb = inputImage[uint2(GlobalInvocationID.x + i, GlobalInvocationID.y + j)].rgb;
|
||||
r[n] = rgb.r;
|
||||
g[n] = rgb.g;
|
||||
b[n] = rgb.b;
|
||||
}
|
||||
}
|
||||
|
||||
float kernel[9];
|
||||
kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0;
|
||||
kernel[3] = -1.0; kernel[4] = 9.0; kernel[5] = -1.0;
|
||||
kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0;
|
||||
|
||||
float4 res = float4(
|
||||
conv(kernel, r, 1.0, 0.0),
|
||||
conv(kernel, g, 1.0, 0.0),
|
||||
conv(kernel, b, 1.0, 0.0),
|
||||
1.0);
|
||||
|
||||
resultImage[int2(GlobalInvocationID.xy)] = res;
|
||||
}
|
||||
41
shaders/slang/computeshader/texture.slang
Normal file
41
shaders/slang/computeshader/texture.slang
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float3 Pos;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
Sampler2D samplerColor;
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input)
|
||||
{
|
||||
VSOutput output;
|
||||
output.UV = input.UV;
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0)));
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VSOutput input)
|
||||
{
|
||||
return samplerColor.Sample(input.UV);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue