55 lines
1.5 KiB
GLSL
55 lines
1.5 KiB
GLSL
#version 330 core
|
|
|
|
const uint lights = 2u;
|
|
|
|
uniform sampler2D texBase;
|
|
uniform samplerCubeShadow texShadowMaps[lights];
|
|
|
|
float VectorToDepth (vec3 Vec)
|
|
{
|
|
vec3 AbsVec = abs(Vec);
|
|
float LocalZcomp = max(AbsVec.x, max(AbsVec.y, AbsVec.z));
|
|
//float LocalZcomp = length(AbsVec);
|
|
|
|
// Replace f and n with the far and near plane values you used when
|
|
// you drew your cube map.
|
|
const float f = 128.0;
|
|
const float n = 1.0;
|
|
|
|
// float NormZComp = (f+n) / (f-n) - (2*f*n)/(f-n)/LocalZcomp;
|
|
return (f/(f-n))+(f*n/(n-f))/LocalZcomp;
|
|
//return (NormZComp + 1.0) * 0.5;
|
|
}
|
|
|
|
in vec2 fragTC;
|
|
//in vec3 fragNorm;
|
|
//in vec3 light0Vect;
|
|
in vec3 lightColors[lights];
|
|
in vec3 lightVecs[lights];
|
|
|
|
out vec4 color;
|
|
|
|
const float bias = 0.0;
|
|
|
|
void main(void) {
|
|
vec4 texColor = texture(texBase, fragTC);
|
|
|
|
vec4 col = vec4(0.0, 0.0, 0.0, 0.0);
|
|
{
|
|
float depth = VectorToDepth(lightVecs[0])-bias;
|
|
vec3 nlv = normalize(lightVecs[0]);
|
|
float depth_compare = texture(texShadowMaps[0], vec4(nlv, depth));
|
|
// color = vec4(depth_compare, 0.0, 0.0, 1.0);
|
|
col += texColor*vec4(lightColors[0], 1.0)*depth_compare;
|
|
}
|
|
{
|
|
float depth = VectorToDepth(lightVecs[1])-bias;
|
|
vec3 nlv = normalize(lightVecs[1]);
|
|
float depth_compare = texture(texShadowMaps[1], vec4(nlv, depth));
|
|
// color = vec4(depth_compare, 0.0, 0.0, 1.0);
|
|
col += texColor*vec4(lightColors[1], 1.0)*depth_compare;
|
|
}
|
|
color = col+texColor*0.05;
|
|
|
|
}
|