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

This commit is contained in:
2015-11-20 21:19:36 +00:00
parent cabaead1c6
commit 104a7f99ad
48 changed files with 1973 additions and 1273 deletions

View File

@@ -1,46 +1,48 @@
#version 130
#version 150
in vec3 src_normal, normal;//, et;
in vec4 pos, col;
in vec4 pos;
in float fogCoord;
uniform int light_model;
uniform sampler2D t0, t1, t2, t3;
uniform float bump_scale, height_scale;
uniform bool acc_fog, has_diffuse, has_bump, has_height;
uniform bool acc_fog;
uniform vec2 dt;
uniform float z_far, z_near;
const vec3 luma = vec3(0.299, 0.587, 0.114);
void main(void) {
vec4 dc = col;
vec2 tc = gl_TexCoord[0].xy;
float hei = 0.;
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);
float z = pos.w;//((z_near / (z_near-z_far)) * z_far) / (pos.w - (z_far / (z_far-z_near)));
vec4 dc = qgl_FragColor;
vec2 tc = qgl_FragTexture.xy;
float hei = dot(texture2D(qgl_Material.map_relief.map, tc).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset;
//if (acc_fog) dc.xyz = mix(dc.rgb, gl_Fog.color.rgb, fogCoord);
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);
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);
if (has_diffuse) {
/*vec2 dpm = normalize(gl_FragCoord.xy * dt * 2. - vec2(1., 1.)), ntc;
ntc = gl_FragCoord.xy * dt * 2. - vec2(1., 1.) + dpm * hei;
dpm = gl_ModelViewProjectionMatrixInverse
dpm = dpm * gl_ModelViewProjectionMatrixInverse;
dpm += */
//tc += 1+et.xy * hei/10;// / et.z;
dc *= texture2D(qgl_Material.map_diffuse.map, tc) * qgl_Material.map_diffuse.amount + qgl_Material.map_diffuse.offset;
/*vec2 dpm = normalize(gl_FragCoord.xy * dt * 2. - vec2(1., 1.)), ntc;
ntc = gl_FragCoord.xy * dt * 2. - vec2(1., 1.) + dpm * hei;
dpm = gl_ModelViewProjectionMatrixInverse
dpm = dpm * gl_ModelViewProjectionMatrixInverse;
dpm += */
//tc += 1+et.xy * hei/10;// / et.z;
dc *= texture2D(t0, tc);
}
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;
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[2] = vec4(spec.rgb, hei);
qgl_FragData[3] = vec4(pos.xyz, pos.z);
gl_FragData[0] = vec4(dc.rgb, pos.w);
gl_FragData[1] = vec4(n.xyz / 2. + vec3(0.5), gl_FrontMaterial.shininess);
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, hei);
//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);
/*vec4 dp = pos;

View File

@@ -1,7 +1,7 @@
#version 130
#version 150
out vec3 src_normal, normal;//, et;
out vec4 pos, col;
out vec4 pos;
out float fogCoord, fs_gid;
uniform bool acc_fog;
@@ -9,34 +9,19 @@ uniform vec2 dt;
uniform vec3 eye;
void main(void) {
normal = (gl_NormalMatrix * gl_Normal);
pos.xyz = vec3(gl_ModelViewMatrix * gl_Vertex);
col = gl_Color;
if (acc_fog) {
normal = (qgl_NormalMatrix * qgl_Normal);
pos.xyz = vec3(qgl_ModelViewMatrix * qgl_Vertex);
/*if (acc_fog) {
fogCoord = (gl_Fog.end - length(pos.xyz) * 0.85) / (gl_Fog.end - gl_Fog.start);
fogCoord = 1. - clamp(fogCoord, 0., 1.);
}
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = ftransform();
src_normal = normalize(/*gl_NormalMatrix * */vec3(pos.xy * dt * 2., 0));
//pos = gl_Position;
//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);
/*mat3 tbnMatrix = mat3(t.x, b.x, normal.x,
t.y, b.y, normal.y,
t.z, b.z, normal.z);
et = tbnMatrix * v;*/
pos.w = gl_Position.w;
}*/
//gl_TexCoord[0] = gl_MultiTexCoord0;
//gl_TexCoord[1] = gl_MultiTexCoord1;
qgl_FragTexture = qgl_Texture;
qgl_FragColor = qgl_Color;
vec4 tp = qgl_ftransform();
//tp /= tp.w;
src_normal = normalize(vec3(pos.xy * dt * 2., 0));
pos.w = tp.w;
gl_Position = tp;//ftransform();
}

View File

@@ -1,69 +1,77 @@
#version 130
#version 150
//#extension GL_EXT_gpu_shader4 : enable
uniform vec3 ambient;
in vec4 view_dir;
in vec3 view_pos;
uniform sampler2D t0, t1, t2, tb;
uniform vec3 ambient;
uniform sampler2D t0, t1, t2, t3, tb;
uniform sampler2D td;
uniform int gid, lightsCount;
uniform float z_near, z_far;
uniform bool firstPass;
uniform vec2 dt;
uniform vec4 back_color;
uniform mat4 mat;
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;
void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
lpos = gl_LightSource[index].position;
lpos = qgl_Light[index].position;
ldir = lpos.xyz - (pos.xyz * lpos.w);
ldist = length(ldir);
ldir = normalize(ldir);
NdotL = max(dot(n, ldir), 0.);
spot = step(0., NdotL);
if (NdotL > 0.) {
if (gl_LightSource[index].spotCutoff < 180.) {
/*if (gl_LightSource[index].spotCutoff < 180.) {
spot = max(dot(-ldir, gl_LightSource[index].spotDirection.xyz), 0.);
spot *= step(gl_LightSource[index].spotCosCutoff, spot);
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);
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);
//si += spot * gl_LightSource[index].specular.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
///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 += spot * qgl_Light[index].color.rgb * diff;// * light_diffuse(0, ldir, n);
si += spot * qgl_Light[index].color.rgb * (sh_mul / (der*der) / 3.1416);
}
}
void main(void) {
//if (d == 1.) discard;
vec4 v0 = texture2D(t0, gl_TexCoord[0].xy);
vec2 tc = qgl_FragTexture.xy;
vec4 v0 = texture2D(t0, tc);
if (v0.w == 0.) {
gl_FragColor = back_color;
qgl_FragData[0] = back_color;
return;
}
vec4 v1 = texture2D(t1, gl_TexCoord[0].xy), v2 = texture2D(t2, gl_TexCoord[0].xy);//, v3 = texture2D(t2, gl_TexCoord[0].xy);
vec4 v1 = texture2D(t1, tc), v2 = texture2D(t2, tc), v3 = texture2D(t3, tc);
vec2 sp = gl_FragCoord.xy * dt * 2 - vec2(1, 1);
vec3 dc = v0.rgb, n = v1.xyz * 2. - vec3(1.);
float height = v2.w;
li = gl_LightModel.ambient.rgb;
li = qgl_AmbientLight.color.rgb * qgl_AmbientLight.intensity;
//li = vec3(0.);
si = vec3(0.);
pos = vec4(sp, 0, 1.) * mat;
pos *= v0.w;
pos.rgb += n * height;
pos = vec4(sp, 0, 1)*mat_proji;
pos.xyz *= v0.w;
//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);
if (lightsCount > 0) {
//calcLight(0, n, v, v2);
/*if (lightsCount > 0) {
calcLight(0, n, v, v2);
if (lightsCount > 1) {
calcLight(1, n, v, v2);
@@ -86,7 +94,15 @@ void main(void) {
}
}
}
}
gl_FragColor.rgb = li * dc + si * v2.rgb + texture2D(tb, gl_TexCoord[0].xy).rgb;
//gl_FragColor.rgb = vec3(v2.rgb);
}*/
//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));
}

View File

@@ -1,6 +1,13 @@
#version 130
#version 150
in vec4 view_corner;
out vec4 view_dir;
out vec3 view_pos;
void main(void) {
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
view_dir = view_corner;
view_pos = vec3(qgl_ModelViewMatrix * vec4(qgl_Vertex.xy, 1, 1));
qgl_FragTexture = qgl_Texture;
qgl_FragColor = qgl_Color;
gl_Position = qgl_ftransform();
}

View File

@@ -1,7 +1,7 @@
#version 120
#version 150
uniform vec4 id;
void main(void) {
gl_FragColor = id;
qgl_FragData[0] = id;
}

View File

@@ -1,5 +1,5 @@
#version 120
#version 150
void main(void) {
gl_Position = ftransform();
gl_Position = qgl_ftransform();
}

View File

@@ -1,4 +1,4 @@
#version 130
#version 150
uniform vec2 dt;
uniform vec4 selected, color;
@@ -6,13 +6,14 @@ uniform sampler2D t0;
uniform float fill;
void main(void) {
vec4 ds0 = abs(textureLodOffset(t0, gl_TexCoord[0].xy, 0., ivec2(-1, 0)) - selected);
vec4 ds1 = abs(textureLodOffset(t0, gl_TexCoord[0].xy, 0., ivec2( 1, 0)) - selected);
vec4 ds2 = abs(textureLodOffset(t0, gl_TexCoord[0].xy, 0., ivec2(0, -1)) - selected);
vec4 ds3 = abs(textureLodOffset(t0, gl_TexCoord[0].xy, 0., ivec2(0, 1)) - selected);
vec2 tc = qgl_FragTexture.xy;
vec4 ds0 = abs(textureLodOffset(t0, tc, 0., ivec2(-1, 0)) - selected);
vec4 ds1 = abs(textureLodOffset(t0, tc, 0., ivec2( 1, 0)) - selected);
vec4 ds2 = abs(textureLodOffset(t0, tc, 0., ivec2(0, -1)) - selected);
vec4 ds3 = abs(textureLodOffset(t0, tc, 0., ivec2(0, 1)) - selected);
float d0 = dot(ds0, vec4(1., 1., 1., 1.)), d1 = dot(ds1, vec4(1., 1., 1., 1.)), d2 = dot(ds2, vec4(1., 1., 1., 1.)), d3 = dot(ds3, vec4(1., 1., 1., 1.));
float vs = step(1e-6, d0 + d1 + d2 + d3);
float vm = step(1e-3, (d0 * 255.) * (d1 * 255.) * (d2 * 255.) * (d3 * 255.));
float v = mix(vs - vm, vs - vm - vm + 1, fill);
gl_FragColor = vec4(color.rgb, v * color.a);
qgl_FragData[0] = vec4(color.rgb, v * color.a);
}

View File

@@ -1,6 +1,6 @@
#version 130
#version 150
void main(void) {
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
qgl_FragTexture = qgl_Texture;
gl_Position = qgl_ftransform();
}