git-svn-id: svn://db.shs.com.ru/libs@57 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -12,7 +12,7 @@ uniform mat4 prev_ModelViewProjectioMatrix;
|
||||
|
||||
void main(void) {
|
||||
normal = qgl_Normal;//(qgl_NormalMatrix * qgl_Normal);
|
||||
binormal = qgl_Tangent;//(qgl_NormalMatrix * qgl_Normal);
|
||||
binormal = qgl_Bitangent;//(qgl_NormalMatrix * qgl_Normal);
|
||||
pos = qgl_ftransform();
|
||||
TBN = mat3(qgl_Tangent, qgl_Bitangent, qgl_Normal);
|
||||
/*if (acc_fog) {
|
||||
|
||||
@@ -11,17 +11,24 @@ uniform float z_near, z_far;
|
||||
uniform bool firstPass;
|
||||
uniform vec2 dt;
|
||||
uniform vec4 back_color;
|
||||
uniform mat4 mat_proji, mat_viewi, mat_viewproji;
|
||||
uniform mat4 mat_proji, mat_view, mat_viewi, mat_viewproji;
|
||||
|
||||
float light_diffuse(int model, vec3 l, vec3 n) {return max(0., dot(l, n));}
|
||||
float light_specular(int model, vec3 l, vec3 n, vec3 h, vec3 v, float shininess) {return max(0., pow(dot(n, h), shininess));}
|
||||
|
||||
vec4 pos, lpos, shp;
|
||||
vec3 li, si, ldir, halfV, bn, bn2;
|
||||
vec2 vds, vds2;
|
||||
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
|
||||
vec3 vds, vds2;
|
||||
float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff, sdist, shadow;
|
||||
|
||||
|
||||
float getShadow(int light, vec3 view_pos, vec3 dpos) {
|
||||
shp = mat_viewi * vec4(view_pos, 1);
|
||||
shp += vec4(dpos, 0);
|
||||
shp = qgl_Light[light].shadowMatrix * shp;
|
||||
//shp.xyz /= shp.w;
|
||||
shp.z -= 0.1;
|
||||
return textureProj(qgl_Light[light].shadow, shp);
|
||||
}
|
||||
|
||||
void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
lpos = qgl_Light[index].position;
|
||||
@@ -39,19 +46,45 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
//spot = clamp(scos / (-qgl_Light[index].endAngleCos + qgl_Light[index].startAngleCos + 0.0001),0,1);
|
||||
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
|
||||
//spot = pow(spot, (qgl_Light[index].spotExponent + 0.001));
|
||||
shp = qgl_Light[index].shadowMatrix*vec4(pos.xyz,1);
|
||||
|
||||
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/100;//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 *= shadow / 29.;
|
||||
/*shp = qgl_Light[index].shadowMatrix*vec4(pos.xyz,1);
|
||||
//shp.z -= 0.1;
|
||||
shp.xyz /= shp.w;
|
||||
float shr = texture(qgl_Light[index].shadowColor, shp.xy).r;
|
||||
sdist = shp.w - shr - 1.;
|
||||
//if (sdist > 0.) {
|
||||
float ds = 0.01;//max(abs(sdist) / 5000, 0.02);
|
||||
//spot *= clamp(1. - sdist, 0, 1);
|
||||
vds = vec2(ds,0);//bn.xy * ds;
|
||||
vds2 = vec2(0,ds);//bn2.xy * ds;
|
||||
shadow = //shr + //texture(qgl_Light[index].shadowColor, shp.xy, shp.zw)) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds ).r - 1, 0, 1)
|
||||
/*clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds - vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds - vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy + vds + vds2 ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds ).r - 1, 0, 1) +
|
||||
clamp(shp.w - texture(qgl_Light[index].shadowColor, shp.xy - vds - vds2 ).r - 1, 0, 1) +
|
||||
@@ -77,10 +110,10 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r +
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r*/;
|
||||
texture(qgl_Light[index].shadowColor, shp.xy + vds + vds + vds2 + vds2).r;
|
||||
shadow = shadow / 1;// - 0.5;
|
||||
spot *= ds*100;//clamp(1. - shadow, 0, 1);
|
||||
//}
|
||||
//}*/
|
||||
///spot *= textureProj(qgl_Light[index].shadow, shp);
|
||||
}
|
||||
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
|
||||
@@ -112,8 +145,8 @@ void main(void) {
|
||||
v4 = texelFetch(t4, tc, 0);
|
||||
vec2 sp = gl_FragCoord.xy * dt * 2 - vec2(1, 1);
|
||||
vec3 dc = v0.rgb, n = v1.xyz * 2. - vec3(1.);
|
||||
bn = vec3(v3.w, v4.zw);
|
||||
bn2 = normalize(cross(n, bn));
|
||||
//bn = vec3(v3.w, v4.zw);
|
||||
//bn2 = normalize(cross(n, bn));
|
||||
float height = v2.w;
|
||||
li = qgl_AmbientLight.color.rgb * qgl_AmbientLight.intensity;
|
||||
si = vec3(0.);
|
||||
@@ -136,14 +169,14 @@ void main(void) {
|
||||
sh_mul = max(1. - v1.w, 0.0001);
|
||||
//for (int i = 0; i < 8; ++i)
|
||||
// calcLight(i, n, v, v2);
|
||||
calcLight(4, n, v, v2);
|
||||
calcLight(0, n, v, v2);
|
||||
|
||||
qgl_FragData[0].rgb = li * dc + si * v2.rgb + v3.rgb + texelFetch(t_pp, tc, 0).rgb;
|
||||
//qgl_FragData[0].rgb = vec3(abs(lpos.xyz - pos.xyz)/10);
|
||||
//qgl_FragData[0].rgb = li + vec3(texelFetch(t_pp, tc, 0).xyz);
|
||||
//shd = shd - shp.w;
|
||||
//qgl_FragData[0].rgb = vec3(abs(shd)/10000);
|
||||
//qgl_FragData[0].rgb = vec3((shp.z)/1000);
|
||||
qgl_FragData[0].rgb = vec3((shp.w-1 - texture(qgl_Light[4].shadowColor, shp.xy-vec2(0.01,0)).r));
|
||||
//qgl_FragData[0].rgb = vec3(abs(shp.xy/shp.w)/1,0);
|
||||
//qgl_FragData[0].rgb = vec3(abs(mat3(mat_viewi)* qgl_Light[0].direction.xyz));
|
||||
//qgl_FragData[0].rgb = vec3(texture(qgl_Light[0].shadow,shp.xyz/shp.w)/2);
|
||||
//qgl_FragData[0].a = 0.;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user