forked from LukasBanana/LLGL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.CSRelaxation.450core.comp
59 lines (48 loc) · 1.19 KB
/
Example.CSRelaxation.450core.comp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// GLSL Compute Shader "CSRelaxation"
// Generated by XShaderCompiler
// 11/10/2019 20:18:28
#version 450 core
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(std140, row_major, binding = 0) uniform SceneState
{
mat4 wvpMatrix;
mat4 wMatrix;
vec4 gravity;
uvec2 gridSize;
uvec2 _pad0;
float damping;
float dTime;
float dStiffness;
float _pad1;
vec4 lightVec;
};
// Particle buffers
layout(std430, binding = 2) buffer parCurrPos
{
vec4 g_parCurrPos[];
};
layout(std430, binding = 3) buffer parNextPos
{
vec4 g_parNextPos[];
};
layout(std430, binding = 4) buffer parPrevPos
{
vec4 g_parPrevPos[];
};
layout(std430, binding = 5) writeonly buffer parVelocity
{
vec4 g_parVelocity[];
};
// Returns the particle index for the specified grid
uint GridPosToIndex(uvec2 gridPos)
{
return (gridPos.y * gridSize.x + gridPos.x);
}
void main()
{
uint idx = GridPosToIndex(gl_GlobalInvocationID.xy);
// Adjust velocity and store current and previous position
g_parCurrPos[idx] = g_parNextPos[idx];
g_parVelocity[idx] = (g_parCurrPos[idx] - g_parPrevPos[idx]) / dTime;
g_parPrevPos[idx] = g_parCurrPos[idx];
}