Fixed HLSL shaders (mostly ray tracing related)
Updated HLSL compile script
This commit is contained in:
parent
cb836dd6d0
commit
66dce3c991
14 changed files with 53 additions and 28 deletions
|
|
@ -43,7 +43,7 @@ for root, dirs, files in os.walk(dir_path):
|
||||||
if(hlsl_file.find('.vert') != -1):
|
if(hlsl_file.find('.vert') != -1):
|
||||||
profile = 'vs_6_1'
|
profile = 'vs_6_1'
|
||||||
elif(hlsl_file.find('.frag') != -1):
|
elif(hlsl_file.find('.frag') != -1):
|
||||||
profile = 'ps_6_1'
|
profile = 'ps_6_4'
|
||||||
elif(hlsl_file.find('.comp') != -1):
|
elif(hlsl_file.find('.comp') != -1):
|
||||||
profile = 'cs_6_1'
|
profile = 'cs_6_1'
|
||||||
elif(hlsl_file.find('.geom') != -1):
|
elif(hlsl_file.find('.geom') != -1):
|
||||||
|
|
@ -71,6 +71,8 @@ for root, dirs, files in os.walk(dir_path):
|
||||||
'-fspv-extension=SPV_KHR_multiview',
|
'-fspv-extension=SPV_KHR_multiview',
|
||||||
'-fspv-extension=SPV_KHR_shader_draw_parameters',
|
'-fspv-extension=SPV_KHR_shader_draw_parameters',
|
||||||
'-fspv-extension=SPV_EXT_descriptor_indexing',
|
'-fspv-extension=SPV_EXT_descriptor_indexing',
|
||||||
|
'-fspv-extension=SPV_KHR_ray_query',
|
||||||
|
'-fspv-extension=SPV_KHR_fragment_shading_rate',
|
||||||
target,
|
target,
|
||||||
hlsl_file,
|
hlsl_file,
|
||||||
'-Fo', spv_out])
|
'-Fo', spv_out])
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2020 Google LLC
|
// Copyright 2020 Google LLC
|
||||||
|
|
||||||
struct Attribute
|
struct Attributes
|
||||||
{
|
{
|
||||||
float2 attribs;
|
float2 bary;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Payload
|
struct Payload
|
||||||
|
|
@ -11,8 +11,8 @@ struct Payload
|
||||||
};
|
};
|
||||||
|
|
||||||
[shader("closesthit")]
|
[shader("closesthit")]
|
||||||
void main(inout Payload p, in float2 attribs)
|
void main(inout Payload p, in Attributes attribs)
|
||||||
{
|
{
|
||||||
const float3 barycentricCoords = float3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y);
|
const float3 barycentricCoords = float3(1.0f - attribs.bary.x - attribs.bary.y, attribs.bary.x, attribs.bary.y);
|
||||||
p.hitValue = barycentricCoords;
|
p.hitValue = barycentricCoords;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2021 Sascha Willems
|
// Copyright 2021-2023 Sascha Willems
|
||||||
|
|
||||||
struct Payload
|
struct Payload
|
||||||
{
|
{
|
||||||
|
|
@ -10,8 +10,13 @@ struct CallData
|
||||||
float3 outColor;
|
float3 outColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Attributes
|
||||||
|
{
|
||||||
|
float2 bary;
|
||||||
|
};
|
||||||
|
|
||||||
[shader("closesthit")]
|
[shader("closesthit")]
|
||||||
void main(inout Payload p, in float2 attribs)
|
void main(inout Payload p, in Attributes attribs)
|
||||||
{
|
{
|
||||||
// Execute the callable shader indexed by the current geometry being hit
|
// Execute the callable shader indexed by the current geometry being hit
|
||||||
// For our sample this means that the first callable shader in the SBT is invoked for the first triangle, the second callable shader for the second triangle, etc.
|
// For our sample this means that the first callable shader in the SBT is invoked for the first triangle, the second callable shader for the second triangle, etc.
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -8,6 +8,11 @@ struct RayPayload
|
||||||
float reflector;
|
float reflector;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Attributes
|
||||||
|
{
|
||||||
|
float2 bary;
|
||||||
|
};
|
||||||
|
|
||||||
RaytracingAccelerationStructure topLevelAS : register(t0);
|
RaytracingAccelerationStructure topLevelAS : register(t0);
|
||||||
struct UBO
|
struct UBO
|
||||||
{
|
{
|
||||||
|
|
@ -50,7 +55,7 @@ Vertex unpack(uint index)
|
||||||
}
|
}
|
||||||
|
|
||||||
[shader("closesthit")]
|
[shader("closesthit")]
|
||||||
void main(inout RayPayload rayPayload, in float2 attribs)
|
void main(inout RayPayload rayPayload, in Attributes attribs)
|
||||||
{
|
{
|
||||||
uint PrimitiveID = PrimitiveIndex();
|
uint PrimitiveID = PrimitiveIndex();
|
||||||
int3 index = int3(indices[3 * PrimitiveID], indices[3 * PrimitiveID + 1], indices[3 * PrimitiveID + 2]);
|
int3 index = int3(indices[3 * PrimitiveID], indices[3 * PrimitiveID + 1], indices[3 * PrimitiveID + 2]);
|
||||||
|
|
@ -60,7 +65,7 @@ void main(inout RayPayload rayPayload, in float2 attribs)
|
||||||
Vertex v2 = unpack(index.z);
|
Vertex v2 = unpack(index.z);
|
||||||
|
|
||||||
// Interpolate normal
|
// Interpolate normal
|
||||||
const float3 barycentricCoords = float3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y);
|
const float3 barycentricCoords = float3(1.0f - attribs.bary.x - attribs.bary.y, attribs.bary.x, attribs.bary.y);
|
||||||
float3 normal = normalize(v0.normal * barycentricCoords.x + v1.normal * barycentricCoords.y + v2.normal * barycentricCoords.z);
|
float3 normal = normalize(v0.normal * barycentricCoords.x + v1.normal * barycentricCoords.y + v2.normal * barycentricCoords.z);
|
||||||
|
|
||||||
// Basic lighting
|
// Basic lighting
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2020 Google LLC
|
// Copyright 2020 Google LLC
|
||||||
|
|
||||||
struct Attribute
|
struct Attributes
|
||||||
{
|
{
|
||||||
float2 attribs;
|
float2 bary;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Payload
|
struct Payload
|
||||||
|
|
@ -19,7 +19,7 @@ struct SBT {
|
||||||
ConstantBuffer<SBT> sbt;
|
ConstantBuffer<SBT> sbt;
|
||||||
|
|
||||||
[shader("closesthit")]
|
[shader("closesthit")]
|
||||||
void main(inout Payload p, in float2 attribs)
|
void main(inout Payload p, in Attributes attribs)
|
||||||
{
|
{
|
||||||
// Update the hit value to the hit record SBT data associated with this
|
// Update the hit value to the hit record SBT data associated with this
|
||||||
// geometry ID and ray ID
|
// geometry ID and ray ID
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
// Copyright 2020 Google LLC
|
// Copyright 2020 Google LLC
|
||||||
|
|
||||||
struct InPayload
|
struct Payload
|
||||||
{
|
{
|
||||||
[[vk::location(0)]] float3 hitValue;
|
[[vk::location(0)]] float3 hitValue;
|
||||||
|
[[vk::location(1)]] bool shadowed;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InOutPayload
|
struct Attributes
|
||||||
{
|
{
|
||||||
[[vk::location(2)]] bool shadowed;
|
float2 bary;
|
||||||
};
|
};
|
||||||
|
|
||||||
RaytracingAccelerationStructure topLevelAS : register(t0);
|
RaytracingAccelerationStructure topLevelAS : register(t0);
|
||||||
|
|
@ -52,7 +53,7 @@ Vertex unpack(uint index)
|
||||||
}
|
}
|
||||||
|
|
||||||
[shader("closesthit")]
|
[shader("closesthit")]
|
||||||
void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float2 attribs)
|
void main(inout Payload payload, in Attributes attribs)
|
||||||
{
|
{
|
||||||
uint PrimitiveID = PrimitiveIndex();
|
uint PrimitiveID = PrimitiveIndex();
|
||||||
int3 index = int3(indices[3 * PrimitiveID], indices[3 * PrimitiveID + 1], indices[3 * PrimitiveID + 2]);
|
int3 index = int3(indices[3 * PrimitiveID], indices[3 * PrimitiveID + 1], indices[3 * PrimitiveID + 2]);
|
||||||
|
|
@ -62,13 +63,13 @@ void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float2 att
|
||||||
Vertex v2 = unpack(index.z);
|
Vertex v2 = unpack(index.z);
|
||||||
|
|
||||||
// Interpolate normal
|
// Interpolate normal
|
||||||
const float3 barycentricCoords = float3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y);
|
const float3 barycentricCoords = float3(1.0f - attribs.bary.x - attribs.bary.y, attribs.bary.x, attribs.bary.y);
|
||||||
float3 normal = normalize(v0.normal * barycentricCoords.x + v1.normal * barycentricCoords.y + v2.normal * barycentricCoords.z);
|
float3 normal = normalize(v0.normal * barycentricCoords.x + v1.normal * barycentricCoords.y + v2.normal * barycentricCoords.z);
|
||||||
|
|
||||||
// Basic lighting
|
// Basic lighting
|
||||||
float3 lightVector = normalize(ubo.lightPos.xyz);
|
float3 lightVector = normalize(ubo.lightPos.xyz);
|
||||||
float dot_product = max(dot(lightVector, normal), 0.2);
|
float dot_product = max(dot(lightVector, normal), 0.2);
|
||||||
inPayload.hitValue = v0.color.rgb * dot_product;
|
payload.hitValue = v0.color.rgb * dot_product;
|
||||||
|
|
||||||
RayDesc rayDesc;
|
RayDesc rayDesc;
|
||||||
rayDesc.Origin = WorldRayOrigin() + WorldRayDirection() * RayTCurrent();
|
rayDesc.Origin = WorldRayOrigin() + WorldRayDirection() * RayTCurrent();
|
||||||
|
|
@ -76,10 +77,10 @@ void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float2 att
|
||||||
rayDesc.TMin = 0.001;
|
rayDesc.TMin = 0.001;
|
||||||
rayDesc.TMax = 100.0;
|
rayDesc.TMax = 100.0;
|
||||||
|
|
||||||
inOutPayload.shadowed = true;
|
payload.shadowed = true;
|
||||||
// Offset indices to match shadow hit/miss index
|
// Offset indices to match shadow hit/miss index
|
||||||
TraceRay(topLevelAS, RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_SKIP_CLOSEST_HIT_SHADER, 0xff, 0, 0, 1, rayDesc, inOutPayload);
|
TraceRay(topLevelAS, RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_SKIP_CLOSEST_HIT_SHADER, 0xff, 0, 0, 1, rayDesc, payload);
|
||||||
if (inOutPayload.shadowed) {
|
if (payload.shadowed) {
|
||||||
inPayload.hitValue *= 0.3;
|
payload.hitValue *= 0.3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,7 +1,13 @@
|
||||||
// Copyright 2020 Google LLC
|
// Copyright 2020 Google LLC
|
||||||
|
|
||||||
[shader("miss")]
|
struct Payload
|
||||||
void main([[vk::location(0)]] in float3 hitValue)
|
|
||||||
{
|
{
|
||||||
hitValue = float3(0.0, 0.0, 0.2);
|
[[vk::location(0)]] float3 hitValue;
|
||||||
|
[[vk::location(1)]] bool shadowed;
|
||||||
|
};
|
||||||
|
|
||||||
|
[shader("miss")]
|
||||||
|
void main(inout Payload payload)
|
||||||
|
{
|
||||||
|
payload.hitValue = float3(0.0, 0.0, 0.2);
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -1,7 +1,13 @@
|
||||||
// Copyright 2020 Google LLC
|
// Copyright 2020 Google LLC
|
||||||
|
|
||||||
[shader("miss")]
|
struct Payload
|
||||||
void main([[vk::location(2)]] in bool shadowed)
|
|
||||||
{
|
{
|
||||||
shadowed = false;
|
[[vk::location(0)]] float3 hitValue;
|
||||||
|
[[vk::location(1)]] bool shadowed;
|
||||||
|
};
|
||||||
|
|
||||||
|
[shader("miss")]
|
||||||
|
void main(inout Payload payload)
|
||||||
|
{
|
||||||
|
payload.shadowed = false;
|
||||||
}
|
}
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue