Hair - ShortCut rendering technique and pipeline with Marschner lighting model (#4871)
- This rendering technique reduces the memory required per pipeline by 750MB compared to the PPLL technique!! - Using 3 screen buffers representing the closest 3 hair gragments depths. - Going through second geometry pass that disqualify any fragment further than the third depth, the technique blends the three closes shaders hair fragments. - Supports the Marschner lighting model (big change from the original TressFX 4.1 implementation) - The current technique is almost twice the performance of the PPLL but not quite as advacned when come to final visual quality. Remarks: Unlike the PPLL, this technique is still lacking some of the advanced features added to the PPLL such as 1. Back lobe (TT) conseal by depth comparison 2. Thickness dependency in light transfer (mainly TT) 3. Allowing TT transfer for thin separated hair strands (might be supported by default with no distinction) Signed-off-by: Adi-Amazon <Adi Bar-Lev 82479970+Adi-Amazon@users.noreply.github.com> Signed-off-by: Adi-Amazon <Adi Bar-Lev barlev@amazon.com> Signed-off-by: Adi-Amazon <Adi Bar-Lev 82479970+Adi-Amazon@users.noreply.github.com> Signed-off-by: Adi-Amazon <Adi Bar-Lev barlev@amazon.com> Co-authored-by: Adi-Amazon <Adi Bar-Lev 82479970+Adi-Amazon@users.noreply.github.com>monroegm-disable-blank-issue-2
parent
546102077f
commit
64bbc700fa
@ -0,0 +1,391 @@
|
|||||||
|
{
|
||||||
|
"Type": "JsonSerialization",
|
||||||
|
"Version": 1,
|
||||||
|
"ClassName": "PassAsset",
|
||||||
|
"ClassData": {
|
||||||
|
"PassTemplate": {
|
||||||
|
"Name": "HairParentShortCutPassTemplate",
|
||||||
|
"PassClass": "ParentPass",
|
||||||
|
"Slots": [
|
||||||
|
{
|
||||||
|
"Name": "RenderTargetInputOutput",
|
||||||
|
"SlotType": "InputOutput",
|
||||||
|
"ScopeAttachmentUsage": "RenderTarget"
|
||||||
|
},
|
||||||
|
{ // used for copy from MSAA to regular RT
|
||||||
|
"Name": "RenderTargetInputOnly",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
},
|
||||||
|
// This is the depth stencil buffer that is to be used by the fill pass
|
||||||
|
// to early reject pixels by depth and in the resolve pass to write the
|
||||||
|
// the hair depth
|
||||||
|
{
|
||||||
|
"Name": "Depth",
|
||||||
|
"SlotType": "InputOutput",
|
||||||
|
"ScopeAttachmentUsage": "DepthStencil"
|
||||||
|
},
|
||||||
|
// Keep DepthLinear as input - used to set the size of the Head PPLL image buffer.
|
||||||
|
// If DepthLinear is not availbale - connect to another viewport (non MSAA) image.
|
||||||
|
{
|
||||||
|
"Name": "DepthLinearInput",
|
||||||
|
"SlotType": "InputOutput"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "DepthLinear",
|
||||||
|
"SlotType": "Output"
|
||||||
|
},
|
||||||
|
|
||||||
|
// Lights & Shadows resources
|
||||||
|
{
|
||||||
|
"Name": "DirectionalShadowmap",
|
||||||
|
"SlotType": "Input"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "DirectionalESM",
|
||||||
|
"SlotType": "Input"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ProjectedShadowmap",
|
||||||
|
"SlotType": "Input"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ProjectedESM",
|
||||||
|
"SlotType": "Input"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "TileLightData",
|
||||||
|
"SlotType": "Input"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "LightListRemapped",
|
||||||
|
"SlotType": "Input"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "DepthLinear",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "DepthToDepthLinearPass",
|
||||||
|
"Attachment": "Output"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"PassRequests": [
|
||||||
|
{
|
||||||
|
"Name": "HairGlobalShapeConstraintsComputePass",
|
||||||
|
"TemplateName": "HairGlobalShapeConstraintsComputePassTemplate",
|
||||||
|
"Enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairCalculateStrandLevelDataComputePass",
|
||||||
|
"TemplateName": "HairCalculateStrandLevelDataComputePassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "SkinnedHairSharedBuffer",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairGlobalShapeConstraintsComputePass",
|
||||||
|
"Attachment": "SkinnedHairSharedBuffer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairVelocityShockPropagationComputePass",
|
||||||
|
"TemplateName": "HairVelocityShockPropagationComputePassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "SkinnedHairSharedBuffer",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairCalculateStrandLevelDataComputePass",
|
||||||
|
"Attachment": "SkinnedHairSharedBuffer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairLocalShapeConstraintsComputePass",
|
||||||
|
"TemplateName": "HairLocalShapeConstraintsComputePassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "SkinnedHairSharedBuffer",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairVelocityShockPropagationComputePass",
|
||||||
|
"Attachment": "SkinnedHairSharedBuffer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairLengthConstraintsWindAndCollisionComputePass",
|
||||||
|
"TemplateName": "HairLengthConstraintsWindAndCollisionComputePassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "SkinnedHairSharedBuffer",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairLocalShapeConstraintsComputePass",
|
||||||
|
"Attachment": "SkinnedHairSharedBuffer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairUpdateFollowHairComputePass",
|
||||||
|
"TemplateName": "HairUpdateFollowHairComputePassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "SkinnedHairSharedBuffer",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairLengthConstraintsWindAndCollisionComputePass",
|
||||||
|
"Attachment": "SkinnedHairSharedBuffer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Render Target Copy from MS to Regular
|
||||||
|
{
|
||||||
|
"Name": "RenderTargetCopyPass",
|
||||||
|
"TemplateName": "FullscreenCopyTemplate",
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "Input",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "RenderTargetInputOnly"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "Output",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "This",
|
||||||
|
"Attachment": "Output"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ImageAttachments": [
|
||||||
|
{
|
||||||
|
"Name": "Output",
|
||||||
|
"SizeSource": {
|
||||||
|
"Source": {
|
||||||
|
"Pass": "This",
|
||||||
|
"Attachment": "Input"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"FormatSource": {
|
||||||
|
"Pass": "This",
|
||||||
|
"Attachment": "Input"
|
||||||
|
},
|
||||||
|
"GenerateFullMipChain": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Rendering Passes
|
||||||
|
{
|
||||||
|
"Name": "HairShortCutGeometryDepthAlphaPass",
|
||||||
|
"TemplateName": "HairShortCutGeometryDepthAlphaPassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "SkinnedHairSharedBuffer",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairUpdateFollowHairComputePass",
|
||||||
|
"Attachment": "SkinnedHairSharedBuffer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "Depth",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "Depth"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "InverseAlphaRTOutput",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "This",
|
||||||
|
"Attachment": "InverseAlphaRTOutput"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "HairDepthsTextureArray",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "This",
|
||||||
|
"Attachment": "HairDepthsTextureArray"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"Name": "HairShortCutResolveDepthPass",
|
||||||
|
"TemplateName": "HairShortCutResolveDepthPassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "Depth",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "Depth"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "HairDepthsTextureArray",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairShortCutGeometryDepthAlphaPass",
|
||||||
|
"Attachment": "HairDepthsTextureArray"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"Name": "HairShortCutGeometryShadingPass",
|
||||||
|
"TemplateName": "HairShortCutGeometryShadingPassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "HairColorRenderTarget",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "This",
|
||||||
|
"Attachment": "HairColorRenderTarget"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ // The final render target - this is MSAA mode RT - would it be cheaper to
|
||||||
|
// use non-MSAA and then copy?
|
||||||
|
"LocalSlot": "RenderTargetInputOutput",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "RenderTargetInputOutput"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "DepthLinear",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "DepthLinearInput"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "Depth",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "Depth"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "SkinnedHairSharedBuffer",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairUpdateFollowHairComputePass",
|
||||||
|
"Attachment": "SkinnedHairSharedBuffer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Shadows resources
|
||||||
|
{
|
||||||
|
"LocalSlot": "DirectionalShadowmap",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "DirectionalShadowmap"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "DirectionalESM",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "DirectionalESM"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "ProjectedShadowmap",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "ProjectedShadowmap"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "ProjectedESM",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "ProjectedESM"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Lights Resources
|
||||||
|
{
|
||||||
|
"LocalSlot": "TileLightData",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "TileLightData"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "LightListRemapped",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "LightListRemapped"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"Name": "HairShortCutResolveColorPass",
|
||||||
|
"TemplateName": "HairShortCutResolveColorPassTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{ // The final render target - this is MSAA mode RT - would it be cheaper to
|
||||||
|
// use non-MSAA and then copy?
|
||||||
|
"LocalSlot": "RenderTargetInputOutput",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "RenderTargetInputOutput"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "AccumulatedInverseAlpha",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairShortCutGeometryDepthAlphaPass",
|
||||||
|
"Attachment": "InverseAlphaRTOutput"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"LocalSlot": "HairColorTexture",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairShortCutGeometryShadingPass",
|
||||||
|
"Attachment": "HairColorRenderTarget"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// This pass copies the updated depth buffer (now contains hair depth) to linear depth texture
|
||||||
|
// for downstream passes to use. This can be optimized even further by writing into the stencil
|
||||||
|
// buffer pixels that were touched by HairPPLLResolvePass hence preventing depth update unless
|
||||||
|
// it is hair.
|
||||||
|
"Name": "DepthToDepthLinearPass",
|
||||||
|
"TemplateName": "DepthToLinearTemplate",
|
||||||
|
"Enabled": true,
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "Input",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "HairShortCutResolveDepthPass",
|
||||||
|
"Attachment": "Depth"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
{
|
||||||
|
"Type": "JsonSerialization",
|
||||||
|
"Version": 1,
|
||||||
|
"ClassName": "PassAsset",
|
||||||
|
"ClassData": {
|
||||||
|
"PassTemplate": {
|
||||||
|
"Name": "HairShortCutGeometryDepthAlphaPassTemplate",
|
||||||
|
"PassClass": "HairShortCutGeometryDepthAlphaPass",
|
||||||
|
"Slots": [
|
||||||
|
{
|
||||||
|
"Name": "SkinnedHairSharedBuffer",
|
||||||
|
"ShaderInputName": "m_skinnedHairSharedBuffer",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
},
|
||||||
|
{ // DepthStencil for early disqualifying the pixel based on depth. No write.
|
||||||
|
"Name": "Depth",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "DepthStencil"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// the regular render target is blended using inverse alpha to reduce the
|
||||||
|
// incoming color contribution based on the hair thickness and alpha.
|
||||||
|
"Name": "InverseAlphaRTOutput",
|
||||||
|
"SlotType": "Output",
|
||||||
|
"ScopeAttachmentUsage": "RenderTarget",
|
||||||
|
"LoadStoreAction": {
|
||||||
|
"LoadAction": "Clear",
|
||||||
|
"ClearValue": {
|
||||||
|
"Value": [ 1.0, 1.0, 1.0, 1.0 ]
|
||||||
|
},
|
||||||
|
"StoreAction": "Store"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairDepthsTextureArray",
|
||||||
|
"SlotType": "Output",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ShaderInputName": "m_RWFragmentDepthsTexture",
|
||||||
|
"LoadStoreAction": {
|
||||||
|
"LoadAction": "Clear",
|
||||||
|
"ClearValue": { // reverse depth order: closer --> 1.0
|
||||||
|
"Value": [ 0.0, 0.0, 0.0, 0.0 ]
|
||||||
|
},
|
||||||
|
"StoreAction": "Store"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ImageAttachments": [
|
||||||
|
{
|
||||||
|
// This buffer is used as the render target and should be at non-MSAA screen resolution
|
||||||
|
// to make sure no overwork is done.
|
||||||
|
"Name": "InverseAlphaRTOutput",
|
||||||
|
"SizeSource": {
|
||||||
|
"Source": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "DepthLinear"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ImageDescriptor": {
|
||||||
|
"Format": "R32_FLOAT",
|
||||||
|
"SharedQueueMask": "Graphics",
|
||||||
|
"BindFlags": [
|
||||||
|
"Color",
|
||||||
|
"ShaderRead"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairDepthsTextureArray",
|
||||||
|
"SizeSource": {
|
||||||
|
"Source": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "DepthLinear"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ImageDescriptor": {
|
||||||
|
"Format": "R32_UINT",
|
||||||
|
"ArraySize": "3",
|
||||||
|
"SharedQueueMask": "Graphics",
|
||||||
|
"BindFlags": [
|
||||||
|
"ShaderReadWrite",
|
||||||
|
"ShaderWrite",
|
||||||
|
"ShaderRead"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"PassData": {
|
||||||
|
"$type": "RasterPassData",
|
||||||
|
"DrawListTag": "HairGeometryDepthAlphaDrawList",
|
||||||
|
"PipelineViewTag": "MainCamera",
|
||||||
|
"PassSrgShaderAsset": {
|
||||||
|
// Looking for it in the Shaders directory relative to the Assets directory
|
||||||
|
"FilePath": "Shaders/HairShortCutGeometryDepthAlpha.shader"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,155 @@
|
|||||||
|
{
|
||||||
|
"Type": "JsonSerialization",
|
||||||
|
"Version": 1,
|
||||||
|
"ClassName": "PassAsset",
|
||||||
|
"ClassData": {
|
||||||
|
"PassTemplate": {
|
||||||
|
"Name": "HairShortCutGeometryShadingPassTemplate",
|
||||||
|
"PassClass": "HairShortCutGeometryShadingPass",
|
||||||
|
"Slots": [
|
||||||
|
|
||||||
|
{ // Temporary color buffer to store the gathered shaded hair color - MSAA
|
||||||
|
"Name": "HairColorRenderTarget",
|
||||||
|
"SlotType": "Output",
|
||||||
|
"ScopeAttachmentUsage": "RenderTarget",
|
||||||
|
"LoadStoreAction": {
|
||||||
|
"LoadAction": "Clear",
|
||||||
|
"ClearValue": { // reverse depth order: closer --> 1.0
|
||||||
|
"Value": [ 0.0, 0.0, 0.0, 0.0 ]
|
||||||
|
},
|
||||||
|
"StoreAction": "Store"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// This RT is MSAA - is it cheaper to avoid doing this work and only do a copy at a separate pass?
|
||||||
|
"Name": "RenderTargetInputOutput",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
},
|
||||||
|
{ // Used to get the transform from screen space to world space.
|
||||||
|
"Name": "DepthLinear",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
},
|
||||||
|
{ // For comparing the depth to early disqualify but not to write
|
||||||
|
"Name": "Depth",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "DepthStencil"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "SkinnedHairSharedBuffer",
|
||||||
|
"ShaderInputName": "m_skinnedHairSharedBuffer",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
},
|
||||||
|
|
||||||
|
//------------- Shadowing Resources -------------
|
||||||
|
{
|
||||||
|
"Name": "DirectionalShadowmap",
|
||||||
|
"ShaderInputName": "m_directionalLightShadowmap",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ImageViewDesc": {
|
||||||
|
"IsArray": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "DirectionalESM",
|
||||||
|
"ShaderInputName": "m_directionalLightExponentialShadowmap",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ImageViewDesc": {
|
||||||
|
"IsArray": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ProjectedShadowmap",
|
||||||
|
"ShaderInputName": "m_projectedShadowmaps",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ImageViewDesc": {
|
||||||
|
"IsArray": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ProjectedESM",
|
||||||
|
"ShaderInputName": "m_projectedExponentialShadowmap",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ImageViewDesc": {
|
||||||
|
"IsArray": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//------------- Lighting Resources -------------
|
||||||
|
{
|
||||||
|
"Name": "BRDFTextureInput",
|
||||||
|
"ShaderInputName": "m_brdfMap",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "TileLightData",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ShaderInputName": "m_tileLightData",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "LightListRemapped",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ShaderInputName": "m_lightListRemapped",
|
||||||
|
"ScopeAttachmentUsage": "Shader"
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
"ImageAttachments": [
|
||||||
|
{
|
||||||
|
// The shader hair color render target - important to have at a non-MSAA mode
|
||||||
|
// so that no overwork is done on sampling.
|
||||||
|
"Name": "HairColorRenderTarget",
|
||||||
|
"SizeSource": {
|
||||||
|
"Source": {
|
||||||
|
"Pass": "Parent",
|
||||||
|
"Attachment": "RenderTargetInputOutput"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ImageDescriptor": {
|
||||||
|
"Format": "R16G16B16A16_FLOAT",
|
||||||
|
"SharedQueueMask": "Graphics",
|
||||||
|
"BindFlags": [
|
||||||
|
"Color",
|
||||||
|
"ShaderRead"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "BRDFTexture",
|
||||||
|
"Lifetime": "Imported",
|
||||||
|
"AssetRef": {
|
||||||
|
"FilePath": "Textures/BRDFTexture.attimage"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Connections": [
|
||||||
|
{
|
||||||
|
"LocalSlot": "BRDFTextureInput",
|
||||||
|
"AttachmentRef": {
|
||||||
|
"Pass": "This",
|
||||||
|
"Attachment": "BRDFTexture"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"PassData": {
|
||||||
|
"$type": "RasterPassData",
|
||||||
|
"DrawListTag": "HairGeometryShadingDrawList",
|
||||||
|
"PipelineViewTag": "MainCamera",
|
||||||
|
"PassSrgShaderAsset": {
|
||||||
|
// Looking for it in the Shaders directory relative to the Assets directory
|
||||||
|
"FilePath": "Shaders/HairShortCutGeometryShading.shader"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"Type": "JsonSerialization",
|
||||||
|
"Version": 1,
|
||||||
|
"ClassName": "PassAsset",
|
||||||
|
"ClassData": {
|
||||||
|
"PassTemplate": {
|
||||||
|
"Name": "HairShortCutResolveColorPassTemplate",
|
||||||
|
"PassClass": "FullScreenTriangle",
|
||||||
|
"Slots": [
|
||||||
|
{
|
||||||
|
// This RT is MSAA - is it cheaper to avoid doing this work and only do a copy at a separate pass?
|
||||||
|
"Name": "RenderTargetInputOutput",
|
||||||
|
"SlotType": "InputOutput",
|
||||||
|
"ScopeAttachmentUsage": "RenderTarget",
|
||||||
|
"LoadStoreAction": {
|
||||||
|
"LoadAction": "Load",
|
||||||
|
"StoreAction": "Store"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "HairColorTexture",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ShaderInputName": "m_hairColorTexture"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "AccumulatedInverseAlpha",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ShaderInputName": "m_accumInvAlpha"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Connections": [
|
||||||
|
],
|
||||||
|
"PassData": {
|
||||||
|
"$type": "FullscreenTrianglePassData",
|
||||||
|
"ShaderAsset": {
|
||||||
|
// Looking for it in the Shaders directory relative to the Assets directory
|
||||||
|
"FilePath": "Shaders/HairShortCutResolveColor.shader"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"Type": "JsonSerialization",
|
||||||
|
"Version": 1,
|
||||||
|
"ClassName": "PassAsset",
|
||||||
|
"ClassData": {
|
||||||
|
"PassTemplate": {
|
||||||
|
"Name": "HairShortCutResolveDepthPassTemplate",
|
||||||
|
"PassClass": "FullScreenTriangle",
|
||||||
|
"Slots": [
|
||||||
|
//------ General Input/Output resources and Render Target ------
|
||||||
|
{
|
||||||
|
"Name": "Depth",
|
||||||
|
"SlotType": "InputOutput",
|
||||||
|
"ScopeAttachmentUsage": "DepthStencil",
|
||||||
|
"LoadStoreAction": {
|
||||||
|
"LoadAction": "Load",
|
||||||
|
"StoreAction": "Store"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ // This holds the K nearset depths. The furthest depth will be taken to be written in the depth buffer.
|
||||||
|
"Name": "HairDepthsTextureArray",
|
||||||
|
"SlotType": "Input",
|
||||||
|
"ScopeAttachmentUsage": "Shader",
|
||||||
|
"ShaderInputName": "m_fragmentDepthsTexture"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"PassData": {
|
||||||
|
"$type": "FullscreenTrianglePassData",
|
||||||
|
"ShaderAsset": {
|
||||||
|
// Looking for it in the Shaders directory relative to the Assets directory
|
||||||
|
"FilePath": "Shaders/HairShortCutResolveDepth.shader"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Modifications Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: (Apache-2.0 OR MIT) AND MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Atom/Features/PostProcessing/FullscreenVertexInfo.azsli>
|
||||||
|
#include <Atom/Features/PostProcessing/FullscreenVertexUtil.azsli>
|
||||||
|
#include <viewsrg.srgi>
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
// Generate a fullscreen triangle from pipeline provided vertex id
|
||||||
|
VSOutput FullScreenVS(VSInput input)
|
||||||
|
{
|
||||||
|
VSOutput OUT;
|
||||||
|
|
||||||
|
float4 posTex = GetVertexPositionAndTexCoords(input.m_vertexID);
|
||||||
|
|
||||||
|
OUT.m_texCoord = float2(posTex.z, posTex.w); // [To Do] - test sign of Y based on original code
|
||||||
|
OUT.m_position = float4(posTex.xy, 0.0, 1.0);
|
||||||
|
|
||||||
|
return OUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
// Given the depth buffer depth of the current pixel and the fragment XY position,
|
||||||
|
// reconstruct the NDC.
|
||||||
|
// screenCoords - from 0.. dimension of the screen of the current pixel
|
||||||
|
// screenTexture - screen buffer texture representing the same resolution we work in
|
||||||
|
// sDepth - the depth buffer depth at the fragment location
|
||||||
|
// NDC - Normalized Device Coordinates = warped screen space ( -1.1, -1..1, 0..1 )
|
||||||
|
float3 ScreenPosToNDC( Texture2D<float> screenTexture, float2 screenCoords, float depth )
|
||||||
|
{
|
||||||
|
uint2 dimensions;
|
||||||
|
screenTexture.GetDimensions(dimensions.x, dimensions.y);
|
||||||
|
float2 UV = saturate(screenCoords / dimensions.xy);
|
||||||
|
|
||||||
|
float x = UV.x * 2.0f - 1.0f;
|
||||||
|
float y = (1.0f - UV.y) * 2.0f - 1.0f;
|
||||||
|
float3 NDC = float3(x, y, depth);
|
||||||
|
|
||||||
|
return NDC;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given the depth buffer depth of the current pixel and the fragment XY position,
|
||||||
|
// reconstruct the world space position
|
||||||
|
float3 ScreenPosToWorldPos(
|
||||||
|
Texture2D<float> screenTexture, float2 screenCoords, float depth,
|
||||||
|
inout float3 screenPosNDC )
|
||||||
|
{
|
||||||
|
screenPosNDC = ScreenPosToNDC(screenTexture, screenCoords, depth);
|
||||||
|
float4 projectedPos = float4(screenPosNDC, 1.0f); // warped projected space [0..1]
|
||||||
|
float4 positionVS = mul(ViewSrg::m_projectionMatrixInverse, projectedPos);
|
||||||
|
positionVS /= positionVS.w; // notice the normalization factor - crucial!
|
||||||
|
float4 positionWS = mul(ViewSrg::m_viewMatrixInverse, positionVS);
|
||||||
|
|
||||||
|
return positionWS.xyz;
|
||||||
|
}
|
||||||
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* Modifications Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: (Apache-2.0 OR MIT) AND MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <Atom/Features/SrgSemantics.azsli>
|
||||||
|
#include <HairRenderingSrgs.azsli>
|
||||||
|
|
||||||
|
//!------------------------------ SRG Structure --------------------------------
|
||||||
|
//! Per pass SRG that holds the dynamic shared read-write buffer shared
|
||||||
|
//! across all dispatches and draw calls. It is used for all the dynamic buffers
|
||||||
|
//! that can change between passes due to the application of skinning, simulation
|
||||||
|
//! and physics affect.
|
||||||
|
//! Once the compute pases are done, it is read by the rendering shaders.
|
||||||
|
ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
|
||||||
|
{
|
||||||
|
//! This shared buffer needs to match the SharedBuffer structure
|
||||||
|
//! shared between all draw calls / dispatches for the hair skinning
|
||||||
|
StructuredBuffer<int> m_skinnedHairSharedBuffer;
|
||||||
|
|
||||||
|
//! Based on [[vk::binding(0, 3)]] RWTexture2DArray<uint> RWFragmentDepthsTexture : register(u0, space3);
|
||||||
|
RWTexture2DArray<uint> m_RWFragmentDepthsTexture;
|
||||||
|
}
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
//!------------------------------ SRG Structure --------------------------------
|
||||||
|
//! Per instance/draw SRG representing dynamic read-write set of buffers
|
||||||
|
//! that are unique per instance and are shared and changed between passes due
|
||||||
|
//! to the application of skinning, simulation and physics affect.
|
||||||
|
//! It is then also read by the rendering shaders.
|
||||||
|
//! This Srg is NOT shared by the passes since it requires having barriers between
|
||||||
|
//! both passes and draw calls, instead, all buffers are allocated from a single
|
||||||
|
//! shared buffer (through BufferViews) and that buffer is then shared between
|
||||||
|
//! the passes via the PerPass Srg frequency.
|
||||||
|
ShaderResourceGroup HairDynamicDataSrg : SRG_PerObject // space 1 - per instance / object
|
||||||
|
{
|
||||||
|
Buffer<float4> m_hairVertexPositions;
|
||||||
|
Buffer<float4> m_hairVertexTangents;
|
||||||
|
|
||||||
|
//! Per hair object offset to the start location of each buffer within
|
||||||
|
//! 'm_skinnedHairSharedBuffer'. The offset is in bytes!
|
||||||
|
uint m_positionBufferOffset;
|
||||||
|
uint m_tangentBufferOffset;
|
||||||
|
};
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Allow for the code to run with minimal changes - skinning / simulation compute passes
|
||||||
|
// Usage of per-instance buffer
|
||||||
|
#define g_GuideHairVertexPositions HairDynamicDataSrg::m_hairVertexPositions
|
||||||
|
#define g_GuideHairVertexTangents HairDynamicDataSrg::m_hairVertexTangents
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <HairStrands.azsli> // VS resides here
|
||||||
|
|
||||||
|
//!=============================================================================
|
||||||
|
//! Geometry Depth Alpha - First Pass of ShortCut Render
|
||||||
|
//! It is a Geometry pass that stores the K=3 front fragment depths, and accumulates
|
||||||
|
//! product of 1-alpha multiplications (fade out) of the input render target.
|
||||||
|
//!
|
||||||
|
//! Short explanation: in the original AMD implementation 1-alpha is multiplied
|
||||||
|
//! repeatedly with the incoming render target (back buffer) hence blending out
|
||||||
|
//! the existing back buffer color based on the density and transparency of the hair.
|
||||||
|
//! This implies that later on the hair color should be added based on the inverse
|
||||||
|
//! of this operation.
|
||||||
|
//!=============================================================================
|
||||||
|
[earlydepthstencil]
|
||||||
|
float HairShortCutDepthsAlphaPS(PS_INPUT_HAIR input) : SV_Target
|
||||||
|
{
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// [To Do] Hair: anti aliasing via coverage requires work and is disabled for now
|
||||||
|
// float3 vNDC = ScreenPosToNDC(PassSrg::m_linearDepth, input.Position.xy, input.Position.z);
|
||||||
|
// uint2 dimensions;
|
||||||
|
// PassSrg::m_linearDepth.GetDimensions(dimensions.x, dimensions.y);
|
||||||
|
// float coverage = ComputeCoverage(input.p0p1.xy, input.p0p1.zw, vNDC.xy, float2(dimensions.x, dimensions.y));
|
||||||
|
float coverage = 1.0;
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
float alpha = coverage * MatBaseColor.a;
|
||||||
|
|
||||||
|
if (alpha < SHORTCUT_MIN_ALPHA)
|
||||||
|
return 1.0;
|
||||||
|
|
||||||
|
int2 vScreenAddress = int2(input.Position.xy);
|
||||||
|
uint uDepth = asuint(input.Position.z);
|
||||||
|
uint uDepth0Prev, uDepth1Prev, uDepth2Prev;
|
||||||
|
|
||||||
|
// Min of depth 0 and input depth - in Atom the Z order is reverse
|
||||||
|
// Original value is uDepth0Prev
|
||||||
|
InterlockedMax(PassSrg::m_RWFragmentDepthsTexture[uint3(vScreenAddress, 0)], uDepth, uDepth0Prev);
|
||||||
|
|
||||||
|
// Min of depth 1 and greater of the last compare - in Atom the Z order is reverse
|
||||||
|
// If fragment opaque, always use input depth (don't need greater depths)
|
||||||
|
uDepth = (alpha > 0.98) ? uDepth : max(uDepth, uDepth0Prev);
|
||||||
|
|
||||||
|
InterlockedMax(PassSrg::m_RWFragmentDepthsTexture[uint3(vScreenAddress, 1)], uDepth, uDepth1Prev);
|
||||||
|
|
||||||
|
// Min of depth 2 and greater of the last compare - in Atom the Z order is reverse
|
||||||
|
// If fragment opaque, always use input depth (don't need greater depths)
|
||||||
|
uDepth = (alpha > 0.98) ? uDepth : max(uDepth, uDepth1Prev);
|
||||||
|
|
||||||
|
InterlockedMax(PassSrg::m_RWFragmentDepthsTexture[uint3(vScreenAddress, 2)], uDepth, uDepth2Prev);
|
||||||
|
|
||||||
|
// Accumulate the alpha multiplication from all hair components by multiplying the inverse and
|
||||||
|
// therefore going down towards 0. At the end product, the inverse will be taken as the hair
|
||||||
|
// alpha and the remainder will be used to blend the back buffer.
|
||||||
|
return 1.0 - alpha;
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"Source" : "HairShortCutGeometryDepthAlpha.azsl",
|
||||||
|
"DrawList" : "HairGeometryDepthAlphaDrawList",
|
||||||
|
|
||||||
|
"DepthStencilState" :
|
||||||
|
{
|
||||||
|
"Depth" :
|
||||||
|
{
|
||||||
|
"Enable" : true,
|
||||||
|
"WriteMask" : "Zero", // Avoid writing the depth
|
||||||
|
"CompareFunc" : "GreaterEqual"
|
||||||
|
// Originally in TressFX this is LessEqual - Atom is using reverse sort
|
||||||
|
},
|
||||||
|
"Stencil" :
|
||||||
|
{
|
||||||
|
"Enable" : false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"BlendState" :
|
||||||
|
{
|
||||||
|
"Enable" : true,
|
||||||
|
"BlendSource" : "Zero",
|
||||||
|
"BlendDest" : "ColorSource",
|
||||||
|
"BlendOp" : "Add",
|
||||||
|
"BlendAlphaSource" : "Zero",
|
||||||
|
"BlendAlphaDest" : "AlphaSource",
|
||||||
|
"BlendAlphaOp" : "Add"
|
||||||
|
},
|
||||||
|
|
||||||
|
"ProgramSettings":
|
||||||
|
{
|
||||||
|
"EntryPoints":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "RenderHairVS",
|
||||||
|
"type": "Vertex"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "HairShortCutDepthsAlphaPS",
|
||||||
|
"type": "Fragment"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Modifications Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: (Apache-2.0 OR MIT) AND MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Shader code related to lighting and shadowing for TressFX
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <Atom/Features/SrgSemantics.azsli>
|
||||||
|
#include <HairRenderingSrgs.azsli>
|
||||||
|
|
||||||
|
#define AMD_TRESSFX_MAX_HAIR_GROUP_RENDER 16
|
||||||
|
|
||||||
|
//!------------------------------ SRG Structure --------------------------------
|
||||||
|
//! Per pass SRG that holds the dynamic shared read-write buffer shared
|
||||||
|
//! across all dispatches and draw calls. It is used for all the dynamic buffers
|
||||||
|
//! that can change between passes due to the application of skinning, simulation
|
||||||
|
//! and physics affect.
|
||||||
|
//! Once the compute pases are done, it is read by the rendering shaders.
|
||||||
|
ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
|
||||||
|
{
|
||||||
|
//! This shared buffer needs to match the SharedBuffer structure
|
||||||
|
//! shared between all draw calls / dispatches for the hair skinning
|
||||||
|
StructuredBuffer<int> m_skinnedHairSharedBuffer;
|
||||||
|
|
||||||
|
//! Per hair object material array used by the PPLL resolve pass
|
||||||
|
//! Originally in TressFXRendering.hlsl this is space 0
|
||||||
|
HairObjectShadeParams m_hairParams[AMD_TRESSFX_MAX_HAIR_GROUP_RENDER];
|
||||||
|
|
||||||
|
// Linear depth is used for getting the screen to world transform
|
||||||
|
Texture2D<float> m_linearDepth;
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
// Lighting Data
|
||||||
|
//------------------------------
|
||||||
|
Sampler LinearSampler
|
||||||
|
{ // Required by LightingData.azsli
|
||||||
|
MinFilter = Linear;
|
||||||
|
MagFilter = Linear;
|
||||||
|
MipFilter = Linear;
|
||||||
|
AddressU = Clamp;
|
||||||
|
AddressV = Clamp;
|
||||||
|
AddressW = Clamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
Texture2DArray<float> m_directionalLightShadowmap;
|
||||||
|
Texture2DArray<float> m_directionalLightExponentialShadowmap;
|
||||||
|
Texture2DArray<float> m_projectedShadowmaps;
|
||||||
|
Texture2DArray<float> m_projectedExponentialShadowmap;
|
||||||
|
Texture2D m_brdfMap;
|
||||||
|
Texture2D<uint4> m_tileLightData;
|
||||||
|
StructuredBuffer<uint> m_lightListRemapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
//! The hair objects' material array buffer used by the rendering resolve pass
|
||||||
|
#define HairParams PassSrg::m_hairParams
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
//!------------------------------ SRG Structure --------------------------------
|
||||||
|
//! Per instance/draw SRG representing dynamic read-write set of buffers
|
||||||
|
//! that are unique per instance and are shared and changed between passes due
|
||||||
|
//! to the application of skinning, simulation and physics affect.
|
||||||
|
//! It is then also read by the rendering shaders.
|
||||||
|
//! This Srg is NOT shared by the passes since it requires having barriers between
|
||||||
|
//! both passes and draw calls, instead, all buffers are allocated from a single
|
||||||
|
//! shared buffer (through BufferViews) and that buffer is then shared between
|
||||||
|
//! the passes via the PerPass Srg frequency.
|
||||||
|
ShaderResourceGroup HairDynamicDataSrg : SRG_PerObject // space 1 - per instance / object
|
||||||
|
{
|
||||||
|
Buffer<float4> m_hairVertexPositions;
|
||||||
|
Buffer<float4> m_hairVertexTangents;
|
||||||
|
|
||||||
|
//! Per hair object offset to the start location of each buffer within
|
||||||
|
//! 'm_skinnedHairSharedBuffer'. The offset is in bytes!
|
||||||
|
uint m_positionBufferOffset;
|
||||||
|
uint m_tangentBufferOffset;
|
||||||
|
};
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Allow for the code to run with minimal changes - skinning / simulation compute passes
|
||||||
|
// Usage of per-instance buffer
|
||||||
|
#define g_GuideHairVertexPositions HairDynamicDataSrg::m_hairVertexPositions
|
||||||
|
#define g_GuideHairVertexTangents HairDynamicDataSrg::m_hairVertexTangents
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <HairStrands.azsli> // VS resides here
|
||||||
|
#include <HairFullScreenUtils.azsli> // Required for world coordinates calculation
|
||||||
|
#include <HairLighting.azsli>
|
||||||
|
|
||||||
|
//!=============================================================================
|
||||||
|
//! Geometry Shading - Third Pass of ShortCut Render
|
||||||
|
//! Geometry pass that shades pixels that passes the early depth test. Due to this, it
|
||||||
|
//! is limited to the stored K near fragments due to previous depth write pass that
|
||||||
|
//! wrote the furthest depth of the K stored depths.
|
||||||
|
//! Colors are accumulated in the render target for a weighted average in final pass.
|
||||||
|
//! [To Do] - in the original short cut, the alpha is taken from the depth alpha pass
|
||||||
|
//!=============================================================================
|
||||||
|
[earlydepthstencil]
|
||||||
|
float4 HairShortCutGeometryColorPS(PS_INPUT_HAIR input) : SV_Target
|
||||||
|
{
|
||||||
|
// Strand Color read in is either the BaseMatColor, or BaseMatColor modulated with a color read from texture
|
||||||
|
// on vertex shader for base color along with modulation by the tip color
|
||||||
|
float4 strandColor = float4(input.StrandColor.rgb, MatBaseColor.a);
|
||||||
|
|
||||||
|
// If we are supporting strand UV texturing, further blend in the texture color/alpha
|
||||||
|
// Do this while computing NDC and coverage to hide latency from texture lookup
|
||||||
|
if (EnableStrandUV)
|
||||||
|
{
|
||||||
|
// Grab the uv in case we need it
|
||||||
|
float2 uv = float2(input.Tangent.w, input.StrandColor.w);
|
||||||
|
|
||||||
|
// Apply StrandUVTiling
|
||||||
|
float2 strandUV = float2(uv.x, (uv.y * StrandUVTilingFactor) - floor(uv.y * StrandUVTilingFactor));
|
||||||
|
|
||||||
|
strandColor.rgb *= StrandAlbedoTexture.Sample(LinearWrapSampler, strandUV).rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// [To Do] Hair: anti aliasing via coverage requires work and is disabled for now
|
||||||
|
// float3 vNDC = ScreenPosToNDC(PassSrg::m_linearDepth, input.Position.xy, input.Position.z);
|
||||||
|
// uint2 dimensions;
|
||||||
|
// PassSrg::m_linearDepth.GetDimensions(dimensions.x, dimensions.y);
|
||||||
|
// float2 screenCoords = saturate(pixelCoord / dimensions.xy);
|
||||||
|
// float coverage = ComputeCoverage(input.p0p1.xy, input.p0p1.zw, vNDC.xy, float2(dimensions.x, dimensions.y));
|
||||||
|
// original: float coverage = ComputeCoverage(input.p0p1.xy, input.p0p1.zw, vNDC.xy, g_vViewport.zw - g_vViewport.xy);
|
||||||
|
float coverage = 1.0;
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
float alpha = coverage;
|
||||||
|
|
||||||
|
// Update the alpha to have proper value (accounting for coverage, base alpha, and strand alpha)
|
||||||
|
alpha *= strandColor.w;
|
||||||
|
|
||||||
|
// Early out
|
||||||
|
if (alpha < SHORTCUT_MIN_ALPHA)
|
||||||
|
{
|
||||||
|
return float4(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float2 pixelCoord = input.Position.xy;
|
||||||
|
float depth = input.Position.z;
|
||||||
|
// [To Do] - the thickness will need to be corrected somehow since this technique doesn't
|
||||||
|
// keeps track of the accumulated alpha / thickness
|
||||||
|
float thickness = alpha;
|
||||||
|
float3 shadedFragment = TressFXShading(pixelCoord, depth, input.Tangent.xyz, strandColor.rgb, thickness, RenderParamsIndex);
|
||||||
|
|
||||||
|
// Color channel: Pre-multiply with alpha to create non-normalized weighted sum.
|
||||||
|
// Alpha Channel: Sum up all the hair alphas - this will be used to normalize the color
|
||||||
|
// per fragment at the next pass.
|
||||||
|
return float4(shadedFragment * alpha, alpha);
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"Source" : "HairShortCutGeometryShading.azsl",
|
||||||
|
"DrawList" : "HairGeometryShadingDrawList",
|
||||||
|
|
||||||
|
"DepthStencilState" :
|
||||||
|
{
|
||||||
|
"Depth" :
|
||||||
|
{
|
||||||
|
"Enable" : true,
|
||||||
|
"WriteMask" : "Zero", // Avoid writing the depth
|
||||||
|
"CompareFunc" : "GreaterEqual"
|
||||||
|
// Originally in TressFX this is LessEqual - Atom is using reverse sort
|
||||||
|
},
|
||||||
|
"Stencil" :
|
||||||
|
{
|
||||||
|
"Enable" : false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"BlendState" :
|
||||||
|
{
|
||||||
|
"Enable" : true,
|
||||||
|
"BlendSource" : "One",
|
||||||
|
"BlendDest" : "One",
|
||||||
|
"BlendOp" : "Add",
|
||||||
|
"BlendAlphaSource" : "One",
|
||||||
|
"BlendAlphaDest" : "One",
|
||||||
|
"BlendAlphaOp" : "Add"
|
||||||
|
},
|
||||||
|
|
||||||
|
"ProgramSettings":
|
||||||
|
{
|
||||||
|
"EntryPoints":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "RenderHairVS",
|
||||||
|
"type": "Vertex"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "HairShortCutGeometryColorPS",
|
||||||
|
"type": "Fragment"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Modifications Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: (Apache-2.0 OR MIT) AND MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Atom/Features/SrgSemantics.azsli>
|
||||||
|
#include <HairUtilities.azsli>
|
||||||
|
|
||||||
|
//!------------------------------ SRG Structure --------------------------------
|
||||||
|
//! Per pass SRG that holds the dynamic shared read-write buffer shared
|
||||||
|
//! across all dispatches and draw calls. It is used for all the dynamic buffers
|
||||||
|
//! that can change between passes due to the application of skinning, simulation
|
||||||
|
//! and physics affect.
|
||||||
|
//! Once the compute pases are done, it is read by the rendering shaders.
|
||||||
|
ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
|
||||||
|
{
|
||||||
|
// oiriginally: [[vk::binding(0, 0)]] Texture2D<float4> HaiColorTexture : register(t0, space0);
|
||||||
|
// oiriginally: [[vk::binding(1, 0)]] Texture2D<float> AccumInvAlpha : register(t1, space0);
|
||||||
|
Texture2D<float4> m_hairColorTexture;
|
||||||
|
Texture2D<float> m_accumInvAlpha;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <HairFullScreenUtils.azsli> // provides the Vertex Shader
|
||||||
|
|
||||||
|
//!=============================================================================
|
||||||
|
//! HairColorPS - Fourth Pass of ShortCut Render
|
||||||
|
//! Full-screen pass that finalizes the weighted average, and blends using the
|
||||||
|
//! accumulated 1-alpha product.
|
||||||
|
//!=============================================================================
|
||||||
|
[earlydepthstencil]
|
||||||
|
float4 HairShortCutResolveColorPS(VSOutput input) : SV_Target
|
||||||
|
{
|
||||||
|
int2 vScreenAddress = int2(input.m_position.xy);
|
||||||
|
|
||||||
|
float fInvAlpha = PassSrg::m_accumInvAlpha[vScreenAddress];
|
||||||
|
float fAlpha = 1.0 - fInvAlpha;
|
||||||
|
|
||||||
|
if (fAlpha < SHORTCUT_MIN_ALPHA)
|
||||||
|
{
|
||||||
|
// next we discard of non-hair pixels to avoid manipulating them depending
|
||||||
|
// on the alpha blend state - this is the safer and faster approach as there
|
||||||
|
// is no hair in these pixels
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 finalColor;
|
||||||
|
float weightSum = PassSrg::m_hairColorTexture[vScreenAddress].w;
|
||||||
|
|
||||||
|
// Normalize the sum of the shaded fragment from the previous pass and
|
||||||
|
// then multiply it by the alpha blend of the hairs done in the depth-alpha pass.
|
||||||
|
finalColor.xyz = PassSrg::m_hairColorTexture[vScreenAddress] * fAlpha / weightSum;
|
||||||
|
|
||||||
|
// The alpha is set to the inverse alpha of the hair so that the original
|
||||||
|
// background will be blended using this factor emulating single step alpha blend
|
||||||
|
// over the sum of all hair fragment blends.
|
||||||
|
finalColor.w = fInvAlpha;
|
||||||
|
|
||||||
|
return finalColor;
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"Source" : "HairShortCutResolveColor.azsl",
|
||||||
|
|
||||||
|
"DepthStencilState" :
|
||||||
|
{
|
||||||
|
"Depth" :
|
||||||
|
{
|
||||||
|
"Enable" : false // Avoid comparing depth
|
||||||
|
},
|
||||||
|
"Stencil" :
|
||||||
|
{
|
||||||
|
"Enable" : false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"BlendState" :
|
||||||
|
{
|
||||||
|
"Enable" : true,
|
||||||
|
"BlendSource" : "One",
|
||||||
|
"BlendDest" : "AlphaSource",
|
||||||
|
"BlendOp" : "Add",
|
||||||
|
"BlendAlphaSource" : "Zero",
|
||||||
|
"BlendAlphaDest" : "Zero",
|
||||||
|
"BlendAlphaOp" : "Add"
|
||||||
|
},
|
||||||
|
|
||||||
|
"ProgramSettings":
|
||||||
|
{
|
||||||
|
"EntryPoints":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "FullScreenVS",
|
||||||
|
"type": "Vertex"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "HairShortCutResolveColorPS",
|
||||||
|
"type": "Fragment"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Modifications Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: (Apache-2.0 OR MIT) AND MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <Atom/Features/SrgSemantics.azsli>
|
||||||
|
|
||||||
|
//!------------------------------ SRG Structure --------------------------------
|
||||||
|
//! Per pass SRG that holds the dynamic shared read-write buffer shared
|
||||||
|
//! across all dispatches and draw calls. It is used for all the dynamic buffers
|
||||||
|
//! that can change between passes due to the application of skinning, simulation
|
||||||
|
//! and physics affect.
|
||||||
|
//! Once the compute pases are done, it is read by the rendering shaders.
|
||||||
|
ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
|
||||||
|
{
|
||||||
|
// Originally: [[vk::binding(0, 0)]] Texture2DArray<uint> FragmentDepthsTexture : register(t0, space0);
|
||||||
|
Texture2DArray<uint> m_fragmentDepthsTexture;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <HairFullScreenUtils.azsli> // provides the Vertex Shader
|
||||||
|
|
||||||
|
//!=============================================================================
|
||||||
|
//! Resolve Depth - Second Pass of ShortCut
|
||||||
|
//! Full-screen pass that writes the farthest of the stored K near depths so it
|
||||||
|
//! could be used for depth culling during the following geometry shading pass.
|
||||||
|
//!=============================================================================
|
||||||
|
float HairShortCutResolveDepthPS(VSOutput input) : SV_Depth
|
||||||
|
{
|
||||||
|
// Blend the layers of fragments from back to front
|
||||||
|
int2 vScreenAddress = int2(input.m_position.xy);
|
||||||
|
|
||||||
|
// Write farthest depth value for culling in the next pass.
|
||||||
|
// It may be the initial value of 1.0 if there were not enough fragments to write all depths, but then culling not important.
|
||||||
|
const int farthestDepthIndex = 2;
|
||||||
|
uint uDepth = PassSrg::m_fragmentDepthsTexture[uint3(vScreenAddress, farthestDepthIndex)];
|
||||||
|
|
||||||
|
// The following line is writing the depth into the actual depth buffer
|
||||||
|
return asfloat(uDepth);
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"Source" : "HairShortCutResolveDepth.azsl",
|
||||||
|
|
||||||
|
"DepthStencilState" :
|
||||||
|
{
|
||||||
|
"Depth" :
|
||||||
|
{
|
||||||
|
"Enable" : true, // test the written depth and accept/discard based on the depth buffer
|
||||||
|
"CompareFunc" : "GreaterEqual"
|
||||||
|
// Originally in TressFX this is LessEqual - Atom is using reverse sort
|
||||||
|
},
|
||||||
|
"Stencil" :
|
||||||
|
{
|
||||||
|
"Enable" : false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"BlendState" :
|
||||||
|
{
|
||||||
|
"Enable" : false
|
||||||
|
},
|
||||||
|
|
||||||
|
"ProgramSettings":
|
||||||
|
{
|
||||||
|
"EntryPoints":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "FullScreenVS",
|
||||||
|
"type": "Vertex"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "HairShortCutResolveDepthPS",
|
||||||
|
"type": "Fragment"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Atom/RPI.Reflect/Pass/RasterPassData.h>
|
||||||
|
#include <Atom/RPI.Reflect/Pass/PassTemplate.h>
|
||||||
|
#include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
|
||||||
|
|
||||||
|
#include <Passes/HairShortCutGeometryDepthAlphaPass.h>
|
||||||
|
#include <Rendering/HairRenderObject.h>
|
||||||
|
#include <Rendering/HairFeatureProcessor.h>
|
||||||
|
|
||||||
|
namespace AZ
|
||||||
|
{
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
namespace Hair
|
||||||
|
{
|
||||||
|
|
||||||
|
HairShortCutGeometryDepthAlphaPass::HairShortCutGeometryDepthAlphaPass(const RPI::PassDescriptor& descriptor)
|
||||||
|
: HairGeometryRasterPass(descriptor)
|
||||||
|
{
|
||||||
|
SetShaderPath("Shaders/hairshortcutgeometrydepthalpha.azshader");
|
||||||
|
}
|
||||||
|
|
||||||
|
RPI::Ptr<HairShortCutGeometryDepthAlphaPass> HairShortCutGeometryDepthAlphaPass::Create(const RPI::PassDescriptor& descriptor)
|
||||||
|
{
|
||||||
|
RPI::Ptr<HairShortCutGeometryDepthAlphaPass> pass = aznew HairShortCutGeometryDepthAlphaPass(descriptor);
|
||||||
|
return pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HairShortCutGeometryDepthAlphaPass::BuildInternal()
|
||||||
|
{
|
||||||
|
RasterPass::BuildInternal(); // change this to call parent if the method exists
|
||||||
|
|
||||||
|
if (!AcquireFeatureProcessor())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadShaderAndPipelineState();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Hair
|
||||||
|
} // namespace Render
|
||||||
|
} // namespace AZ
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Passes/HairGeometryRasterPass.h>
|
||||||
|
|
||||||
|
namespace AZ
|
||||||
|
{
|
||||||
|
namespace RHI
|
||||||
|
{
|
||||||
|
struct DrawItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
namespace Hair
|
||||||
|
{
|
||||||
|
//! This geometry pass uses the following Srgs:
|
||||||
|
//! - PerPassSrg shared by all hair passes for the shared dynamic buffer
|
||||||
|
//! - PerMaterialSrg - used solely by this pass to alter the vertices and apply the visual
|
||||||
|
//! hair properties to each fragment.
|
||||||
|
//! - HairDynamicDataSrg (PerObjectSrg) - shared buffers views for this hair object only.
|
||||||
|
//! - PerViewSrg and PerSceneSrg - as per the data from Atom.
|
||||||
|
class HairShortCutGeometryDepthAlphaPass
|
||||||
|
: public HairGeometryRasterPass
|
||||||
|
{
|
||||||
|
AZ_RPI_PASS(HairShortCutGeometryDepthAlphaPass);
|
||||||
|
|
||||||
|
public:
|
||||||
|
AZ_RTTI(HairShortCutGeometryDepthAlphaPass, "{F09A0411-B1FF-4085-98E7-6B8B0E1B2C3D}", HairGeometryRasterPass);
|
||||||
|
AZ_CLASS_ALLOCATOR(HairShortCutGeometryDepthAlphaPass, SystemAllocator, 0);
|
||||||
|
|
||||||
|
static RPI::Ptr<HairShortCutGeometryDepthAlphaPass> Create(const RPI::PassDescriptor& descriptor);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit HairShortCutGeometryDepthAlphaPass(const RPI::PassDescriptor& descriptor);
|
||||||
|
|
||||||
|
// Pass behavior overrides
|
||||||
|
void BuildInternal() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Hair
|
||||||
|
} // namespace Render
|
||||||
|
} // namespace AZ
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Atom/RPI.Reflect/Pass/RasterPassData.h>
|
||||||
|
#include <Atom/RPI.Reflect/Pass/PassTemplate.h>
|
||||||
|
#include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
|
||||||
|
|
||||||
|
#include <Passes/HairShortCutGeometryShadingPass.h>
|
||||||
|
#include <Rendering/HairRenderObject.h>
|
||||||
|
#include <Rendering/HairFeatureProcessor.h>
|
||||||
|
|
||||||
|
namespace AZ
|
||||||
|
{
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
namespace Hair
|
||||||
|
{
|
||||||
|
|
||||||
|
HairShortCutGeometryShadingPass::HairShortCutGeometryShadingPass(const RPI::PassDescriptor& descriptor)
|
||||||
|
: HairGeometryRasterPass(descriptor)
|
||||||
|
{
|
||||||
|
o_enableShadows = AZ::Name("o_enableShadows");
|
||||||
|
o_enableDirectionalLights = AZ::Name("o_enableDirectionalLights");
|
||||||
|
o_enablePunctualLights = AZ::Name("o_enablePunctualLights");
|
||||||
|
o_enableAreaLights = AZ::Name("o_enableAreaLights");
|
||||||
|
o_enableIBL = AZ::Name("o_enableIBL");
|
||||||
|
o_hairLightingModel = AZ::Name("o_hairLightingModel");
|
||||||
|
o_enableMarschner_R = AZ::Name("o_enableMarschner_R");
|
||||||
|
o_enableMarschner_TRT = AZ::Name("o_enableMarschner_TRT");
|
||||||
|
o_enableMarschner_TT = AZ::Name("o_enableMarschner_TT");
|
||||||
|
o_enableLongtitudeCoeff = AZ::Name("o_enableLongtitudeCoeff");
|
||||||
|
o_enableAzimuthCoeff = AZ::Name("o_enableAzimuthCoeff");
|
||||||
|
|
||||||
|
SetShaderPath("Shaders/hairshortcutgeometryshading.azshader");
|
||||||
|
}
|
||||||
|
|
||||||
|
RPI::Ptr<HairShortCutGeometryShadingPass> HairShortCutGeometryShadingPass::Create(const RPI::PassDescriptor& descriptor)
|
||||||
|
{
|
||||||
|
RPI::Ptr<HairShortCutGeometryShadingPass> pass = aznew HairShortCutGeometryShadingPass(descriptor);
|
||||||
|
return pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HairShortCutGeometryShadingPass::UpdateGlobalShaderOptions()
|
||||||
|
{
|
||||||
|
RPI::ShaderOptionGroup shaderOption = m_shader->CreateShaderOptionGroup();
|
||||||
|
|
||||||
|
m_featureProcessor->GetHairGlobalSettings(m_hairGlobalSettings);
|
||||||
|
|
||||||
|
shaderOption.SetValue(o_enableShadows, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableShadows });
|
||||||
|
shaderOption.SetValue(o_enableDirectionalLights, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableDirectionalLights });
|
||||||
|
shaderOption.SetValue(o_enablePunctualLights, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enablePunctualLights });
|
||||||
|
shaderOption.SetValue(o_enableAreaLights, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableAreaLights });
|
||||||
|
shaderOption.SetValue(o_enableIBL, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableIBL });
|
||||||
|
shaderOption.SetValue(o_hairLightingModel, AZ::Name{ "HairLightingModel::" + AZStd::string(HairLightingModelNamespace::ToString(m_hairGlobalSettings.m_hairLightingModel)) });
|
||||||
|
shaderOption.SetValue(o_enableMarschner_R, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableMarschner_R });
|
||||||
|
shaderOption.SetValue(o_enableMarschner_TRT, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableMarschner_TRT });
|
||||||
|
shaderOption.SetValue(o_enableMarschner_TT, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableMarschner_TT });
|
||||||
|
shaderOption.SetValue(o_enableLongtitudeCoeff, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableLongtitudeCoeff });
|
||||||
|
shaderOption.SetValue(o_enableAzimuthCoeff, AZ::RPI::ShaderOptionValue{ m_hairGlobalSettings.m_enableAzimuthCoeff });
|
||||||
|
|
||||||
|
m_shaderOptions = shaderOption.GetShaderVariantKeyFallbackValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HairShortCutGeometryShadingPass::CompileResources(const RHI::FrameGraphCompileContext& context)
|
||||||
|
{
|
||||||
|
if (!m_shaderResourceGroup || !AcquireFeatureProcessor())
|
||||||
|
{
|
||||||
|
AZ_Error("Hair Gem", m_shaderResourceGroup, "HairShortCutGeometryShadingPass: missing Srg or no feature processor yet");
|
||||||
|
return; // no error message due to FP - initialization not complete yet, wait for the next frame
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateGlobalShaderOptions();
|
||||||
|
|
||||||
|
if (m_shaderResourceGroup->HasShaderVariantKeyFallbackEntry())
|
||||||
|
{
|
||||||
|
m_shaderResourceGroup->SetShaderVariantKeyFallbackValue(m_shaderOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the material array constant buffer within the per pass srg
|
||||||
|
SrgBufferDescriptor descriptor = SrgBufferDescriptor(
|
||||||
|
RPI::CommonBufferPoolType::Constant, RHI::Format::Unknown,
|
||||||
|
sizeof(AMD::TressFXShadeParams), 1,
|
||||||
|
Name{ "HairMaterialsArray" }, Name{ "m_hairParams" }, 0, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
m_featureProcessor->GetMaterialsArray().UpdateGPUData(m_shaderResourceGroup, descriptor);
|
||||||
|
|
||||||
|
// Compilation of remaining srgs will be done by the parent class
|
||||||
|
RPI::RasterPass::CompileResources(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HairShortCutGeometryShadingPass::BuildInternal()
|
||||||
|
{
|
||||||
|
RasterPass::BuildInternal(); // change this to call parent if the method exists
|
||||||
|
|
||||||
|
if (!AcquireFeatureProcessor())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadShaderAndPipelineState();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Hair
|
||||||
|
} // namespace Render
|
||||||
|
} // namespace AZ
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Passes/HairGeometryRasterPass.h>
|
||||||
|
#include <Rendering/HairGlobalSettings.h>
|
||||||
|
|
||||||
|
namespace AZ
|
||||||
|
{
|
||||||
|
namespace RHI
|
||||||
|
{
|
||||||
|
struct DrawItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
namespace Hair
|
||||||
|
{
|
||||||
|
//! This geometry pass uses the following Srgs:
|
||||||
|
//! - PerPassSrg shared by all hair passes for the shared dynamic buffer
|
||||||
|
//! - PerMaterialSrg - used solely by this pass to alter the vertices and apply the visual
|
||||||
|
//! hair properties to each fragment.
|
||||||
|
//! - HairDynamicDataSrg (PerObjectSrg) - shared buffers views for this hair object only.
|
||||||
|
//! - PerViewSrg and PerSceneSrg - as per the data from Atom.
|
||||||
|
class HairShortCutGeometryShadingPass
|
||||||
|
: public HairGeometryRasterPass
|
||||||
|
{
|
||||||
|
AZ_RPI_PASS(HairShortCutGeometryShadingPass);
|
||||||
|
|
||||||
|
public:
|
||||||
|
AZ_RTTI(HairShortCutGeometryShadingPass, "{11BA673D-0788-4B25-978D-9737BF4E48FE}", HairGeometryRasterPass);
|
||||||
|
AZ_CLASS_ALLOCATOR(HairShortCutGeometryShadingPass, SystemAllocator, 0);
|
||||||
|
|
||||||
|
static RPI::Ptr<HairShortCutGeometryShadingPass> Create(const RPI::PassDescriptor& descriptor);
|
||||||
|
|
||||||
|
void CompileResources(const RHI::FrameGraphCompileContext& context) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
AZ::Name o_enableShadows;
|
||||||
|
AZ::Name o_enableDirectionalLights;
|
||||||
|
AZ::Name o_enablePunctualLights;
|
||||||
|
AZ::Name o_enableAreaLights;
|
||||||
|
AZ::Name o_enableIBL;
|
||||||
|
AZ::Name o_hairLightingModel;
|
||||||
|
AZ::Name o_enableMarschner_R;
|
||||||
|
AZ::Name o_enableMarschner_TRT;
|
||||||
|
AZ::Name o_enableMarschner_TT;
|
||||||
|
AZ::Name o_enableLongtitudeCoeff;
|
||||||
|
AZ::Name o_enableAzimuthCoeff;
|
||||||
|
|
||||||
|
explicit HairShortCutGeometryShadingPass(const RPI::PassDescriptor& descriptor);
|
||||||
|
|
||||||
|
void UpdateGlobalShaderOptions();
|
||||||
|
|
||||||
|
// Pass behavior overrides
|
||||||
|
void BuildInternal() override;
|
||||||
|
|
||||||
|
HairGlobalSettings m_hairGlobalSettings;
|
||||||
|
AZ::RPI::ShaderVariantKey m_shaderOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Hair
|
||||||
|
} // namespace Render
|
||||||
|
} // namespace AZ
|
||||||
Loading…
Reference in New Issue