22#extension GL_ARB_separate_shader_objects : enable
33
44#include "math.glsl"
5+ #include "brdf.glsl"
56#include "pl_shader_interop.h"
67#include "pl_shader_interop_renderer.h"
78
@@ -18,7 +19,6 @@ layout(std140, set = 0, binding = 8) buffer _tBufferOut6{ vec4 atPixelData[]; }
1819// enum
1920const int cLambertian = 0;
2021const int cGGX = 1;
21- const int cCharlie = 2;
2222
2323//-----------------------------------------------------------------------------
2424// [SECTION] dynamic bind group
@@ -74,37 +74,6 @@ pl_write_face(int iPixel, int iFace, vec3 tColorIn)
7474 tFaceOut5.atPixelData[iPixel] = tColor;
7575}
7676
77- vec2
78- pl_hammersley_2d(int i, int iN)
79- {
80- // Hammersley Points on the Hemisphere
81- // CC BY 3.0 (Holger Dammertz)
82- // http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
83- // with adapted interface
84- uint uBits = uint(i);
85- uBits = (uBits << 16u) | (uBits >> 16u);
86- uBits = ((uBits & 0x55555555u) << 1u) | ((uBits & 0xAAAAAAAAu) >> 1u);
87- uBits = ((uBits & 0x33333333u) << 2u) | ((uBits & 0xCCCCCCCCu) >> 2u);
88- uBits = ((uBits & 0x0F0F0F0Fu) << 4u) | ((uBits & 0xF0F0F0F0u) >> 4u);
89- uBits = ((uBits & 0x00FF00FFu) << 8u) | ((uBits & 0xFF00FF00u) >> 8u);
90- float rdi = float(uBits) * 2.3283064365386963e-10; // / 0x100000000
91-
92- // hammersley2d describes a sequence of points in the 2d unit square [0,1)^2
93- // that can be used for quasi Monte Carlo integration
94- return vec2(float(i)/float(iN), rdi);
95- }
96-
97- float
98- pl_random(vec2 co)
99- {
100- float a = 12.9898;
101- float b = 78.233;
102- float c = 43758.5453;
103- float dt = dot(co.xy, vec2(a, b));
104- float sn = mod(dt, 3.14);
105- return fract(sin(sn) * c);
106- }
107-
10877mat3
10978pl_generate_tbn(vec3 tNormal)
11079{
@@ -179,35 +148,6 @@ pl_ggx(vec2 tXi, float fRoughness)
179148 return tGgx;
180149}
181150
182- float
183- pl_d_charlie(float fSheenRoughness, float fNdotH)
184- {
185- fSheenRoughness = max(fSheenRoughness, 0.000001); //clamp (0,1]
186- const float fInvR = 1.0 / fSheenRoughness;
187- const float fCos2h = fNdotH * fNdotH;
188- const float fSin2h = 1.0 - fCos2h;
189- return (2.0 + fInvR) * pow(fSin2h, fInvR * 0.5) / (2.0 * PL_PI);
190- }
191-
192- MicrofacetDistributionSample
193- pl_charlie(vec2 tXi, float fRoughness)
194- {
195- MicrofacetDistributionSample tCharlie;
196-
197- const float fAlpha = fRoughness * fRoughness;
198- tCharlie.sinTheta = pow(tXi.y, fAlpha / (2.0 * fAlpha + 1.0));
199- tCharlie.cosTheta = sqrt(1.0 - tCharlie.sinTheta * tCharlie.sinTheta);
200- tCharlie.phi = 2.0 * PL_PI * tXi.x;
201-
202- // evaluate Charlie pdf (for half vector)
203- tCharlie.pdf = pl_d_charlie(fAlpha, tCharlie.cosTheta);
204-
205- // Apply the Jacobian to obtain a pdf that is parameterized by l
206- tCharlie.pdf /= 4.0;
207-
208- return tCharlie;
209- }
210-
211151MicrofacetDistributionSample
212152pl_lambertian(vec2 tXi, float fRoughness)
213153{
@@ -246,10 +186,6 @@ pl_get_importance_sample(int iSampleIndex, vec3 tN, float fRoughness)
246186 // https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html
247187 tImportanceSample = pl_ggx(tXi, fRoughness);
248188 }
249- else if(tDynamicData.tData.iDistribution == cCharlie)
250- {
251- tImportanceSample = pl_charlie(tXi, fRoughness);
252- }
253189
254190 tImportanceSample.phi = tImportanceSample.phi + pl_random(tN.xz) * 0.1;
255191
@@ -327,26 +263,6 @@ pl_filter_color(vec3 tN)
327263
328264 tColor += tLambertian;
329265 }
330- else if(tDynamicData.tData.iDistribution == cGGX || tDynamicData.tData.iDistribution == cCharlie)
331- {
332- // Note: reflect takes incident vector.
333- const vec3 tV = tN;
334- const vec3 tL = normalize(reflect(-tV, tH));
335- const float fNdotL = dot(tN, tL);
336-
337- if (fNdotL > 0.0)
338- {
339- if(tDynamicData.tData.fRoughness == 0.0)
340- {
341- // without this the roughness=0 lod is too high
342- fLod = tDynamicData.tData.fLodBias;
343- }
344- vec3 sampleColor = textureLod(samplerCube(uCubeMap, tDefaultSampler), tL, fLod).rgb;
345- // sampleColor = pl_linear_to_srgb(sampleColor);
346- tColor += sampleColor * fNdotL;
347- fWeight += fNdotL;
348- }
349- }
350266 }
351267
352268 if(fWeight != 0.0)
@@ -420,23 +336,12 @@ pl_lut(float fNdotV, float fRoughness)
420336 // Taken from: https://bruop.github.io/ibl
421337 // Shadertoy: https://www.shadertoy.com/view/3lXXDB
422338 // Terms besides V are from the GGX PDF we're dividing by.
423- float fVPdf = pl_v_smith_ggx_correlated(fNdotV, fNdotL , fRoughness) * fVdotH * fNdotL / fNdotH;
339+ float fVPdf = pl_v_smith_ggx_correlated(fNdotL, fNdotV , fRoughness) * fVdotH * fNdotL / fNdotH;
424340 float fFc = pow(1.0 - fVdotH, 5.0);
425341 fA += (1.0 - fFc) * fVPdf;
426342 fB += fFc * fVPdf;
427343 fC += 0.0;
428344 }
429-
430- if (tDynamicData.tData.iDistribution == cCharlie)
431- {
432- // LUT for Charlie distribution.
433- float fSheenDistribution = pl_d_charlie(fRoughness, fNdotH);
434- float fSheenVisibility = pl_v_ashikhmin(fNdotL, fNdotV);
435-
436- fA += 0.0;
437- fB += 0.0;
438- fC += fSheenVisibility * fSheenDistribution * fNdotL * fVdotH;
439- }
440345 }
441346 }
442347
0 commit comments