From 2f797c4fbcfa3406693f57bc71ee93be6268e2f4 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Tue, 10 May 2022 23:54:10 +0000 Subject: [PATCH 1/3] Update Shader To Fix Broken Texture Maps (#157) --- .../Projects/DefaultProject/10041.ERS | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Source/EditorAssets/Projects/DefaultProject/10041.ERS b/Source/EditorAssets/Projects/DefaultProject/10041.ERS index 095cb94b91..9267385fea 100644 --- a/Source/EditorAssets/Projects/DefaultProject/10041.ERS +++ b/Source/EditorAssets/Projects/DefaultProject/10041.ERS @@ -131,20 +131,26 @@ uniform float Gamma_; const float PI = 3.14159265358979; vec3 GetNormalFromMap(sampler2D Normal) { - vec3 TangentNormal = texture(Normal, Object.TexCoords).xyz * 2.0f - 1.0f; - vec3 Q1 = dFdx(Object.WorldPos); - vec3 Q2 = dFdy(Object.WorldPos); - vec2 st1 = dFdx(Object.TexCoords); - vec2 st2 = dFdy(Object.TexCoords); + vec3 SampledColor = texture(Normal, Object.TexCoords).xyz; + if (!HasNormals && (SampledColor == vec3(0.0f))) { + SampledColor = vec3(0.5f, 0.5f, 1.0f); + } + + vec3 TangentNormal = SampledColor * 2.0f - 1.0f; - vec3 N = normalize(Object.Normal); - vec3 T = normalize(Q1*st2.t - Q2*st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T,B,N); + vec3 Q1 = dFdx(Object.WorldPos); + vec3 Q2 = dFdy(Object.WorldPos); + vec2 st1 = dFdx(Object.TexCoords); + vec2 st2 = dFdy(Object.TexCoords); - return normalize(TBN * TangentNormal); + vec3 N = normalize(Object.Normal); + vec3 T = normalize(Q1*st2.t - Q2*st1.t); + vec3 B = -normalize(cross(N, T)); + mat3 TBN = mat3(T,B,N); + return normalize(TBN * TangentNormal); + } @@ -451,3 +457,4 @@ void main() { + From 0bc0cf20237a024c1586fb7e2a75ba397c12228a Mon Sep 17 00:00:00 2001 From: datacrystals Date: Tue, 10 May 2022 23:55:27 +0000 Subject: [PATCH 2/3] Update Shader To Fix Broken Texture Maps (#157) --- .../Projects/DefaultProject/10041.ERS | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Source/EditorAssets/Projects/DefaultProject/10041.ERS b/Source/EditorAssets/Projects/DefaultProject/10041.ERS index 9267385fea..2aee2de24f 100644 --- a/Source/EditorAssets/Projects/DefaultProject/10041.ERS +++ b/Source/EditorAssets/Projects/DefaultProject/10041.ERS @@ -132,25 +132,26 @@ const float PI = 3.14159265358979; vec3 GetNormalFromMap(sampler2D Normal) { + // Ensure That Textures Are Present/Valid, If Not, Provide Fallback vec3 SampledColor = texture(Normal, Object.TexCoords).xyz; if (!HasNormals && (SampledColor == vec3(0.0f))) { SampledColor = vec3(0.5f, 0.5f, 1.0f); } - vec3 TangentNormal = SampledColor * 2.0f - 1.0f; + // Use Texture Data To Calculate Normal Data + vec3 TangentNormal = SampledColor * 2.0f - 1.0f; - vec3 Q1 = dFdx(Object.WorldPos); - vec3 Q2 = dFdy(Object.WorldPos); - vec2 st1 = dFdx(Object.TexCoords); - vec2 st2 = dFdy(Object.TexCoords); + vec3 Q1 = dFdx(Object.WorldPos); + vec3 Q2 = dFdy(Object.WorldPos); + vec2 st1 = dFdx(Object.TexCoords); + vec2 st2 = dFdy(Object.TexCoords); - vec3 N = normalize(Object.Normal); - vec3 T = normalize(Q1*st2.t - Q2*st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T,B,N); + vec3 N = normalize(Object.Normal); + vec3 T = normalize(Q1*st2.t - Q2*st1.t); + vec3 B = -normalize(cross(N, T)); + mat3 TBN = mat3(T,B,N); - return normalize(TBN * TangentNormal); - + return normalize(TBN * TangentNormal); } From a606e6201ad1df7b61b56c7030a760c5d9642881 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Tue, 10 May 2022 23:57:31 +0000 Subject: [PATCH 3/3] Update Shader To Fix Broken Texture Maps (#157) --- Source/EditorAssets/Projects/DefaultProject/10041.ERS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/EditorAssets/Projects/DefaultProject/10041.ERS b/Source/EditorAssets/Projects/DefaultProject/10041.ERS index 2aee2de24f..dc23cab2b3 100644 --- a/Source/EditorAssets/Projects/DefaultProject/10041.ERS +++ b/Source/EditorAssets/Projects/DefaultProject/10041.ERS @@ -134,7 +134,7 @@ vec3 GetNormalFromMap(sampler2D Normal) { // Ensure That Textures Are Present/Valid, If Not, Provide Fallback vec3 SampledColor = texture(Normal, Object.TexCoords).xyz; - if (!HasNormals && (SampledColor == vec3(0.0f))) { + if (!HasNormals || (SampledColor == vec3(0.0f))) { SampledColor = vec3(0.5f, 0.5f, 1.0f); } @@ -459,3 +459,4 @@ void main() { +