Skip to content

Commit

Permalink
Implemented Ashikhmin-Shirley diffuse term
Browse files Browse the repository at this point in the history
  • Loading branch information
vcoda committed Aug 15, 2020
1 parent 2c3b1b4 commit 15ec80e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cook-torrance/shaders/cookTorrance.frag
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "common/sRGB.h"
#define D_BECKMANN
#define G_COOK_TORRANCE
#define F_DIFFUSE_NDL
#define RD_ASHIKHMIN_SHIRLEY
#include "brdf/cookTorrance.h"

layout(constant_id = 0) const bool c_gammaCorrection = true;
Expand Down
1 change: 1 addition & 0 deletions framework/framework.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<ClInclude Include="debugOutputStream.h" />
<ClInclude Include="graphicsApp.h" />
<ClInclude Include="shaders\brdf\cookTorrance.h" />
<ClInclude Include="shaders\brdf\diffuse.h" />
<ClInclude Include="shaders\brdf\distribution.h" />
<ClInclude Include="shaders\brdf\geometric.h" />
<ClInclude Include="shaders\brdf\phong.h" />
Expand Down
3 changes: 3 additions & 0 deletions framework/framework.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<ClInclude Include="shaders\common\luma.h">
<Filter>Resource Files</Filter>
</ClInclude>
<ClInclude Include="shaders\brdf\diffuse.h">
<Filter>Resource Files\brdf</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="arcball.cpp">
Expand Down
12 changes: 6 additions & 6 deletions framework/shaders/brdf/cookTorrance.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "geometric.h"
#include "distribution.h"
#include "schlick.h"
#include "diffuse.h"

vec3 cookTorrance(vec3 n, vec3 l, vec3 v,
vec3 f0, float roughness,
Expand Down Expand Up @@ -31,11 +32,10 @@ vec3 cookTorrance(vec3 n, vec3 l, vec3 v,
#error geometric function not defined
#endif
vec3 spec = F * D * G/max(4. * NdL * NdV, 1e-6);
#if defined(F_DIFFUSE_NDL)
vec3 Fd = fresnelSchlick(f0, NdL);
#else // UE4 computes it as dot(h, v)
vec3 Fd = F;
#if defined(RD_ASHIKHMIN_SHIRLEY)
vec3 diff = ashikhminShirleyDiffuse(albedo, luma709(f0), NdL, NdV);
#else
vec3 diff = albedo/PI * (1. - luma709(F));
#endif
vec3 diff = albedo * (1. - luma709(Fd))/4.;
return Idiff * (max(NdL, 0.) * diff + spec);
return Idiff * max(NdL, 0.) * (diff + spec);
}
14 changes: 14 additions & 0 deletions framework/shaders/brdf/diffuse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
float halfcosPow5(float cosTheta)
{
float x = 1. - cosTheta/2.;
float x_2 = x * x;
return x_2 * x_2 * x;
}

// https://pdfs.semanticscholar.org/808d/048d4331cf5dac5fd924b50249b7915c6d73.pdf
vec3 ashikhminShirleyDiffuse(vec3 albedo, float f0, float NdL, float NdV)
{
return 28./23. * albedo/PI * (1. - f0) *
(1. - halfcosPow5(NdL)) *
(1. - halfcosPow5(NdV));
}
Binary file modified screenshots/cook-torrance.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 15ec80e

Please sign in to comment.