Обводка выбранного объекта

This commit is contained in:
Ковалев Роман Евгеньевич 2023-04-03 18:19:18 +03:00 committed by re.kovalev
parent 68a8f4d0d0
commit 329bea7124
2 changed files with 24 additions and 1 deletions

View File

@ -40,6 +40,9 @@ uniform sampler2D gAmbientSpecular;
uniform sampler2DArray sunShadowDepth;
uniform samplerCubeArray pointShadowDepth;
uniform sampler2D ssao;
uniform usampler2D gID;
uniform uvec3 selectedID;
layout(std140, binding = 4) uniform gamma
{
@ -198,4 +201,21 @@ void main()
// Применение гамма-коррекции
color.rgb = pow(color.rgb, vec3(inv_gamma));
vec3 ID = texture(gID, texCoord).rgb;
// Обводка выбранного объекта
if (length(selectedID.rg) > 0 && selectedID.rg == ID.rg && ID.b == 0)
{
int border_width = 3;
vec2 size = 1.0f / textureSize(gID, 0);
for (int i = -border_width; i <= +border_width; i++)
for (int j = -border_width; j <= +border_width; j++)
{
if (i == 0 && j == 0)
continue;
if (texture(gID, texCoord + vec2(i, j) * size).rg != selectedID.rg)
color.rgb = vec3(1.0);
}
}
}

View File

@ -209,7 +209,7 @@ int main(void)
lightShader.load(GL_FRAGMENT_SHADER, "shaders/lighting.frag");
lightShader.link();
// Привязка текстур
const char* gtextures_shader_names[] = {"gPosition", "gNormal", "gDiffuseP", "gAmbientSpecular", "sunShadowDepth", "pointShadowDepth", "ssao"};
const char* gtextures_shader_names[] = {"gPosition", "gNormal", "gDiffuseP", "gAmbientSpecular", "sunShadowDepth", "pointShadowDepth", "ssao", "gID"};
lightShader.bindTextures(gtextures_shader_names, sizeof(gtextures_shader_names)/sizeof(const char*));
// Загрузка данных о границах каскадов
glUniform1fv(lightShader.getUniformLoc("camera_cascade_distances"), CAMERA_CASCADE_COUNT, &camera_cascade_distances[1]);
@ -529,6 +529,9 @@ int main(void)
gNormal.use();
gDiffuseP.use();
gAmbientSpecular.use();
gID.use();
// Идентификатор выбранного объекта для обводки
glUniform3uiv(lightShader.getUniformLoc("selectedID"), 1, (GLuint*) &selected);
// Подключаем текстуры теней
sunShadowDepth.use();
pointShadowDepth.use();