Renamed particle fire sample

This commit is contained in:
Sascha Willems 2023-07-16 16:03:29 +02:00
parent 384b2031a2
commit 9dcc8110cf
25 changed files with 15 additions and 15 deletions

View file

@ -0,0 +1,44 @@
// Copyright 2020 Google LLC
Texture2D textureColorMap : register(t1);
SamplerState samplerColorMap : register(s1);
Texture2D textureNormalHeightMap : register(t2);
SamplerState samplerNormalHeightMap : register(s2);
#define lightRadius 45.0
struct VSOutput
{
[[vk::location(0)]] float2 UV : TEXCOORD0;
[[vk::location(1)]] float3 LightVec : TEXCOORD2;
[[vk::location(2)]] float3 LightVecB : TEXCOORD3;
[[vk::location(3)]] float3 LightDir : TEXCOORD4;
[[vk::location(4)]] float3 ViewVec : TEXCOORD1;
};
float4 main(VSOutput input) : SV_TARGET
{
float3 specularColor = float3(0.85, 0.5, 0.0);
float invRadius = 1.0/lightRadius;
float ambient = 0.25;
float3 rgb, normal;
rgb = textureColorMap.Sample(samplerColorMap, input.UV).rgb;
normal = normalize((textureNormalHeightMap.Sample(samplerNormalHeightMap, input.UV).rgb - 0.5) * 2.0);
float distSqr = dot(input.LightVecB, input.LightVecB);
float3 lVec = input.LightVecB * rsqrt(distSqr);
float atten = max(clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0), ambient);
float diffuse = clamp(dot(lVec, normal), 0.0, 1.0);
float3 light = normalize(-input.LightVec);
float3 view = normalize(input.ViewVec);
float3 reflectDir = reflect(-light, normal);
float specular = pow(max(dot(view, reflectDir), 0.0), 4.0);
return float4((rgb * atten + (diffuse * rgb + 0.5 * specular * specularColor.rgb)) * atten, 1.0);
}

Binary file not shown.

View file

@ -0,0 +1,61 @@
// Copyright 2020 Google LLC
struct VSInput
{
[[vk::location(0)]] float3 Pos : POSITION0;
[[vk::location(1)]] float2 UV : TEXCOORD0;
[[vk::location(2)]] float3 Normal : NORMAL0;
[[vk::location(3)]] float4 Tangent : TEXCOORD1;
};
struct UBO
{
float4x4 projection;
float4x4 model;
float4x4 normal;
float4 lightPos;
};
cbuffer ubo : register(b0) { UBO ubo; }
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float2 UV : TEXCOORD0;
[[vk::location(1)]] float3 LightVec : TEXCOORD2;
[[vk::location(2)]] float3 LightVecB : TEXCOORD3;
[[vk::location(3)]] float3 LightDir : TEXCOORD4;
[[vk::location(4)]] float3 ViewVec : TEXCOORD1;
};
VSOutput main(VSInput input)
{
VSOutput output = (VSOutput)0;
float3 vertexPosition = mul(ubo.model, float4(input.Pos, 1.0)).xyz;
output.LightDir = normalize(ubo.lightPos.xyz - vertexPosition);
float3 biTangent = cross(input.Normal, input.Tangent.xyz);
// Setup (t)angent-(b)inormal-(n)ormal matrix for converting
// object coordinates into tangent space
float3x3 tbnMatrix;
tbnMatrix[0] = mul((float3x3)ubo.normal, input.Tangent);
tbnMatrix[1] = mul((float3x3)ubo.normal, biTangent);
tbnMatrix[2] = mul((float3x3)ubo.normal, input.Normal);
output.LightVec.xyz = mul(float3(ubo.lightPos.xyz - vertexPosition), tbnMatrix);
float3 lightDist = ubo.lightPos.xyz - input.Pos;
output.LightVecB.x = dot(input.Tangent, lightDist);
output.LightVecB.y = dot(biTangent, lightDist);
output.LightVecB.z = dot(input.Normal, lightDist);
output.ViewVec.x = dot(input.Tangent, input.Pos);
output.ViewVec.y = dot(biTangent, input.Pos);
output.ViewVec.z = dot(input.Normal, input.Pos);
output.UV = input.UV;
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos, 1.0)));
return output;
}

Binary file not shown.

View file

@ -0,0 +1,52 @@
// Copyright 2020 Google LLC
Texture2D textureSmoke : register(t1);
SamplerState samplerSmoke : register(s1);
Texture2D textureFire : register(t2);
SamplerState samplerFire : register(s2);
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float4 Color : COLOR0;
[[vk::location(1)]] float Alpha : TEXCOODR0;
[[vk::location(2)]] int Type : TEXCOODR1;
[[vk::location(3)]] float Rotation : TEXCOODR2;
[[vk::location(4)]] float2 CenterPos : POSITION1;
[[vk::location(5)]] float PointSize : TEXCOORD3;
};
float4 main (VSOutput input) : SV_TARGET
{
float4 color;
float alpha = (input.Alpha <= 1.0) ? input.Alpha : 2.0 - input.Alpha;
// Rotate texture coordinates
// Rotate UV
float rotCenter = 0.5;
float rotCos = cos(input.Rotation);
float rotSin = sin(input.Rotation);
float2 PointCoord = (input.Pos.xy - input.CenterPos.xy) / input.PointSize + 0.5;
float2 rotUV = float2(
rotCos * (PointCoord.x - rotCenter) + rotSin * (PointCoord.y - rotCenter) + rotCenter,
rotCos * (PointCoord.y - rotCenter) - rotSin * (PointCoord.x - rotCenter) + rotCenter);
float4 outFragColor;
if (input.Type == 0)
{
// Flame
color = textureFire.Sample(samplerFire, rotUV);
outFragColor.a = 0.0;
}
else
{
// Smoke
color = textureSmoke.Sample(samplerSmoke, rotUV);
outFragColor.a = color.a * alpha;
}
outFragColor.rgb = color.rgb * input.Color.rgb * alpha;
return outFragColor;
}

Binary file not shown.

View file

@ -0,0 +1,54 @@
// Copyright 2020 Google LLC
struct VSInput
{
[[vk::location(0)]] float4 Pos : POSITION0;
[[vk::location(1)]] float4 Color : COLOR0;
[[vk::location(2)]] float Alpha : TEXCOORD0;
[[vk::location(3)]] float Size : TEXCOORD1;
[[vk::location(4)]] float Rotation : TEXCOORD2;
[[vk::location(5)]] int Type : TEXCOORD3;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::builtin("PointSize")]] float PSize : PSIZE;
[[vk::location(0)]] float4 Color : COLOR0;
[[vk::location(1)]] float Alpha : TEXCOORD0;
[[vk::location(2)]] int Type : TEXCOORD1;
[[vk::location(3)]] float Rotation : TEXCOORD2;
[[vk::location(4)]] float2 CenterPos : POSITION1;
[[vk::location(5)]] float PointSize : TEXCOORD3;
};
struct UBO
{
float4x4 projection;
float4x4 modelview;
float2 viewportDim;
float pointSize;
};
cbuffer ubo : register(b0) { UBO ubo; }
VSOutput main (VSInput input)
{
VSOutput output = (VSOutput)0;
output.Color = input.Color;
output.Alpha = input.Alpha;
output.Type = input.Type;
output.Rotation = input.Rotation;
output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz, 1.0)));
// Base size of the point sprites
float spriteSize = 8.0 * input.Size;
// Scale particle size depending on camera projection
float4 eyePos = mul(ubo.modelview, float4(input.Pos.xyz, 1.0));
float4 projectedCorner = mul(ubo.projection, float4(0.5 * spriteSize, 0.5 * spriteSize, eyePos.z, eyePos.w));
output.PointSize = output.PSize = ubo.viewportDim.x * projectedCorner.x / projectedCorner.w;
output.CenterPos = ((output.Pos.xy / output.Pos.w) + 1.0) * 0.5 * ubo.viewportDim;
return output;
}

Binary file not shown.