Hey. After much searching, I found the right shader for IBL, but I have a problem with porting. As far as I know, Unity does not support hlsl language. Can somebody help me with porting this?
More about this shader here, on page 47: ftp://ftp.cordis.europa.eu/pub/ist/docs/kct/gametools-tutorial-t12_en.pdf
half M;
half PI;
half n;
float4 ka, kd, ks;
samplerCUBE LRCubeMap;
half3 Cntr(half3 x, half3 L, half3 N, half3 V)
{
half l = length(L);
half dw = 1 / sqrt(1 + 4/(M*M*l*l*l*PI)); //Solid angle of the texel
half doy = texCUBE(LRCubeMap, L).a;
half doy2 = doy * doy;
half3 y = L / l * doy;
half doy_dxy2 = doy2 / dot(y-x, y-x);
half dws = 2*PI - dw /sqrt((dw*dw*(1-doy_dxy2)+doy_dxy2));
half3 I = normalize(y - x); //Illumination direction
half3 H = normalize(I + V);
half3 a = kd * max(dot(N,I),0) + ks * pow(max(dot(N,H),0),n);
half3 Lin = texCUBE(LRCubeMap, L).rgb;
return Lin * a * dws;
}
half3 RefRadPS (
half3 N : TEXCOORD0, // normal
half3 V : TEXCOORD1, // view
half3 x : TEXCOORD2 ) : COLOR0
{
half3 Lr = 0; // reflected radiance
V = normalize( V );
N = normalize( N );
for (int X = 0; X < M; X++) // for each texel
for (int Y = 0; Y < M; Y++)
{
half2 t = half2((1+0.5f)/M, (1+0.5f)/M);
half2 l = 2 * t - 1; // [0,1]->[-1,1]
Lr += Cntr(x, half3(l.x,l.y, 1), N, V);
Lr += Cntr(x, half3(l.x,l.y,-1), N, V);
Lr += Cntr(x, half3(l.x, 1,l.y), N, V);
Lr += Cntr(x, half3(l.x,-1, l.y), N, V);
Lr += Cntr(x, half3(1,l.x,l.y), N, V);
Lr += Cntr(x, half3(-1, l.x,l.y), N, V);
}
return Lr;
}