-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PopcornFX Bot
committed
Oct 7, 2024
1 parent
8fc9708
commit 2be0aca
Showing
49 changed files
with
2,203 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
//---------------------------------------------------------------------------- | ||
// Copyright Persistant Studios, SARL. All Rights Reserved. | ||
// https://www.popcornfx.com/terms-and-conditions/ | ||
//---------------------------------------------------------------------------- | ||
|
||
#include <scenesrg.srgi> | ||
#include <viewsrg.srgi> | ||
|
||
#define PK_LIT_SHADER | ||
|
||
#include "../../Common/MaterialSrg.azsli" | ||
#include "../../Common/LightingHelper.azsli" | ||
|
||
// Billboarding shader: | ||
#include "../../Common/ComputeBillboardVertex.azsli" | ||
// Material: | ||
#include "../../Common/RendererFeatures.azsli" | ||
|
||
option bool o_hasDiffuse = false; | ||
option bool o_hasEmissive = true; | ||
|
||
struct VertexInput | ||
{ | ||
float2 m_uv : POSITION; | ||
uint m_instanceID : SV_InstanceID; | ||
}; | ||
|
||
struct VSOutput | ||
{ | ||
precise float4 m_position : SV_Position; | ||
float3 m_normal: NORMAL; | ||
float3 m_tangent : TANGENT; | ||
float3 m_bitangent : BITANGENT; | ||
float3 m_worldPosition : UV0; | ||
|
||
float2 m_texCoord0 : UV1; | ||
float2 m_texCoord1 : UV2; | ||
float m_texFrameLerp : UV3; | ||
float4 m_diffuseColor : COLOR0; | ||
float4 m_emissiveColor : COLOR1; | ||
float m_alphaCursor : UV4; | ||
float4 m_clipPosition : UV5; | ||
}; | ||
|
||
VSOutput BillboardVS(VertexInput input) | ||
{ | ||
VSOutput output; | ||
uint particleIdx = RendererSrg::m_indices[GetParticleId_Sliced(input.m_instanceID)]; | ||
|
||
// Billboarding outputs: | ||
float3 vtxWorldPos; | ||
float3 vtxNormal; | ||
float4 vtxTangent; | ||
float2 vtxUV0; | ||
float2 vtxUV1; | ||
float vtxTexFrameLerp; | ||
|
||
ComputeBillboardVertex(particleIdx, input.m_uv, vtxWorldPos, vtxNormal, vtxTangent, vtxUV0, vtxUV1, vtxTexFrameLerp); | ||
|
||
// TBN: | ||
float3 vtxBitangent = cross(vtxNormal, vtxTangent.xyz) * vtxTangent.w; | ||
|
||
output.m_normal = vtxNormal; | ||
output.m_tangent = vtxTangent.xyz; | ||
output.m_bitangent = vtxBitangent; | ||
output.m_worldPosition = vtxWorldPos; | ||
output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(vtxWorldPos, 1.0f)); | ||
output.m_clipPosition = output.m_position; | ||
output.m_texCoord0 = vtxUV0; | ||
|
||
// Atlas animation blending: | ||
if (HasOneRendererFlags(Has_AnimBlend)) | ||
{ | ||
output.m_texCoord1 = vtxUV1; | ||
output.m_texFrameLerp = vtxTexFrameLerp; | ||
} | ||
else | ||
{ | ||
output.m_texCoord1 = float2(0, 0); | ||
output.m_texFrameLerp = 0; | ||
} | ||
|
||
if (HasOneRendererFlags(Has_Emissive)) | ||
output.m_emissiveColor = GetEmissiveParticleColor(particleIdx); | ||
// Alpha remap: | ||
output.m_alphaCursor = 0; | ||
if (HasOneRendererFlags(Has_AlphaRemap)) | ||
output.m_alphaCursor = RendererSrg::m_alphaCursors[particleIdx]; | ||
|
||
// Get additional fields: | ||
if (o_hasDiffuse) | ||
{ | ||
output.m_diffuseColor = RendererSrg::m_diffuseColors[particleIdx]; | ||
} | ||
if (o_hasEmissive) | ||
{ | ||
output.m_emissiveColor = GetEmissiveParticleColor(particleIdx); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
ForwardPassOutput BillboardFS(VSOutput input, bool isFrontFace : SV_IsFrontFace) | ||
{ | ||
float2 texCoord0 = input.m_texCoord0; | ||
float2 texCoord1 = input.m_texCoord1; | ||
|
||
// Motion vectors: | ||
GetMotionVectorsUV(texCoord0, texCoord1, input.m_texFrameLerp); | ||
|
||
float4 diffuseColor = float4(0, 0, 0, 0); | ||
float4 emissiveColor = float4(0, 0, 0, 0); | ||
|
||
if (o_hasDiffuse) | ||
{ | ||
diffuseColor = GetDiffuseColor(input.m_texCoord0); | ||
if (HasOneRendererFlags(Has_AlphaRemap)) | ||
diffuseColor = ApplyAlphaRemap(diffuseColor, input.m_alphaCursor); | ||
diffuseColor *= input.m_diffuseColor; | ||
diffuseColor.a = clamp(diffuseColor.a, 0, 1); | ||
|
||
ApplyOpaqueMasked(diffuseColor.a); | ||
} | ||
|
||
if (o_hasEmissive) | ||
{ | ||
emissiveColor = GetEmissiveColor(input.m_texCoord0); | ||
emissiveColor *= input.m_emissiveColor; | ||
} | ||
|
||
float3 vertexNormal = normalize(isFrontFace ? input.m_normal : -input.m_normal); | ||
float3 normal = vertexNormal; | ||
const float3 tangent = normalize(input.m_tangent); | ||
const float3 bitangent = normalize(input.m_bitangent); | ||
|
||
// Normal map: | ||
if (HasOneRendererFlags(Has_NormalMap)) | ||
{ | ||
float2 texNormal = MaterialSrg::m_normalMap.Sample(MaterialSrg::m_sampler, input.m_texCoord0).xy; | ||
if (HasOneRendererFlags(Has_AnimBlend)) | ||
{ | ||
// Lerping between normal maps is not the correct way to handle that | ||
// We should use ReorientTangentSpaceNormal instead | ||
float2 texNormal1 = MaterialSrg::m_normalMap.Sample(MaterialSrg::m_sampler, input.m_texCoord1).xy; | ||
texNormal = lerp(texNormal, texNormal1, input.m_texFrameLerp); | ||
} | ||
normal = GetWorldSpaceNormal(texNormal, normal, tangent, bitangent); | ||
} | ||
|
||
if (HasOneRendererFlags(Has_Soft)) | ||
{ | ||
float3 clipPos = input.m_clipPosition.xyz / input.m_clipPosition.w; | ||
float fade = GetSoftParticleFade(clipPos); | ||
diffuseColor *= fade; | ||
emissiveColor *= fade; | ||
} | ||
|
||
// Compute lighting: | ||
return ComputeParticleLighting( input.m_worldPosition, | ||
input.m_position, | ||
vertexNormal, | ||
normal, | ||
tangent, | ||
bitangent, | ||
diffuseColor, | ||
emissiveColor.rgb * emissiveColor.a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"Source" : "BillboardLit.azsl", | ||
|
||
"DepthStencilState" : | ||
{ | ||
"Depth" : | ||
{ | ||
"Enable" : true, | ||
"CompareFunc" : "GreaterEqual" | ||
}, | ||
"Stencil" : | ||
{ | ||
"Enable" : true, | ||
"ReadMask" : "0x00", | ||
"WriteMask" : "0xFF", | ||
"FrontFace" : | ||
{ | ||
"Func" : "Always", | ||
"DepthFailOp" : "Keep", | ||
"FailOp" : "Keep", | ||
"PassOp" : "Replace" | ||
} | ||
} | ||
}, | ||
|
||
"RasterState" : | ||
{ | ||
"CullMode" : "None" | ||
}, | ||
|
||
"GlobalTargetBlendState" : | ||
{ | ||
"Enable" : true, | ||
"BlendSource" : "One", | ||
"BlendDest" : "AlphaSourceInverse", | ||
"BlendAlphaOp" : "Add" | ||
}, | ||
|
||
"ProgramSettings": | ||
{ | ||
"EntryPoints": | ||
[ | ||
{ | ||
"name": "BillboardVS", | ||
"type": "Vertex" | ||
}, | ||
{ | ||
"name": "BillboardFS", | ||
"type": "Fragment" | ||
} | ||
] | ||
}, | ||
|
||
"DrawList" : "transparent" | ||
} |
Oops, something went wrong.