|
6 | 6 | #include <irr/builtin/glsl/bxdf/brdf/specular/beckmann.glsl>
|
7 | 7 | #include <irr/builtin/glsl/bxdf/bsdf/specular/common.glsl>
|
8 | 8 |
|
9 |
| -irr_glsl_BxDFSample irr_glsl_beckmann_dielectric_cos_generate_wo_clamps(in vec3 localV, in bool backside, in vec3 upperHemisphereLocalV, in mat3 m, in vec3 u, in float ax, in float ay, in float rcpOrientedEta, in float orientedEta2, in float rcpOrientedEta2) |
| 9 | +irr_glsl_LightSample irr_glsl_beckmann_dielectric_cos_generate_wo_clamps(in vec3 localV, in bool backside, in vec3 upperHemisphereLocalV, in mat3 m, in vec3 u, in float ax, in float ay, in float rcpOrientedEta, in float orientedEta2, in float rcpOrientedEta2, out irr_glsl_AnisotropicMicrofacetCache _cache) |
10 | 10 | {
|
11 | 11 | // thanks to this manouvre the H will always be in the upper hemisphere (NdotH>0.0)
|
12 | 12 | const vec3 H = irr_glsl_beckmann_cos_generate_wo_clamps(upperHemisphereLocalV,u.xy,ax,ay);
|
13 |
| - |
14 |
| - const float reflectance = 1.0;// irr_glsl_fresnel_dielectric_common(orientedEta2, upperHemisphereLocalV.z); |
| 13 | + |
| 14 | + const float VdotH = dot(localV,H); |
| 15 | + const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,abs(VdotH)); |
15 | 16 |
|
16 | 17 | float rcpChoiceProb;
|
17 | 18 | bool transmitted = irr_glsl_partitionRandVariable(reflectance, u.z, rcpChoiceProb);
|
18 | 19 |
|
19 |
| - const float VdotH = dot(localV,H); |
20 |
| - return irr_glsl_createBSDFSample(transmitted,H,localV,backside,VdotH,VdotH*VdotH,m,rcpOrientedEta,rcpOrientedEta2); |
| 20 | + vec3 localL; |
| 21 | + _cache = irr_glsl_calcAnisotropicMicrofacetCache(transmitted,localV,H,localL,rcpOrientedEta,rcpOrientedEta2); |
| 22 | + |
| 23 | + return irr_glsl_createLightSampleTangentSpace(localV,localL,m); |
21 | 24 | }
|
22 | 25 |
|
23 |
| -irr_glsl_BxDFSample irr_glsl_beckmann_dielectric_cos_generate(in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in vec3 u, in float ax, in float ay, in float eta) |
| 26 | +irr_glsl_LightSample irr_glsl_beckmann_dielectric_cos_generate(in irr_glsl_AnisotropicViewSurfaceInteraction interaction, in vec3 u, in float ax, in float ay, in float eta, out irr_glsl_AnisotropicMicrofacetCache _cache) |
24 | 27 | {
|
25 | 28 | const vec3 localV = irr_glsl_getTangentSpaceV(interaction);
|
26 |
| - const float NdotV = localV.z; |
27 | 29 |
|
28 |
| - float rcpOrientedEta, orientedEta2, rcpOrientedEta2; |
29 |
| - const bool backside = irr_glsl_getOrientedEtas(rcpOrientedEta, orientedEta2, rcpOrientedEta2, NdotV, eta); |
| 30 | + float orientedEta, rcpOrientedEta; |
| 31 | + const bool backside = irr_glsl_getOrientedEtas(orientedEta, rcpOrientedEta, interaction.isotropic.NdotV, eta); |
30 | 32 |
|
31 | 33 | const vec3 upperHemisphereV = backside ? (-localV):localV;
|
32 | 34 |
|
33 | 35 | const mat3 m = irr_glsl_getTangentFrame(interaction);
|
34 |
| - return irr_glsl_beckmann_dielectric_cos_generate_wo_clamps(localV,backside,upperHemisphereV,m,u,ax,ay, rcpOrientedEta,orientedEta2,rcpOrientedEta2); |
| 36 | + return irr_glsl_beckmann_dielectric_cos_generate_wo_clamps(localV,backside,upperHemisphereV,m, u,ax,ay, rcpOrientedEta,orientedEta*orientedEta,rcpOrientedEta*rcpOrientedEta,_cache); |
35 | 37 | }
|
36 | 38 |
|
37 | 39 |
|
38 | 40 |
|
39 | 41 | // isotropic PDF
|
40 |
| -float irr_glsl_beckmann_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float ndf, in float absNdotV, in float NdotV2, in float a2, out float onePlusLambda_V) |
41 |
| -{ |
42 |
| - return irr_glsl_VNDF_fresnel_sampled_BRDF_pdf_to_BSDF_pdf(transmitted,reflectance,irr_glsl_beckmann_pdf_wo_clamps(ndf,absNdotV,NdotV2,a2,onePlusLambda_V)); |
43 |
| -} |
44 |
| - |
45 |
| -float irr_glsl_beckmann_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float NdotH2, in float absNdotV, in float NdotV2, in float a2) |
| 42 | +float irr_glsl_beckmann_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float ndf, in float absNdotV, in float NdotV2, in float VdotH, in float LdotH, in float VdotHLdotH, in float a2, in float orientedEta, out float onePlusLambda_V) |
46 | 43 | {
|
47 |
| - return irr_glsl_VNDF_fresnel_sampled_BRDF_pdf_to_BSDF_pdf(transmitted,reflectance,irr_glsl_beckmann_pdf_wo_clamps(NdotH2,absNdotV,NdotV2,a2)); |
| 44 | + const float lambda = irr_glsl_smith_beckmann_Lambda(NdotV2, a2); |
| 45 | + return irr_glsl_smith_VNDF_pdf_wo_clamps(ndf,lambda,absNdotV,transmitted,VdotH,LdotH,VdotHLdotH,orientedEta,reflectance,onePlusLambda_V); |
48 | 46 | }
|
49 | 47 |
|
50 | 48 | // anisotropic PDF
|
51 |
| -float irr_glsl_beckmann_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float ndf, in float absNdotV, in float TdotV2, in float BdotV2, in float NdotV2, in float ax2, in float ay2, out float onePlusLambda_V) |
52 |
| -{ |
53 |
| - return irr_glsl_VNDF_fresnel_sampled_BRDF_pdf_to_BSDF_pdf(transmitted,reflectance,irr_glsl_beckmann_pdf_wo_clamps(ndf,absNdotV,TdotV2,BdotV2,NdotV2,ax2,ay2,onePlusLambda_V)); |
54 |
| -} |
55 |
| - |
56 |
| -float irr_glsl_beckmann_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float NdotH2, in float TdotH2, in float BdotH2, in float absNdotV, in float TdotV2, in float BdotV2, in float NdotV2, in float ax, in float ax2, in float ay, in float ay2) |
| 49 | +float irr_glsl_beckmann_dielectric_pdf_wo_clamps(in bool transmitted, in float reflectance, in float ndf, in float absNdotV, in float TdotV2, in float BdotV2, in float NdotV2, in float VdotH, in float LdotH, in float VdotHLdotH, in float ax2, in float ay2, in float orientedEta, out float onePlusLambda_V) |
57 | 50 | {
|
58 |
| - return irr_glsl_VNDF_fresnel_sampled_BRDF_pdf_to_BSDF_pdf(transmitted,reflectance,irr_glsl_beckmann_pdf_wo_clamps(NdotH2,TdotH2,BdotH2,absNdotV,TdotV2,BdotV2,NdotV2,ax,ax2,ay,ay2)); |
| 51 | + float c2 = irr_glsl_smith_beckmann_C2(TdotV2, BdotV2, NdotV2, ax2, ay2); |
| 52 | + float lambda = irr_glsl_smith_beckmann_Lambda(c2); |
| 53 | + return irr_glsl_smith_VNDF_pdf_wo_clamps(ndf,lambda,absNdotV,transmitted,VdotH,LdotH,VdotHLdotH,orientedEta,reflectance,onePlusLambda_V); |
59 | 54 | }
|
60 | 55 |
|
61 | 56 |
|
62 | 57 |
|
63 |
| -float irr_glsl_beckmann_dielectric_cos_remainder_and_pdf_wo_clamps(out float pdf, in float ndf, in bool transmitted, in float absNdotL, in float NdotL2, in float absNdotV, in float NdotV2, in float reflectance, in float transmission_relative_to_reflection_differential_factor, in float a2) |
| 58 | +float irr_glsl_beckmann_dielectric_cos_remainder_and_pdf_wo_clamps(out float pdf, in float ndf, in bool transmitted, in float NdotL2, in float absNdotV, in float NdotV2, in float VdotH, in float LdotH, in float VdotHLdotH, in float reflectance, in float orientedEta, in float a2) |
64 | 59 | {
|
65 | 60 | float onePlusLambda_V;
|
66 |
| - pdf = irr_glsl_beckmann_dielectric_pdf_wo_clamps(transmitted, 1.0, ndf, absNdotV, NdotV2, a2, onePlusLambda_V); |
| 61 | + pdf = irr_glsl_beckmann_dielectric_pdf_wo_clamps(transmitted, reflectance, ndf, absNdotV, NdotV2, VdotH, LdotH, VdotHLdotH, a2, orientedEta, onePlusLambda_V); |
67 | 62 |
|
68 |
| - const float G2_over_G1 = irr_glsl_beckmann_smith_G2_over_G1(onePlusLambda_V, absNdotL, NdotL2, a2); |
69 |
| - return G2_over_G1; |
70 |
| - //return irr_glsl_VNDF_fresnel_sampled_BSDF_cos_remainder(transmitted,G2_over_G1,transmission_relative_to_reflection_differential_factor); |
| 63 | + return irr_glsl_beckmann_smith_G2_over_G1(onePlusLambda_V, NdotL2, a2); |
71 | 64 | }
|
72 |
| -float irr_glsl_beckmann_dielectric_cos_remainder_and_pdf(out float pdf, in irr_glsl_BxDFSample s, in irr_glsl_IsotropicViewSurfaceInteraction interaction, in float eta, in float a2) |
73 |
| -{ |
74 |
| - const float NdotH2 = s.NdotH * s.NdotH; |
75 |
| - const float ndf = irr_glsl_beckmann(a2, NdotH2); |
76 |
| - |
77 |
| - const float NdotL2 = s.NdotL * s.NdotL; |
78 |
| - |
79 |
| - const float absNdotV = abs(interaction.NdotV); |
80 |
| - |
81 |
| - float orientedEta, orientedEta2, rcpOrientedEta2; |
82 |
| - const bool backside = irr_glsl_getOrientedEtas(orientedEta, orientedEta2, rcpOrientedEta2, interaction.NdotV, eta); |
83 |
| - const float VdotH2 = s.VdotH * s.VdotH; |
84 |
| - const float LdotH = irr_glsl_refract_compute_NdotT(backside,VdotH2,rcpOrientedEta2); |
85 | 65 |
|
86 |
| - const float VdotHLdotH = s.VdotH*LdotH; |
87 |
| - const bool transmitted = isnan(LdotH);//VdotHLdotH < 0.0; |
88 |
| - |
89 |
| - const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,s.VdotH); |
| 66 | +float irr_glsl_beckmann_dielectric_cos_remainder_and_pdf(out float pdf, in irr_glsl_LightSample _sample, in irr_glsl_IsotropicViewSurfaceInteraction interaction, in irr_glsl_IsotropicMicrofacetCache _cache, in float eta, in float a2) |
| 67 | +{ |
| 68 | + const float ndf = irr_glsl_beckmann(a2,_cache.NdotH2); |
| 69 | + |
| 70 | + float orientedEta, rcpOrientedEta; |
| 71 | + const bool backside = irr_glsl_getOrientedEtas(orientedEta, rcpOrientedEta, _cache.VdotH, eta); |
| 72 | + const float orientedEta2 = orientedEta*orientedEta; |
| 73 | + const float rcpOrientedEta2 = rcpOrientedEta*rcpOrientedEta; |
90 | 74 |
|
91 |
| - const float factor = 1.0;// irr_glsl_microfacet_transmission_relative_to_reflection_differential_factor(s.VdotH, LdotH, VdotHLdotH, 1.0 / orientedEta); |
| 75 | + const float VdotHLdotH = _cache.VdotH*_cache.LdotH; |
| 76 | + const bool transmitted = VdotHLdotH<0.0; |
| 77 | + |
| 78 | + const float reflectance = irr_glsl_fresnel_dielectric_common(orientedEta2,abs(_cache.VdotH)); |
92 | 79 |
|
93 |
| - return irr_glsl_beckmann_dielectric_cos_remainder_and_pdf_wo_clamps(pdf, ndf, transmitted, abs(s.NdotL), NdotL2, absNdotV, interaction.NdotV_squared, reflectance, factor, a2); |
| 80 | + const float absNdotV = abs(interaction.NdotV); |
| 81 | + return irr_glsl_beckmann_dielectric_cos_remainder_and_pdf_wo_clamps(pdf, ndf, transmitted, _sample.NdotL2, absNdotV, interaction.NdotV_squared, _cache.VdotH, _cache.LdotH, VdotHLdotH, reflectance, orientedEta, a2); |
94 | 82 | }
|
95 | 83 |
|
96 | 84 | #if 0
|
|
0 commit comments