Skip to content

Commit

Permalink
Fix eye bug (#289)
Browse files Browse the repository at this point in the history
* refactor: fix eye bug
  • Loading branch information
hhhhkrx authored Jul 22, 2024
1 parent c6b717f commit 511e27f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ void PBRFragment(Varyings varyings) {

#ifdef RENDERER_HAS_TANGENT
mat3 tbn = mat3(surfaceData.tangent, surfaceData.bitangent, surfaceData.normal);
#else
mat3 tbn = getTBNByDerivatives(aoUV, normal, varyings.positionWS, gl_FrontFacing);
#endif

// Modify surfaceData by eye algorithm
surfaceData.albedoColor = calculateEyeColor(varyings.uv, tbn);
surfaceData.albedoColor = calculateEyeColor(varyings.uv, tbn, surfaceData);
surfaceData.normal =calculateEyeNormal(varyings.uv, tbn, gl_FrontFacing);
surfaceData.f0 = 0.04;

Expand Down Expand Up @@ -108,7 +110,6 @@ void PBRFragment(Varyings varyings) {
// Emissive
color.rgb += surfaceData.emissiveColor;


#if SCENE_FOG_MODE != 0
color = fog(color, varyings.positionVS);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ vec2 parallaxOffset( float heighttex, float height, vec3 viewDir )
{
float heightTex = heighttex * height- height/2.0;
vec3 s = viewDir;
s.z -= 0.42;
s.y -= s.y;
s.z += 0.42;
return heightTex * (s.xy / s.z);
}

vec3 calculateEyeColor(Varyings varyings, mat3 tbn)
vec3 calculateEyeColor(Varyings varyings, mat3 tbn, SurfaceData surfaceData)
{
// Sclera UV
vec2 scleraUV = (varyings.uv * material_ScleraSize)-((material_ScleraSize-1.0)/2.0);
Expand Down Expand Up @@ -68,15 +67,15 @@ vec3 calculateEyeColor(Varyings varyings, mat3 tbn)
#ifdef MATERIAL_HAS_SCLERA_MASK
vec3 irisMaskTex = (texture2D(material_ScleraMask, irisSizeUV)).rgb;
float uvmask = 1.0 - (texture2D(material_ScleraMask, varyings.uv )).b;
heighttexture = 1.0 - (texture2D(material_ScleraMask, parallaxUV)).b;
heighttexture = (texture2D(material_ScleraMask, parallaxUV)).b;
#else
vec3 irisMaskTex = vec3(1.0);
float uvmask = 1.0;
heighttexture = 1.0;
#endif

// Transform ViewdirWS To ViewdirTS
vec3 vDir = normalize(camera_Position - varyings.positionWS);
vec3 vDir = surfaceData.viewDir;
vec3 viewDirInTBN = tbn * vDir;

vec2 offset = parallaxOffset(heighttexture, material_Parallax, viewDirInTBN);
Expand Down

0 comments on commit 511e27f

Please sign in to comment.