git-svn-id: svn://db.shs.com.ru/libs@555 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -34,57 +34,55 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
ldist = length(ldir);
|
||||
ldir = normalize(ldir);
|
||||
halfV = normalize(ldir + v);
|
||||
NdotL = max(dot(n, ldir), 0.);
|
||||
NdotH = max(dot(n, halfV), 0.);
|
||||
NdotL = max(dot(n, ldir), 0.0001);
|
||||
NdotH = max(dot(n, halfV), 0.0001);
|
||||
spot = step(0., NdotL) * qgl_Light[index].intensity;
|
||||
if (NdotL > 0.) {
|
||||
if (qgl_Light[index].endAngle <= 90.) {
|
||||
float scos = max(dot(-ldir, qgl_Light[index].direction.xyz), 0.);
|
||||
spot *= scos * step(qgl_Light[index].endAngleCos, scos);
|
||||
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
|
||||
lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
|
||||
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
|
||||
//bn2 = normalize(cross(lwdir, bn));
|
||||
float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02);
|
||||
//spot *= clamp(1. - sdist, 0, 1);
|
||||
vds = ds * bn.xyz;
|
||||
vds2 = ds * bn2.xyz;
|
||||
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3. +
|
||||
getShadow(index, pos.xyz, vds ) * 2. +
|
||||
getShadow(index, pos.xyz, - vds ) * 2. +
|
||||
getShadow(index, pos.xyz, - vds2 ) * 2. +
|
||||
getShadow(index, pos.xyz, + vds2 ) * 2. +
|
||||
getShadow(index, pos.xyz, vds - vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, vds + vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, - vds - vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, - vds + vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, vds + vds ) +
|
||||
getShadow(index, pos.xyz, - vds - vds ) +
|
||||
getShadow(index, pos.xyz, - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, + vds2 + vds2) +
|
||||
getShadow(index, pos.xyz, vds + vds - vds2 ) +
|
||||
getShadow(index, pos.xyz, - vds - vds - vds2 ) +
|
||||
getShadow(index, pos.xyz, vds + vds + vds2 ) +
|
||||
getShadow(index, pos.xyz, - vds - vds + vds2 ) +
|
||||
getShadow(index, pos.xyz, vds - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, vds + vds2 + vds2) +
|
||||
getShadow(index, pos.xyz, - vds - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, - vds + vds2 + vds2);
|
||||
spot *= mix(1., shadow / 29., shadow_on);
|
||||
}
|
||||
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
|
||||
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
|
||||
//si += spot * qgl_Light[index].color.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
|
||||
float NdotLs = NdotL*NdotL;
|
||||
float NdotHs = NdotH*NdotH;
|
||||
float ndlc = (1. - NdotLs) / NdotLs;
|
||||
float der = NdotLs * (sh_mul + ndlc);
|
||||
diff = 2. / (1. + sqrt(1. + (1. - sh_mul) * ndlc));
|
||||
li += spot * qgl_Light[index].color.rgb * diff;// * light_diffuse(0, ldir, n);
|
||||
ndlc = (1. - NdotHs) / NdotHs;
|
||||
der = NdotHs * (sh_mul + ndlc);
|
||||
si += spot * qgl_Light[index].color.rgb * (sh_mul / (der*der) / 3.1416);
|
||||
if (qgl_Light[index].endAngle <= 90.) {
|
||||
float scos = max(dot(-ldir, qgl_Light[index].direction.xyz), 0.);
|
||||
spot *= scos * step(qgl_Light[index].endAngleCos, scos);
|
||||
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
|
||||
lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
|
||||
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
|
||||
//bn2 = normalize(cross(lwdir, bn));
|
||||
float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02);
|
||||
//spot *= clamp(1. - sdist, 0, 1);
|
||||
vds = ds * bn.xyz;
|
||||
vds2 = ds * bn2.xyz;
|
||||
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3. +
|
||||
getShadow(index, pos.xyz, vds ) * 2. +
|
||||
getShadow(index, pos.xyz, - vds ) * 2. +
|
||||
getShadow(index, pos.xyz, - vds2 ) * 2. +
|
||||
getShadow(index, pos.xyz, + vds2 ) * 2. +
|
||||
getShadow(index, pos.xyz, vds - vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, vds + vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, - vds - vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, - vds + vds2 ) * 1.5 +
|
||||
getShadow(index, pos.xyz, vds + vds ) +
|
||||
getShadow(index, pos.xyz, - vds - vds ) +
|
||||
getShadow(index, pos.xyz, - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, + vds2 + vds2) +
|
||||
getShadow(index, pos.xyz, vds + vds - vds2 ) +
|
||||
getShadow(index, pos.xyz, - vds - vds - vds2 ) +
|
||||
getShadow(index, pos.xyz, vds + vds + vds2 ) +
|
||||
getShadow(index, pos.xyz, - vds - vds + vds2 ) +
|
||||
getShadow(index, pos.xyz, vds - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, vds + vds2 + vds2) +
|
||||
getShadow(index, pos.xyz, - vds - vds2 - vds2) +
|
||||
getShadow(index, pos.xyz, - vds + vds2 + vds2);
|
||||
spot *= mix(1., shadow / 29., shadow_on);
|
||||
}
|
||||
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
|
||||
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
|
||||
//si += spot * qgl_Light[index].color.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
|
||||
float NdotLs = NdotL*NdotL;
|
||||
float NdotHs = NdotH*NdotH;
|
||||
float ndlc = (1. - NdotLs) / NdotLs;
|
||||
float der = NdotLs * (sh_mul + ndlc);
|
||||
diff = 2. / (1. + sqrt(1. + (1. - sh_mul) * ndlc));
|
||||
li += spot * qgl_Light[index].color.rgb * diff;// * light_diffuse(0, ldir, n);
|
||||
ndlc = (1. - NdotHs) / NdotHs;
|
||||
der = NdotHs * (sh_mul + ndlc);
|
||||
si += spot * qgl_Light[index].color.rgb * (sh_mul / (der*der) / 3.1416);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user