git-svn-id: svn://db.shs.com.ru/libs@42 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2015-11-16 18:20:13 +00:00
parent c27e345c51
commit ddcd5c716a
18 changed files with 389 additions and 158 deletions

View File

@@ -1,6 +1,6 @@
#version 130
in vec3 src_normal, normal, et;
in vec3 src_normal, normal;//, et;
in vec4 pos, col;
in float fogCoord;
@@ -19,9 +19,13 @@ void main(void) {
if (has_height) hei = dot(texture2D(t2, gl_TexCoord[0].xy).rgb, luma) * height_scale;
if (acc_fog) dc.xyz = mix(dc.rgb, gl_Fog.color.rgb, fogCoord);
vec3 n;
if (has_bump) n = normalize(normal - (texture2D(t1, gl_TexCoord[0].xy).rgb - vec3(0.5, 0.5, 1.)) * bump_scale);
else n = normalize(normal);
vec3 n, dn;
if (has_bump) {
dn = (texture2D(t1, gl_TexCoord[0].xy).rgb - vec3(0.5, 0.5, 1.)) * bump_scale;
dn.x = -dn.x;
dn = dn * mat3(gl_ModelViewMatrixInverse);
n = normalize(normal - dn);
} else n = normalize(normal);
if (has_diffuse) {
@@ -30,7 +34,7 @@ void main(void) {
dpm = gl_ModelViewProjectionMatrixInverse
dpm = dpm * gl_ModelViewProjectionMatrixInverse;
dpm += */
tc += 1-et.xy * hei/10;// / et.z;
//tc += 1+et.xy * hei/10;// / et.z;
dc *= texture2D(t0, tc);
}

View File

@@ -6,7 +6,7 @@ in vec3 normal[];
out vec3 tangent[];
void main() {
for (int i = 0; i < gl_in.length(); i++ ) {
for (int i = 0; i < gl_in.length(); i++) {
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}

View File

@@ -1,6 +1,6 @@
#version 130
out vec3 src_normal, normal, et;
out vec3 src_normal, normal;//, et;
out vec4 pos, col;
out float fogCoord, fs_gid;
@@ -23,19 +23,19 @@ void main(void) {
src_normal = normalize(/*gl_NormalMatrix * */vec3(pos.xy * dt * 2., 0));
//pos = gl_Position;
vec3 v = normalize(-pos.xyz); // vector to the eye
//vec3 v = normalize(-pos.xyz); // vector to the eye
/*vec3 t = gl_NormalMatrix * vec3(1., 0., 0.);
vec3 b = gl_NormalMatrix * vec3(0., 1., 0.);
et = vec3(dot(v, t), dot(v, b), dot(v, normal));*/
vec3 t = normalize(gl_NormalMatrix * vec3(gl_MultiTexCoord0.yx, 1));
vec3 b = cross(normal, t);
//vec3 t = normalize(gl_NormalMatrix * vec3(gl_MultiTexCoord0.yx, 1));
//vec3 b = cross(normal, t);
mat3 tbnMatrix = mat3(t.x, b.x, normal.x,
/*mat3 tbnMatrix = mat3(t.x, b.x, normal.x,
t.y, b.y, normal.y,
t.z, b.z, normal.z);
et = tbnMatrix * v;
et = tbnMatrix * v;*/
pos.w = gl_Position.w;

View File

@@ -8,17 +8,14 @@ uniform int gid, lightsCount;
uniform bool firstPass;
uniform vec2 dt;
uniform vec4 back_color;
//uniform vec3 eye;
//uniform vec4 lpos[8];
uniform mat4 mat;
//uniform float zNear, zFar;
float light_diffuse(int model, vec3 l, vec3 n, vec3 h, vec3 v, float shininess) {return max(0., dot(l, n));}
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;
vec3 li, si, ldir, halfV;
float sh, dist, NdotL, spot, ldist;
float sh_pow, sh_mul, dist, NdotL, spot, ldist, diff;
void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
lpos = gl_LightSource[index].position;
@@ -34,14 +31,16 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
spot = pow(spot, (gl_LightSource[index].spotExponent + 0.001));
}
halfV = normalize(ldir + v);
//i += gl_LightSource[i].diffuse.rgb * NdotL;
//si += gl_LightSource[i].specular.rgb * pow(max(dot(n, halfV), 0.), sh);
spot /= (gl_LightSource[index].constantAttenuation + ldist * (gl_LightSource[index].linearAttenuation + ldist * gl_LightSource[index].quadraticAttenuation));
li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n, halfV, v, sh);
si += spot * gl_LightSource[index].specular.rgb * v2.rgb * light_specular(0, ldir, n, halfV, v, sh);
//li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
//si += spot * gl_LightSource[index].specular.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
float NdotLs = NdotL*NdotL;
float ndlc = (1. - NdotLs) / NdotLs;
float der = NdotLs * (sh_mul + ndlc);
diff = 2. / (1. + sqrt(1. + (1. - sh_mul) * ndlc));
li += spot * gl_LightSource[index].diffuse.rgb * diff * light_diffuse(0, ldir, n);
si += spot * gl_LightSource[index].specular.rgb * (sh_mul / (der*der) / 3.1416);
}
//li = vec3(gl_LightSource[index].spotExponent);
//si = vec3(0);
}
void main(void) {
@@ -51,7 +50,7 @@ void main(void) {
gl_FragColor = back_color;
return;
}
vec4 v1 = texture2D(t1, gl_TexCoord[0].xy), v2 = texture2D(t2, gl_TexCoord[0].xy);//, v3 = texture2D(t3, gl_TexCoord[0].xy);
vec4 v1 = texture2D(t1, gl_TexCoord[0].xy), v2 = texture2D(t2, gl_TexCoord[0].xy);//, v3 = texture2D(t2, gl_TexCoord[0].xy);
vec2 sp = gl_FragCoord.xy * dt * 2 - vec2(1, 1);
vec3 dc = v0.rgb, n = v1.xyz * 2. - vec3(1.);
float height = v2.w;
@@ -62,9 +61,8 @@ void main(void) {
pos *= v0.w;
pos.rgb += n * height;
vec3 v = normalize(-pos.xyz);
sh = v1.w;
//int light_model = int(v3.r * 255. + 0.5);
//li = ambient;
sh_pow = 1. / max((1. - v1.w), 0.0001);
sh_mul = max(1. - v1.w, 0.0001);
if (lightsCount > 0) {
calcLight(0, n, v, v2);
if (lightsCount > 1) {
@@ -89,6 +87,6 @@ void main(void) {
}
}
}
gl_FragColor.rgb = li * dc + si + texture2D(tb, gl_TexCoord[0].xy).rgb;
//gl_FragColor.rgb = v0.rgb;
gl_FragColor.rgb = li * dc + si * v2.rgb + texture2D(tb, gl_TexCoord[0].xy).rgb;
//gl_FragColor.rgb = vec3(v2.rgb);
}