Skip to content

Commit

Permalink
Fix Terrain Uber Shader normal textures
Browse files Browse the repository at this point in the history
(cherry picked from commit 34b90f1)
  • Loading branch information
JamesTKhan committed Oct 25, 2022
1 parent 1b919c1 commit 18115f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ protected String createPrefixForRenderable(Renderable renderable) {
if (textureAttribute.terrainTexture.hasNormalTextures()) {
prefix += "#define normalTextureFlag\n";

if (textureAttribute.terrainTexture.hasNormalChannel(SplatTexture.Channel.BASE)) {
prefix += "#define baseNormalFlag\n";
}

if (textureAttribute.terrainTexture.hasNormalChannel(SplatTexture.Channel.R)) {
prefix += "#define splatRNormalFlag\n";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const MED vec4 COLOR_BRUSH = vec4(0.4,0.4,0.4, 0.4);
// splat textures
uniform sampler2D u_baseTexture;

#ifdef baseNormalFlag
uniform sampler2D u_texture_base_normal;
#endif

#ifdef splatFlag
varying vec2 v_splatPosition;
uniform sampler2D u_texture_splat;
Expand All @@ -53,11 +57,16 @@ uniform sampler2D u_baseTexture;
uniform sampler2D u_texture_a;
#endif

#ifdef normalTextureFlag
uniform sampler2D u_texture_base_normal;
#ifdef splatRNormalFlag
uniform sampler2D u_texture_r_normal;
#endif
#ifdef splatGNormalFlag
uniform sampler2D u_texture_g_normal;
#endif
#ifdef splatBNormalFlag
uniform sampler2D u_texture_b_normal;
#endif
#ifdef splatANormalFlag
uniform sampler2D u_texture_a_normal;
#endif

Expand Down Expand Up @@ -89,7 +98,8 @@ void main(void) {
vec3 normal;

gl_FragColor = texture2D(u_baseTexture, v_texCoord0);
#ifdef normalTextureFlag

#ifdef baseNormalFlag
normal = texture2D(u_texture_base_normal, v_texCoord0).rgb;
#endif

Expand Down

0 comments on commit 18115f7

Please sign in to comment.