Fix texture lookup out of bounds in imposter
@@ -10,10 +10,11 @@ layout (location = 1) out vec4 out_normal;
void main()
{
- float layer = float(no_views) * t;
+ float layer = float(no_views) * clamp(t, 0.0, 0.999);
float index0 = floor(layer);
float index1 = float((int(index0) + 1) % no_views);
+ float frac = layer - index0;
vec4 color0 = texture(tex, vec3(uv, index0));
if(color0.a < 0.01) { // No diffuse intensity. Test depth instead? Dithering?
@@ -23,11 +24,11 @@ void main()
if(color1.a < 0.01) { // No diffuse intensity. Test depth instead? Dithering?
discard;
}
- out_color = mix(color0, color1, fract(layer));
+ out_color = mix(color0, color1, frac);
vec4 normal0 = texture(tex, vec3(uv, float(no_views) + index0));
vec4 normal1 = texture(tex, vec3(uv, float(no_views) + index1));
- out_normal = mix(normal0, normal1, fract(layer));
+ out_normal = mix(normal0, normal1, frac);
out_normal.xyz = 2.0 * out_normal.xyz - 1.0;
out_normal.xyz = 0.5 + 0.5 * normalize(vec3(cs.x * out_normal.x + cs.y * out_normal.z, out_normal.y, -cs.y * out_normal.x + cs.x * out_normal.z));
// Maybe update depth as well?
