Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Specular-AA #2141

Merged
merged 15 commits into from Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions jme3-core/src/main/java/com/jme3/texture/Texture.java
Expand Up @@ -637,11 +637,11 @@ public void read(JmeImporter importer) throws IOException {
}
}

anisotropicFilter = capsule.readInt("anisotropicFilter", 1);
minificationFilter = capsule.readEnum("minificationFilter",
setAnisotropicFilter(capsule.readInt("anisotropicFilter", 1));
setMinFilter(capsule.readEnum("minificationFilter",
MinFilter.class,
MinFilter.BilinearNoMipMaps);
magnificationFilter = capsule.readEnum("magnificationFilter",
MagFilter.class, MagFilter.Bilinear);
MinFilter.BilinearNoMipMaps));
setMagFilter(capsule.readEnum("magnificationFilter",
MagFilter.class, MagFilter.Bilinear));
}
}
Expand Up @@ -56,6 +56,9 @@ MaterialDef PBR Lighting {
// Parallax/height map
Texture2D ParallaxMap -LINEAR

// Specular-AA
Boolean SpecularAA

riccardobl marked this conversation as resolved.
Show resolved Hide resolved
//Set to true if parallax map is stored in the alpha channel of the normal map
Boolean PackedNormalParallax

Expand Down Expand Up @@ -163,6 +166,7 @@ MaterialDef PBR Lighting {
USE_PACKED_MR: MetallicRoughnessMap
USE_PACKED_SG: SpecularGlossinessMap
SPECULARMAP : SpecularMap
SPECULAR_AA : SpecularAA
GLOSSINESSMAP : GlossinessMap
NORMAL_TYPE: NormalType
VERTEX_COLOR : UseVertexColor
Expand Down
21 changes: 21 additions & 0 deletions jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib
Expand Up @@ -6,6 +6,24 @@
#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/com.unity.render-pipelines.high-definition@15.0/manual/Geometric-Specular-Anti-Aliasing.html
void Specular_Anti_Aliasing(in vec3 normal, in vec3 half_vector,
inout float alpha_x)
{

float sigma = 0.50f; //- screen space variance
float Kappa = 0.18f; //- clamping treshold
vec3 dndu = dFdx(normal);
vec3 dndv = dFdy(normal);
float variance = sigma*sigma*(dot(dndu, dndu) + dot(dndv, dndv));
float kernel_roughness = min(Kappa, variance);
alpha_x = sqrt(alpha_x*alpha_x + 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);
Expand Down Expand Up @@ -54,6 +72,9 @@ 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;
#ifdef SPECULAR_AA
Specular_Anti_Aliasing(normal, halfVec, alpha);
#endif

//D, GGX normal Distribution function
float alpha2 = alpha * alpha;
Expand Down