Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else()
option(GREX_ENABLE_VULKAN "Build Vulkan projects" ON)
endif()


option(GREX_ENABLE_SLANG "Build Slang version of Vulkan projects" OFF)
option(GREX_ENABLE_MISC_PROJECTS "Build misc projects" OFF)

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -53,6 +53,14 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# ------------------------------------------------------------------------------
# Compiler otions
# ------------------------------------------------------------------------------
if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()

# ------------------------------------------------------------------------------
# Compile flags and definitions
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -127,6 +135,28 @@ if (VULKAN_INCLUDE_DIR)
message(" Vulkan library directory: ${VULKAN_LIBRARY_DIR}")
endif()

# ------------------------------------------------------------------------------
# Slang
# ------------------------------------------------------------------------------
if (GREX_ENABLE_SLANG)
if (NOT SLANG_DIR)
message(FATAL_ERROR "GREX_ENABLE_SLANG requires -DSLANG_DIR=<path to Slang>")
endif()

set(SLANG_INCLUDE_DIR "${SLANG_DIR}/include")
set(SLANG_LIBRARY_DIR "${SLANG_DIR}/lib")

if (NOT EXISTS "${SLANG_DIR}/include/slang.h")
message(FATAL_ERROR "Could not find slang.h at ${SLANG_DIR}/include/slang.h")
endif()

message("Found Slang:")
message(" Slang include directory: ${SLANG_INCLUDE_DIR}")
message(" Slang library directory: ${SLANG_LIBRARY_DIR}")

include(cmake/slang.cmake)
endif()

# ------------------------------------------------------------------------------
# glslang
# ------------------------------------------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions assets/projects/111_mesh_shader_meshlets/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ struct Vertex {
};

struct Meshlet {
uint VertexOffset;
uint TriangleOffset;
uint VertexCount;
uint TriangleCount;
uint VertexOffset;
uint TriangleOffset;
uint VertexCount;
uint TriangleCount;
};

StructuredBuffer<Vertex> Vertices : register(t1);
Expand All @@ -33,6 +33,7 @@ struct MeshOutput {
float3 Color : COLOR;
};

[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -74,6 +75,7 @@ void msmain(
}
}

[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
return float4(input.Color, 1);
Expand Down
3 changes: 3 additions & 0 deletions assets/projects/112_mesh_shader_amplification/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ groupshared Payload sPayload;
// -------------------------------------------------------------------------------------------------
// Amplification Shader
// -------------------------------------------------------------------------------------------------
[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand All @@ -59,6 +60,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -106,6 +108,7 @@ void msmain(
// -------------------------------------------------------------------------------------------------
// Pixel Shader
// -------------------------------------------------------------------------------------------------
[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
return float4(input.Color, 1);
Expand Down
3 changes: 3 additions & 0 deletions assets/projects/113_mesh_shader_instancing/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ groupshared Payload sPayload;
// -------------------------------------------------------------------------------------------------
// Amplification Shader
// -------------------------------------------------------------------------------------------------
[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand All @@ -78,6 +79,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -128,6 +130,7 @@ void msmain(
// -------------------------------------------------------------------------------------------------
// Pixel Shader
// -------------------------------------------------------------------------------------------------
[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
return float4(input.Color, 1);
Expand Down
5 changes: 4 additions & 1 deletion assets/projects/114_mesh_shader_culling/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ bool VisibleFrustumConeAndNearPlane(float4 sphere)
{
bool i0 = VisibleFrustumCone(sphere);

FrustumPlane frNear = Scene.Frustum.Planes[FRUSTUM_PLANE_NEAR];
FrustumPlane frNear = Scene.Frustum.Planes[(int)FRUSTUM_PLANE_NEAR];
float d0 = SignedPointPlaneDistance(sphere.xyz, frNear.Normal, frNear.Position);
bool i1 = (abs(d0) < sphere.w); // Intersects with near plane
bool i2 = (d0 > 0); // On positive half space of near plane

return i0 && (i1 || i2);
};

[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand Down Expand Up @@ -200,6 +201,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -250,6 +252,7 @@ void msmain(
// -------------------------------------------------------------------------------------------------
// Pixel Shader
// -------------------------------------------------------------------------------------------------
[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
return float4(input.Color, 1);
Expand Down
3 changes: 3 additions & 0 deletions assets/projects/115_mesh_shader_lod/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ groupshared Payload sPayload;
// -------------------------------------------------------------------------------------------------
// Amplification Shader
// -------------------------------------------------------------------------------------------------
[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand Down Expand Up @@ -86,6 +87,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -136,6 +138,7 @@ void msmain(
// -------------------------------------------------------------------------------------------------
// Pixel Shader
// -------------------------------------------------------------------------------------------------
[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
return float4(input.Color, 1);
Expand Down
3 changes: 3 additions & 0 deletions assets/projects/116_mesh_shader_calc_lod/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ groupshared Payload sPayload;
// -------------------------------------------------------------------------------------------------
// Amplification Shader
// -------------------------------------------------------------------------------------------------
[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand Down Expand Up @@ -112,6 +113,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -162,6 +164,7 @@ void msmain(
// -------------------------------------------------------------------------------------------------
// Pixel Shader
// -------------------------------------------------------------------------------------------------
[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
return float4(input.Color, 1);
Expand Down
5 changes: 4 additions & 1 deletion assets/projects/117_mesh_shader_cull_lod/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,15 @@ bool VisibleFrustumConeAndNearPlane(float4 sphere)
{
bool i0 = VisibleFrustumCone(sphere);

FrustumPlane frNear = Scene.Frustum.Planes[FRUSTUM_PLANE_NEAR];
FrustumPlane frNear = Scene.Frustum.Planes[(int)FRUSTUM_PLANE_NEAR];
float d0 = SignedPointPlaneDistance(sphere.xyz, frNear.Normal, frNear.Position);
bool i1 = (abs(d0) < sphere.w); // Intersects with near plane
bool i2 = (d0 > 0); // On positive half space of near plane

return i0 && (i1 || i2);
};

[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand Down Expand Up @@ -239,6 +240,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -289,6 +291,7 @@ void msmain(
// -------------------------------------------------------------------------------------------------
// Pixel Shader
// -------------------------------------------------------------------------------------------------
[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
return float4(input.Color, 1);
Expand Down
3 changes: 3 additions & 0 deletions assets/projects/118_mesh_shader_vertex_attrs/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ groupshared Payload sPayload;
// -------------------------------------------------------------------------------------------------
// Amplification Shader
// -------------------------------------------------------------------------------------------------
[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand All @@ -63,6 +64,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -110,6 +112,7 @@ void msmain(
// -------------------------------------------------------------------------------------------------
// Pixel Shader
// -------------------------------------------------------------------------------------------------
[shader("pixel")]
float4 psmain(MeshOutput input) : SV_TARGET
{
float3 color = input.PositionWS;
Expand Down
3 changes: 3 additions & 0 deletions assets/projects/119_mesh_shader_vertex_bary/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ groupshared Payload sPayload;
// -------------------------------------------------------------------------------------------------
// Amplification Shader
// -------------------------------------------------------------------------------------------------
[shader("amplification")]
[numthreads(AS_GROUP_SIZE, 1, 1)]
void asmain(
uint gtid : SV_GroupThreadID,
Expand All @@ -61,6 +62,7 @@ void asmain(
// -------------------------------------------------------------------------------------------------
// Mesh Shader
// -------------------------------------------------------------------------------------------------
[shader("mesh")]
[outputtopology("triangle")]
[numthreads(128, 1, 1)]
void msmain(
Expand Down Expand Up @@ -114,6 +116,7 @@ struct PSInput {
float3 Bary : SV_BARYCENTRICS;
};

[shader("pixel")]
float4 psmain(PSInput input) : SV_TARGET
{
// Get triangle's vertex indices
Expand Down
8 changes: 5 additions & 3 deletions assets/projects/201_pbr_spheres/drawtexture.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ struct VSOutput
float2 TexCoord : TEXCOORD;
};

VSOutput vsmain(float3 PositionOS : POSITION, float2 TexCoord : TEXCOORD)
{
[shader("vertex")]
VSOutput vsmain(float3 PositionOS : POSITION, float2 TexCoord : TEXCOORD)
{
VSOutput output = (VSOutput)0;
output.PositionCS = mul(SceneParams.MVP, float4(PositionOS, 1));
output.TexCoord = TexCoord;
return output;
}
}


//
Expand All @@ -36,6 +37,7 @@ float3 ACESFilm(float3 x){
return saturate((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14));
}

[shader("pixel")]
float4 psmain(VSOutput input) : SV_Target
{
float3 color = IBLEnvironmentMap.SampleLevel(IBLMapSampler, input.TexCoord, 0).xyz;
Expand Down
6 changes: 4 additions & 2 deletions assets/projects/201_pbr_spheres/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct SceneParameters {
uint IBLEnvironmentNumLevels;
};

#ifdef __spirv__
#if defined(__spirv__)

struct DrawParameters {
float4x4 ModelMatrix;
Expand All @@ -43,7 +43,7 @@ struct MaterialParameters {
ConstantBuffer<DrawParameters> DrawParams : register(b1);
ConstantBuffer<MaterialParameters> MaterialParams : register(b2);

#endif
#endif // defined(__spirv__)

ConstantBuffer<SceneParameters> SceneParams : register(b0);
Texture2D IBLIntegrationLUT : register(t3);
Expand All @@ -61,6 +61,7 @@ struct VSOutput {
float3 Normal : NORMAL;
};

[shader("vertex")]
VSOutput vsmain(
float3 PositionOS : POSITION,
float3 Normal : NORMAL
Expand Down Expand Up @@ -197,6 +198,7 @@ float3 ACESFilm(float3 x)
return saturate((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14));
}

[shader("pixel")]
float4 psmain(VSOutput input) : SV_TARGET
{
// Scene and geometry variables - world space
Expand Down
8 changes: 5 additions & 3 deletions assets/projects/202_pbr_camera/drawtexture.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct VSOutput
float2 TexCoord : TEXCOORD;
};

[shader("vertex")]
VSOutput vsmain(float3 PositionOS : POSITION, float2 TexCoord : TEXCOORD)
{
VSOutput output = (VSOutput)0;
Expand All @@ -36,10 +37,11 @@ float3 ACESFilm(float3 x){
return saturate((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14));
}

float4 psmain(VSOutput input) : SV_Target
{
[shader("pixel")]
float4 psmain(VSOutput input) : SV_Target
{
float3 color = IBLEnvironmentMap.SampleLevel(IBLMapSampler, input.TexCoord, 0).xyz;
color = ACESFilm(color);
color = pow(color, 1 / 1.6);
return float4(color, 1);
}
}
2 changes: 2 additions & 0 deletions assets/projects/202_pbr_camera/shaders.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct VSOutput {
float3 Bitangent : BITANGENT;
};

[shader("vertex")]
VSOutput vsmain(
float3 PositionOS : POSITION,
float2 TexCoord : TEXCOORD,
Expand Down Expand Up @@ -206,6 +207,7 @@ float3 ACESFilm(float3 x)
return saturate((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14));
}

[shader("pixel")]
float4 psmain(VSOutput input) : SV_TARGET
{
uint baseColorIdx = 5 * DrawParams.MaterialIndex + 0;
Expand Down
Loading