Skip to content

Commit

Permalink
PopcornFX Gem 2.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PopcornFX Bot committed Oct 7, 2024
1 parent 8fc9708 commit 2be0aca
Show file tree
Hide file tree
Showing 49 changed files with 2,203 additions and 103 deletions.
68 changes: 43 additions & 25 deletions Assets/shaders/Billboard/Default/Billboard.azsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

#include <scenesrg.srgi>
#include <viewsrg.srgi>
#include <Atom/Features/SrgSemantics.azsli>

#include "../../Common/PopcornOptions.azsli"
#include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>

#include "../../Common/MaterialSrg.azsli"

// Billboarding shader:
#include "../../Common/ComputeBillboardVertex.azsli"
// Material:
#include "../../Common/MaterialSrg.azsli"
#include "../../Common/RendererFeatures.azsli"

option bool o_hasDiffuse;
option bool o_hasEmissive;
Expand All @@ -24,11 +28,13 @@ struct VertexInput
struct VertexOutput
{
float4 m_position : SV_Position;
float2 m_texCoords0 : UV0;
float2 m_texCoords1 : UV1;
float2 m_texCoord0 : UV0;
float2 m_texCoord1 : UV1;
float m_texFrameLerp : UV2;
float4 m_diffuseColor : COLOR0;
float3 m_emissiveColor : COLOR1;
float4 m_emissiveColor : COLOR1;
float m_alphaCursor : UV3;
float4 m_clipPosition : UV4;
};

VertexOutput BillboardVS(VertexInput input)
Expand All @@ -45,13 +51,21 @@ VertexOutput BillboardVS(VertexInput input)
ComputeBillboardVertex(particleIdx, input.m_uv, vtxWorldPos, vtxUV0, vtxUV1, vtxTexFrameLerp);

output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(vtxWorldPos, 1.0f));
output.m_texCoords0 = vtxUV0;
output.m_clipPosition = output.m_position;
output.m_texCoord0 = vtxUV0;

// Atlas animation blending:
output.m_texCoord1 = float2(0, 0);
output.m_texFrameLerp = 0;
if (HasOneRendererFlags(Has_AnimBlend))
{
output.m_texCoord1 = vtxUV1;
output.m_texFrameLerp = vtxTexFrameLerp;
output.m_texCoords1 = vtxUV1;
}
// Alpha remap:
output.m_alphaCursor = 0;
if (HasOneRendererFlags(Has_AlphaRemap))
output.m_alphaCursor = RendererSrg::m_alphaCursors[particleIdx];

// Get additional fields:
if (o_hasDiffuse)
Expand All @@ -60,8 +74,9 @@ VertexOutput BillboardVS(VertexInput input)
}
if (o_hasEmissive)
{
output.m_emissiveColor = RendererSrg::m_emissiveColors[particleIdx];
output.m_emissiveColor = GetEmissiveParticleColor(particleIdx);
}

return output;
}

Expand All @@ -73,33 +88,36 @@ struct PixelOutput
PixelOutput BillboardFS(VertexOutput input)
{
PixelOutput output;

float4 diffuseColor = float4(0, 0, 0, 0);
float4 emissiveColor = float4(0, 0, 0, 0);

if (o_hasDiffuse)
{
float4 texColor = MaterialSrg::m_diffuseMap.Sample(MaterialSrg::m_sampler, input.m_texCoords0);
if (HasOneRendererFlags(Has_AnimBlend_Linear))
{
float4 texColor1 = MaterialSrg::m_diffuseMap.Sample(MaterialSrg::m_sampler, input.m_texCoords1);
texColor = lerp(texColor, texColor1, input.m_texFrameLerp);
}
diffuseColor = texColor;
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)
{
float4 texColor = MaterialSrg::m_emissiveMap.Sample(MaterialSrg::m_sampler, input.m_texCoords0);
if (HasOneRendererFlags(Has_AnimBlend_Linear))
{
float4 texColor1 = MaterialSrg::m_emissiveMap.Sample(MaterialSrg::m_sampler, input.m_texCoords1);
texColor = lerp(texColor, texColor1, input.m_texFrameLerp);
}
emissiveColor = texColor;
emissiveColor.rgb *= input.m_emissiveColor;
emissiveColor = GetEmissiveColor(input.m_texCoord0);
emissiveColor *= input.m_emissiveColor;
}

if (HasOneRendererFlags(Has_Soft))
{
float3 clipPos = input.m_clipPosition.xyz / input.m_clipPosition.w;
float fade = GetSoftParticleFade(clipPos);
diffuseColor *= fade;
emissiveColor *= fade;
}

output.m_color = float4(diffuseColor.rgb * diffuseColor.a + emissiveColor.rgb * emissiveColor.a, diffuseColor.a);
return output;
}
}

167 changes: 167 additions & 0 deletions Assets/shaders/Billboard/Default/BillboardLit.azsl
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);
}
55 changes: 55 additions & 0 deletions Assets/shaders/Billboard/Default/BillboardLit.shader
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"
}
Loading

0 comments on commit 2be0aca

Please sign in to comment.