Weight sample in importance sampling

This commit is contained in:
Vincent Lejeune 2014-12-07 18:26:51 +01:00
parent 7686628401
commit e491422bdc

@ -16,15 +16,18 @@ void main(void)
vec3 up = (RayDir.y < .99) ? vec3(0., 1., 0.) : vec3(0., 0., 1.);
vec3 Tangent = normalize(cross(up, RayDir));
vec3 Bitangent = cross(RayDir, Tangent);
float weight = 0.;
for (int i = 0; i < 1024; i++)
{
float Theta = samples[2 * i];
float Phi = samples[2 * i + 1];
vec3 sampleDir = cos(Theta) * RayDir + sin(Theta) * cos(Phi) * Tangent + sin(Theta) * sin(Phi) * Bitangent;
FinalColor += textureLod(tex, sampleDir, 0.);
vec3 L = cos(Theta) * RayDir + sin(Theta) * cos(Phi) * Tangent + sin(Theta) * sin(Phi) * Bitangent;
float NdotL = clamp(dot(RayDir, L), 0., 1.);
FinalColor += textureLod(tex, L, 0.) * NdotL;
weight += NdotL;
}
FragColor = FinalColor / 1024.;
FragColor = FinalColor / weight;
}