1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#X3D V4.0 utf8
PROFILE Interchange
# Flashlight screen effect.
#
# See https://castle-engine.io/x3d_extensions_screen_effects.php
# for docs how to write screen effects for CGE.
ScreenEffect {
needsDepth TRUE
shaders ComposedShader {
language "GLSL"
parts ShaderPart {
type "FRAGMENT"
url "data:text/plain,
void main (void)
{
gl_FragColor = screenf_get_original_color();
float dist = distance(vec2(screen_position()), vec2(screen_width, screen_height) / 2.0);
// calculate radius_out, \"how large would be light radius for wall at this depth\"
float radius_out = min(float(screen_width), float(screen_height)) / 2.0;
float depth = screenf_get_original_depth();
depth = 1.0 - pow(depth, 20.0);
radius_out = mix(radius_out / 3.0, radius_out, depth);
/* Radeon fglrx (crappy OpenGL driver) refuses to correctly do \"* 0.8\" below */
float radius_in = 4.0 * radius_out / 5.0;
float p = mix(1.0 / 4.0, 1.0, smoothstep(radius_in, radius_out, dist));
gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(p, p, p));
}
"
}
}
}
|