shadows basically works
This commit is contained in:
@@ -19,7 +19,8 @@ in vec3 view_dir, world_dir;
|
||||
uniform vec2 dt;
|
||||
uniform float z_near;
|
||||
uniform sampler2D tex_coeffs[2];
|
||||
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4;
|
||||
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_sh;
|
||||
uniform sampler2DShadow tex_shadow[16];
|
||||
uniform samplerCube tex_env;
|
||||
uniform int lights_start, lights_count;
|
||||
|
||||
@@ -29,12 +30,20 @@ uniform mat3 view_mat;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
const float _min_rough = 1.e-8, max_lod = 8;
|
||||
const float PI = 3.1416;
|
||||
|
||||
vec4 pos, lpos, shp;
|
||||
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
|
||||
//vec3 vds, vds2;
|
||||
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow;
|
||||
|
||||
vec4 mapScreenToShadow(in int light_index) {
|
||||
vec4 shp = qgl_light_position[light_index].shadow_matrix * pos;
|
||||
shp.z += 0.095;
|
||||
return shp;
|
||||
}
|
||||
|
||||
|
||||
void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
lpos = qgl_light_position[index].position;
|
||||
ldir = lpos.xyz - (pos.xyz * lpos.w);
|
||||
@@ -49,6 +58,10 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
float scos = max(dot(-ldir, qgl_light_position[index].direction.xyz), 0.);
|
||||
spot *= scos * step(qgl_light_parameter[index].angles.w, scos);
|
||||
spot *= smoothstep(qgl_light_parameter[index].angles.w, qgl_light_parameter[index].angles.y, scos);
|
||||
|
||||
vec4 shp = mapScreenToShadow(index);
|
||||
spot *= textureProj(tex_shadow[index - lights_start], shp);
|
||||
|
||||
/*//lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
|
||||
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
|
||||
//bn2 = normalize(cross(lwdir, bn));
|
||||
@@ -93,7 +106,7 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
|
||||
ndlc = (1. - NdotHs) / NdotHs;
|
||||
float der = NdotHs * (rough_spec + ndlc);
|
||||
spec = rough_spec / (der*der) / 3.1416;
|
||||
spec = rough_spec / (der*der) / PI;
|
||||
//spec = texture(tex_coeffs[1], vec2(roughness, (NdotHs))).r;
|
||||
si += spot * spec * qgl_light_parameter[index].color.rgb;
|
||||
}
|
||||
@@ -172,7 +185,17 @@ void main(void) {
|
||||
res_col = mix(res_col, fog_color.rgb, fog);
|
||||
|
||||
qgl_FragColor = vec4(res_col, alpha);
|
||||
|
||||
/*
|
||||
#ifdef SPOT
|
||||
vec4 wpos = vec4(world_dir * z, 1);
|
||||
vec4 shp = qgl_light_position[lights_start].shadow_matrix * (pos);
|
||||
//shp.z += 0.095;
|
||||
//qgl_FragColor.rgb = vec3(texture(tex_sh, shp.xy).rgb);
|
||||
qgl_FragColor.rgb = vec3(textureProj(tex_shadow[0], shp));
|
||||
//vec4 rp = qgl_ViewProjMatrix*vec4(qgl_FragTexture.xy,z,1);
|
||||
//qgl_FragColor.rgb = vec3(shp.xy,0);
|
||||
#endif
|
||||
*/
|
||||
//vec3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
|
||||
//qgl_FragColor.rgb = vec3(shlick * brdf.x + brdf.y);
|
||||
//qgl_FragColor.rgb = vec3(alpha);
|
||||
|
||||
Reference in New Issue
Block a user