85 lines
3.4 KiB
Plaintext
85 lines
3.4 KiB
Plaintext
// Taken from the godot-demo-projects repo.
|
|
// GODOT ENGINE
|
|
// http://www.godotengine.org
|
|
//
|
|
// ************************************************************************
|
|
//
|
|
// Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
// a copy of this software and associated documentation files (the
|
|
// "Software"), to deal in the Software without restriction, including
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
// the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be
|
|
// included in all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
//
|
|
//************************************************************************
|
|
|
|
uniform highp float outline_width; // = 2.0;
|
|
uniform highp vec4 outline_color; // =vec4(1.0,0.0,0.0,0.33);
|
|
uniform bool outline_fullbright; // =false;
|
|
uniform highp float light_boost; // = 4.0;
|
|
uniform highp float light_gamma; // = 1.0;
|
|
uniform highp float light_whitepoint; // = 1.0;
|
|
|
|
highp float grayscale(highp vec3 col) {
|
|
return mix(0.0, 1.0, (col.r * 0.299) + (col.g * 0.587) + (col.b * 0.114)); //These luminance values are taken from Rec. ITU-R BT.601-7. This isn't suitable for player-facing grayscaling due to SDTV having a funky colorspace, but it's perfect for outlines.
|
|
}
|
|
|
|
void fragment() {
|
|
highp vec4 col = zTexture(UV);
|
|
highp vec2 ps = TEXTURE_PIXEL_SIZE;
|
|
highp float a;
|
|
highp float maxa = col.a;
|
|
highp float mina = col.a;
|
|
|
|
// note: these bypass zTexture because only alpha is queried.
|
|
a = texture2D(TEXTURE, UV + vec2(0.0, -outline_width)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
a = texture2D(TEXTURE, UV + vec2(-outline_width, -outline_width)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
a = texture2D(TEXTURE, UV + vec2(0.0, outline_width)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
a = texture2D(TEXTURE, UV + vec2(outline_width, -outline_width)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
a = texture2D(TEXTURE, UV + vec2(-outline_width,0.0)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
a = texture2D(TEXTURE, UV + vec2(-outline_width, outline_width)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
a = texture2D(TEXTURE, UV + vec2(outline_width, 0.0)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
a = texture2D(TEXTURE, UV + vec2(outline_width, outline_width)*ps).a;
|
|
maxa = max(a, maxa);
|
|
mina = min(a, mina);
|
|
|
|
lowp float sampledLight = outline_fullbright ? 1.0 : clamp( (pow( grayscale(lightSample.rgb) * light_whitepoint, light_gamma) / light_whitepoint ) * light_boost, 0.0, 1.0);
|
|
COLOR = mix(col, outline_color * vec4(vec3(1.0), sampledLight), maxa - col.a);
|
|
lightSample = vec3(1.0);
|
|
}
|