Files
filament/shaders/src/main.fs
T
Mathias Agopian ceeccde92c Implement lod bias for user materials
A lod bias can be applied to textures when dynamic resolution is
enabled. A proper lod bias is calculated and applied for quality levels
HIGH and ULTRA.

Lod Bias is implemented in glslang, which mean it's ignored when
glslang is not used, which currently happens with OpenGL backends with
optimization turned off (which includes filament LITE). This may be
fixed in the future.
2021-09-15 17:19:40 -07:00

51 lines
1.5 KiB
GLSL

layout(location = 0) out vec4 fragColor;
#if defined(MATERIAL_HAS_POST_LIGHTING_COLOR)
void blendPostLightingColor(const MaterialInputs material, inout vec4 color) {
#if defined(POST_LIGHTING_BLEND_MODE_OPAQUE)
color = material.postLightingColor;
#elif defined(POST_LIGHTING_BLEND_MODE_TRANSPARENT)
color = material.postLightingColor + color * (1.0 - material.postLightingColor.a);
#elif defined(POST_LIGHTING_BLEND_MODE_ADD)
color += material.postLightingColor;
#elif defined(POST_LIGHTING_BLEND_MODE_MULTIPLY)
color *= material.postLightingColor;
#elif defined(POST_LIGHTING_BLEND_MODE_SCREEN)
color += material.postLightingColor * (1.0 - color);
#endif
}
#endif
void main() {
filament_lodBias = frameUniforms.lodBias;
// See shading_parameters.fs
// Computes global variables we need to evaluate material and lighting
computeShadingParams();
// Initialize the inputs to sensible default values, see material_inputs.fs
MaterialInputs inputs;
initMaterial(inputs);
// Invoke user code
material(inputs);
fragColor = evaluateMaterial(inputs);
#if defined(HAS_DIRECTIONAL_LIGHTING) && defined(HAS_SHADOWING)
bool visualizeCascades = bool(frameUniforms.cascades & 0x10u);
if (visualizeCascades) {
fragColor.rgb *= uintToColorDebug(getShadowCascade());
}
#endif
#if defined(HAS_FOG)
vec3 view = getWorldPosition() - getWorldCameraPosition();
fragColor = fog(fragColor, view);
#endif
#if defined(MATERIAL_HAS_POST_LIGHTING_COLOR)
blendPostLightingColor(inputs, fragColor);
#endif
}