Move shaders into glsl and hlsl directories

Move `data/shaders` to `data/shaders/glsl`
Move `data/hlsl` to `data/shaders/hlsl`

Fix up shader paths in the cpp files to point to the new glsl location.

`data/shaders/hlsl/compile.py` still overwrites the glsl .spv files (for
now).

Issue: #723
This commit is contained in:
Ben Clayton 2020-05-29 16:08:53 +01:00
parent cac1d2e850
commit ca884587a4
1043 changed files with 1207 additions and 1201 deletions

View file

@ -0,0 +1,74 @@
// Copyright 2020 Google LLC
struct Particle
{
float2 pos;
float2 vel;
float4 gradientPos;
};
// Binding 0 : Position storage buffer
RWStructuredBuffer<Particle> particles : register(u0);
struct UBO
{
float deltaT;
float destX;
float destY;
int particleCount;
};
cbuffer ubo : register(b1) { UBO ubo; }
float2 attraction(float2 pos, float2 attractPos)
{
float2 delta = attractPos - pos;
const float damp = 0.5;
float dDampedDot = dot(delta, delta) + damp;
float invDist = 1.0f / sqrt(dDampedDot);
float invDistCubed = invDist*invDist*invDist;
return delta * invDistCubed * 0.0035;
}
float2 repulsion(float2 pos, float2 attractPos)
{
float2 delta = attractPos - pos;
float targetDistance = sqrt(dot(delta, delta));
return delta * (1.0 / (targetDistance * targetDistance * targetDistance)) * -0.000035;
}
[numthreads(256, 1, 1)]
void main(uint3 GlobalInvocationID : SV_DispatchThreadID)
{
// Current SSBO index
uint index = GlobalInvocationID.x;
// Don't try to write beyond particle count
if (index >= ubo.particleCount)
return;
// Read position and velocity
float2 vVel = particles[index].vel.xy;
float2 vPos = particles[index].pos.xy;
float2 destPos = float2(ubo.destX, ubo.destY);
float2 delta = destPos - vPos;
float targetDistance = sqrt(dot(delta, delta));
vVel += repulsion(vPos, destPos.xy) * 0.05;
// Move by velocity
vPos += vVel * ubo.deltaT;
// collide with boundary
if ((vPos.x < -1.0) || (vPos.x > 1.0) || (vPos.y < -1.0) || (vPos.y > 1.0))
vVel = (-vVel * 0.1) + attraction(vPos, destPos) * 12;
else
particles[index].pos.xy = vPos;
// Write back
particles[index].vel.xy = vVel;
particles[index].gradientPos.x += 0.02 * ubo.deltaT;
if (particles[index].gradientPos.x > 1.0)
particles[index].gradientPos.x -= 1.0;
}

View file

@ -0,0 +1,22 @@
// Copyright 2020 Google LLC
Texture2D textureColorMap : register(t0);
SamplerState samplerColorMap : register(s0);
Texture2D textureGradientRamp : register(t1);
SamplerState samplerGradientRamp : register(s1);
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float4 Color : COLOR0;
[[vk::location(1)]] float GradientPos : POSITION0;
[[vk::location(2)]] float2 CenterPos : POSITION1;
[[vk::location(3)]] float PointSize : TEXCOORD0;
};
float4 main (VSOutput input) : SV_TARGET
{
float3 color = textureGradientRamp.Sample(samplerGradientRamp, float2(input.GradientPos, 0.0)).rgb;
float2 PointCoord = (input.Pos.xy - input.CenterPos.xy) / input.PointSize + 0.5;
return float4(textureColorMap.Sample(samplerColorMap, PointCoord).rgb * color, 1.0);
}

View file

@ -0,0 +1,35 @@
// Copyright 2020 Google LLC
struct VSInput
{
[[vk::location(0)]] float2 Pos : POSITION0;
[[vk::location(1)]] float4 GradientPos : POSITION1;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::builtin("PointSize")]] float PSize : PSIZE;
[[vk::location(0)]] float4 Color : COLOR0;
[[vk::location(1)]] float GradientPos : POSITION0;
[[vk::location(2)]] float2 CenterPos : POSITION1;
[[vk::location(3)]] float PointSize : TEXCOORD0;
};
struct PushConsts
{
float2 screendim;
};
[[vk::push_constant]] PushConsts pushConstants;
VSOutput main (VSInput input)
{
VSOutput output = (VSOutput)0;
output.PSize = output.PointSize = 8.0;
output.Color = float4(0.035, 0.035, 0.035, 0.035);
output.GradientPos = input.GradientPos.x;
output.Pos = float4(input.Pos.xy, 1.0, 1.0);
output.CenterPos = ((output.Pos.xy / output.Pos.w) + 1.0) * 0.5 * pushConstants.screendim;
return output;
}