Skip to content

Commit 0823d32

Browse files
committed
Merge branch 'render-with-outline' of https://github.com/dov/vsgExamples into dov-render-with-outline
2 parents 5cee928 + b832a94 commit 0823d32

File tree

4 files changed

+537
-0
lines changed

4 files changed

+537
-0
lines changed

data/shaders/shader_Outline.frag

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#version 450
2+
#extension GL_ARB_separate_shader_objects : enable
3+
4+
layout(binding = 0) uniform sampler2D texSampler;
5+
6+
layout(location = 0) in vec3 fragColor;
7+
layout(location = 1) in vec2 fragTexCoord;
8+
9+
layout(location = 0) out vec4 outColor;
10+
11+
void main() {
12+
vec4 shadowColor = {1.0,0.5,0.0,0.5 }; // Color of the shadow/outline
13+
14+
vec2 texSize = textureSize(texSampler, 0);
15+
vec2 texOffset = vec2(1.0) / texSize; // Size of a single texel
16+
17+
float shadowAlpha = 0.0;
18+
19+
shadowAlpha = 0.0;
20+
int n=3; // Size of surrounding for outline sampling
21+
for (int x=-n; x<=n; ++x) {
22+
for (int y=-n; y<=n; ++y) {
23+
shadowAlpha += texture(texSampler,
24+
+fragTexCoord
25+
+vec2(x,y)*texOffset).a;
26+
}
27+
}
28+
29+
// Get the original texture color
30+
vec4 original = texture(texSampler, fragTexCoord);
31+
32+
// First combine the shadow with the background color
33+
outColor = mix(vec4(0.1,0.1,0.3,1.0), shadowColor, min(shadowAlpha,1.0));
34+
35+
// Now combine with the original model
36+
outColor = mix(outColor, original, original.a);
37+
}
38+

examples/app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_subdirectory(vsgvalidate)
1919
add_subdirectory(vsgaxes)
2020
add_subdirectory(vsgcolorspace)
2121
add_subdirectory(vsgmultiwindowmultiview)
22+
add_subdirectory(vsgrenderoutline)
2223

2324
if (vsgXchange_FOUND)
2425
add_subdirectory(vsghelloworld)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(SOURCES
2+
vsgrenderoutline.cpp
3+
)
4+
5+
add_executable(vsgrenderoutline ${SOURCES})
6+
7+
target_link_libraries(vsgrenderoutline vsg::vsg)
8+
9+
if (vsgXchange_FOUND)
10+
target_compile_definitions(vsgrenderoutline PRIVATE vsgXchange_FOUND)
11+
target_link_libraries(vsgrenderoutline vsgXchange::vsgXchange)
12+
endif()
13+
14+
install(TARGETS vsgrenderoutline RUNTIME DESTINATION bin)

0 commit comments

Comments
 (0)