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):
|
||||
profile = 'vs_6_1'
|
||||
elif(hlsl_file.find('.frag') != -1):
|
||||
profile = 'ps_6_1'
|
||||
profile = 'ps_6_4'
|
||||
elif(hlsl_file.find('.comp') != -1):
|
||||
profile = 'cs_6_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_shader_draw_parameters',
|
||||
'-fspv-extension=SPV_EXT_descriptor_indexing',
|
||||
'-fspv-extension=SPV_KHR_ray_query',
|
||||
'-fspv-extension=SPV_KHR_fragment_shading_rate',
|
||||
target,
|
||||
hlsl_file,
|
||||
'-Fo', spv_out])
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct Attribute
|
||||
struct Attributes
|
||||
{
|
||||
float2 attribs;
|
||||
float2 bary;
|
||||
};
|
||||
|
||||
struct Payload
|
||||
|
|
@ -11,8 +11,8 @@ struct Payload
|
|||
};
|
||||
|
||||
[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;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Sascha Willems
|
||||
// Copyright 2021-2023 Sascha Willems
|
||||
|
||||
struct Payload
|
||||
{
|
||||
|
|
@ -10,8 +10,13 @@ struct CallData
|
|||
float3 outColor;
|
||||
};
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float2 bary;
|
||||
};
|
||||
|
||||
[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
|
||||
// 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;
|
||||
};
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float2 bary;
|
||||
};
|
||||
|
||||
RaytracingAccelerationStructure topLevelAS : register(t0);
|
||||
struct UBO
|
||||
{
|
||||
|
|
@ -50,7 +55,7 @@ Vertex unpack(uint index)
|
|||
}
|
||||
|
||||
[shader("closesthit")]
|
||||
void main(inout RayPayload rayPayload, in float2 attribs)
|
||||
void main(inout RayPayload rayPayload, in Attributes attribs)
|
||||
{
|
||||
uint PrimitiveID = PrimitiveIndex();
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Basic lighting
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct Attribute
|
||||
struct Attributes
|
||||
{
|
||||
float2 attribs;
|
||||
float2 bary;
|
||||
};
|
||||
|
||||
struct Payload
|
||||
|
|
@ -19,7 +19,7 @@ struct SBT {
|
|||
ConstantBuffer<SBT> sbt;
|
||||
|
||||
[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
|
||||
// geometry ID and ray ID
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct InPayload
|
||||
struct Payload
|
||||
{
|
||||
[[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);
|
||||
|
|
@ -52,7 +53,7 @@ Vertex unpack(uint index)
|
|||
}
|
||||
|
||||
[shader("closesthit")]
|
||||
void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float2 attribs)
|
||||
void main(inout Payload payload, in Attributes attribs)
|
||||
{
|
||||
uint PrimitiveID = PrimitiveIndex();
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Basic lighting
|
||||
float3 lightVector = normalize(ubo.lightPos.xyz);
|
||||
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.Origin = WorldRayOrigin() + WorldRayDirection() * RayTCurrent();
|
||||
|
|
@ -76,10 +77,10 @@ void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float2 att
|
|||
rayDesc.TMin = 0.001;
|
||||
rayDesc.TMax = 100.0;
|
||||
|
||||
inOutPayload.shadowed = true;
|
||||
payload.shadowed = true;
|
||||
// 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);
|
||||
if (inOutPayload.shadowed) {
|
||||
inPayload.hitValue *= 0.3;
|
||||
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 (payload.shadowed) {
|
||||
payload.hitValue *= 0.3;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,7 +1,13 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
[shader("miss")]
|
||||
void main([[vk::location(0)]] in float3 hitValue)
|
||||
struct Payload
|
||||
{
|
||||
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
|
||||
|
||||
[shader("miss")]
|
||||
void main([[vk::location(2)]] in bool shadowed)
|
||||
struct Payload
|
||||
{
|
||||
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