Skip to content

Commit

Permalink
fix: merge engine version error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxudong committed Jul 22, 2024
1 parent 643fa46 commit c6b717f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/shaderlab/src/shaders/Normal.glsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#ifndef NORMAL_INCLUDED
#define NORMAL_INCLUDED

// gl_FrontFacing has random value on Adreno GPUs
// the Adreno bug is only when gl_FrontFacing is inside a function
// https://bugs.chromium.org/p/chromium/issues/detail?id=1154842
vec3 getNormal(vec3 normal, bool isFrontFacing){
normal *= float( isFrontFacing ) * 2.0 - 1.0;
return normal;
}

vec3 getNormalByNormalTexture(mat3 tbn, sampler2D normalTexture, float normalIntensity, vec2 uv, bool isFrontFacing){
vec3 normal = (texture2D(normalTexture, uv)).rgb;
Expand All @@ -32,7 +25,8 @@ mat3 getTBNByDerivatives(vec2 uv, vec3 normal, vec3 position, bool isFrontFacing
vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;
vec3 bitangent = dp2perp * duv1.y + dp1perp * duv2.y;
// construct a scale-invariant frame
float invmax = inversesqrt(max(dot(tangent, tangent), dot(bitangent, bitangent)));
float denom = max( dot(tangent, tangent), dot(bitangent, bitangent) );
float invmax = (denom == 0.0) ? 0.0 : camera_ProjectionParams.x / sqrt( denom );
return mat3(tangent * invmax, bitangent * invmax, normal);
#else
return mat3(vec3(0.0), vec3(0.0), normal);
Expand Down
1 change: 1 addition & 0 deletions packages/shaderlab/src/shaders/Transform.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ mat4 renderer_NormalMat;

vec3 camera_Position;
vec3 camera_Forward;
vec4 camera_ProjectionParams;

#endif
2 changes: 2 additions & 0 deletions packages/shaderlab/src/shaders/shadingPBR/FragmentPBR.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ SurfaceData getSurfaceData(Varyings v, vec2 aoUV, bool isFrontFacing){
vec3 pos_dx = dFdx(v.positionWS);
vec3 pos_dy = dFdy(v.positionWS);
vec3 normal = normalize( cross(pos_dx, pos_dy) );
normal *= camera_ProjectionParams.x;
#else
vec3 normal = vec3(0, 0, 1);
#endif

normal *= float( isFrontFacing ) * 2.0 - 1.0;
surfaceData.normal = normal;

// Tangent
Expand Down

0 comments on commit c6b717f

Please sign in to comment.