/usr/src/castle-game-engine-4.1.1/x3d/opengl/glsl/template_add_light.glsl is in castle-game-engine-src 4.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | /* Shader code used for adding light source contribution. */
/* TODO: use this, i.e. define PLUG_geometry_vertex_*
for every light source to pass these */
#ifdef HAS_GEOMETRY_SHADER
#define castle_light_light_number_radius castle_light_light_number_radius_geoshader
#define castle_light_light_number_beam_width castle_light_light_number_beam_width_geoshader
#endif
#ifdef LIGHT_HAS_RADIUS
uniform float castle_light_light_number_radius;
#endif
#ifdef LIGHT_HAS_BEAM_WIDTH
uniform float castle_light_light_number_beam_width;
#endif
void PLUG_add_light_contribution_side(inout vec4 color,
const in vec4 vertex_eye,
const in vec3 normal_eye,
const in gl_MaterialParameters material)
{
vec3 light_dir;
/* Calculate light_dir */
#ifdef LIGHT_TYPE_POSITIONAL
/* positional light. We assume in this case
gl_LightSource[light_number].position.w == 1, so there's no need
to divide by it. This is true for our VRML/X3D lights. */
light_dir = gl_LightSource[light_number].position.xyz - vec3(vertex_eye);
float distance_to_light = length(light_dir);
light_dir /= distance_to_light;
#else
light_dir = normalize(gl_LightSource[light_number].position.xyz);
#endif
#ifdef LIGHT_TYPE_SPOT
/* Check gl_LightSource[light_number].position first, as we want to add nothing
(not even ambient term) when were outside of spot light cone. */
float spot_cos = dot(normalize(gl_LightSource[light_number].spotDirection), -light_dir);
/* non-spot lights have always cutoff = 180, with cos = -1,
so the check below will always be false. No need to explicitly
compare with -1, nice. */
if (spot_cos < gl_LightSource[light_number].spotCosCutoff)
return;
#endif
float scale = 1.0;
/* PLUG: light_scale (scale, normal_eye, light_dir, gl_LightSource[light_number], gl_SideLightProduct[light_number], material) */
#ifdef LIGHT_TYPE_SPOT
#ifdef LIGHT_HAS_BEAM_WIDTH
/* calculate spot following VRML 2.0/X3D idea of beamWidth */
float cutOffAngle = radians(gl_LightSource[light_number].spotCutoff);
scale *= clamp(
( acos(spot_cos) - cutOffAngle) /
(castle_light_light_number_beam_width - cutOffAngle),
0.0, 1.0);
#endif
#ifdef LIGHT_HAS_SPOT_EXPONENT
/* calculate spot like fixed-function pipeline, using exponent */
scale *= pow(spot_cos, gl_LightSource[light_number].spotExponent);
#endif
#endif
#ifdef LIGHT_HAS_ATTENUATION
scale /= max(1.0,
gl_LightSource[light_number].constantAttenuation +
gl_LightSource[light_number].linearAttenuation * distance_to_light +
gl_LightSource[light_number].quadraticAttenuation * distance_to_light * distance_to_light);
#endif
#ifdef LIGHT_HAS_RADIUS
if (distance_to_light >= castle_light_light_number_radius)
scale = 0.0;
#endif
/* add ambient term */
vec4 light_color =
#ifdef LIGHT_HAS_AMBIENT
gl_SideLightProduct[light_number].ambient;
#else
vec4(0.0);
#endif
/* add diffuse term */
vec4 diffuse = gl_SideLightProduct[light_number].diffuse;
/* PLUG: material_light_diffuse (diffuse, vertex_eye, normal_eye, gl_LightSource[light_number], material) */
float diffuse_factor = max(dot(normal_eye, light_dir), 0.0);
light_color += diffuse * diffuse_factor;
#ifdef LIGHT_HAS_SPECULAR
/* add specular term */
if (diffuse_factor != 0.0)
light_color += gl_SideLightProduct[light_number].specular *
pow(max(dot(vec3(gl_LightSource[light_number].halfVector), normal_eye),
0.0), material.shininess);
#endif
color += light_color * scale;
#undef LIGHT_TYPE_POSITIONAL
#undef LIGHT_TYPE_SPOT
#undef LIGHT_HAS_AMBIENT
#undef LIGHT_HAS_SPECULAR
#undef LIGHT_HAS_ATTENUATION
#undef LIGHT_HAS_RADIUS
}
|