This repository has been archived on 2020-09-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
libs/qglview/shaders/dsl_pass_0.frag

57 lines
1.7 KiB
GLSL

#version 130
in vec3 src_normal, normal;//, et;
in vec4 pos, col;
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 vec2 dt;
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);
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) {
/*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);
}
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;
dp.x = floor(dp.w / 255.) / 255.;
dp.w -= dp.x * 65025;
dp.y = floor(dp.w) / 255.;
dp.w -= dp.y * 255.;
dp.z = fract(dp.w);*/
//dp.x = dp.w;
//dp.w = (gl_FrontMaterial.specular.r + gl_FrontMaterial.specular.g + gl_FrontMaterial.specular.b) / 3. / 25.5;
//gl_FragData[2] = dp;
//gl_FragData[3] = vec4(light_model / 255., 0, 0, 0);
}