Skip to content

Commit

Permalink
Fixed bug where TessDisplacement.frag shader did not compile on some …
Browse files Browse the repository at this point in the history
…graphics hardware

Mainly affected AMD cards which have strict rules regarding unsized array indexing. The DETAIL_SAMPLER_COUNT define was not set correctly, resulting in a sampler array being unsized.

Also incremented TreeBillboard.frag GLSL version to 440 to resolve array indexing compiler issue for some strict drivers.

# Conflicts:
#	Assets/Core/Shaders/TessDisplacement.frag
  • Loading branch information
Matthew Reid committed Jul 22, 2024
1 parent e082db3 commit 2443978
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions Assets/Core/Shaders/TessDisplacement.frag
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ vec3 blendErosion(vec3 base, vec3 blend, vec3 falloff)
}

#ifdef DETAIL_SAMPLER_COUNT
vec4 sampleDetailTexture()
{
vec3 detailTexCoordPerMeter = wrappedNoiseCoord * 10000.0; // repeats [0,1) per meter
vec3 texCoord = detailAlbedoUvScale[0] * detailTexCoordPerMeter;
return texture(albedoDetailSamplers[0], texCoord.xy);
}
#endif // DETAIL_SAMPLER_COUNT

#if DETAIL_SAMPLER_COUNT > 1
vec4 sampleDetailAlbedo(int i, vec3 normal, vec3 texCoord, vec2 normalUv)
{
return texture(albedoDetailSamplers[i], texCoord.xy);
Expand All @@ -175,13 +184,6 @@ vec4 sampleDetailAlbedoMultiScale(int i, vec3 normal, vec3 texCoord, vec2 normal
return mix(c, d, clamp(1-lod*0.5, 0, 1));
}

vec4 sampleDetailTexture()
{
vec3 detailTexCoordPerMeter = wrappedNoiseCoord * 10000.0; // repeats [0,1) per meter
vec3 texCoord = detailAlbedoUvScale[0] * detailTexCoordPerMeter;
return texture(albedoDetailSamplers[0], texCoord.xy);
}

vec4 sampleAttributeDetailTextures(vec3 normal, vec2 normalUv, vec3 albedo)
{
vec3 detailTexCoordPerMeter = wrappedNoiseCoord * 5000.0; // repeats [0,1) per meter
Expand Down Expand Up @@ -254,12 +256,12 @@ vec4 sampleAttributeDetailTextures(vec3 normal, vec2 normalUv, vec3 albedo)
vec3 albedoDetailTexCoord = detailAlbedoUvScale[index] * detailTexCoordPerMeter;
attributeColor += sampleDetailAlbedo(index, normal, albedoDetailTexCoord, normalUv) * attrWeights[i];
}
#endif
#endif //OVERLAY_BLEND
#endif
return attributeColor;
}

#endif
#endif // DETAIL_SAMPLER_COUNT > 1

#ifdef EXPERIMENTAL_DETAIL_ALBEDO
vec4 sampleDetailAlbedoAdvanced(int i, vec3 normal, vec3 texCoord, vec2 normalUv)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Core/Shaders/TreeBillboard.frag
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#version 330 core
#version 440 core
#pragma import_defines ( CAST_SHADOWS )
#pragma import_defines ( ENABLE_SHADOWS )

Expand Down
2 changes: 1 addition & 1 deletion src/Skybolt/SkyboltVis/Renderable/Planet/Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void setupTerrainStateSet(osg::StateSet& ss, const TerrainConfig& config)
if (auto uniformTechnique = dynamic_cast<const UniformDetailMappingTechnique*>(config.detailMappingTechnique.get()); uniformTechnique)
{
ss.setDefine("DETAIL_MAPPING_TECHNIQUE_UNIFORM");
ss.setDefine("DETAIL_SAMPLER_COUNT");
ss.setDefine("DETAIL_SAMPLER_COUNT", "1");

ss.setTextureAttributeAndModes(unit, uniformTechnique->albedoDetailMap);
ss.addUniform(createUniformSampler2d("albedoDetailSamplers", unit++));
Expand Down

0 comments on commit 2443978

Please sign in to comment.