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,122 @@
#version 450
layout (constant_id = 0) const int MAX_LOD_LEVEL = 5;
struct InstanceData
{
vec3 pos;
float scale;
};
// Binding 0: Instance input data for culling
layout (binding = 0, std140) buffer Instances
{
InstanceData instances[ ];
};
// Same layout as VkDrawIndexedIndirectCommand
struct IndexedIndirectCommand
{
uint indexCount;
uint instanceCount;
uint firstIndex;
uint vertexOffset;
uint firstInstance;
};
// Binding 1: Multi draw output
layout (binding = 1, std430) writeonly buffer IndirectDraws
{
IndexedIndirectCommand indirectDraws[ ];
};
// Binding 2: Uniform block object with matrices
layout (binding = 2) uniform UBO
{
mat4 projection;
mat4 modelview;
vec4 cameraPos;
vec4 frustumPlanes[6];
} ubo;
// Binding 3: Indirect draw stats
layout (binding = 3) buffer UBOOut
{
uint drawCount;
uint lodCount[MAX_LOD_LEVEL + 1];
} uboOut;
// Binding 4: level-of-detail information
struct LOD
{
uint firstIndex;
uint indexCount;
float distance;
float _pad0;
};
layout (binding = 4) readonly buffer LODs
{
LOD lods[ ];
};
layout (local_size_x = 16) in;
bool frustumCheck(vec4 pos, float radius)
{
// Check sphere against frustum planes
for (int i = 0; i < 6; i++)
{
if (dot(pos, ubo.frustumPlanes[i]) + radius < 0.0)
{
return false;
}
}
return true;
}
layout (local_size_x = 16) in;
void main()
{
uint idx = gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x;
// Clear stats on first invocation
if (idx == 0)
{
atomicExchange(uboOut.drawCount, 0);
for (uint i = 0; i < MAX_LOD_LEVEL + 1; i++)
{
atomicExchange(uboOut.lodCount[i], 0);
}
}
vec4 pos = vec4(instances[idx].pos.xyz, 1.0);
// Check if object is within current viewing frustum
if (frustumCheck(pos, 1.0))
{
indirectDraws[idx].instanceCount = 1;
// Increase number of indirect draw counts
atomicAdd(uboOut.drawCount, 1);
// Select appropriate LOD level based on distance to camera
uint lodLevel = MAX_LOD_LEVEL;
for (uint i = 0; i < MAX_LOD_LEVEL; i++)
{
if (distance(instances[idx].pos.xyz, ubo.cameraPos.xyz) < lods[i].distance)
{
lodLevel = i;
break;
}
}
indirectDraws[idx].firstIndex = lods[lodLevel].firstIndex;
indirectDraws[idx].indexCount = lods[lodLevel].indexCount;
// Update stats
atomicAdd(uboOut.lodCount[lodLevel], 1);
}
else
{
indirectDraws[idx].instanceCount = 0;
}
}

Binary file not shown.

View file

@ -0,0 +1,17 @@
#version 450
layout (location = 0) in vec3 inNormal;
layout (location = 1) in vec3 inColor;
layout (location = 2) in vec3 inViewVec;
layout (location = 3) in vec3 inLightVec;
layout (location = 0) out vec4 outFragColor;
void main()
{
vec3 N = normalize(inNormal);
vec3 L = normalize(inLightVec);
vec3 ambient = vec3(0.25);
vec3 diffuse = vec3(max(dot(N, L), 0.0));
outFragColor = vec4((ambient + diffuse) * inColor, 1.0);
}

View file

@ -0,0 +1,42 @@
#version 450
// Vertex attributes
layout (location = 0) in vec4 inPos;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec3 inColor;
// Instanced attributes
layout (location = 4) in vec3 instancePos;
layout (location = 5) in float instanceScale;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 modelview;
} ubo;
layout (location = 0) out vec3 outNormal;
layout (location = 1) out vec3 outColor;
layout (location = 2) out vec3 outViewVec;
layout (location = 3) out vec3 outLightVec;
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
{
outColor = inColor;
outNormal = inNormal;
vec4 pos = vec4((inPos.xyz * instanceScale) + instancePos, 1.0);
gl_Position = ubo.projection * ubo.modelview * pos;
vec4 wPos = ubo.modelview * vec4(pos.xyz, 1.0);
vec4 lPos = vec4(0.0, 10.0, 50.0, 1.0);
outLightVec = lPos.xyz - pos.xyz;
outViewVec = -pos.xyz;
}