Skip to content

Commit

Permalink
matc: remove access to public functions that should be undefined
Browse files Browse the repository at this point in the history
When tangents are not supplied in a material, all "normals" related
public methods become undefined; remove access to them so we get 
compile time errors instead of garbage values in the shader.
  • Loading branch information
pixelflinger committed Dec 10, 2024
1 parent 6b7080e commit 6743818
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions libs/filamat/src/shaders/ShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,13 @@ std::string ShaderGenerator::createFragmentProgram(ShaderModel shaderModel,
CodeGenerator::generateDepthShaderMain(fs, ShaderStage::FRAGMENT);
} else {
appendShader(fs, mMaterialFragmentCode, mMaterialLineOffset);
if (filament::Variant::isSSRVariant(variant)) {
CodeGenerator::generateShaderReflections(fs, ShaderStage::FRAGMENT);
} else if (material.isLit) {
CodeGenerator::generateShaderLit(fs, ShaderStage::FRAGMENT, variant,
material.shading,material.hasCustomSurfaceShading);
if (material.isLit) {
if (filament::Variant::isSSRVariant(variant)) {
CodeGenerator::generateShaderReflections(fs, ShaderStage::FRAGMENT);
} else {
CodeGenerator::generateShaderLit(fs, ShaderStage::FRAGMENT, variant,
material.shading,material.hasCustomSurfaceShading);
}
} else {
CodeGenerator::generateShaderUnlit(fs, ShaderStage::FRAGMENT, variant,
material.hasShadowMultiplier);
Expand Down
2 changes: 2 additions & 0 deletions shaders/src/common_shading.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
highp mat3 shading_tangentToWorld; // TBN matrix
highp vec3 shading_position; // position of the fragment in world space
vec3 shading_view; // normalized vector from the fragment to the eye
#if defined(HAS_ATTRIBUTE_TANGENTS)
vec3 shading_normal; // normalized transformed normal, in world space
vec3 shading_geometricNormal; // normalized geometric normal, in world space
vec3 shading_reflected; // reflection of view about normal
Expand All @@ -15,5 +16,6 @@ highp vec3 shading_position; // position of the fragment in world space
#if defined(MATERIAL_HAS_CLEAR_COAT)
vec3 shading_clearCoatNormal; // normalized clear coat layer normal, in world space
#endif
#endif

highp vec2 shading_normalizedViewportCoord;
4 changes: 4 additions & 0 deletions shaders/src/getters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ bool isPerspectiveProjection() {
return frameUniforms.clipFromViewMatrix[2].w != 0.0;
}

#if defined(HAS_ATTRIBUTE_TANGENTS)

/** @public-api */
vec3 getWorldNormalVector() {
return shading_normal;
Expand All @@ -83,6 +85,8 @@ float getNdotV() {
return shading_NoV;
}

#endif

highp vec3 getNormalizedPhysicalViewportCoord() {
// make sure to handle our reversed-z
return vec3(shading_normalizedViewportCoord, gl_FragCoord.z);
Expand Down

0 comments on commit 6743818

Please sign in to comment.