vector campos = chv("campos");
vector lgtpos = chv("lgtpos");
float rough = chf("rough");
vector wi = normalize(lgtpos - @P);
vector wo = normalize(campos - @P);
vector h = normalize(wi+wo);
float lambert = max(dot(@N, wi), 0);
float D_GGX_TR(vector N;vector H;float a)
{
float a2 = a*a;
float NdotH = max(dot(N, H), 0.0);
float NdotH2 = NdotH*NdotH;
float nom = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return nom / denom;
}
float GeometrySchlickGGX(float NdotV; float k)
{
float nom = NdotV;
float denom = NdotV * (1.0 - k) + k;
return nom / denom;
}
float GeometrySmith(vector N; vector V;vector L; float k)
{
float NdotV = max(dot(N, V), 0.0);
float NdotL = max(dot(N, L), 0.0);
float ggx1 = GeometrySchlickGGX(NdotV, k);
float ggx2 = GeometrySchlickGGX(NdotL, k);
return ggx1 * ggx2;
}
float kdirect(float rough){
return pow(rough,2) / 2.0f ;
}
vector fresnelSchlick(float cosTheta; vector F0)
{
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
}
vector rough_tex = texture(chs("image"),@uv.x, @uv.y);
vector diff = texture(chs("diff"),@uv.x, @uv.y);
float ggx_tr = D_GGX_TR(@N,h,rough_tex.x );
float ggx_trbase = D_GGX_TR(@N,h,rough );
float k = kdirect(rough_tex.x);
float ggx_smith = GeometrySmith(@N, wo, wi, k);
ggx_smith = max(ggx_smith , 0.0);
//@Cd = diff + ggx_smith * ggx_tr ;
vector fresnelv = fresnelSchlick(dot(@N,wo), chf("fresnel" ));
@Cd = diff*.2 + ggx_tr* ggx_smith * fresnelv;
maybe someone can explain and make this in Real Scene @bentraje