/
particle.vs.glsl
61 lines (47 loc) · 1.52 KB
/
particle.vs.glsl
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
59
60
61
#version 460 core
#include "particle.h"
layout(std430, binding = 0) readonly restrict buffer ParticlesShareds
{
ParticleSharedData particlesShared[];
};
layout(std430, binding = 1) readonly restrict buffer ParticlesUpdate
{
ParticleUpdateData particlesUpdate[];
};
layout(std430, binding = 2) readonly restrict buffer ParticlesRender
{
ParticleRenderData particlesRender[];
};
layout(std430, binding = 3) readonly restrict buffer DrawIndices
{
uint drawIndices[];
};
layout(location = 0) uniform mat4 u_viewProj;
layout(location = 1) uniform vec3 u_cameraRight;
layout(location = 2) uniform vec3 u_cameraUp;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec4 vColor;
// vertices in [0, 1]
vec2 CreateQuad(in uint vertexID) // triangle fan
{
uint b = 1 << vertexID;
return vec2((0x3 & b) != 0, (0x9 & b) != 0);
}
void main()
{
vTexCoord = CreateQuad(gl_VertexID);
vec2 aPos = vTexCoord - 0.5;
int index = int(drawIndices[gl_InstanceID]);
//int index = gl_InstanceID;
ParticleSharedData psd = particlesShared[index];
ParticleRenderData prd = particlesRender[index];
vec2 scale = unpackHalf2x16(prd.packedScaleX_packedColorY.x);
vColor = unpackUnorm4x8(prd.packedScaleX_packedColorY.y);
//vec2 scale = prd.scale.xy;
//vColor = prd.color;
vec3 vertexPosition_worldspace =
psd.position.xyz +
u_cameraRight * aPos.x * scale.x +
u_cameraUp * aPos.y * scale.y;
gl_Position = u_viewProj * vec4(vertexPosition_worldspace, 1.0);
}