feat: add click to select
This commit is contained in:
@@ -11,7 +11,7 @@ struct InstanceData {
|
||||
mat4 transform;
|
||||
VertexBuffer vertexBuffer;
|
||||
uint materialID;
|
||||
uint padding;
|
||||
uint objectID;
|
||||
};
|
||||
|
||||
layout (buffer_reference, scalar) readonly buffer InstanceBuffer {
|
||||
|
||||
@@ -13,9 +13,23 @@ layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inNormal;
|
||||
layout (location = 3) in vec4 inTangent;
|
||||
layout (location = 4) flat in uint inMaterialID;
|
||||
layout (location = 5) flat in uint inObjectID;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
// Stable per object, the same object keeps its color between frames and runs
|
||||
vec3 selectionColor(uint objectID)
|
||||
{
|
||||
if (objectID == 0u) {
|
||||
return vec3(0.0);
|
||||
}
|
||||
uint hash = objectID * 2654435761u;
|
||||
hash ^= hash >> 15;
|
||||
hash *= 2246822519u;
|
||||
hash ^= hash >> 13;
|
||||
return vec3(hash & 255u, (hash >> 8) & 255u, (hash >> 16) & 255u) / 255.0;
|
||||
}
|
||||
|
||||
vec3 calculateNormal(MaterialData material, uint samplerID)
|
||||
{
|
||||
vec3 n = normalize(inNormal);
|
||||
@@ -127,6 +141,10 @@ void main()
|
||||
fragColor = mix(fragColor, lightHeatmapColor(tileLightCount), 0.5);
|
||||
}
|
||||
|
||||
if (pcs.sceneData.debugSelectionView != 0) {
|
||||
fragColor = selectionColor(inObjectID);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// TANGENT DEBUG
|
||||
if (inTangent == vec4(0.0)) {
|
||||
|
||||
@@ -9,6 +9,7 @@ layout (location = 1) out vec2 outUV;
|
||||
layout (location = 2) out vec3 outNormal;
|
||||
layout (location = 3) out vec4 outTangent;
|
||||
layout (location = 4) flat out uint outMaterialID;
|
||||
layout (location = 5) flat out uint outObjectID;
|
||||
|
||||
// The depth pre-pass reuses this shader, positions have to match bit for bit
|
||||
// so the main pass can depth test against it with LESS_OR_EQUAL
|
||||
@@ -34,4 +35,5 @@ void main()
|
||||
// w is the bitangent sign, the fragment shader builds the TBN from the interpolated vectors
|
||||
outTangent = vec4(mat3(instance.transform) * v.tangent.xyz, v.tangent.w);
|
||||
outMaterialID = instance.materialID;
|
||||
outObjectID = instance.objectID;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ layout (buffer_reference, scalar) readonly buffer SceneDataBuffer {
|
||||
// directional shadows
|
||||
uint shadowMapId;
|
||||
float shadowNormalOffset;
|
||||
uint padding;
|
||||
uint debugSelectionView;
|
||||
mat4 lightViewProj;
|
||||
|
||||
// spot shadows
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#version 460
|
||||
|
||||
// Same interface as mesh.vert, only the object ID is used
|
||||
layout (location = 0) in vec3 inPos;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inNormal;
|
||||
layout (location = 3) in vec4 inTangent;
|
||||
layout (location = 4) flat in uint inMaterialID;
|
||||
layout (location = 5) flat in uint inObjectID;
|
||||
|
||||
layout (location = 0) out uint outObjectID;
|
||||
|
||||
void main()
|
||||
{
|
||||
outObjectID = inObjectID;
|
||||
}
|
||||
Reference in New Issue
Block a user