spot light map
This commit is contained in:
@@ -71,6 +71,14 @@ float rand(vec2 co) {
|
||||
return fract(sin(sn) * c) - 0.5;
|
||||
}
|
||||
|
||||
vec4 qgl_lightTexture(int index, vec2 coord, vec4 tex_shift) {
|
||||
coord *= qgl_light_parameter[index].map.scale;
|
||||
vec4 t = texture(qgl_texture_array[qgl_light_parameter[index].map.array_index],
|
||||
vec3(coord, qgl_light_parameter[index].map.map_index));
|
||||
t += tex_shift;
|
||||
t.rgb *= qgl_light_parameter[index].map.amount + qgl_light_parameter[index].map.offset;
|
||||
return t;
|
||||
}
|
||||
|
||||
void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
lpos = qgl_light_position[index].position;
|
||||
@@ -82,16 +90,20 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
NdotL = max(dot(n, ldir), 1E-8);
|
||||
NdotH = max(dot(n, halfV), 1E-8);
|
||||
spot = step(1.001E-8, NdotL) * qgl_light_parameter[index].decay_intensity.w;
|
||||
vec3 light_color = qgl_light_parameter[index].color.rgb;
|
||||
#ifdef SPOT
|
||||
float scos = max(dot(-ldir, qgl_light_position[index].direction.xyz), 0.);
|
||||
spot *= scos * step(qgl_light_parameter[index].angles.w, scos);
|
||||
spot *= smoothstep(qgl_light_parameter[index].angles.w, qgl_light_parameter[index].angles.y, scos);
|
||||
vec4 shp = mapScreenToShadow(index, vec3(0));
|
||||
vec4 light_map_pix = qgl_lightTexture(index, shp.xy / shp.w, vec4(0));
|
||||
light_color *= light_map_pix.rgb;
|
||||
spot *= light_map_pix.a;
|
||||
|
||||
if (int(round(qgl_light_parameter[index].flags)) == 1 && bitfieldExtract(flags, 3, 1) == 1) {
|
||||
|
||||
int layer = index - lights_start;
|
||||
float shadow = 0.;
|
||||
vec4 shp = mapScreenToShadow(index, vec3(0));
|
||||
|
||||
if (soft_shadows_enabled) {
|
||||
|
||||
@@ -168,13 +180,13 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
float ndlc = (1. - NdotLs) / NdotLs;
|
||||
diff = 2. / (1. + sqrt(1. + (1. - rough_diff) * ndlc));
|
||||
//diff = texture(tex_coeffs[0], vec2(roughness, (NdotLs))).r;
|
||||
li += spot * diff * qgl_light_parameter[index].color.rgb;
|
||||
li += spot * diff * light_color;
|
||||
|
||||
ndlc = (1. - NdotHs) / NdotHs;
|
||||
float der = NdotHs * (rough_spec + ndlc);
|
||||
spec = rough_spec / (der*der) / PI;
|
||||
//spec = texture(tex_coeffs[1], vec2(roughness, (NdotHs))).r;
|
||||
si += spot * spec * qgl_light_parameter[index].color.rgb;
|
||||
si += spot * spec * light_color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user