|
@@ -3,101 +3,103 @@
|
|
|
// Code licensed under the BSD License.
|
|
// Code licensed under the BSD License.
|
|
|
// http://www.anki3d.org/LICENSE
|
|
// http://www.anki3d.org/LICENSE
|
|
|
|
|
|
|
|
|
|
+#pragma anki hlsl
|
|
|
|
|
+
|
|
|
#pragma anki mutator ANKI_TECHNIQUE 0 1
|
|
#pragma anki mutator ANKI_TECHNIQUE 0 1
|
|
|
|
|
|
|
|
#include <AnKi/Shaders/Include/ParticleTypes.h>
|
|
#include <AnKi/Shaders/Include/ParticleTypes.h>
|
|
|
#include <AnKi/Shaders/Include/MaterialTypes.h>
|
|
#include <AnKi/Shaders/Include/MaterialTypes.h>
|
|
|
#include <AnKi/Shaders/Include/GpuSceneTypes.h>
|
|
#include <AnKi/Shaders/Include/GpuSceneTypes.h>
|
|
|
-#include <AnKi/Shaders/Functions.glsl>
|
|
|
|
|
|
|
+#include <AnKi/Shaders/Functions.hlsl>
|
|
|
|
|
|
|
|
#pragma anki reflect AnKiLocalUniforms
|
|
#pragma anki reflect AnKiLocalUniforms
|
|
|
#pragma anki struct AnKiLocalUniforms
|
|
#pragma anki struct AnKiLocalUniforms
|
|
|
-#pragma anki member ANKI_RP Vec3 m_diffColor
|
|
|
|
|
-#pragma anki member ANKI_RP F32 m_roughness
|
|
|
|
|
-#pragma anki member ANKI_RP Vec3 m_specColor
|
|
|
|
|
-#pragma anki member ANKI_RP F32 m_metallic
|
|
|
|
|
-#pragma anki member ANKI_RP Vec3 m_initialEmission
|
|
|
|
|
-#pragma anki member ANKI_RP Vec3 m_finalEmission
|
|
|
|
|
|
|
+#pragma anki member RVec3 m_diffColor
|
|
|
|
|
+#pragma anki member RF32 m_roughness
|
|
|
|
|
+#pragma anki member RVec3 m_specColor
|
|
|
|
|
+#pragma anki member RF32 m_metallic
|
|
|
|
|
+#pragma anki member RVec3 m_initialEmission
|
|
|
|
|
+#pragma anki member RVec3 m_finalEmission
|
|
|
#pragma anki struct end
|
|
#pragma anki struct end
|
|
|
|
|
|
|
|
-layout(set = kMaterialSetLocal, binding = kMaterialBindingLocalUniforms, std430) buffer b_localUniforms
|
|
|
|
|
-{
|
|
|
|
|
- U32 u_localUniforms[];
|
|
|
|
|
-};
|
|
|
|
|
|
|
+[[vk::binding(kMaterialBindingLocalUniforms, kMaterialSetLocal)]] StructuredBuffer<U32> u_localUniforms;
|
|
|
|
|
+[[vk::binding(kMaterialBindingRenderableGpuView, kMaterialSetLocal)]] StructuredBuffer<RenderableGpuView>
|
|
|
|
|
+ u_renderableGpuViews;
|
|
|
|
|
+[[vk::binding(kMaterialBindingGlobalUniforms, kMaterialSetGlobal)]] ConstantBuffer<MaterialGlobalUniforms>
|
|
|
|
|
+ u_globalUniforms;
|
|
|
|
|
+[[vk::binding(kMaterialBindingFirstNonStandardLocal, kMaterialSetLocal)]] StructuredBuffer<GpuParticle> u_particles;
|
|
|
|
|
|
|
|
-layout(set = kMaterialSetLocal, binding = kMaterialBindingRenderableGpuView) uniform b_renderableGpuView
|
|
|
|
|
|
|
+struct VertIn
|
|
|
{
|
|
{
|
|
|
- RenderableGpuView u_renderableGpuViews[1];
|
|
|
|
|
|
|
+ U32 m_svVertexId : SV_VERTEXID;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-layout(set = kMaterialSetGlobal, binding = kMaterialBindingGlobalUniforms) uniform b_globalUniforms
|
|
|
|
|
|
|
+struct VertOut
|
|
|
{
|
|
{
|
|
|
- MaterialGlobalUniforms u_globalUniforms;
|
|
|
|
|
|
|
+ Vec2 m_velocity : VELOCITY;
|
|
|
|
|
+ nointerpolation RF32 m_lifeFactor : LIFE;
|
|
|
|
|
+ nointerpolation RVec3 m_normal : NORMAL;
|
|
|
|
|
+ Vec4 m_svPosition : SV_POSITION;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-layout(set = kMaterialSetLocal, binding = kMaterialBindingFirstNonStandardLocal) buffer b_particles
|
|
|
|
|
|
|
+struct FragOut
|
|
|
{
|
|
{
|
|
|
- GpuParticle u_particles[];
|
|
|
|
|
|
|
+ Vec4 m_color0 : SV_TARGET0;
|
|
|
|
|
+ Vec4 m_color1 : SV_TARGET1;
|
|
|
|
|
+ Vec4 m_color2 : SV_TARGET2;
|
|
|
|
|
+ Vec2 m_color3 : SV_TARGET3;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
#pragma anki start vert
|
|
#pragma anki start vert
|
|
|
|
|
|
|
|
-layout(location = 0) out Vec2 out_velocity;
|
|
|
|
|
-layout(location = 1) flat out ANKI_RP F32 out_lifeFactor;
|
|
|
|
|
-layout(location = 2) out flat ANKI_RP Vec3 out_normal;
|
|
|
|
|
-
|
|
|
|
|
-void main()
|
|
|
|
|
|
|
+VertOut main(VertIn input)
|
|
|
{
|
|
{
|
|
|
- const GpuParticle part = u_particles[gl_VertexIndex / 2];
|
|
|
|
|
|
|
+ VertOut output;
|
|
|
|
|
+ const GpuParticle part = u_particles[input.m_svVertexId / 2];
|
|
|
|
|
|
|
|
Vec4 crntClipPos =
|
|
Vec4 crntClipPos =
|
|
|
Vec4(transform(u_renderableGpuViews[0].m_worldTransform, Vec4(part.m_newWorldPosition, 1.0)), 1.0);
|
|
Vec4(transform(u_renderableGpuViews[0].m_worldTransform, Vec4(part.m_newWorldPosition, 1.0)), 1.0);
|
|
|
- crntClipPos = u_globalUniforms.m_viewProjectionMatrix * crntClipPos;
|
|
|
|
|
|
|
+ crntClipPos = mul(u_globalUniforms.m_viewProjectionMatrix, crntClipPos);
|
|
|
|
|
|
|
|
Vec4 prevClipPos =
|
|
Vec4 prevClipPos =
|
|
|
Vec4(transform(u_renderableGpuViews[0].m_worldTransform, Vec4(part.m_oldWorldPosition, 1.0)), 1.0);
|
|
Vec4(transform(u_renderableGpuViews[0].m_worldTransform, Vec4(part.m_oldWorldPosition, 1.0)), 1.0);
|
|
|
- prevClipPos = u_globalUniforms.m_viewProjectionMatrix * prevClipPos;
|
|
|
|
|
|
|
+ prevClipPos = mul(u_globalUniforms.m_viewProjectionMatrix, prevClipPos);
|
|
|
|
|
|
|
|
- gl_Position = ((gl_VertexIndex & 1) == 0) ? crntClipPos : prevClipPos;
|
|
|
|
|
|
|
+ output.m_svPosition = ((input.m_svVertexId & 1) == 0) ? crntClipPos : prevClipPos;
|
|
|
|
|
|
|
|
const Vec2 crntNdc = crntClipPos.xy / crntClipPos.w;
|
|
const Vec2 crntNdc = crntClipPos.xy / crntClipPos.w;
|
|
|
const Vec2 prevNdc = prevClipPos.xy / prevClipPos.w;
|
|
const Vec2 prevNdc = prevClipPos.xy / prevClipPos.w;
|
|
|
|
|
|
|
|
// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:
|
|
// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:
|
|
|
- out_velocity = ((gl_VertexIndex & 1) == 0) ? Vec2(0.0) : (prevNdc - crntNdc) * 0.5;
|
|
|
|
|
|
|
+ output.m_velocity = ((input.m_svVertexId & 1) == 0) ? Vec2(0.0, 0.0) : (prevNdc - crntNdc) * 0.5;
|
|
|
|
|
|
|
|
- out_lifeFactor = saturate(1.0 - (part.m_life / part.m_startingLife));
|
|
|
|
|
|
|
+ output.m_lifeFactor = saturate(1.0 - (part.m_life / part.m_startingLife));
|
|
|
|
|
|
|
|
- out_normal = normalize(u_globalUniforms.m_cameraTransform[3]);
|
|
|
|
|
|
|
+ output.m_normal = normalize(Vec3(u_globalUniforms.m_cameraTransform[0][2], u_globalUniforms.m_cameraTransform[1][2],
|
|
|
|
|
+ u_globalUniforms.m_cameraTransform[1][2]));
|
|
|
|
|
+
|
|
|
|
|
+ return output;
|
|
|
}
|
|
}
|
|
|
#pragma anki end
|
|
#pragma anki end
|
|
|
|
|
|
|
|
#pragma anki start frag
|
|
#pragma anki start frag
|
|
|
-#define MAX_EMISSION 1024.0
|
|
|
|
|
-#include <AnKi/Shaders/PackFunctions.glsl>
|
|
|
|
|
-
|
|
|
|
|
-layout(location = 0) out Vec4 out_gbuffer0;
|
|
|
|
|
-layout(location = 1) out Vec4 out_gbuffer1;
|
|
|
|
|
-layout(location = 2) out Vec4 out_gbuffer2;
|
|
|
|
|
-layout(location = 3) out Vec2 out_gbuffer3;
|
|
|
|
|
-
|
|
|
|
|
-layout(location = 0) in Vec2 in_velocity;
|
|
|
|
|
-layout(location = 1) flat in ANKI_RP F32 in_lifeFactor;
|
|
|
|
|
-layout(location = 2) in flat ANKI_RP Vec3 in_normal;
|
|
|
|
|
|
|
+#include <AnKi/Shaders/PackFunctions.hlsl>
|
|
|
|
|
|
|
|
-void main()
|
|
|
|
|
|
|
+FragOut main(VertOut input)
|
|
|
{
|
|
{
|
|
|
|
|
+ FragOut output;
|
|
|
const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
|
|
const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
|
|
|
|
|
|
|
|
GbufferInfo g;
|
|
GbufferInfo g;
|
|
|
g.m_diffuse = localUniforms.m_diffColor;
|
|
g.m_diffuse = localUniforms.m_diffColor;
|
|
|
- g.m_normal = in_normal;
|
|
|
|
|
|
|
+ g.m_normal = input.m_normal;
|
|
|
g.m_f0 = localUniforms.m_specColor;
|
|
g.m_f0 = localUniforms.m_specColor;
|
|
|
g.m_roughness = localUniforms.m_roughness;
|
|
g.m_roughness = localUniforms.m_roughness;
|
|
|
g.m_subsurface = 0.0;
|
|
g.m_subsurface = 0.0;
|
|
|
- g.m_emission = mix(localUniforms.m_initialEmission, localUniforms.m_finalEmission, in_lifeFactor);
|
|
|
|
|
|
|
+ g.m_emission = lerp(localUniforms.m_initialEmission, localUniforms.m_finalEmission, input.m_lifeFactor);
|
|
|
g.m_metallic = localUniforms.m_metallic;
|
|
g.m_metallic = localUniforms.m_metallic;
|
|
|
- g.m_velocity = in_velocity;
|
|
|
|
|
- packGBuffer(g, out_gbuffer0, out_gbuffer1, out_gbuffer2, out_gbuffer3);
|
|
|
|
|
|
|
+ g.m_velocity = input.m_velocity;
|
|
|
|
|
+ packGBuffer(g, output.m_color0, output.m_color1, output.m_color2, output.m_color3);
|
|
|
|
|
+ return output;
|
|
|
}
|
|
}
|
|
|
#pragma anki end
|
|
#pragma anki end
|