Files
Vulkan-Samples/shaders/synchronization_2/hlsl/particle_integrate.comp.hlsl
T
2025-09-04 10:54:47 +08:00

44 lines
1.2 KiB
HLSL

/* Copyright (c) 2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
struct Particle
{
float4 pos;
float4 vel;
};
[[vk::binding(0, 0)]]
RWStructuredBuffer<Particle> particles : register(u0);
struct UBO
{
float deltaT;
int particleCount;
};
[[vk::binding(1, 0)]]
ConstantBuffer<UBO> ubo : register(b1);
#define TIME_FACTOR 0.05
[numthreads(256, 1, 1)]
void main(uint3 GlobalInvocationID : SV_DispatchThreadID)
{
int index = int(GlobalInvocationID.x);
float4 position = particles[index].pos;
float4 velocity = particles[index].vel;
position += ubo.deltaT * TIME_FACTOR * velocity;
particles[index].pos = position;
}