git-svn-id: svn://db.shs.com.ru/libs@45 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
in vec3 src_normal, normal;//, et;
|
||||
in vec4 pos;
|
||||
in float fogCoord;
|
||||
in mat3 TBN;
|
||||
|
||||
uniform bool acc_fog;
|
||||
uniform vec2 dt;
|
||||
@@ -18,10 +19,14 @@ void main(void) {
|
||||
//if (acc_fog) dc.xyz = mix(dc.rgb, gl_Fog.color.rgb, fogCoord);
|
||||
|
||||
vec3 n, dn;
|
||||
dn = (texture2D(qgl_Material.map_bump.map, tc).rgb - vec3(0.5, 0.5, 1.)) * qgl_Material.map_bump.amount + qgl_Material.map_bump.offset;
|
||||
dn.x = -dn.x;
|
||||
dn = dn * mat3(qgl_ModelViewMatrixInverse);
|
||||
n = normalize(normal - dn);
|
||||
dn = (texture2D(qgl_Material.map_normal.map, tc).rgb - vec3(0.5, 0.5, 1.)) * qgl_Material.map_normal.amount + qgl_Material.map_normal.offset;
|
||||
//float tx = dn.x;
|
||||
dn.y = -dn.y;
|
||||
//dn.y = tx;
|
||||
dn = TBN * dn;
|
||||
//dn = dn * mat3(qgl_ModelViewMatrix)*10;//*(mat3(qgl_NormalMatrix));
|
||||
n = normalize(qgl_NormalMatrix*(normal+dn));//normalize(qgl_NormalMatrix * (normal - dn));
|
||||
//n = dn;
|
||||
|
||||
/*vec2 dpm = normalize(gl_FragCoord.xy * dt * 2. - vec2(1., 1.)), ntc;
|
||||
ntc = gl_FragCoord.xy * dt * 2. - vec2(1., 1.) + dpm * hei;
|
||||
@@ -32,16 +37,15 @@ void main(void) {
|
||||
dc *= texture2D(qgl_Material.map_diffuse.map, tc) * qgl_Material.map_diffuse.amount + qgl_Material.map_diffuse.offset;
|
||||
|
||||
vec4 spec = texture2D(qgl_Material.map_specular.map, tc) * qgl_Material.map_specular.amount + qgl_Material.map_specular.offset;
|
||||
spec *= qgl_Material.color_specular * qgl_Material.specular;
|
||||
vec4 rough = texture2D(qgl_Material.map_roughness.map, tc) * qgl_Material.map_roughness.amount + qgl_Material.map_roughness.offset;
|
||||
rough *= qgl_Material.roughness;
|
||||
spec *= qgl_Material.color_specular;
|
||||
vec4 specularity = texture2D(qgl_Material.map_specularity.map, tc) * qgl_Material.map_specularity.amount + qgl_Material.map_specularity.offset;
|
||||
vec4 self = texture2D(qgl_Material.map_self_illumination.map, tc) * qgl_Material.map_self_illumination.amount + qgl_Material.map_self_illumination.offset;
|
||||
self *= qgl_Material.color_self_illumination;
|
||||
|
||||
qgl_FragData[0] = vec4(dc.rgb, z);
|
||||
qgl_FragData[1] = vec4(n.xyz / 2. + vec3(0.5), rough);
|
||||
qgl_FragData[1] = vec4(n.xyz / 2. + vec3(0.5), specularity);
|
||||
qgl_FragData[2] = vec4(spec.rgb, hei);
|
||||
qgl_FragData[3] = vec4(pos.xyz, pos.z);
|
||||
qgl_FragData[3] = vec4(self.rgb, pos.w);
|
||||
|
||||
//gl_FragData[0] = vec4(et.xyz, pos.w);
|
||||
//gl_FragDepth = gl_FragCoord.z - clamp(hei / pos.z / pos.z / (abs(n.z) + 1), -0.01, 0.01);
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
out vec3 src_normal, normal;//, et;
|
||||
out vec4 pos;
|
||||
out float fogCoord, fs_gid;
|
||||
out mat3 TBN;
|
||||
|
||||
uniform bool acc_fog;
|
||||
uniform vec2 dt;
|
||||
uniform vec3 eye;
|
||||
|
||||
void main(void) {
|
||||
normal = (qgl_NormalMatrix * qgl_Normal);
|
||||
pos.xyz = vec3(qgl_ModelViewMatrix * qgl_Vertex);
|
||||
normal = qgl_Normal;//(qgl_NormalMatrix * qgl_Normal);
|
||||
pos.xyzw = vec4(qgl_ModelViewMatrix * qgl_Vertex);
|
||||
TBN = (mat3(qgl_Tangent, qgl_Bitangent, qgl_Normal));
|
||||
/*if (acc_fog) {
|
||||
fogCoord = (gl_Fog.end - length(pos.xyz) * 0.85) / (gl_Fog.end - gl_Fog.start);
|
||||
fogCoord = 1. - clamp(fogCoord, 0., 1.);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#version 150
|
||||
//#extension GL_EXT_gpu_shader4 : enable
|
||||
|
||||
in vec4 view_dir;
|
||||
in vec3 view_pos;
|
||||
in vec4 view_dir, view_pos;
|
||||
|
||||
uniform vec3 ambient;
|
||||
uniform sampler2D t0, t1, t2, t3, tb;
|
||||
@@ -15,19 +14,21 @@ uniform vec4 back_color;
|
||||
uniform mat4 mat_proji;
|
||||
|
||||
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));}
|
||||
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_pow, sh_mul, dist, NdotL, spot, ldist, diff;
|
||||
float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff;
|
||||
|
||||
void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
lpos = qgl_Light[index].position;
|
||||
ldir = lpos.xyz - (pos.xyz * lpos.w);
|
||||
ldist = length(ldir);
|
||||
ldir = normalize(ldir);
|
||||
halfV = normalize(ldir + v);
|
||||
NdotL = max(dot(n, ldir), 0.);
|
||||
spot = step(0., NdotL);
|
||||
NdotH = max(dot(n, halfV), 0.);
|
||||
spot = step(0., NdotL) * qgl_Light[index].intensity;
|
||||
if (NdotL > 0.) {
|
||||
/*if (gl_LightSource[index].spotCutoff < 180.) {
|
||||
spot = max(dot(-ldir, gl_LightSource[index].spotDirection.xyz), 0.);
|
||||
@@ -35,15 +36,18 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
spot = pow(spot, (gl_LightSource[index].spotExponent + 0.001));
|
||||
}*/
|
||||
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
|
||||
halfV = normalize(ldir + v);
|
||||
///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);
|
||||
//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);
|
||||
//si += der;//dot(n, halfV);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,14 +67,22 @@ void main(void) {
|
||||
//li = vec3(0.);
|
||||
si = vec3(0.);
|
||||
|
||||
pos = vec4(sp, 0, 1)*mat_proji;
|
||||
pos.xyz *= v0.w;
|
||||
float posz = z_near * z_far / (texture2D(td, tc).r * (z_far - z_near) - z_far);
|
||||
pos = vec4(sp, 0., 1) * mat_proji;
|
||||
pos.xy *= v3.w;
|
||||
pos.z = posz;
|
||||
pos.xyz += n * height;
|
||||
//pos = v3;
|
||||
//pos = vec4(sp, 0, 1.) * mat_proji;
|
||||
//pos *= v0.w;
|
||||
//pos.z += 1;
|
||||
//pos.xy *= 10.;
|
||||
//pos.z = v0.w;
|
||||
vec3 v = normalize(-pos.xyz);
|
||||
sh_pow = 1. / max((1. - v1.w), 0.0001);
|
||||
sh_mul = max(1. - v1.w, 0.0001);
|
||||
//calcLight(0, n, v, v2);
|
||||
for (int i = 0; i < 16; ++i)
|
||||
calcLight(i, n, v, v2);
|
||||
/*if (lightsCount > 0) {
|
||||
calcLight(0, n, v, v2);
|
||||
if (lightsCount > 1) {
|
||||
@@ -95,14 +107,9 @@ void main(void) {
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//qgl_FragData[0].rgb = li * dc + si * v2.rgb + v3.rgb;// + texture2D(tb, tc).rgb;
|
||||
//vec4 lp = mat*qgl_Light[0].position;
|
||||
lpos = qgl_Light[0].position;
|
||||
ldir = lpos.xyz - pos.xyz;
|
||||
ldist = length(ldir);
|
||||
float d = texture2D(td, tc).r;
|
||||
//float z = ((z_near / (z_near-z_far)) * z_far) / (d - (z_far / (z_far-z_near)));
|
||||
float z = z_near * z_far / (d * (z_far - z_near) - z_far);
|
||||
//qgl_FragData[0].rgb = vec3(abs((v0.w)+(v3.z))-0.5);
|
||||
qgl_FragData[0].rgb = vec3((-z*view_pos));
|
||||
qgl_FragData[0].rgb = li * dc + si * v2.rgb + v3.rgb;// + texture2D(tb, tc).rgb;
|
||||
//qgl_FragData[0].rgb = vec3(abs(lpos.xyz - pos.xyz)/10);
|
||||
//qgl_FragData[0].rgb = vec3(li.xyz);
|
||||
//qgl_FragData[0].rgb = vec3(v1.xyz);
|
||||
//qgl_FragData[0].a = 0.;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
in vec4 view_corner;
|
||||
out vec4 view_dir;
|
||||
out vec3 view_pos;
|
||||
out vec4 view_pos;
|
||||
|
||||
void main(void) {
|
||||
view_dir = view_corner;
|
||||
view_pos = vec3(qgl_ModelViewMatrix * vec4(qgl_Vertex.xy, 1, 1));
|
||||
view_pos = vec4(qgl_ModelViewMatrix * vec4(qgl_Vertex.xy, 1, 1));
|
||||
view_pos /= view_pos.w;
|
||||
qgl_FragTexture = qgl_Texture;
|
||||
qgl_FragColor = qgl_Color;
|
||||
gl_Position = qgl_ftransform();
|
||||
|
||||
Reference in New Issue
Block a user