2023-02-22 16:39:21 +08:00
|
|
|
#version 450
|
|
|
|
#extension GL_ARB_separate_shader_objects : enable
|
|
|
|
#extension GL_ARB_shading_language_420pack : enable
|
|
|
|
#extension GL_EXT_nonuniform_qualifier : require
|
|
|
|
|
|
|
|
struct MatPropData
|
|
|
|
{
|
|
|
|
int textureIndex;
|
|
|
|
float highlightPosition;
|
2023-02-25 21:56:49 +08:00
|
|
|
float thickness;
|
2023-02-22 16:39:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GenericData
|
|
|
|
{
|
|
|
|
//! Delta time
|
|
|
|
float dt;
|
|
|
|
|
|
|
|
//! Elapsed time of the application
|
|
|
|
float elapsedTime;
|
|
|
|
|
|
|
|
//! Viewport width of the scene (excluding imgui, that means smaller than window)
|
|
|
|
uint viewportWidth;
|
|
|
|
|
|
|
|
//! Ditto but for height
|
|
|
|
uint viewportHeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
layout(location = 0) in struct
|
|
|
|
{
|
|
|
|
vec4 vertPos; // location 0
|
|
|
|
vec2 uv; // location = 1
|
|
|
|
vec4 normal; // location = 2
|
|
|
|
vec4 worldPos; // location = 3
|
|
|
|
} In;
|
|
|
|
|
|
|
|
// material stuff
|
|
|
|
layout(location = 4) flat in struct
|
|
|
|
{
|
|
|
|
int materialIndex;
|
|
|
|
uint eid;
|
|
|
|
uint lightLayerIndex;
|
|
|
|
vec3 screenSpacePos;
|
|
|
|
|
|
|
|
} In2;
|
|
|
|
|
|
|
|
layout (set = 0, binding = 0) uniform GenericDataBuffer
|
|
|
|
{
|
|
|
|
GenericData data;
|
|
|
|
} genericDataBuffer;
|
|
|
|
|
|
|
|
layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global)
|
|
|
|
layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials
|
|
|
|
{
|
|
|
|
MatPropData data[];
|
|
|
|
} MatProp;
|
|
|
|
|
|
|
|
layout(location = 0) out vec4 position;
|
|
|
|
layout(location = 1) out uint outEntityID;
|
|
|
|
layout(location = 2) out uint lightLayerIndices;
|
|
|
|
layout(location = 3) out vec4 normals;
|
|
|
|
layout(location = 4) out vec4 albedo;
|
|
|
|
layout(location = 5) out vec4 worldSpacePosition;
|
|
|
|
layout(location = 6) out vec4 objectVFX;
|
|
|
|
|
2023-02-24 08:27:04 +08:00
|
|
|
float map (float value, float srcLow, float srcHigh, float dstLow, float dstHigh)
|
|
|
|
{
|
|
|
|
return dstLow + (value - srcLow) * (dstHigh - dstLow) / (srcHigh - srcLow);
|
|
|
|
}
|
|
|
|
|
2023-02-22 16:39:21 +08:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
position = In.vertPos;
|
|
|
|
normals = In.normal;
|
|
|
|
albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
|
|
|
|
worldSpacePosition = In.worldPos;
|
|
|
|
|
|
|
|
outEntityID = In2.eid;
|
|
|
|
lightLayerIndices = In2.lightLayerIndex;
|
|
|
|
|
2023-02-25 21:56:49 +08:00
|
|
|
float vpHeight = float (In2.screenSpacePos.y) - MatProp.data[In2.materialIndex].highlightPosition;
|
2023-02-24 08:27:04 +08:00
|
|
|
vpHeight = float (int (vpHeight) % genericDataBuffer.data.viewportHeight);
|
2023-02-25 21:56:49 +08:00
|
|
|
float scanlineScale = MatProp.data[In2.materialIndex].thickness * (1.0f - In2.screenSpacePos.z) * 100.0f;
|
2023-02-22 16:39:21 +08:00
|
|
|
|
|
|
|
float lowerLimit = vpHeight - scanlineScale;
|
|
|
|
float upperLimit = vpHeight + scanlineScale;
|
|
|
|
if (gl_FragCoord.y > lowerLimit && gl_FragCoord.y < upperLimit)
|
2023-02-24 08:27:04 +08:00
|
|
|
{
|
|
|
|
float opacity = 0.0f;
|
|
|
|
opacity = map (abs (gl_FragCoord.y - vpHeight), 0.0f, upperLimit - vpHeight, 0.0f, 1.0f);
|
|
|
|
opacity = 1.0f - clamp (opacity, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
objectVFX = vec4(opacity);
|
|
|
|
}
|
2023-02-22 16:39:21 +08:00
|
|
|
else
|
|
|
|
objectVFX = vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
}
|