forked from jMonkeyEngine/jmonkeyengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for Specular-AA (jMonkeyEngine#2141)
* Fixes Issue jMonkeyEngine#2132 * jme3-core:Adding support for Specular-AA * jme3-core:del Specular_Anti_Aliasing2 * jme3-core:update Specular_Anti_Aliasing * jme3-core:update Specular_Anti_Aliasing * jme3-core:add MatParam:Sigma,Kappa * jme3-terrain:Adding support for Specular-AA * jme3-core:update PBRLighting.j3md(with SpecularAA) * jme3-terrain:update PBRTerrain.j3md(with SpecularAA) * jmee-core:remove the "f" suffix * jmee-terrain:remove the "f" suffix * jme3-core:Updated parameter names in PBRLighting.j3md * jme3-terrain:Updated parameter names in PBRTerrain.j3md/AdvacedPBRTerrain.j3md * jme3-core:Updated macro definitions in PBRLighting.j3md * jme3-terrain:Updated macro definitions in PBRTerrain.j3md/AdvancedPBRTerrain.j3md --------- Co-authored-by: chenliming <[email protected]>
- Loading branch information
Showing
7 changed files
with
165 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,22 @@ | |
#define NB_PROBES 0 | ||
#endif | ||
|
||
// BEGIN-@jhonkkk,Specular AA -------------------------------------------------------------- | ||
// see:http://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA(slides).pdf | ||
// https://docs.unity3d.com/Packages/[email protected]/manual/Geometric-Specular-Anti-Aliasing.html | ||
float Specular_Anti_Aliasing(in vec3 normal, in vec3 half_vector, | ||
float alpha, in float sigma, in float kappa) | ||
{ | ||
|
||
vec3 dndu = dFdx(normal); | ||
vec3 dndv = dFdy(normal); | ||
float variance = sigma*sigma*(dot(dndu, dndu) + dot(dndv, dndv)); | ||
float kernel_roughness = min(kappa, variance); | ||
return sqrt(alpha*alpha + kernel_roughness); | ||
} | ||
// END-@jhonkkk | ||
|
||
|
||
//Specular fresnel computation | ||
vec3 F_Shlick(float vh, vec3 F0){ | ||
float fresnelFact = pow(2.0, (-5.55473*vh - 6.98316) * vh); | ||
|
@@ -34,12 +50,11 @@ vec3 sphericalHarmonics( const in vec3 normal, const vec3 sph[9] ){ | |
return max(result, vec3(0.0)); | ||
} | ||
|
||
|
||
float PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir, | ||
vec3 lightColor, vec3 fZero, float roughness, float ndotv, | ||
// BEGIN-@jhonkkk,todo:Keeping the original PBR_ComputeDirectLight function signature is for backwards compatibility, but this adds an extra internal function call, theoretically here we should use a macro to define Inner_PBR_ComputeDirectLight, or best to calculate alpha externally and directly call the Inner_PBR_ComputeDirectLight function. | ||
float Inner_PBR_ComputeDirectLight( | ||
vec3 normal, vec3 halfVec, vec3 lightDir, vec3 viewDir, | ||
vec3 lightColor, vec3 fZero, float alpha, float ndotv, | ||
out vec3 outDiffuse, out vec3 outSpecular){ | ||
// Compute halfway vector. | ||
vec3 halfVec = normalize(lightDir + viewDir); | ||
|
||
// Compute ndotl, ndoth, vdoth terms which are needed later. | ||
float ndotl = max( dot(normal, lightDir), 0.0); | ||
|
@@ -53,8 +68,6 @@ float PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir, | |
|
||
//cook-torrence, microfacet BRDF : http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf | ||
|
||
float alpha = roughness * roughness; | ||
|
||
//D, GGX normal Distribution function | ||
float alpha2 = alpha * alpha; | ||
float sum = ((ndoth * ndoth) * (alpha2 - 1.0) + 1.0); | ||
|
@@ -89,6 +102,31 @@ float PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir, | |
return hdotv; | ||
} | ||
|
||
float PBR_ComputeDirectLight( | ||
vec3 normal, vec3 lightDir, vec3 viewDir, | ||
vec3 lightColor, vec3 fZero, float roughness, float ndotv, | ||
out vec3 outDiffuse, out vec3 outSpecular){ | ||
// Compute halfway vector. | ||
vec3 halfVec = normalize(lightDir + viewDir); | ||
return Inner_PBR_ComputeDirectLight(normal, halfVec, lightDir, viewDir, | ||
lightColor, fZero, roughness * roughness, ndotv, | ||
outDiffuse, outSpecular); | ||
} | ||
|
||
float PBR_ComputeDirectLightWithSpecularAA( | ||
vec3 normal, vec3 lightDir, vec3 viewDir, | ||
vec3 lightColor, vec3 fZero, float roughness, float sigma, float kappa, float ndotv, | ||
out vec3 outDiffuse, out vec3 outSpecular){ | ||
// Compute halfway vector. | ||
vec3 halfVec = normalize(lightDir + viewDir); | ||
// Specular-AA | ||
float alpha = Specular_Anti_Aliasing(normal, halfVec, roughness * roughness, sigma, kappa); | ||
return Inner_PBR_ComputeDirectLight(normal, halfVec, lightDir, viewDir, | ||
lightColor, fZero, alpha, ndotv, | ||
outDiffuse, outSpecular); | ||
} | ||
// END-@jhonkkk | ||
|
||
vec3 integrateBRDFApprox( const in vec3 specular, float roughness, float NoV ){ | ||
const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022 ); | ||
const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04 ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters