From 329bea7124a33759e40f89c3d824faf332f9089c Mon Sep 17 00:00:00 2001 From: "R.E. Kovalev" Date: Mon, 3 Apr 2023 18:19:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=B2=D0=BE=D0=B4=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B1=D1=80=D0=B0=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shaders/lighting.frag | 20 ++++++++++++++++++++ src/main.cpp | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/shaders/lighting.frag b/shaders/lighting.frag index 87944d3..9f83932 100644 --- a/shaders/lighting.frag +++ b/shaders/lighting.frag @@ -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); + } + } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a299e1e..dbce366 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -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();