From 9ca4d7e3e694b73162678062ffe3c6536420dd19 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Wed, 22 Oct 2014 14:49:06 +0200 Subject: [PATCH] Improve ibl specular reflexion using mipmap chain --- data/shaders/diffuseenvmap.frag | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/shaders/diffuseenvmap.frag b/data/shaders/diffuseenvmap.frag index 2ded6b2b0..4a5087f18 100644 --- a/data/shaders/diffuseenvmap.frag +++ b/data/shaders/diffuseenvmap.frag @@ -50,7 +50,9 @@ void main(void) sampleDirection = (InverseViewMatrix * vec4(sampleDirection, 0.)).xyz; float specval = texture(ntex, uv).z; - float lodval = 16 * (1. - ((log2(specval) - 1.) / 10.)); + // From http://graphics.cs.williams.edu/papers/EnvMipReport2013/ + int texSize = textureSize(tex, 0).x; + float lodval = log2(texSize * sqrt(3)) - .5 * log2(specval + 1); vec4 specular = textureLod(tex, sampleDirection, lodval); Spec = max(specular, vec4(0.)); }