Migrating to Slang from GLSL¶
Overview¶
This guide provides a reference for migrating GLSL shaders to Slang.
Type and Syntax Reference¶
When converting GLSL shaders to Slang, you’ll need to translate GLSL types and syntax to their Slang equivalents.
Scalar Types¶
GLSL Type |
Slang Type |
Description |
---|---|---|
|
|
32-bit floating point |
|
|
16-bit floating point |
|
|
32-bit signed integer |
|
|
32-bit unsigned integer |
|
|
Boolean value |
|
|
64-bit floating point |
|
|
8-bit signed integer |
|
|
8-bit unsigned integer |
|
|
16-bit signed integer |
|
|
16-bit unsigned integer |
|
|
64-bit signed integer |
|
|
64-bit unsigned integer |
Vector Types¶
GLSL Type |
Slang Type |
Description |
---|---|---|
|
|
2-component float vector |
|
|
3-component float vector |
|
|
4-component float vector |
|
|
2-component half-precision float vector |
|
|
3-component half-precision float vector |
|
|
4-component half-precision float vector |
|
|
2-component int vector |
|
|
3-component int vector |
|
|
4-component int vector |
|
|
2-component uint vector |
|
|
3-component uint vector |
|
|
4-component uint vector |
|
|
2-component boolean vector |
|
|
3-component boolean vector |
|
|
4-component boolean vector |
|
|
2-component double vector |
|
|
3-component double vector |
|
|
4-component double vector |
Matrix Types¶
GLSL Type |
Slang Type |
Description |
---|---|---|
|
|
2×2 float matrix |
|
|
3×3 float matrix |
|
|
4×4 float matrix |
|
|
2×3 float matrix |
|
|
2×4 float matrix |
|
|
3×2 float matrix |
|
|
3×4 float matrix |
|
|
4×2 float matrix |
|
|
4×3 float matrix |
|
|
2×2 half-precision float matrix |
|
|
3×3 half-precision float matrix |
|
|
4×4 half-precision float matrix |
|
|
2×3 half-precision float matrix |
|
|
2×4 half-precision float matrix |
|
|
3×2 half-precision float matrix |
|
|
3×4 half-precision float matrix |
|
|
4×2 half-precision float matrix |
|
|
4×3 half-precision float matrix |
Vector/Matrix Construction¶
GLSL:
vec4 color = vec4(1.0, 0.5, 0.2, 1.0);
mat4 transform = mat4(
vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 1.0, 0.0),
vec4(0.0, 0.0, 0.0, 1.0)
);
Slang:
float4 color = float4(1.0, 0.5, 0.2, 1.0);
float4x4 transform = float4x4(
float4(1.0, 0.0, 0.0, 0.0),
float4(0.0, 1.0, 0.0, 0.0),
float4(0.0, 0.0, 1.0, 0.0),
float4(0.0, 0.0, 0.0, 1.0)
);
Matrix Operations¶
GLSL:
mat4 a, b, c;
vec4 v;
// Matrix multiplication
c = a * b;
// Vector transformation (vector is treated as a row vector)
vec4 transformed = v * a; // row vector * matrix
Slang:
float4x4 a, b, c;
float4 v;
// Matrix multiplication
c = mul(a, b);
// Vector transformation (vector is treated as a column vector)
float4 transformed = mul(a, v); // matrix * column vector
Note: Slang uses the mul()
function for matrix multiplication rather than the *
operator. Also, vectors are treated as column vectors in Slang, while they’re treated as row vectors in GLSL, so the order of arguments is inverted.
Shader Inputs and Outputs¶
GLSL and Slang handle shader inputs and outputs differently. Here’s a fragment/pixel shader example:
GLSL:
// Fragment shader input
in vec2 texCoord;
// Fragment shader output
layout(location = 0) out vec4 fragColor;
void main() {
// Use texCoord to sample a texture
fragColor = vec4(texCoord, 0.0, 1.0);
}
Slang (Method 1 - Using structures):
// Input structure
struct PSInput {
float2 texCoord : TEXCOORD0;
};
// Output structure
struct PSOutput {
float4 color : SV_Target0;
};
// Pixel shader using structures
[shader("pixel")]
PSOutput main(PSInput input) {
PSOutput output;
// Use input.texCoord to sample a texture
output.color = float4(input.texCoord, 0.0, 1.0);
return output;
}
Slang (Method 2 - Direct parameters):
// Pixel shader using direct parameters
[shader("pixel")]
float4 main(float2 texCoord : TEXCOORD0) : SV_Target0 {
// Use texCoord to sample a texture
return float4(texCoord, 0.0, 1.0);
}
Both Slang methods produce the same result, but Method 1 is more organized for complex shaders with many inputs and outputs, while Method 2 is more concise for simple shaders.
Built-in Variables¶
GLSL provides built-in variables that can be accessed directly in shaders, while Slang requires these variables to be explicitly declared as inputs or outputs in shader entry point functions. Unlike regular shader inputs and outputs which you define yourself, built-in variables provide access to system values like vertex IDs, screen positions, etc.
Example: Minimal Vertex Shader with Built-in Variables¶
Here’s a simplified example showing how built-in variables work in both GLSL and Slang:
GLSL:
#version 460
// No need to declare gl_VertexID - it's implicitly available
void main() {
// Access input built-in variable directly
int vertID = gl_VertexID;
// Set position based on vertex ID
float x = (vertID == 0) ? -0.5 : ((vertID == 1) ? 0.5 : 0.0);
float y = (vertID == 2) ? 0.5 : -0.5;
// Set output built-in variable directly
gl_Position = vec4(x, y, 0.0, 1.0);
}
Slang:
// Slang: Built-in variables must be explicitly declared in the function signature
[shader("vertex")]
float4 main(uint vertexID : SV_VertexID) : SV_Position {
// Input built-in is passed as a function parameter
// Calculate position based on vertex ID
float x = (vertexID == 0) ? -0.5 : ((vertexID == 1) ? 0.5 : 0.0);
float y = (vertexID == 2) ? 0.5 : -0.5;
// Output built-in is returned from the function
return float4(x, y, 0.0, 1.0);
}
Notice the key differences:
In GLSL,
gl_VertexID
(input) andgl_Position
(output) are accessed directly as global variablesIn Slang, the input
SV_VertexID
is a function parameter, and the outputSV_Position
is the function return value
For more complex shaders, you can use structures for inputs and outputs as shown in the previous section.
Built-in Variables Reference¶
The following table maps GLSL built-in variables to their corresponding Slang system value semantics across standard shader stages. In GLSL, these variables are accessed directly as globals, while in Slang they must be declared explicitly in function signatures with appropriate semantic annotations.
GLSL Built-in |
Slang System Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ray Tracing Built-ins¶
Ray tracing built-ins in Slang are accessed through function calls rather than system value semantics. The following table maps GLSL ray tracing built-ins to their corresponding Slang functions:
GLSL Built-in |
Slang Function |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Built-in Functions and Operators¶
When porting GLSL shaders to Slang, most common mathematical functions (sin, cos, tan, pow, sqrt, abs, etc.) share identical names in both languages. However, there are several important differences to be aware of, listed below:
Key Function Differences¶
GLSL |
Slang |
Description |
---|---|---|
|
|
Linear interpolation |
|
|
Fractional part of x |
|
|
Inverse square root (1/sqrt) |
|
|
Arc tangent of y/x |
|
|
Derivative with respect to screen-space x |
|
|
Derivative with respect to screen-space y |
|
|
Matrix multiplication |
|
|
Vector-matrix multiplication |
Resource Handling¶
This section covers how to convert GLSL resource declarations to Slang, including different buffer types, textures, and specialized resources.
Resource Binding Models¶
Slang supports three different binding syntax options to accommodate both HLSL-style and GLSL-style resource declarations:
GLSL Binding Model¶
// GLSL uses binding and set numbers
layout(binding = 0, set = 0) uniform UniformBufferA { ... };
Slang Binding Models¶
Option 1: HLSL Register Syntax¶
// Using register semantics with space (equivalent to set)
ConstantBuffer<UniformBufferA> bufferA : register(b0, space0);
Option 2: GLSL-style Layout Syntax¶
// Using GLSL-style binding with [[vk::binding(binding, set)]]
[[vk::binding(0, 0)]]
ConstantBuffer<UniformBufferA> bufferA;
Option 3: Direct GLSL Layout Syntax¶
// Using layout syntax identical to GLSL
layout(binding = 0, set = 0) ConstantBuffer<UniformBufferA> bufferA;
All binding syntax options work the same way for all resource types (ConstantBuffer, Texture2D, RWStructuredBuffer, etc.). The GLSL-style options (2 and 3) can be particularly helpful when porting GLSL shaders without changing the binding model.
Buffer Types¶
Resource Type |
GLSL |
Slang |
Description |
---|---|---|---|
Uniform Buffer |
|
|
Read-only constant data |
Storage Buffer |
|
|
Read-write structured data |
Read-only Storage Buffer |
|
|
Read-only structured data |
Example in GLSL:
#version 460
layout(std140, binding = 0) uniform Params {
float scale;
};
struct Data {
vec3 value;
};
layout(std430, binding = 1) buffer Storage {
Data data;
};
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
float s = scale;
data.value *= s;
}
Example in Slang:
struct Params {
float scale;
};
layout(binding = 0) ConstantBuffer<Params> params;
struct Data {
float3 value;
};
layout(binding = 1) RWStructuredBuffer<Data> data;
[shader("compute")]
[numthreads(1, 1, 1)]
void main() {
float s = params.scale;
data[0].value *= s;
}
Key differences to note:
Slang uses the
RW
prefix to distinguish read-write resources from read-only onesIn Slang, structured buffers must be indexed even for a single element (e.g.,
data[0].value
)In Slang, all buffer members are accessed through the buffer variable name (e.g.,
params.scale
,data[0].value
)
Texture Resources¶
This section covers the declaration and usage of texture resources in Slang compared to GLSL.
Combined Texture Samplers¶
GLSL:
// Texture declaration
layout(binding = 0) uniform sampler2D inputTexture;
layout(location = 0) out vec4 fragColor;
void main() {
// Simple texture sampling and copy to output
vec2 uv = gl_FragCoord.xy / vec2(1280.0, 720.0);
fragColor = texture(inputTexture, uv);
}
Slang:
// Texture declaration
layout(binding = 0) Sampler2D inputTexture;
[shader("pixel")]
float4 main(float4 position : SV_Position) : SV_Target0 {
// Simple texture sampling and return
float2 uv = position.xy / float2(1280.0, 720.0);
return inputTexture.Sample(uv);
}
Texture Type Mapping:
GLSL Type |
Slang Type |
Description |
---|---|---|
|
|
1D texture with built-in sampler |
|
|
2D texture with built-in sampler |
|
|
3D texture with built-in sampler |
|
|
Cube texture with built-in sampler |
|
|
2D texture array with built-in sampler |
|
|
Cube texture array with built-in sampler |
|
|
Shadow sampler for depth comparisons |
|
|
Integer 2D texture with built-in sampler |
|
|
Unsigned integer 2D texture with built-in sampler |
Texture Function Mapping (Combined Sampler Approach):
GLSL Function |
Slang Function |
Description |
---|---|---|
|
|
Basic texture sampling |
|
|
Sample with specific mip level |
|
|
Sample with explicit derivatives |
|
|
Sample with offset |
|
|
Direct texel fetch |
|
|
Get texture dimensions |
|
|
Gather four texels |
|
|
Gather with offset |
Separate Texture Samplers¶
GLSL:
// Declare texture and sampler separately
uniform texture2D colorTexture;
uniform sampler texSampler;
void main() {
vec2 uv = gl_FragCoord.xy / vec2(1280.0, 720.0);
// Combine texture and sampler for sampling
vec4 color = texture(sampler2D(colorTexture, texSampler), uv);
fragColor = color;
}
Slang:
// Declare texture and sampler state separately
Texture2D colorTexture;
SamplerState texSampler;
[shader("pixel")]
float4 main(float4 position : SV_Position) : SV_Target {
float2 uv = position.xy / float2(1280.0, 720.0);
// Pass sampler state explicitly to the Sample method
return colorTexture.Sample(texSampler, uv);
}
Image Resources¶
This section covers the declaration and usage of image resources in Slang compared to GLSL, including how to perform image load/store operations.
GLSL:
// Image declaration
layout(binding = 4, rgba8) uniform image2D outputImage;
layout(local_size_x = 8, local_size_y = 8) in;
void main() {
// Get the pixel coordinate for this thread
ivec2 pixelCoord = ivec2(gl_GlobalInvocationID.xy);
// Simple image store operation (set to red color)
imageStore(outputImage, pixelCoord, vec4(1.0, 0.0, 0.0, 1.0));
}
Slang:
// Image declaration
layout(binding = 4) RWTexture2D<float4> outputImage;
[shader("compute")]
[numthreads(8, 8, 1)]
void main(uint3 dispatchThreadID : SV_DispatchThreadID) {
// Get the pixel coordinate for this thread
int2 pixelCoord = int2(dispatchThreadID.xy);
// Simple image store operation (set to red color)
outputImage[pixelCoord] = float4(1.0, 0.0, 0.0, 1.0);
}
Image Type Mapping:
GLSL Type |
Slang Type |
Description |
---|---|---|
|
|
1D read-write image |
|
|
2D read-write image |
|
|
3D read-write image |
|
|
Cube read-write image |
|
|
2D array read-write image |
|
|
Integer 2D read-write image |
|
|
Unsigned integer 2D read-write image |
Image Function Mapping:
GLSL Function |
Slang Function |
Description |
---|---|---|
|
|
Read from image |
|
|
Write to image |
|
|
Get image dimensions |
Shader Entry Point Syntax¶
GLSL and Slang use fundamentally different approaches for shader entry points. While GLSL always uses a void main()
function with implicit inputs/outputs through global variables, Slang uses explicitly typed entry points with decorators and function parameters/return values.
This section provides a general overview of the entry point pattern differences. Detailed shader stage-specific conversion information will be covered in a later section.
Core Entry Point Pattern¶
GLSL Pattern:
#version 460
// Global inputs (in) and outputs (out)
in type input_name;
out type output_name;
// Global uniforms and resources
uniform type resource_name;
// Always uses void main() with no parameters
void main() {
// Access inputs and resources directly
// Write to outputs directly
}
Slang Pattern:
// Shader type specified by decorator
[shader("stage_type")]
// Explicit inputs as parameters, outputs as return value
return_type main(parameter_type param : semantic) : return_semantic {
// Access inputs through parameters
// Return output value explicitly
}
Shader Stage Decorators¶
Shader Stage |
Slang Decoration |
---|---|
Vertex |
|
Hull/Tessellation Control |
|
Domain/Tessellation Evaluation |
|
Geometry |
|
Pixel/Fragment |
|
Compute |
|
Amplification/Task |
|
Mesh |
|
Ray Generation |
|
Closest Hit |
|
Miss |
|
Any Hit |
|
Intersection |
|
Callable |
|
Note: For detailed conversions of specific shader stages including tessellation, geometry, mesh, and ray tracing shaders, see the “Shader Stage-Specific Conversions” section later in this guide.
Shader Stage-Specific Conversions¶
This section provides mappings for each shader stage from GLSL to Slang, focusing on essential declarations, attributes, and stage-specific functionality.
Vertex Shaders¶
Core Declaration Mapping¶
GLSL:
// No special attributes required
void main() {
gl_Position = /* output position calculation */;
}
Slang:
[shader("vertex")]
float4 main(float3 position : POSITION) : SV_Position {
return /* output position calculation */;
}
Key Conversion Points¶
Declaration: Add
[shader("vertex")]
decoration
Fragment/Pixel Shaders¶
Core Declaration Mapping¶
GLSL:
// Early depth testing (optional)
layout(early_fragment_tests) in;
// Output color target(s)
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = /* color calculation */;
}
Slang:
// Early depth testing (optional)
[earlydepthstencil]
[shader("pixel")]
float4 main(float4 position : SV_Position) : SV_Target0 {
return /* color calculation */;
}
Key Conversion Points¶
Declaration: Add
[shader("pixel")]
decorationEarly Z testing: Use
[earlydepthstencil]
attributeMultiple outputs: Use a struct with multiple fields with
SV_Target0/1/2
semantics
Compute Shaders¶
Core Declaration Mapping¶
GLSL:
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main() {
// Access thread ID via gl_GlobalInvocationID
}
Slang:
[shader("compute")]
[numthreads(8, 8, 1)]
void main(uint3 dispatchThreadID : SV_DispatchThreadID) {
// Access thread ID via dispatchThreadID parameter
}
Key Conversion Points¶
Thread group size: Replace
layout(local_size_x=X...) in
with[numthreads(X,Y,Z)]
Shared memory: Replace
shared
withgroupshared
Barriers: Replace
barrier()
withGroupMemoryBarrierWithGroupSync()
Hull Shader (Tessellation Control)¶
Core Declaration Mapping¶
GLSL:
// Patch size specification
layout(vertices = 3) out;
void main() {
// Set tessellation levels and compute control points
gl_TessLevelOuter[0] = 1.0;
// ...
}
Slang:
// Hull shader requires multiple attributes and a separate patch constant function
[shader("hull")]
[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("PatchConstantFunction")]
ControlPoint main(InputPatch<Vertex, 3> patch, uint cpID : SV_OutputControlPointID) {
// Compute control points
}
// Separate function for tessellation factors
struct PatchTessFactors {
float4 tessFactor : SV_TessFactor;
float2 insideTessFactor : SV_InsideTessFactor;
};
PatchTessFactors PatchConstantFunction(InputPatch<Vertex, 3> patch) {
// Set tessellation levels
}
Key Attribute Mappings¶
GLSL |
Slang |
Description |
---|---|---|
|
|
Number of control points |
Implicit |
|
Patch domain type |
Implicit |
|
Tessellation pattern |
Implicit |
|
Output topology |
N/A |
|
Function for tessellation factors |
Key Conversion Points¶
Split structure: Separate the per-control-point calculations from patch-constant calculations
Explicit domain/partitioning: Add required attributes that are implicit in GLSL
Patch constants: Create separate function decorated with
[patchconstantfunc]
Input/Output patches: Use
InputPatch<T, N>
and return individual control points
Domain Shader (Tessellation Evaluation)¶
Core Declaration Mapping¶
GLSL:
// Domain and tessellation mode
layout(triangles, equal_spacing, ccw) in;
void main() {
// Use gl_TessCoord to interpolate
gl_Position = /* position calculation using gl_TessCoord */;
}
Slang:
[shader("domain")]
[domain("tri")]
float4 main(
PatchTessFactors patchConstants,
float3 tessCoord : SV_DomainLocation,
const OutputPatch<ControlPoint, 3> patch
) : SV_Position {
// Use tessCoord to interpolate
return /* position calculation using tessCoord */;
}
Key Attribute Mappings¶
GLSL |
Slang |
Description |
---|---|---|
|
|
Patch domain type |
|
Set in hull shader |
Tessellation spacing |
|
Set in hull shader |
Winding order |
Key Conversion Points¶
Domain specification: Use
[domain("tri/quad/isoline")]
attributeTessellation coordinates: Access via
SV_DomainLocation
parameterControl points: Access via
OutputPatch<T, N>
parameterPatch constants: Access via a patch constant struct parameter
Geometry Shader¶
Core Declaration Mapping¶
GLSL:
// Set primitive types and max vertices
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main() {
// Process and emit vertices
EmitVertex();
EndPrimitive();
}
Slang:
[shader("geometry")]
[maxvertexcount(3)]
void main(
triangle VSOutput input[3],
inout TriangleStream<GSOutput> outputStream
) {
// Process and append vertices
outputStream.Append(vertex);
outputStream.RestartStrip();
}
Key Attribute Mappings¶
GLSL |
Slang |
Description |
---|---|---|
|
Input parameter prefix ( |
Input primitive type |
|
Output stream type |
Output primitive type |
|
|
Maximum output vertices |
Key Conversion Points¶
Declaration: Add
[shader("geometry")]
and[maxvertexcount(N)]
Input primitives: Use primitive type prefix on input array parameter
Output primitives: Use appropriate stream type (
PointStream
,LineStream
,TriangleStream
)Vertex emission: Replace
EmitVertex()
withoutputStream.Append(v)
End primitive: Replace
EndPrimitive()
withoutputStream.RestartStrip()
Amplification Shader (Task Shader)¶
Core Declaration Mapping¶
GLSL:
#extension GL_EXT_mesh_shader : require
layout(local_size_x = 32) in;
taskPayloadSharedEXT TaskData payload;
void main() {
// Set mesh shader dispatch count
EmitMeshTasksEXT(taskCount, 1, 1, payload);
}
Slang:
[shader("amplification")]
[numthreads(32, 1, 1)]
void main(
uint gtid : SV_GroupThreadID,
out payload TaskData payload
) {
// Set mesh shader dispatch count
DispatchMesh(taskCount, 1, 1, payload);
}
Key Conversion Points¶
Declaration: Add
[shader("amplification")]
and[numthreads(X,Y,Z)]
decorationsPayload: Replace
taskPayloadSharedEXT
with output parameterDispatch: Replace
EmitMeshTasksEXT
withDispatchMesh
Thread IDs: Access thread IDs through function parameters with semantics
Mesh Shader¶
Core Declaration Mapping¶
GLSL:
#extension GL_EXT_mesh_shader : require
layout(local_size_x = 32) in;
layout(triangles, max_vertices = 64, max_primitives = 126) out;
void main() {
// Set counts
SetMeshOutputsEXT(vertexCount, primitiveCount);
// Write vertices and primitives
gl_MeshVerticesEXT[idx].gl_Position = /* vertex position */;
gl_PrimitiveTriangleIndicesEXT[idx] = uvec3(a, b, c);
}
Slang:
[shader("mesh")]
[numthreads(32, 1, 1)]
[outputtopology("triangle")]
void main(
uint gtid : SV_GroupThreadID,
out vertices MeshVertex verts[64],
out indices uint3 prims[126]
) {
// Set counts
SetMeshOutputCounts(vertexCount, primitiveCount);
// Write vertices and primitives
verts[idx].position = /* vertex position */;
prims[idx] = uint3(a, b, c);
}
Key Attribute Mappings¶
GLSL |
Slang |
Description |
---|---|---|
|
|
Thread group size |
|
|
Output primitive type |
|
Output parameters |
Maximum vertices/primitives |
Key Conversion Points¶
Declaration: Add
[shader("mesh")]
and[numthreads(X,Y,Z)]
decorationsOutput topology: Use
[outputtopology("triangle")]
attributeVertex/primitive count: Replace
SetMeshOutputsEXT
withSetMeshOutputCounts
Vertex access: Replace
gl_MeshVerticesEXT[idx]
withverts[idx]
Primitive access: Replace
gl_PrimitiveTriangleIndicesEXT[idx]
withprims[idx]
Ray Tracing Shaders¶
Ray Generation Shader¶
GLSL:
#extension GL_EXT_ray_tracing : require
layout(location = 0) rayPayloadEXT PayloadData payload;
void main() {
// Launch rays
traceRayEXT(tlas, flags, mask, sbtOffset, stride, miss, origin, tMin, direction, tMax, 0);
}
Slang:
[shader("raygeneration")]
void main() {
RayDesc ray;
ray.Origin = origin;
ray.Direction = direction;
ray.TMin = tMin;
ray.TMax = tMax;
PayloadData payload;
TraceRay(tlas, flags, mask, sbtOffset, stride, miss, ray, payload);
}
Closest Hit Shader¶
GLSL:
#extension GL_EXT_ray_tracing : require
layout(location = 0) rayPayloadInEXT PayloadData payload;
void main() {
// Process hit
payload.hit = true;
}
Slang:
[shader("closesthit")]
void main(inout PayloadData payload, in BuiltInTriangleIntersectionAttributes attr) {
// Process hit
payload.hit = true;
}
Miss Shader¶
GLSL:
#extension GL_EXT_ray_tracing : require
layout(location = 0) rayPayloadInEXT PayloadData payload;
void main() {
// Process miss
payload.hit = false;
}
Slang:
[shader("miss")]
void main(inout PayloadData payload) {
// Process miss
payload.hit = false;
}
Key Conversion Points¶
Declaration: Use appropriate decorator for each shader type
Ray payload: Pass as
inout
parameter instead of global variableRay tracing: Use
TraceRay
with aRayDesc
structBuilt-ins: Access through function calls instead of global variables
Hit attributes: Receive via function parameters