Shadow mapping
This commit is contained in:
@@ -1,16 +1,52 @@
|
||||
#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));
|
||||
|
||||
// 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 (NormZComp + 1.0) * 0.5;
|
||||
}
|
||||
|
||||
in vec2 fragTC;
|
||||
//in vec3 fragNorm;
|
||||
//in vec3 light0Vect;
|
||||
in vec3 light;
|
||||
in vec3 lightColors[lights];
|
||||
in vec3 lightVecs[lights];
|
||||
|
||||
out vec4 color;
|
||||
|
||||
const float bias = 0.00;
|
||||
|
||||
void main(void) {
|
||||
vec4 texColor = texture(texBase, fragTC);
|
||||
|
||||
color = texColor*vec4(light, 1.0)+texColor*0.05;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user