Changed normal of the ground to GL, Now the normal mapping is correct.
This commit is contained in:
@@ -455,14 +455,45 @@
|
||||
#if NORMAL_MAP == 1
|
||||
|
||||
vec4 normalMap = texture(normalSampler, textureCoordinate * uvMultiplier) * 2.0 - 1.0;
|
||||
normal = normalize((v_tangent.xyz * normalMap.x) + (v_binormal.xyz * normalMap.y) + (v_normal.xyz * normalMap.z));
|
||||
//normal = normalize((v_tangent.xyz * normalMap.x) + (v_binormal.xyz * normalMap.y) + (v_normal.xyz * normalMap.z));
|
||||
|
||||
mat3 tangentToWorld = transpose(mat3( v_tangent.xyz ,
|
||||
v_binormal.xyz ,
|
||||
v_normal.xyz));
|
||||
|
||||
|
||||
normal = normalMap.xyz * tangentToWorld;
|
||||
//normal = normalMap.xyz * tangentToWorld;
|
||||
|
||||
|
||||
|
||||
|
||||
vec2 uv = textureCoordinate * uvMultiplier;
|
||||
|
||||
vec2 dUVdx = dFdx(uv);
|
||||
vec2 dUVdy = dFdy(uv);
|
||||
|
||||
vec3 nm = textureGrad(normalSampler, uv, dUVdx, dUVdy).xyz * 2.0 - 1.0;
|
||||
nm = normalize(nm);
|
||||
|
||||
nm = normalize(nm);
|
||||
|
||||
vec3 N = normalize(v_normal.xyz);
|
||||
vec3 T = normalize(v_tangent.xyz);
|
||||
T = normalize(T - N * dot(N, T));
|
||||
vec3 B = normalize(cross(N, T));
|
||||
|
||||
mat3 TBN = mat3(T, B, N);
|
||||
normal = normalize(TBN * nm);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
normal = v_normal.xyz;
|
||||
@@ -543,7 +574,7 @@
|
||||
|
||||
|
||||
#endif
|
||||
float gamma = 1.4;
|
||||
float gamma = 2.2;
|
||||
|
||||
vec3 baseColor;
|
||||
vec4 diffuseMap;
|
||||
@@ -569,6 +600,24 @@
|
||||
f_roughness = texture(roughnessSampler, textureCoordinate).x;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if NORMAL_MAP == 1
|
||||
|
||||
// Screen-space normal variation (specular AA)
|
||||
vec3 n_dx = dFdx(normal);
|
||||
vec3 n_dy = dFdy(normal);
|
||||
|
||||
float variance = max(dot(n_dx, n_dx), dot(n_dy, n_dy));
|
||||
|
||||
// UE-style mapping: converts variance to roughness increase
|
||||
float kernelRoughness = clamp(variance * 0.25, 0.0, 1.0);
|
||||
|
||||
// Combine with material roughness
|
||||
f_roughness = sqrt(clamp(f_roughness * f_roughness + kernelRoughness, 0.0, 1.0));
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
vec3 diffuse = baseColor ;
|
||||
//
|
||||
@@ -579,7 +628,7 @@
|
||||
float reflectance = v_reflectance / 2.0;
|
||||
|
||||
|
||||
vec3 viewDir = (cameraPosition - v_worldposition.xyz);
|
||||
vec3 viewDir = normalize(cameraPosition - v_worldposition.xyz);
|
||||
vec3 reflectionVector = reflect(-viewDir.xyz, normalize(normal.xyz));
|
||||
vec3 reflectionSample = sampleReflection( reflectionVector );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user