Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCryZe

Posted 01 February 2013 - 02:17 AM

Oh wait, you want to do metals with the fresnel equations? If that's the case, your formula from the other thread won't work. Metals usually have complex reflective indices (complex numbers). Fresnel's equations work with complex numbers though, your implementation just doesn't. You need complex multiplication, complex addition and the absolute value (which you didn't implement) needs to work with complex numbers as well. Also since metals have chromatic reflections you would have to calculate your fresnel term for all 3 color channels. I'd use Schlick's approximation, reduce most of it to constant time, and reduce other parts of the formula to scalar calculations, while only the necessary parts get calculated for all color channels.

 

Here's approximately how that code should look like. You should probably calculate the constant part per vertex or per draw call on the CPU, if possible:

 

float2 f0CmplxRed = cmplxDiv(cmplxSub(n1Red, n2Red), cmplxAdd(n1Red, n2Red));
float2 f0CmplxGreen = cmplxDiv(cmplxSub(n1Green, n2Green), cmplxAdd(n1Green, n2Green));
float2 f0CmplxBlue = cmplxDiv(cmplxSub(n1Blue, n2Blue), cmplxAdd(n1Blue, n2Blue));

float3 f0Sqrt = 0;
f0Sqrt.r = cmplxAbs(f0CmplxRed);
f0Sqrt.g = cmplxAbs(f0CmplxGreen);
f0Sqrt.b = cmplxAbs(f0CmplxBlue);

float3 f0 = f0Sqrt * f0Sqrt;
float3 cf0 = 1 - f0;

foreach (light)
{
	float factor = pow(1 - dot(L, H), 5);
	float3 fresnel = f0 + cf0 * factor;
} 

 

 


#1CryZe

Posted 01 February 2013 - 02:07 AM

Oh wait, you want to do metals with the fresnel equations? If that's the case, your formula from the other thread won't work. Metals usually have complex reflective indices (complex numbers). Fresnel's equations work with complex numbers though, your implementation just doesn't. You need complex multiplication, complex addition and the absolute value (which you didn't implement) needs to work with complex numbers as well. Also since metals have chromatic reflections you would have to calculate your fresnel term for all 3 color channels.

I'd use Schlick's approximation, reduce most of it to constant time, and reduce other parts of the formula to scalar calculations, while only the necessary parts get calculated for all color channels.


PARTNERS