From 8511f61fd3d6fdea6b1bc5e587313d022eb48ee8 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Mon, 13 Dec 2021 12:08:00 -0800 Subject: [PATCH 1/8] duplicating standardPBR files for BasePBR Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Materials/Types/BasePBR.materialtype | 1202 +++++++++++++++++ .../Materials/Types/BasePBR_Common.azsli | 95 ++ .../Materials/Types/BasePBR_ForwardPass.azsl | 362 +++++ .../Types/BasePBR_ForwardPass.shader | 54 + .../BasePBR_ForwardPass.shadervariantlist | 29 + .../Types/BasePBR_LowEndForward.azsl | 13 + .../Types/BasePBR_LowEndForward.shader | 59 + .../Materials/Types/BasePBR_ShaderEnable.lua | 82 ++ .../atom_feature_common_asset_files.cmake | 10 + 9 files changed, 1906 insertions(+) create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader create mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype new file mode 100644 index 0000000000..f324394309 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype @@ -0,0 +1,1202 @@ +{ + "description": "Material Type with properties used to define Standard PBR, a metallic-roughness Physically-Based Rendering (PBR) material shading model.", + "version": 4, + "versionUpdates": [ + { + "toVersion": 4, + "actions": [ + {"op": "rename", "from": "opacity.doubleSided", "to": "general.doubleSided"} + ] + } + ], + "propertyLayout": { + "groups": [ + { + "name": "baseColor", + "displayName": "Base Color", + "description": "Properties for configuring the surface reflected color for dielectrics or reflectance values for metals." + }, + { + "name": "metallic", + "displayName": "Metallic", + "description": "Properties for configuring whether the surface is metallic or not." + }, + { + "name": "roughness", + "displayName": "Roughness", + "description": "Properties for configuring how rough the surface appears." + }, + { + "name": "specularF0", + "displayName": "Specular Reflectance f0", + "description": "The constant f0 represents the specular reflectance at normal incidence (Fresnel 0 Angle). Used to adjust reflectance of non-metal surfaces." + }, + { + "name": "normal", + "displayName": "Normal", + "description": "Properties related to configuring surface normal." + }, + { + "name": "occlusion", + "displayName": "Occlusion", + "description": "Properties for baked textures that represent geometric occlusion of light." + }, + { + "name": "emissive", + "displayName": "Emissive", + "description": "Properties to add light emission, independent of other lights in the scene." + }, + { + "name": "clearCoat", + "displayName": "Clear Coat", + "description": "Properties for configuring gloss clear coat" + }, + { + "name": "parallax", + "displayName": "Displacement", + "description": "Properties for parallax effect produced by a height map." + }, + { + "name": "opacity", + "displayName": "Opacity", + "description": "Properties for configuring the materials transparency." + }, + { + "name": "uv", + "displayName": "UVs", + "description": "Properties for configuring UV transforms." + }, + { + // Note: this property group is used in the DiffuseGlobalIllumination pass, it is not read by the StandardPBR shader + "name": "irradiance", + "displayName": "Irradiance", + "description": "Properties for configuring the irradiance used in global illumination." + }, + { + "name": "general", + "displayName": "General Settings", + "description": "General settings." + } + ], + "properties": { + "general": [ + { + "name": "doubleSided", + "displayName": "Double-sided", + "description": "Whether to render back-faces or just front-faces.", + "type": "Bool" + }, + { + "name": "applySpecularAA", + "displayName": "Apply Specular AA", + "description": "Whether to apply specular anti-aliasing in the shader.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderOption", + "name": "o_applySpecularAA" + } + }, + { + "name": "enableShadows", + "displayName": "Enable Shadows", + "description": "Whether to use the shadow maps.", + "type": "Bool", + "defaultValue": true, + "connection": { + "type": "ShaderOption", + "name": "o_enableShadows" + } + }, + { + "name": "enableDirectionalLights", + "displayName": "Enable Directional Lights", + "description": "Whether to use directional lights.", + "type": "Bool", + "defaultValue": true, + "connection": { + "type": "ShaderOption", + "name": "o_enableDirectionalLights" + } + }, + { + "name": "enablePunctualLights", + "displayName": "Enable Punctual Lights", + "description": "Whether to use punctual lights.", + "type": "Bool", + "defaultValue": true, + "connection": { + "type": "ShaderOption", + "name": "o_enablePunctualLights" + } + }, + { + "name": "enableAreaLights", + "displayName": "Enable Area Lights", + "description": "Whether to use area lights.", + "type": "Bool", + "defaultValue": true, + "connection": { + "type": "ShaderOption", + "name": "o_enableAreaLights" + } + }, + { + "name": "enableIBL", + "displayName": "Enable IBL", + "description": "Whether to use Image Based Lighting (IBL).", + "type": "Bool", + "defaultValue": true, + "connection": { + "type": "ShaderOption", + "name": "o_enableIBL" + } + }, + { + "name": "forwardPassIBLSpecular", + "displayName": "Forward Pass IBL Specular", + "description": "Whether to apply IBL specular in the forward pass.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderOption", + "name": "o_materialUseForwardPassIBLSpecular" + } + } + ], + "baseColor": [ + { + "name": "color", + "displayName": "Color", + "description": "Color is displayed as sRGB but the values are stored as linear color.", + "type": "Color", + "defaultValue": [ 1.0, 1.0, 1.0 ], + "connection": { + "type": "ShaderInput", + "name": "m_baseColor" + } + }, + { + "name": "factor", + "displayName": "Factor", + "description": "Strength factor for scaling the base color values. Zero (0.0) is black, white (1.0) is full color.", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_baseColorFactor" + } + }, + { + "name": "textureMap", + "displayName": "Texture", + "description": "Base color texture map", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_baseColorMap" + } + }, + { + "name": "useTexture", + "displayName": "Use Texture", + "description": "Whether to use the texture.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Base color map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_baseColorMapUvIndex" + } + }, + { + "name": "textureBlendMode", + "displayName": "Texture Blend Mode", + "description": "Selects the equation to use when combining Color, Factor, and Texture.", + "type": "Enum", + "enumValues": [ "Multiply", "LinearLight", "Lerp", "Overlay" ], + "defaultValue": "Multiply", + "connection": { + "type": "ShaderOption", + "name": "o_baseColorTextureBlendMode" + } + } + ], + "metallic": [ + { + "name": "factor", + "displayName": "Factor", + "description": "This value is linear, black is non-metal and white means raw metal.", + "type": "Float", + "defaultValue": 0.0, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_metallicFactor" + } + }, + { + "name": "textureMap", + "displayName": "Texture", + "description": "", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_metallicMap" + } + }, + { + "name": "useTexture", + "displayName": "Use Texture", + "description": "Whether to use the texture, or just default to the Factor value.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Metallic map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_metallicMapUvIndex" + } + } + ], + "roughness": [ + { + "name": "textureMap", + "displayName": "Texture", + "description": "Texture for defining surface roughness.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_roughnessMap" + } + }, + { + "name": "useTexture", + "displayName": "Use Texture", + "description": "Whether to use the texture, or just default to the Factor value.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Roughness map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_roughnessMapUvIndex" + } + }, + { + // Note that "factor" is mutually exclusive with "lowerBound"/"upperBound". These are swapped by a lua functor. + "name": "lowerBound", + "displayName": "Lower Bound", + "description": "The roughness value that corresponds to black in the texture.", + "type": "Float", + "defaultValue": 0.0, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_roughnessLowerBound" + } + }, + { + // Note that "factor" is mutually exclusive with "lowerBound"/"upperBound". These are swapped by a lua functor. + "name": "upperBound", + "displayName": "Upper Bound", + "description": "The roughness value that corresponds to white in the texture.", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_roughnessUpperBound" + } + }, + { + // Note that "factor" is mutually exclusive with "lowerBound"/"upperBound". These are swapped by a lua functor. + "name": "factor", + "displayName": "Factor", + "description": "Controls the roughness value", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_roughnessFactor" + } + } + ], + "specularF0": [ + { + "name": "factor", + "displayName": "Factor", + "description": "The default IOR is 1.5, which gives you 0.04 (4% of light reflected at 0 degree angle for dielectric materials). F0 values lie in the range 0-0.08, so that is why the default F0 slider is set on 0.5.", + "type": "Float", + "defaultValue": 0.5, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_specularF0Factor" + } + }, + { + "name": "textureMap", + "displayName": "Texture", + "description": "Texture for defining surface reflectance.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_specularF0Map" + } + }, + { + "name": "useTexture", + "displayName": "Use Texture", + "description": "Whether to use the texture, or just default to the Factor value.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Specular reflection map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_specularF0MapUvIndex" + } + }, + // Consider moving this to the "general" group to be consistent with StandardMultilayerPBR + { + "name": "enableMultiScatterCompensation", + "displayName": "Multiscattering Compensation", + "description": "Whether to enable multiple scattering compensation.", + "type": "Bool", + "connection": { + "type": "ShaderOption", + "name": "o_specularF0_enableMultiScatterCompensation" + } + } + ], + "clearCoat": [ + { + "name": "enable", + "displayName": "Enable", + "description": "Enable clear coat", + "type": "Bool", + "defaultValue": false + }, + { + "name": "factor", + "displayName": "Factor", + "description": "Strength factor for scaling the percentage of effect applied", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatFactor" + } + }, + { + "name": "influenceMap", + "displayName": " Influence Map", + "description": "Strength factor texture", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatInfluenceMap" + } + }, + { + "name": "useInfluenceMap", + "displayName": " Use Texture", + "description": "Whether to use the texture, or just default to the Factor value.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "influenceMapUv", + "displayName": " UV", + "description": "Strength factor map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatInfluenceMapUvIndex" + } + }, + { + "name": "roughness", + "displayName": "Roughness", + "description": "Clear coat layer roughness", + "type": "Float", + "defaultValue": 0.0, + "min": 0.0, + "max": 1.0, + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatRoughness" + } + }, + { + "name": "roughnessMap", + "displayName": " Roughness Map", + "description": "Texture for defining surface roughness", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatRoughnessMap" + } + }, + { + "name": "useRoughnessMap", + "displayName": " Use Texture", + "description": "Whether to use the texture, or just default to the roughness value.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "roughnessMapUv", + "displayName": " UV", + "description": "Roughness map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatRoughnessMapUvIndex" + } + }, + { + "name": "normalStrength", + "displayName": "Normal Strength", + "description": "Scales the impact of the clear coat normal map", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "max": 2.0, + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatNormalStrength" + } + }, + { + "name": "normalMap", + "displayName": "Normal Map", + "description": "Normal map for clear coat layer, as top layer material clear coat doesn't affect by base layer normal map", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatNormalMap" + } + }, + { + "name": "useNormalMap", + "displayName": " Use Texture", + "description": "Whether to use the normal map", + "type": "Bool", + "defaultValue": true + }, + { + "name": "normalMapUv", + "displayName": " UV", + "description": "Normal map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_clearCoatNormalMapUvIndex" + } + } + ], + "normal": [ + { + "name": "textureMap", + "displayName": "Texture", + "description": "Texture for defining surface normal direction.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_normalMap" + } + }, + { + "name": "useTexture", + "displayName": "Use Texture", + "description": "Whether to use the texture, or just rely on vertex normals.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Normal map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_normalMapUvIndex" + } + }, + { + "name": "flipX", + "displayName": "Flip X Channel", + "description": "Flip tangent direction for this normal map.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderInput", + "name": "m_flipNormalX" + } + }, + { + "name": "flipY", + "displayName": "Flip Y Channel", + "description": "Flip bitangent direction for this normal map.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderInput", + "name": "m_flipNormalY" + } + }, + { + "name": "factor", + "displayName": "Factor", + "description": "Strength factor for scaling the values", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "softMax": 2.0, + "connection": { + "type": "ShaderInput", + "name": "m_normalFactor" + } + } + ], + "opacity": [ + { + "name": "mode", + "displayName": "Opacity Mode", + "description": "Indicates the general approach how transparency is to be applied.", + "type": "Enum", + "enumValues": [ "Opaque", "Cutout", "Blended", "TintedTransparent" ], + "defaultValue": "Opaque", + "connection": { + "type": "ShaderOption", + "name": "o_opacity_mode" + } + }, + { + "name": "alphaSource", + "displayName": "Alpha Source", + "description": "Indicates whether to get the opacity texture from the Base Color map (Packed) or from a separate greyscale texture (Split).", + "type": "Enum", + "enumValues": [ "Packed", "Split", "None" ], + "defaultValue": "Packed", + "connection": { + "type": "ShaderOption", + "name": "o_opacity_source" + } + }, + { + "name": "textureMap", + "displayName": "Texture", + "description": "Texture for defining surface opacity.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_opacityMap" + } + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Opacity map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_opacityMapUvIndex" + } + }, + { + "name": "factor", + "displayName": "Factor", + "description": "Factor for cutout threshold and blending", + "type": "Float", + "min": 0.0, + "max": 1.0, + "defaultValue": 0.5, + "connection": { + "type": "ShaderInput", + "name": "m_opacityFactor" + } + }, + { + "name": "alphaAffectsSpecular", + "displayName": "Alpha affects specular", + "description": "How much the alpha value should also affect specular reflection. This should be 0.0 for materials where light can transmit through their physical surface (like glass), but 1.0 when alpha determines the very presence of a surface (like hair or grass)", + "type": "float", + "min": 0.0, + "max": 1.0, + "defaultValue": 0.0, + "connection": { + "type": "ShaderInput", + "name": "m_opacityAffectsSpecularFactor" + } + } + ], + "uv": [ + { + "name": "center", + "displayName": "Center", + "description": "Center point for scaling and rotation transformations.", + "type": "vector2", + "vectorLabels": [ "U", "V" ], + "defaultValue": [ 0.5, 0.5 ] + }, + { + "name": "tileU", + "displayName": "Tile U", + "description": "Scales texture coordinates in U.", + "type": "float", + "defaultValue": 1.0, + "step": 0.1 + }, + { + "name": "tileV", + "displayName": "Tile V", + "description": "Scales texture coordinates in V.", + "type": "float", + "defaultValue": 1.0, + "step": 0.1 + }, + { + "name": "offsetU", + "displayName": "Offset U", + "description": "Offsets texture coordinates in the U direction.", + "type": "float", + "defaultValue": 0.0, + "min": -1.0, + "max": 1.0 + }, + { + "name": "offsetV", + "displayName": "Offset V", + "description": "Offsets texture coordinates in the V direction.", + "type": "float", + "defaultValue": 0.0, + "min": -1.0, + "max": 1.0 + }, + { + "name": "rotateDegrees", + "displayName": "Rotate", + "description": "Rotates the texture coordinates (degrees).", + "type": "float", + "defaultValue": 0.0, + "min": -180.0, + "max": 180.0, + "step": 1.0 + }, + { + "name": "scale", + "displayName": "Scale", + "description": "Scales texture coordinates in both U and V.", + "type": "float", + "defaultValue": 1.0, + "step": 0.1 + } + ], + "occlusion": [ + { + "name": "diffuseTextureMap", + "displayName": "Diffuse AO", + "description": "Texture for defining occlusion area for diffuse ambient lighting.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_diffuseOcclusionMap" + } + }, + { + "name": "diffuseUseTexture", + "displayName": " Use Texture", + "description": "Whether to use the Diffuse AO map.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "diffuseTextureMapUv", + "displayName": " UV", + "description": "Diffuse AO map UV set.", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_diffuseOcclusionMapUvIndex" + } + }, + { + "name": "diffuseFactor", + "displayName": " Factor", + "description": "Strength factor for scaling the values of Diffuse AO", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "softMax": 2.0, + "connection": { + "type": "ShaderInput", + "name": "m_diffuseOcclusionFactor" + } + }, + { + "name": "specularTextureMap", + "displayName": "Specular Cavity", + "description": "Texture for defining occlusion area for specular lighting.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_specularOcclusionMap" + } + }, + { + "name": "specularUseTexture", + "displayName": " Use Texture", + "description": "Whether to use the Specular Cavity map.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "specularTextureMapUv", + "displayName": " UV", + "description": "Specular Cavity map UV set.", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_specularOcclusionMapUvIndex" + } + }, + { + "name": "specularFactor", + "displayName": " Factor", + "description": "Strength factor for scaling the values of Specular Cavity", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "softMax": 2.0, + "connection": { + "type": "ShaderInput", + "name": "m_specularOcclusionFactor" + } + } + ], + "emissive": [ + { + "name": "enable", + "displayName": "Enable", + "description": "Enable the emissive group", + "type": "Bool", + "defaultValue": false + }, + { + "name": "unit", + "displayName": "Units", + "description": "The photometric units of the Intensity property.", + "type": "Enum", + "enumValues": ["Ev100"], + "defaultValue": "Ev100" + }, + { + "name": "color", + "displayName": "Color", + "description": "Color is displayed as sRGB but the values are stored as linear color.", + "type": "Color", + "defaultValue": [ 1.0, 1.0, 1.0 ], + "connection": { + "type": "ShaderInput", + "name": "m_emissiveColor" + } + }, + { + "name": "intensity", + "displayName": "Intensity", + "description": "The amount of energy emitted.", + "type": "Float", + "defaultValue": 4, + "min": -10, + "max": 20, + "softMin": -6, + "softMax": 16 + }, + { + "name": "textureMap", + "displayName": "Texture", + "description": "Texture for defining emissive area.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_emissiveMap" + } + }, + { + "name": "useTexture", + "displayName": "Use Texture", + "description": "Whether to use the texture.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Emissive map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_emissiveMapUvIndex" + } + } + ], + "parallax": [ + { + "name": "textureMap", + "displayName": "Height Map", + "description": "Displacement height map to create parallax effect.", + "type": "Image", + "connection": { + "type": "ShaderInput", + "name": "m_heightmap" + } + }, + { + "name": "useTexture", + "displayName": "Use Texture", + "description": "Whether to use the height map.", + "type": "Bool", + "defaultValue": true + }, + { + "name": "textureMapUv", + "displayName": "UV", + "description": "Height map UV set", + "type": "Enum", + "enumIsUv": true, + "defaultValue": "Tiled", + "connection": { + "type": "ShaderInput", + "name": "m_parallaxUvIndex" + } + }, + { + "name": "factor", + "displayName": "Height Map Scale", + "description": "The total height of the height map in local model units.", + "type": "Float", + "defaultValue": 0.05, + "min": 0.0, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "name": "m_heightmapScale" + } + }, + { + "name": "offset", + "displayName": "Offset", + "description": "Adjusts the overall displacement amount in local model units.", + "type": "Float", + "defaultValue": 0.0, + "softMin": -0.1, + "softMax": 0.1, + "connection": { + "type": "ShaderInput", + "name": "m_heightmapOffset" + } + }, + { + "name": "algorithm", + "displayName": "Algorithm", + "description": "Select the algorithm to use for parallax mapping.", + "type": "Enum", + "enumValues": [ "Basic", "Steep", "POM", "Relief", "ContactRefinement" ], + "defaultValue": "POM", + "connection": { + "type": "ShaderOption", + "name": "o_parallax_algorithm" + } + }, + { + "name": "quality", + "displayName": "Quality", + "description": "Quality of parallax mapping.", + "type": "Enum", + "enumValues": [ "Low", "Medium", "High", "Ultra" ], + "defaultValue": "Low", + "connection": { + "type": "ShaderOption", + "name": "o_parallax_quality" + } + }, + { + "name": "pdo", + "displayName": "Pixel Depth Offset", + "description": "Enable PDO to offset the original pixel depths. This will affect any shaders using depth, for example, when receiving shadows.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderOption", + "name": "o_parallax_enablePixelDepthOffset" + } + }, + { + "name": "showClipping", + "displayName": "Show Clipping", + "description": "Highlight areas where the height map is clipped by the mesh surface.", + "type": "Bool", + "defaultValue": false, + "connection": { + "type": "ShaderOption", + "name": "o_parallax_highlightClipping" + } + } + ], + "irradiance": [ + // Note: this property group is used in the DiffuseGlobalIllumination pass and not by the main forward shader + { + "name": "color", + "displayName": "Color", + "description": "Color is displayed as sRGB but the values are stored as linear color.", + "type": "Color", + "defaultValue": [ 1.0, 1.0, 1.0 ] + }, + { + "name": "factor", + "displayName": "Factor", + "description": "Strength factor for scaling the irradiance color values. Zero (0.0) is black, white (1.0) is full color.", + "type": "Float", + "defaultValue": 1.0, + "min": 0.0, + "max": 1.0 + } + ] + } + }, + "shaders": [ + { + "file": "./StandardPBR_ForwardPass.shader", + "tag": "ForwardPass" + }, + { + "file": "./StandardPBR_ForwardPass_EDS.shader", + "tag": "ForwardPass_EDS" + }, + { + "file": "./StandardPBR_LowEndForward.shader", + "tag": "LowEndForward" + }, + { + "file": "./StandardPBR_LowEndForward_EDS.shader", + "tag": "LowEndForward_EDS" + }, + { + "file": "Shaders/Shadow/Shadowmap.shader", + "tag": "Shadowmap" + }, + { + "file": "./StandardPBR_Shadowmap_WithPS.shader", + "tag": "Shadowmap_WithPS" + }, + { + "file": "Shaders/Depth/DepthPass.shader", + "tag": "DepthPass" + }, + { + "file": "./StandardPBR_DepthPass_WithPS.shader", + "tag": "DepthPass_WithPS" + }, + { + "file": "Shaders/MotionVector/MeshMotionVector.shader", + "tag": "MeshMotionVector" + }, + // Used by the light culling system to produce accurate depth bounds for this object when it uses blended transparency + { + "file": "Shaders/Depth/DepthPassTransparentMin.shader", + "tag": "DepthPassTransparentMin" + }, + { + "file": "Shaders/Depth/DepthPassTransparentMax.shader", + "tag": "DepthPassTransparentMax" + } + ], + "functors": [ + { + // Maps 2D scale, offset, and rotate properties into a float3x3 transform matrix. + "type": "Transform2D", + "args": { + "transformOrder": [ "Rotate", "Translate", "Scale" ], + "centerProperty": "uv.center", + "scaleProperty": "uv.scale", + "scaleXProperty": "uv.tileU", + "scaleYProperty": "uv.tileV", + "translateXProperty": "uv.offsetU", + "translateYProperty": "uv.offsetV", + "rotateDegreesProperty": "uv.rotateDegrees", + "float3x3ShaderInput": "m_uvMatrix", + "float3x3InverseShaderInput": "m_uvMatrixInverse" + } + }, + { + // Convert emissive unit. + "type": "ConvertEmissiveUnit", + "args": { + "intensityProperty": "emissive.intensity", + "lightUnitProperty": "emissive.unit", + "shaderInput": "m_emissiveIntensity", + "ev100Index": 0, + "nitIndex" : 1, + "ev100MinMax": [-10, 20], + "nitMinMax": [0.001, 100000.0] + } + }, + { + "type": "UseTexture", + "args": { + "textureProperty": "baseColor.textureMap", + "useTextureProperty": "baseColor.useTexture", + "dependentProperties": ["baseColor.textureMapUv", "baseColor.textureBlendMode"], + "shaderOption": "o_baseColor_useTexture" + } + }, + { + "type": "UseTexture", + "args": { + "textureProperty": "specularF0.textureMap", + "useTextureProperty": "specularF0.useTexture", + "dependentProperties": ["specularF0.textureMapUv"], + "shaderOption": "o_specularF0_useTexture" + } + }, + { + "type": "UseTexture", + "args": { + "textureProperty": "normal.textureMap", + "useTextureProperty": "normal.useTexture", + "dependentProperties": ["normal.textureMapUv", "normal.factor", "normal.flipX", "normal.flipY"], + "shaderOption": "o_normal_useTexture" + } + }, + { + "type": "UseTexture", + "args": { + "textureProperty": "occlusion.diffuseTextureMap", + "useTextureProperty": "occlusion.diffuseUseTexture", + "dependentProperties": ["occlusion.diffuseTextureMapUv", "occlusion.diffuseFactor"], + "shaderOption": "o_diffuseOcclusion_useTexture" + } + }, + { + "type": "UseTexture", + "args": { + "textureProperty": "occlusion.specularTextureMap", + "useTextureProperty": "occlusion.specularUseTexture", + "dependentProperties": ["occlusion.specularTextureMapUv", "occlusion.specularFactor"], + "shaderOption": "o_specularOcclusion_useTexture" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_ClearCoatState.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_ClearCoatEnableFeature.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_EmissiveState.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_ParallaxState.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_Roughness.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_Metallic.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_HandleOpacityDoubleSided.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_HandleOpacityMode.lua" + } + }, + { + "type": "Lua", + "args": { + "file": "StandardPBR_ShaderEnable.lua" + } + } + ], + "uvNameMap": { + "UV0": "Tiled", + "UV1": "Unwrapped" + } +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli new file mode 100644 index 0000000000..0aebc11f1d --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli @@ -0,0 +1,95 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include "MaterialInputs/BaseColorInput.azsli" +#include "MaterialInputs/RoughnessInput.azsli" +#include "MaterialInputs/MetallicInput.azsli" +#include "MaterialInputs/SpecularInput.azsli" +#include "MaterialInputs/NormalInput.azsli" +#include "MaterialInputs/ClearCoatInput.azsli" +#include "MaterialInputs/OcclusionInput.azsli" +#include "MaterialInputs/EmissiveInput.azsli" +#include "MaterialInputs/ParallaxInput.azsli" +#include "MaterialInputs/UvSetCount.azsli" + +ShaderResourceGroup MaterialSrg : SRG_PerMaterial +{ + // Auto-generate material SRG fields for common inputs + COMMON_SRG_INPUTS_BASE_COLOR() + COMMON_SRG_INPUTS_ROUGHNESS() + COMMON_SRG_INPUTS_METALLIC() + COMMON_SRG_INPUTS_SPECULAR_F0() + COMMON_SRG_INPUTS_NORMAL() + COMMON_SRG_INPUTS_CLEAR_COAT() + COMMON_SRG_INPUTS_OCCLUSION() + COMMON_SRG_INPUTS_EMISSIVE() + COMMON_SRG_INPUTS_PARALLAX() + + uint m_parallaxUvIndex; + + float3x3 m_uvMatrix; + float4 m_pad1; // [GFX TODO][ATOM-14595] This is a workaround for a data stomping bug. Remove once it's fixed. + float3x3 m_uvMatrixInverse; + float4 m_pad2; // [GFX TODO][ATOM-14595] This is a workaround for a data stomping bug. Remove once it's fixed. + + float m_opacityFactor; + float m_opacityAffectsSpecularFactor; + Texture2D m_opacityMap; + uint m_opacityMapUvIndex; + + Sampler m_sampler + { + AddressU = Wrap; + AddressV = Wrap; + MinFilter = Linear; + MagFilter = Linear; + MipFilter = Linear; + MaxAnisotropy = 16; + }; + + Texture2D m_brdfMap; + + Sampler m_samplerBrdf + { + AddressU = Clamp; + AddressV = Clamp; + MinFilter = Linear; + MagFilter = Linear; + MipFilter = Linear; + }; +} + +// Callback function for ParallaxMapping.azsli +DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) +{ + return SampleDepthFromHeightmap(MaterialSrg::m_heightmap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy); +} + + +COMMON_OPTIONS_PARALLAX() + +bool ShouldHandleParallax() +{ + // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled. + return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useHeightmap; +} + +bool ShouldHandleParallaxInDepthShaders() +{ + // The depth pass shaders need to calculate parallax when the result could affect the depth buffer, or when + // parallax could affect texel clipping. + return ShouldHandleParallax() && (o_parallax_enablePixelDepthOffset || o_opacity_mode == OpacityMode::Cutout); +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl new file mode 100644 index 0000000000..1d5e4ad9e3 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl @@ -0,0 +1,362 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include "Atom/Features/ShaderQualityOptions.azsli" + +#include "StandardPBR_Common.azsli" + +// SRGs +#include +#include + +// Pass Output +#include + +// Utility +#include +#include + +// Custom Surface & Lighting +#include + +// Decals +#include + + +// ---------- Material Parameters ---------- + +COMMON_OPTIONS_BASE_COLOR() +COMMON_OPTIONS_ROUGHNESS() +COMMON_OPTIONS_METALLIC() +COMMON_OPTIONS_SPECULAR_F0() +COMMON_OPTIONS_NORMAL() +COMMON_OPTIONS_CLEAR_COAT() +COMMON_OPTIONS_OCCLUSION() +COMMON_OPTIONS_EMISSIVE() +// Note COMMON_OPTIONS_PARALLAX is in StandardPBR_Common.azsli because it's needed by all StandardPBR shaders. + +// Alpha +#include "MaterialInputs/AlphaInput.azsli" + +// ---------- Vertex Shader ---------- + +struct VSInput +{ + // Base fields (required by the template azsli file)... + float3 m_position : POSITION; + float3 m_normal : NORMAL; + float4 m_tangent : TANGENT; + float3 m_bitangent : BITANGENT; + + // Extended fields (only referenced in this azsl file)... + float2 m_uv0 : UV0; + float2 m_uv1 : UV1; +}; + +struct VSOutput +{ + // Base fields (required by the template azsli file)... + // "centroid" is needed for SV_Depth to compile + linear centroid float4 m_position : SV_Position; + float3 m_normal: NORMAL; + float3 m_tangent : TANGENT; + float3 m_bitangent : BITANGENT; + float3 m_worldPosition : UV0; + float3 m_shadowCoords[ViewSrg::MaxCascadeCount] : UV3; + + // Extended fields (only referenced in this azsl file)... + float2 m_uv[UvSetCount] : UV1; +}; + +#include + +VSOutput StandardPbr_ForwardPassVS(VSInput IN) +{ + VSOutput OUT; + + float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1.0)).xyz; + + // By design, only UV0 is allowed to apply transforms. + OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; + OUT.m_uv[1] = IN.m_uv1; + + // Shadow coords will be calculated in the pixel shader in this case + bool skipShadowCoords = ShouldHandleParallax() && o_parallax_enablePixelDepthOffset; + + VertexHelper(IN, OUT, worldPosition, skipShadowCoords); + + return OUT; +} + + +// ---------- Pixel Shader ---------- + +PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float depthNDC) +{ + const float3 vertexNormal = normalize(IN.m_normal); + + // ------- Tangents & Bitangets ------- + float3 tangents[UvSetCount] = { IN.m_tangent.xyz, IN.m_tangent.xyz }; + float3 bitangents[UvSetCount] = { IN.m_bitangent.xyz, IN.m_bitangent.xyz }; + + if (ShouldHandleParallax() || o_normal_useTexture || (o_clearCoat_enabled && o_clearCoat_normal_useTexture)) + { + PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents); + } + + // ------- Depth & Parallax ------- + + depthNDC = IN.m_position.z; + + bool displacementIsClipped = false; + + if(ShouldHandleParallax()) + { + + float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); + float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset, + ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, + IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depthNDC, IN.m_position.w, displacementIsClipped); + + // Adjust directional light shadow coordinates for parallax correction + if(o_parallax_enablePixelDepthOffset) + { + const uint shadowIndex = ViewSrg::m_shadowIndexDirectionalLight; + if (o_enableShadows && shadowIndex < SceneSrg::m_directionalLightCount) + { + DirectionalLightShadow::GetShadowCoords(shadowIndex, IN.m_worldPosition, vertexNormal, IN.m_shadowCoords); + } + } + } + + Surface surface; + surface.position = IN.m_worldPosition.xyz; + + // ------- Alpha & Clip ------- + + float2 baseColorUv = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; + float2 opacityUv = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; + float alpha = GetAlphaInputAndClip(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUv, opacityUv, MaterialSrg::m_sampler, MaterialSrg::m_opacityFactor, o_opacity_source); + + // ------- Normal ------- + + float2 normalUv = IN.m_uv[MaterialSrg::m_normalMapUvIndex]; + float3x3 uvMatrix = MaterialSrg::m_normalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); // By design, only UV0 is allowed to apply transforms. + surface.vertexNormal = vertexNormal; + surface.normal = GetNormalInputWS(MaterialSrg::m_normalMap, MaterialSrg::m_sampler, normalUv, MaterialSrg::m_flipNormalX, MaterialSrg::m_flipNormalY, isFrontFace, IN.m_normal, + tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], uvMatrix, o_normal_useTexture, MaterialSrg::m_normalFactor); + + // ------- Base Color ------- + + float3 sampledColor = GetBaseColorInput(MaterialSrg::m_baseColorMap, MaterialSrg::m_sampler, baseColorUv, MaterialSrg::m_baseColor.rgb, o_baseColor_useTexture); + float3 baseColor = BlendBaseColor(sampledColor, MaterialSrg::m_baseColor.rgb, MaterialSrg::m_baseColorFactor, o_baseColorTextureBlendMode, o_baseColor_useTexture); + + if(o_parallax_highlightClipping && displacementIsClipped) + { + ApplyParallaxClippingHighlight(baseColor); + } + + // ------- Metallic ------- + + float2 metallicUv = IN.m_uv[MaterialSrg::m_metallicMapUvIndex]; + float metallic = GetMetallicInput(MaterialSrg::m_metallicMap, MaterialSrg::m_sampler, metallicUv, MaterialSrg::m_metallicFactor, o_metallic_useTexture); + + // ------- Specular ------- + + float2 specularUv = IN.m_uv[MaterialSrg::m_specularF0MapUvIndex]; + float specularF0Factor = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); + + surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic); + + // ------- Roughness ------- + + float2 roughnessUv = IN.m_uv[MaterialSrg::m_roughnessMapUvIndex]; + surface.roughnessLinear = GetRoughnessInput(MaterialSrg::m_roughnessMap, MaterialSrg::m_sampler, roughnessUv, MaterialSrg::m_roughnessFactor, + MaterialSrg::m_roughnessLowerBound, MaterialSrg::m_roughnessUpperBound, o_roughness_useTexture); + surface.CalculateRoughnessA(); + + // ------- Lighting Data ------- + + LightingData lightingData; + + // Light iterator + lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); + lightingData.Init(surface.position, surface.normal, surface.roughnessLinear); + + // Directional light shadow coordinates + lightingData.shadowCoords = IN.m_shadowCoords; + + // ------- Emissive ------- + + float2 emissiveUv = IN.m_uv[MaterialSrg::m_emissiveMapUvIndex]; + lightingData.emissiveLighting = GetEmissiveInput(MaterialSrg::m_emissiveMap, MaterialSrg::m_sampler, emissiveUv, MaterialSrg::m_emissiveIntensity, MaterialSrg::m_emissiveColor.rgb, o_emissiveEnabled, o_emissive_useTexture); + + // ------- Occlusion ------- + + lightingData.diffuseAmbientOcclusion = GetOcclusionInput(MaterialSrg::m_diffuseOcclusionMap, MaterialSrg::m_sampler, IN.m_uv[MaterialSrg::m_diffuseOcclusionMapUvIndex], MaterialSrg::m_diffuseOcclusionFactor, o_diffuseOcclusion_useTexture); + lightingData.specularOcclusion = GetOcclusionInput(MaterialSrg::m_specularOcclusionMap, MaterialSrg::m_sampler, IN.m_uv[MaterialSrg::m_specularOcclusionMapUvIndex], MaterialSrg::m_specularOcclusionFactor, o_specularOcclusion_useTexture); + + // ------- Clearcoat ------- + + // [GFX TODO][ATOM-14603]: Clean up the double uses of these clear coat flags + if(o_clearCoat_feature_enabled) + { + if(o_clearCoat_enabled) + { + float3x3 uvMatrix = MaterialSrg::m_clearCoatNormalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); + GetClearCoatInputs(MaterialSrg::m_clearCoatInfluenceMap, IN.m_uv[MaterialSrg::m_clearCoatInfluenceMapUvIndex], MaterialSrg::m_clearCoatFactor, o_clearCoat_factor_useTexture, + MaterialSrg::m_clearCoatRoughnessMap, IN.m_uv[MaterialSrg::m_clearCoatRoughnessMapUvIndex], MaterialSrg::m_clearCoatRoughness, o_clearCoat_roughness_useTexture, + MaterialSrg::m_clearCoatNormalMap, IN.m_uv[MaterialSrg::m_clearCoatNormalMapUvIndex], IN.m_normal, o_clearCoat_normal_useTexture, MaterialSrg::m_clearCoatNormalStrength, + uvMatrix, tangents[MaterialSrg::m_clearCoatNormalMapUvIndex], bitangents[MaterialSrg::m_clearCoatNormalMapUvIndex], + MaterialSrg::m_sampler, isFrontFace, + surface.clearCoat.factor, surface.clearCoat.roughness, surface.clearCoat.normal); + } + + // manipulate base layer f0 if clear coat is enabled + // modify base layer's normal incidence reflectance + // for the derivation of the following equation please refer to: + // https://google.github.io/filament/Filament.md.html#materialsystem/clearcoatmodel/baselayermodification + float3 f0 = (1.0 - 5.0 * sqrt(surface.specularF0)) / (5.0 - sqrt(surface.specularF0)); + surface.specularF0 = lerp(surface.specularF0, f0 * f0, surface.clearCoat.factor); + } + + // Diffuse and Specular response (used in IBL calculations) + lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear); + lightingData.diffuseResponse = 1.0 - lightingData.specularResponse; + + if(o_clearCoat_feature_enabled) + { + // Clear coat layer has fixed IOR = 1.5 and transparent => F0 = (1.5 - 1)^2 / (1.5 + 1)^2 = 0.04 + lightingData.diffuseResponse *= 1.0 - (FresnelSchlickWithRoughness(lightingData.NdotV, float3(0.04, 0.04, 0.04), surface.clearCoat.roughness) * surface.clearCoat.factor); + } + + // ------- Multiscatter ------- + + lightingData.CalculateMultiscatterCompensation(surface.specularF0, o_specularF0_enableMultiScatterCompensation); + + // ------- Lighting Calculation ------- + + // Apply Decals + ApplyDecals(lightingData.tileIterator, surface); + + // Apply Direct Lighting + ApplyDirectLighting(surface, lightingData); + + // Apply Image Based Lighting (IBL) + ApplyIBL(surface, lightingData); + + // Finalize Lighting + lightingData.FinalizeLighting(); + + PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); + + // ------- Opacity ------- + + if (o_opacity_mode == OpacityMode::Blended || o_opacity_mode == OpacityMode::TintedTransparent) + { + // Increase opacity at grazing angles for surfaces with a low m_opacityAffectsSpecularFactor. + // For m_opacityAffectsSpecularFactor values close to 0, that indicates a transparent surface + // like glass, so it becomes less transparent at grazing angles. For m_opacityAffectsSpecularFactor + // values close to 1.0, that indicates the absence of a surface entirely, so this effect should + // not apply. + float fresnelAlpha = FresnelSchlickWithRoughness(lightingData.NdotV, alpha, surface.roughnessLinear).x; + alpha = lerp(fresnelAlpha, alpha, MaterialSrg::m_opacityAffectsSpecularFactor); + } + + if (o_opacity_mode == OpacityMode::Blended) + { + // [GFX_TODO ATOM-13187] PbrLighting shouldn't be writing directly to render targets. It's confusing when + // specular is being added to diffuse just because we're calling render target 0 "diffuse". + + // For blended mode, we do (dest * alpha) + (source * 1.0). This allows the specular + // to be added on top of the diffuse, but then the diffuse must be pre-multiplied. + // It's done this way because surface transparency doesn't really change specular response (eg, glass). + + lightingOutput.m_diffuseColor.rgb *= lightingOutput.m_diffuseColor.w; // pre-multiply diffuse + + // Add specular. m_opacityAffectsSpecularFactor controls how much the alpha masks out specular contribution. + float3 specular = lightingOutput.m_specularColor.rgb; + specular = lerp(specular, specular * lightingOutput.m_diffuseColor.w, MaterialSrg::m_opacityAffectsSpecularFactor); + lightingOutput.m_diffuseColor.rgb += specular; + + lightingOutput.m_diffuseColor.w = alpha; + } + else if (o_opacity_mode == OpacityMode::TintedTransparent) + { + // See OpacityMode::Blended above for the basic method. TintedTransparent adds onto the above concept by supporting + // colored alpha. This is currently a very basic calculation that uses the baseColor as a multiplier with strength + // determined by the alpha. We'll modify this later to be more physically accurate and allow surface depth, + // absorption, and interior color to be specified. + // + // The technique uses dual source blending to allow two separate sources to be part of the blending equation + // even though ultimately only a single render target is being written to. m_diffuseColor is render target 0 and + // m_specularColor render target 1, and the blend mode is (dest * source1color) + (source * 1.0). + // + // This means that m_specularColor.rgb (source 1) is multiplied against the destination, then + // m_diffuseColor.rgb (source) is added to that, and the final result is stored in render target 0. + + lightingOutput.m_diffuseColor.rgb *= lightingOutput.m_diffuseColor.w; // pre-multiply diffuse + + // Add specular. m_opacityAffectsSpecularFactor controls how much the alpha masks out specular contribution. + float3 specular = lightingOutput.m_specularColor.rgb; + specular = lerp(specular, specular * lightingOutput.m_diffuseColor.w, MaterialSrg::m_opacityAffectsSpecularFactor); + lightingOutput.m_diffuseColor.rgb += specular; + + lightingOutput.m_specularColor.rgb = baseColor * (1.0 - alpha); + } + else + { + lightingOutput.m_diffuseColor.w = -1; // Disable subsurface scattering + } + + return lightingOutput; +} + +ForwardPassOutputWithDepth StandardPbr_ForwardPassPS(VSOutput IN, bool isFrontFace : SV_IsFrontFace) +{ + ForwardPassOutputWithDepth OUT; + float depth; + + PbrLightingOutput lightingOutput = ForwardPassPS_Common(IN, isFrontFace, depth); + +#ifdef UNIFIED_FORWARD_OUTPUT + OUT.m_color.rgb = lightingOutput.m_diffuseColor.rgb + lightingOutput.m_specularColor.rgb; + OUT.m_color.a = lightingOutput.m_diffuseColor.a; + OUT.m_depth = depth; +#else + OUT.m_diffuseColor = lightingOutput.m_diffuseColor; + OUT.m_specularColor = lightingOutput.m_specularColor; + OUT.m_specularF0 = lightingOutput.m_specularF0; + OUT.m_albedo = lightingOutput.m_albedo; + OUT.m_normal = lightingOutput.m_normal; + OUT.m_depth = depth; +#endif + return OUT; +} + +[earlydepthstencil] +ForwardPassOutput StandardPbr_ForwardPassPS_EDS(VSOutput IN, bool isFrontFace : SV_IsFrontFace) +{ + ForwardPassOutput OUT; + float depth; + + PbrLightingOutput lightingOutput = ForwardPassPS_Common(IN, isFrontFace, depth); + +#ifdef UNIFIED_FORWARD_OUTPUT + OUT.m_color.rgb = lightingOutput.m_diffuseColor.rgb + lightingOutput.m_specularColor.rgb; + OUT.m_color.a = lightingOutput.m_diffuseColor.a; +#else + OUT.m_diffuseColor = lightingOutput.m_diffuseColor; + OUT.m_specularColor = lightingOutput.m_specularColor; + OUT.m_specularF0 = lightingOutput.m_specularF0; + OUT.m_albedo = lightingOutput.m_albedo; + OUT.m_normal = lightingOutput.m_normal; +#endif + return OUT; +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader new file mode 100644 index 0000000000..d8df49f4b0 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader @@ -0,0 +1,54 @@ +{ + "Source" : "./StandardPBR_ForwardPass.azsl", + + "DepthStencilState" : + { + "Depth" : + { + "Enable" : true, + "CompareFunc" : "GreaterEqual" + }, + "Stencil" : + { + "Enable" : true, + "ReadMask" : "0x00", + "WriteMask" : "0xFF", + "FrontFace" : + { + "Func" : "Always", + "DepthFailOp" : "Keep", + "FailOp" : "Keep", + "PassOp" : "Replace" + }, + "BackFace" : + { + "Func" : "Always", + "DepthFailOp" : "Keep", + "FailOp" : "Keep", + "PassOp" : "Replace" + } + } + }, + + + "CompilerHints" : { + "DisableOptimizations" : false + }, + + "ProgramSettings": + { + "EntryPoints": + [ + { + "name": "StandardPbr_ForwardPassVS", + "type": "Vertex" + }, + { + "name": "StandardPbr_ForwardPassPS", + "type": "Fragment" + } + ] + }, + + "DrawList" : "forward" +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist new file mode 100644 index 0000000000..39f101aca9 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist @@ -0,0 +1,29 @@ +{ + "Shader" : "StandardPBR_ForwardPass.shader", + "Variants": [ + { + "StableId": 1, + "Options": { + "o_directional_shadow_filtering_method": "ShadowFilterMethod::None" + } + }, + { + "StableId": 2, + "Options": { + "o_directional_shadow_filtering_method": "ShadowFilterMethod::Pcf" + } + }, + { + "StableId": 3, + "Options": { + "o_directional_shadow_filtering_method": "ShadowFilterMethod::Esm" + } + }, + { + "StableId": 4, + "Options": { + "o_directional_shadow_filtering_method": "ShadowFilterMethod::EsmPcf" + } + } + ] +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl new file mode 100644 index 0000000000..02e9e93ba2 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl @@ -0,0 +1,13 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +// NOTE: This file is a temporary workaround until .shader files can #define macros for their .azsl files + +#define QUALITY_LOW_END 1 + +#include "StandardPBR_ForwardPass.azsl" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader new file mode 100644 index 0000000000..44139608ca --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader @@ -0,0 +1,59 @@ +{ + // Note: "LowEnd" shaders are for supporting the low end pipeline + // These shaders can be safely added to materials without incurring additional runtime draw + // items as draw items for shaders are only created if the scene has a pass with a matching + // DrawListTag. If your pipeline doesn't have a "lowEndForward" DrawListTag, no draw items + // for this shader will be created. + + "Source" : "./StandardPBR_LowEndForward.azsl", + + "DepthStencilState" : + { + "Depth" : + { + "Enable" : true, + "CompareFunc" : "GreaterEqual" + }, + "Stencil" : + { + "Enable" : true, + "ReadMask" : "0x00", + "WriteMask" : "0xFF", + "FrontFace" : + { + "Func" : "Always", + "DepthFailOp" : "Keep", + "FailOp" : "Keep", + "PassOp" : "Replace" + }, + "BackFace" : + { + "Func" : "Always", + "DepthFailOp" : "Keep", + "FailOp" : "Keep", + "PassOp" : "Replace" + } + } + }, + + "CompilerHints" : { + "DisableOptimizations" : false + }, + + "ProgramSettings": + { + "EntryPoints": + [ + { + "name": "StandardPbr_ForwardPassVS", + "type": "Vertex" + }, + { + "name": "StandardPbr_ForwardPassPS", + "type": "Fragment" + } + ] + }, + + "DrawList" : "lowEndForward" +} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua new file mode 100644 index 0000000000..7e19641c6b --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua @@ -0,0 +1,82 @@ +-------------------------------------------------------------------------------------- +-- +-- Copyright (c) Contributors to the Open 3D Engine Project. +-- For complete copyright and license terms please see the LICENSE at the root of this distribution. +-- +-- SPDX-License-Identifier: Apache-2.0 OR MIT +-- +-- +-- +---------------------------------------------------------------------------------------------------- + +function GetMaterialPropertyDependencies() + return {"opacity.mode", "parallax.textureMap", "parallax.useTexture", "parallax.pdo"} +end + +OpacityMode_Opaque = 0 +OpacityMode_Cutout = 1 +OpacityMode_Blended = 2 +OpacityMode_TintedTransparent = 3 + +function TryGetShaderByTag(context, shaderTag) + if context:HasShaderWithTag(shaderTag) then + return context:GetShaderByTag(shaderTag) + else + return nil + end +end + +function TrySetShaderEnabled(shader, enabled) + if shader then + shader:SetEnabled(enabled) + end +end + +function Process(context) + local opacityMode = context:GetMaterialPropertyValue_enum("opacity.mode") + local displacementMap = context:GetMaterialPropertyValue_Image("parallax.textureMap") + local useDisplacementMap = context:GetMaterialPropertyValue_bool("parallax.useTexture") + local parallaxEnabled = displacementMap ~= nil and useDisplacementMap + local parallaxPdoEnabled = context:GetMaterialPropertyValue_bool("parallax.pdo") + + local depthPass = context:GetShaderByTag("DepthPass") + local shadowMap = context:GetShaderByTag("Shadowmap") + local forwardPassEDS = context:GetShaderByTag("ForwardPass_EDS") + + local depthPassWithPS = context:GetShaderByTag("DepthPass_WithPS") + local shadowMapWithPS = context:GetShaderByTag("Shadowmap_WithPS") + local forwardPass = context:GetShaderByTag("ForwardPass") + + -- Use TryGetShaderByTag because these shaders only exist in StandardPBR but this script is also used for EnhancedPBR + local lowEndForwardEDS = TryGetShaderByTag(context, "LowEndForward_EDS") + local lowEndForward = TryGetShaderByTag(context, "LowEndForward") + + if parallaxEnabled and parallaxPdoEnabled then + depthPass:SetEnabled(false) + shadowMap:SetEnabled(false) + forwardPassEDS:SetEnabled(false) + + depthPassWithPS:SetEnabled(true) + shadowMapWithPS:SetEnabled(true) + forwardPass:SetEnabled(true) + + TrySetShaderEnabled(lowEndForwardEDS, false) + TrySetShaderEnabled(lowEndForward, true) + else + depthPass:SetEnabled(opacityMode == OpacityMode_Opaque) + shadowMap:SetEnabled(opacityMode == OpacityMode_Opaque) + forwardPassEDS:SetEnabled((opacityMode == OpacityMode_Opaque) or (opacityMode == OpacityMode_Blended) or (opacityMode == OpacityMode_TintedTransparent)) + + depthPassWithPS:SetEnabled(opacityMode == OpacityMode_Cutout) + shadowMapWithPS:SetEnabled(opacityMode == OpacityMode_Cutout) + forwardPass:SetEnabled(opacityMode == OpacityMode_Cutout) + + -- Only enable lowEndForwardEDS in Opaque mode, Transparent mode will be handled by forwardPassEDS. The transparent pass uses the "transparent" draw tag + -- for both standard and low end pipelines, so this keeps both shaders from rendering to the transparent draw list. + TrySetShaderEnabled(lowEndForwardEDS, opacityMode == OpacityMode_Opaque) + TrySetShaderEnabled(lowEndForward, opacityMode == OpacityMode_Cutout) + end + + context:GetShaderByTag("DepthPassTransparentMin"):SetEnabled((opacityMode == OpacityMode_Blended) or (opacityMode == OpacityMode_TintedTransparent)) + context:GetShaderByTag("DepthPassTransparentMax"):SetEnabled((opacityMode == OpacityMode_Blended) or (opacityMode == OpacityMode_TintedTransparent)) +end diff --git a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake index c4d198fef9..f595202218 100644 --- a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake +++ b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake @@ -10,6 +10,13 @@ set(FILES Materials/Special/ShadowCatcher.azsl Materials/Special/ShadowCatcher.materialtype Materials/Special/ShadowCatcher.shader + Materials/Types/BasePBR.materialtype + Materials/Types/BasePBR_Common.azsli + Materials/Types/BasePBR_ForwardPass.azsl + Materials/Types/BasePBR_ForwardPass.shader + Materials/Types/BasePBR_LowEndForward.azsl + Materials/Types/BasePBR_LowEndForward.shader + Materials/Types/BasePBR_ShaderEnable.lua Materials/Types/EnhancedPBR.materialtype Materials/Types/EnhancedPBR_Common.azsli Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl @@ -53,6 +60,7 @@ set(FILES Materials/Types/StandardPBR_LowEndForward.azsl Materials/Types/StandardPBR_LowEndForward.shader Materials/Types/StandardPBR_LowEndForward_EDS.shader + Materials/Types/StandardPBR_Metallic.lua Materials/Types/StandardPBR_ParallaxState.lua Materials/Types/StandardPBR_Roughness.lua Materials/Types/StandardPBR_ShaderEnable.lua @@ -129,6 +137,7 @@ set(FILES Passes/DownsampleMipChain.pass Passes/EnvironmentCubeMapDepthMSAA.pass Passes/EnvironmentCubeMapForwardMSAA.pass + Passes/EnvironmentCubeMapForwardSubsurfaceMSAA.pass Passes/EnvironmentCubeMapPipeline.pass Passes/EnvironmentCubeMapSkyBox.pass Passes/EsmShadowmaps.pass @@ -303,6 +312,7 @@ set(FILES ShaderLib/Atom/Features/ScreenSpace/ScreenSpaceUtil.azsli ShaderLib/Atom/Features/Shadow/BicubicPcfFilters.azsli ShaderLib/Atom/Features/Shadow/DirectionalLightShadow.azsli + ShaderLib/Atom/Features/Shadow/ESM.azsli ShaderLib/Atom/Features/Shadow/NormalOffsetShadows.azsli ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli ShaderLib/Atom/Features/Shadow/ReceiverPlaneDepthBias.azsli From 8fa99c47dbd573cd192065bd7682b92ebf90daa4 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Mon, 13 Dec 2021 12:51:34 -0800 Subject: [PATCH 2/8] Work in progress, current shader compilation error Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Materials/Presets/PBR/metal_gold.material | 2 +- .../Presets/PBR/metal_gold_matte.material | 2 +- .../Presets/PBR/metal_gold_polished.material | 2 +- .../Materials/Types/BasePBR.materialtype | 593 +----------------- .../Materials/Types/BasePBR_Common.azsli | 36 -- .../Materials/Types/BasePBR_ForwardPass.azsl | 192 +----- .../Types/BasePBR_ForwardPass.shader | 7 +- .../BasePBR_ForwardPass.shadervariantlist | 2 +- .../Types/BasePBR_LowEndForward.azsl | 2 +- .../Types/BasePBR_LowEndForward.shader | 6 +- .../Materials/Types/BasePBR_ShaderEnable.lua | 52 +- .../Atom/Features/LightCulling/NVLC.azsli | 4 +- 12 files changed, 40 insertions(+), 860 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material index 2638e76a74..f0fd265726 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material +++ b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material @@ -1,6 +1,6 @@ { "description": "", - "materialType": "Materials\\Types\\StandardPBR.materialtype", + "materialType": "Materials\\Types\\Temp\\BasePBR.materialtype", "parentMaterial": "", "propertyLayoutVersion": 3, "properties": { diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material index fd21141048..53ba190084 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material +++ b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material @@ -1,6 +1,6 @@ { "description": "", - "materialType": "Materials\\Types\\StandardPBR.materialtype", + "materialType": "Materials\\Types\\Temp\\BasePBR.materialtype", "parentMaterial": "", "propertyLayoutVersion": 3, "properties": { diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material index 5861c7b533..d200bddbc5 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material +++ b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material @@ -1,6 +1,6 @@ { "description": "", - "materialType": "Materials/Types/StandardPBR.materialtype", + "materialType": "Materials/Types/Temp/BasePBR.materialtype", "parentMaterial": "", "propertyLayoutVersion": 3, "properties": { diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype index f324394309..d4c79a05ef 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype @@ -1,14 +1,6 @@ { - "description": "Material Type with properties used to define Standard PBR, a metallic-roughness Physically-Based Rendering (PBR) material shading model.", - "version": 4, - "versionUpdates": [ - { - "toVersion": 4, - "actions": [ - {"op": "rename", "from": "opacity.doubleSided", "to": "general.doubleSided"} - ] - } - ], + "description": "Material Type with properties used to define Base PBR, a metallic-roughness Physically-Based Rendering (PBR) material shading model.", + "version": 0, "propertyLayout": { "groups": [ { @@ -36,38 +28,13 @@ "displayName": "Normal", "description": "Properties related to configuring surface normal." }, - { - "name": "occlusion", - "displayName": "Occlusion", - "description": "Properties for baked textures that represent geometric occlusion of light." - }, - { - "name": "emissive", - "displayName": "Emissive", - "description": "Properties to add light emission, independent of other lights in the scene." - }, - { - "name": "clearCoat", - "displayName": "Clear Coat", - "description": "Properties for configuring gloss clear coat" - }, - { - "name": "parallax", - "displayName": "Displacement", - "description": "Properties for parallax effect produced by a height map." - }, - { - "name": "opacity", - "displayName": "Opacity", - "description": "Properties for configuring the materials transparency." - }, { "name": "uv", "displayName": "UVs", "description": "Properties for configuring UV transforms." }, { - // Note: this property group is used in the DiffuseGlobalIllumination pass, it is not read by the StandardPBR shader + // Note: this property group is used in the DiffuseGlobalIllumination pass, it is not read by the BasePBR shader "name": "irradiance", "displayName": "Irradiance", "description": "Properties for configuring the irradiance used in global illumination." @@ -403,141 +370,6 @@ } } ], - "clearCoat": [ - { - "name": "enable", - "displayName": "Enable", - "description": "Enable clear coat", - "type": "Bool", - "defaultValue": false - }, - { - "name": "factor", - "displayName": "Factor", - "description": "Strength factor for scaling the percentage of effect applied", - "type": "Float", - "defaultValue": 1.0, - "min": 0.0, - "max": 1.0, - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatFactor" - } - }, - { - "name": "influenceMap", - "displayName": " Influence Map", - "description": "Strength factor texture", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatInfluenceMap" - } - }, - { - "name": "useInfluenceMap", - "displayName": " Use Texture", - "description": "Whether to use the texture, or just default to the Factor value.", - "type": "Bool", - "defaultValue": true - }, - { - "name": "influenceMapUv", - "displayName": " UV", - "description": "Strength factor map UV set", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatInfluenceMapUvIndex" - } - }, - { - "name": "roughness", - "displayName": "Roughness", - "description": "Clear coat layer roughness", - "type": "Float", - "defaultValue": 0.0, - "min": 0.0, - "max": 1.0, - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatRoughness" - } - }, - { - "name": "roughnessMap", - "displayName": " Roughness Map", - "description": "Texture for defining surface roughness", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatRoughnessMap" - } - }, - { - "name": "useRoughnessMap", - "displayName": " Use Texture", - "description": "Whether to use the texture, or just default to the roughness value.", - "type": "Bool", - "defaultValue": true - }, - { - "name": "roughnessMapUv", - "displayName": " UV", - "description": "Roughness map UV set", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatRoughnessMapUvIndex" - } - }, - { - "name": "normalStrength", - "displayName": "Normal Strength", - "description": "Scales the impact of the clear coat normal map", - "type": "Float", - "defaultValue": 1.0, - "min": 0.0, - "max": 2.0, - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatNormalStrength" - } - }, - { - "name": "normalMap", - "displayName": "Normal Map", - "description": "Normal map for clear coat layer, as top layer material clear coat doesn't affect by base layer normal map", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatNormalMap" - } - }, - { - "name": "useNormalMap", - "displayName": " Use Texture", - "description": "Whether to use the normal map", - "type": "Bool", - "defaultValue": true - }, - { - "name": "normalMapUv", - "displayName": " UV", - "description": "Normal map UV set", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_clearCoatNormalMapUvIndex" - } - } - ], "normal": [ { "name": "textureMap", @@ -604,80 +436,6 @@ } } ], - "opacity": [ - { - "name": "mode", - "displayName": "Opacity Mode", - "description": "Indicates the general approach how transparency is to be applied.", - "type": "Enum", - "enumValues": [ "Opaque", "Cutout", "Blended", "TintedTransparent" ], - "defaultValue": "Opaque", - "connection": { - "type": "ShaderOption", - "name": "o_opacity_mode" - } - }, - { - "name": "alphaSource", - "displayName": "Alpha Source", - "description": "Indicates whether to get the opacity texture from the Base Color map (Packed) or from a separate greyscale texture (Split).", - "type": "Enum", - "enumValues": [ "Packed", "Split", "None" ], - "defaultValue": "Packed", - "connection": { - "type": "ShaderOption", - "name": "o_opacity_source" - } - }, - { - "name": "textureMap", - "displayName": "Texture", - "description": "Texture for defining surface opacity.", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_opacityMap" - } - }, - { - "name": "textureMapUv", - "displayName": "UV", - "description": "Opacity map UV set", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_opacityMapUvIndex" - } - }, - { - "name": "factor", - "displayName": "Factor", - "description": "Factor for cutout threshold and blending", - "type": "Float", - "min": 0.0, - "max": 1.0, - "defaultValue": 0.5, - "connection": { - "type": "ShaderInput", - "name": "m_opacityFactor" - } - }, - { - "name": "alphaAffectsSpecular", - "displayName": "Alpha affects specular", - "description": "How much the alpha value should also affect specular reflection. This should be 0.0 for materials where light can transmit through their physical surface (like glass), but 1.0 when alpha determines the very presence of a surface (like hair or grass)", - "type": "float", - "min": 0.0, - "max": 1.0, - "defaultValue": 0.0, - "connection": { - "type": "ShaderInput", - "name": "m_opacityAffectsSpecularFactor" - } - } - ], "uv": [ { "name": "center", @@ -740,263 +498,6 @@ "step": 0.1 } ], - "occlusion": [ - { - "name": "diffuseTextureMap", - "displayName": "Diffuse AO", - "description": "Texture for defining occlusion area for diffuse ambient lighting.", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_diffuseOcclusionMap" - } - }, - { - "name": "diffuseUseTexture", - "displayName": " Use Texture", - "description": "Whether to use the Diffuse AO map.", - "type": "Bool", - "defaultValue": true - }, - { - "name": "diffuseTextureMapUv", - "displayName": " UV", - "description": "Diffuse AO map UV set.", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_diffuseOcclusionMapUvIndex" - } - }, - { - "name": "diffuseFactor", - "displayName": " Factor", - "description": "Strength factor for scaling the values of Diffuse AO", - "type": "Float", - "defaultValue": 1.0, - "min": 0.0, - "softMax": 2.0, - "connection": { - "type": "ShaderInput", - "name": "m_diffuseOcclusionFactor" - } - }, - { - "name": "specularTextureMap", - "displayName": "Specular Cavity", - "description": "Texture for defining occlusion area for specular lighting.", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_specularOcclusionMap" - } - }, - { - "name": "specularUseTexture", - "displayName": " Use Texture", - "description": "Whether to use the Specular Cavity map.", - "type": "Bool", - "defaultValue": true - }, - { - "name": "specularTextureMapUv", - "displayName": " UV", - "description": "Specular Cavity map UV set.", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_specularOcclusionMapUvIndex" - } - }, - { - "name": "specularFactor", - "displayName": " Factor", - "description": "Strength factor for scaling the values of Specular Cavity", - "type": "Float", - "defaultValue": 1.0, - "min": 0.0, - "softMax": 2.0, - "connection": { - "type": "ShaderInput", - "name": "m_specularOcclusionFactor" - } - } - ], - "emissive": [ - { - "name": "enable", - "displayName": "Enable", - "description": "Enable the emissive group", - "type": "Bool", - "defaultValue": false - }, - { - "name": "unit", - "displayName": "Units", - "description": "The photometric units of the Intensity property.", - "type": "Enum", - "enumValues": ["Ev100"], - "defaultValue": "Ev100" - }, - { - "name": "color", - "displayName": "Color", - "description": "Color is displayed as sRGB but the values are stored as linear color.", - "type": "Color", - "defaultValue": [ 1.0, 1.0, 1.0 ], - "connection": { - "type": "ShaderInput", - "name": "m_emissiveColor" - } - }, - { - "name": "intensity", - "displayName": "Intensity", - "description": "The amount of energy emitted.", - "type": "Float", - "defaultValue": 4, - "min": -10, - "max": 20, - "softMin": -6, - "softMax": 16 - }, - { - "name": "textureMap", - "displayName": "Texture", - "description": "Texture for defining emissive area.", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_emissiveMap" - } - }, - { - "name": "useTexture", - "displayName": "Use Texture", - "description": "Whether to use the texture.", - "type": "Bool", - "defaultValue": true - }, - { - "name": "textureMapUv", - "displayName": "UV", - "description": "Emissive map UV set", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_emissiveMapUvIndex" - } - } - ], - "parallax": [ - { - "name": "textureMap", - "displayName": "Height Map", - "description": "Displacement height map to create parallax effect.", - "type": "Image", - "connection": { - "type": "ShaderInput", - "name": "m_heightmap" - } - }, - { - "name": "useTexture", - "displayName": "Use Texture", - "description": "Whether to use the height map.", - "type": "Bool", - "defaultValue": true - }, - { - "name": "textureMapUv", - "displayName": "UV", - "description": "Height map UV set", - "type": "Enum", - "enumIsUv": true, - "defaultValue": "Tiled", - "connection": { - "type": "ShaderInput", - "name": "m_parallaxUvIndex" - } - }, - { - "name": "factor", - "displayName": "Height Map Scale", - "description": "The total height of the height map in local model units.", - "type": "Float", - "defaultValue": 0.05, - "min": 0.0, - "softMax": 0.1, - "connection": { - "type": "ShaderInput", - "name": "m_heightmapScale" - } - }, - { - "name": "offset", - "displayName": "Offset", - "description": "Adjusts the overall displacement amount in local model units.", - "type": "Float", - "defaultValue": 0.0, - "softMin": -0.1, - "softMax": 0.1, - "connection": { - "type": "ShaderInput", - "name": "m_heightmapOffset" - } - }, - { - "name": "algorithm", - "displayName": "Algorithm", - "description": "Select the algorithm to use for parallax mapping.", - "type": "Enum", - "enumValues": [ "Basic", "Steep", "POM", "Relief", "ContactRefinement" ], - "defaultValue": "POM", - "connection": { - "type": "ShaderOption", - "name": "o_parallax_algorithm" - } - }, - { - "name": "quality", - "displayName": "Quality", - "description": "Quality of parallax mapping.", - "type": "Enum", - "enumValues": [ "Low", "Medium", "High", "Ultra" ], - "defaultValue": "Low", - "connection": { - "type": "ShaderOption", - "name": "o_parallax_quality" - } - }, - { - "name": "pdo", - "displayName": "Pixel Depth Offset", - "description": "Enable PDO to offset the original pixel depths. This will affect any shaders using depth, for example, when receiving shadows.", - "type": "Bool", - "defaultValue": false, - "connection": { - "type": "ShaderOption", - "name": "o_parallax_enablePixelDepthOffset" - } - }, - { - "name": "showClipping", - "displayName": "Show Clipping", - "description": "Highlight areas where the height map is clipped by the mesh surface.", - "type": "Bool", - "defaultValue": false, - "connection": { - "type": "ShaderOption", - "name": "o_parallax_highlightClipping" - } - } - ], "irradiance": [ // Note: this property group is used in the DiffuseGlobalIllumination pass and not by the main forward shader { @@ -1020,50 +521,25 @@ }, "shaders": [ { - "file": "./StandardPBR_ForwardPass.shader", - "tag": "ForwardPass" - }, - { - "file": "./StandardPBR_ForwardPass_EDS.shader", + "file": "./BasePBR_ForwardPass.shader", "tag": "ForwardPass_EDS" }, { - "file": "./StandardPBR_LowEndForward.shader", - "tag": "LowEndForward" - }, - { - "file": "./StandardPBR_LowEndForward_EDS.shader", + "file": "./BasePBR_LowEndForward.shader", "tag": "LowEndForward_EDS" }, { "file": "Shaders/Shadow/Shadowmap.shader", "tag": "Shadowmap" }, - { - "file": "./StandardPBR_Shadowmap_WithPS.shader", - "tag": "Shadowmap_WithPS" - }, { "file": "Shaders/Depth/DepthPass.shader", "tag": "DepthPass" }, - { - "file": "./StandardPBR_DepthPass_WithPS.shader", - "tag": "DepthPass_WithPS" - }, { "file": "Shaders/MotionVector/MeshMotionVector.shader", "tag": "MeshMotionVector" - }, - // Used by the light culling system to produce accurate depth bounds for this object when it uses blended transparency - { - "file": "Shaders/Depth/DepthPassTransparentMin.shader", - "tag": "DepthPassTransparentMin" - }, - { - "file": "Shaders/Depth/DepthPassTransparentMax.shader", - "tag": "DepthPassTransparentMax" - } + } ], "functors": [ { @@ -1082,19 +558,6 @@ "float3x3InverseShaderInput": "m_uvMatrixInverse" } }, - { - // Convert emissive unit. - "type": "ConvertEmissiveUnit", - "args": { - "intensityProperty": "emissive.intensity", - "lightUnitProperty": "emissive.unit", - "shaderInput": "m_emissiveIntensity", - "ev100Index": 0, - "nitIndex" : 1, - "ev100MinMax": [-10, 20], - "nitMinMax": [0.001, 100000.0] - } - }, { "type": "UseTexture", "args": { @@ -1122,48 +585,6 @@ "shaderOption": "o_normal_useTexture" } }, - { - "type": "UseTexture", - "args": { - "textureProperty": "occlusion.diffuseTextureMap", - "useTextureProperty": "occlusion.diffuseUseTexture", - "dependentProperties": ["occlusion.diffuseTextureMapUv", "occlusion.diffuseFactor"], - "shaderOption": "o_diffuseOcclusion_useTexture" - } - }, - { - "type": "UseTexture", - "args": { - "textureProperty": "occlusion.specularTextureMap", - "useTextureProperty": "occlusion.specularUseTexture", - "dependentProperties": ["occlusion.specularTextureMapUv", "occlusion.specularFactor"], - "shaderOption": "o_specularOcclusion_useTexture" - } - }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_ClearCoatState.lua" - } - }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_ClearCoatEnableFeature.lua" - } - }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_EmissiveState.lua" - } - }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_ParallaxState.lua" - } - }, { "type": "Lua", "args": { @@ -1191,7 +612,7 @@ { "type": "Lua", "args": { - "file": "StandardPBR_ShaderEnable.lua" + "file": "BasePBR_ShaderEnable.lua" } } ], diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli index 0aebc11f1d..dbec7458fc 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Common.azsli @@ -19,10 +19,6 @@ #include "MaterialInputs/MetallicInput.azsli" #include "MaterialInputs/SpecularInput.azsli" #include "MaterialInputs/NormalInput.azsli" -#include "MaterialInputs/ClearCoatInput.azsli" -#include "MaterialInputs/OcclusionInput.azsli" -#include "MaterialInputs/EmissiveInput.azsli" -#include "MaterialInputs/ParallaxInput.azsli" #include "MaterialInputs/UvSetCount.azsli" ShaderResourceGroup MaterialSrg : SRG_PerMaterial @@ -33,23 +29,13 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial COMMON_SRG_INPUTS_METALLIC() COMMON_SRG_INPUTS_SPECULAR_F0() COMMON_SRG_INPUTS_NORMAL() - COMMON_SRG_INPUTS_CLEAR_COAT() - COMMON_SRG_INPUTS_OCCLUSION() - COMMON_SRG_INPUTS_EMISSIVE() - COMMON_SRG_INPUTS_PARALLAX() - uint m_parallaxUvIndex; float3x3 m_uvMatrix; float4 m_pad1; // [GFX TODO][ATOM-14595] This is a workaround for a data stomping bug. Remove once it's fixed. float3x3 m_uvMatrixInverse; float4 m_pad2; // [GFX TODO][ATOM-14595] This is a workaround for a data stomping bug. Remove once it's fixed. - float m_opacityFactor; - float m_opacityAffectsSpecularFactor; - Texture2D m_opacityMap; - uint m_opacityMapUvIndex; - Sampler m_sampler { AddressU = Wrap; @@ -71,25 +57,3 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial MipFilter = Linear; }; } - -// Callback function for ParallaxMapping.azsli -DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) -{ - return SampleDepthFromHeightmap(MaterialSrg::m_heightmap, MaterialSrg::m_sampler, uv, uv_ddx, uv_ddy); -} - - -COMMON_OPTIONS_PARALLAX() - -bool ShouldHandleParallax() -{ - // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled. - return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_useHeightmap; -} - -bool ShouldHandleParallaxInDepthShaders() -{ - // The depth pass shaders need to calculate parallax when the result could affect the depth buffer, or when - // parallax could affect texel clipping. - return ShouldHandleParallax() && (o_parallax_enablePixelDepthOffset || o_opacity_mode == OpacityMode::Cutout); -} diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl index 1d5e4ad9e3..1a4b386ef1 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl @@ -8,7 +8,7 @@ #include "Atom/Features/ShaderQualityOptions.azsli" -#include "StandardPBR_Common.azsli" +#include "BasePBR_Common.azsli" // SRGs #include @@ -19,7 +19,6 @@ // Utility #include -#include // Custom Surface & Lighting #include @@ -35,13 +34,6 @@ COMMON_OPTIONS_ROUGHNESS() COMMON_OPTIONS_METALLIC() COMMON_OPTIONS_SPECULAR_F0() COMMON_OPTIONS_NORMAL() -COMMON_OPTIONS_CLEAR_COAT() -COMMON_OPTIONS_OCCLUSION() -COMMON_OPTIONS_EMISSIVE() -// Note COMMON_OPTIONS_PARALLAX is in StandardPBR_Common.azsli because it's needed by all StandardPBR shaders. - -// Alpha -#include "MaterialInputs/AlphaInput.azsli" // ---------- Vertex Shader ---------- @@ -75,9 +67,9 @@ struct VSOutput #include -VSOutput StandardPbr_ForwardPassVS(VSInput IN) +VSOutput BasePbr_ForwardPassVS(VSInput IN) { - VSOutput OUT; + VSOutput OUT = (VSOutput)0; float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1.0)).xyz; @@ -85,8 +77,8 @@ VSOutput StandardPbr_ForwardPassVS(VSInput IN) OUT.m_uv[0] = mul(MaterialSrg::m_uvMatrix, float3(IN.m_uv0, 1.0)).xy; OUT.m_uv[1] = IN.m_uv1; - // Shadow coords will be calculated in the pixel shader in this case - bool skipShadowCoords = ShouldHandleParallax() && o_parallax_enablePixelDepthOffset; + // No parallax in BaseBPR, so do shadow coordinate calculations in vertex shader + bool skipShadowCoords = false; VertexHelper(IN, OUT, worldPosition, skipShadowCoords); @@ -96,7 +88,7 @@ VSOutput StandardPbr_ForwardPassVS(VSInput IN) // ---------- Pixel Shader ---------- -PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float depthNDC) +PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) { const float3 vertexNormal = normalize(IN.m_normal); @@ -104,46 +96,14 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float3 tangents[UvSetCount] = { IN.m_tangent.xyz, IN.m_tangent.xyz }; float3 bitangents[UvSetCount] = { IN.m_bitangent.xyz, IN.m_bitangent.xyz }; - if (ShouldHandleParallax() || o_normal_useTexture || (o_clearCoat_enabled && o_clearCoat_normal_useTexture)) + if (o_normal_useTexture) { PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents); } - - // ------- Depth & Parallax ------- - - depthNDC = IN.m_position.z; - bool displacementIsClipped = false; - - if(ShouldHandleParallax()) - { - - float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); - float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_heightmapScale, MaterialSrg::m_heightmapOffset, - ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, - IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depthNDC, IN.m_position.w, displacementIsClipped); - - // Adjust directional light shadow coordinates for parallax correction - if(o_parallax_enablePixelDepthOffset) - { - const uint shadowIndex = ViewSrg::m_shadowIndexDirectionalLight; - if (o_enableShadows && shadowIndex < SceneSrg::m_directionalLightCount) - { - DirectionalLightShadow::GetShadowCoords(shadowIndex, IN.m_worldPosition, vertexNormal, IN.m_shadowCoords); - } - } - } - - Surface surface; + Surface surface = (Surface)0; surface.position = IN.m_worldPosition.xyz; - // ------- Alpha & Clip ------- - - float2 baseColorUv = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; - float2 opacityUv = IN.m_uv[MaterialSrg::m_opacityMapUvIndex]; - float alpha = GetAlphaInputAndClip(MaterialSrg::m_baseColorMap, MaterialSrg::m_opacityMap, baseColorUv, opacityUv, MaterialSrg::m_sampler, MaterialSrg::m_opacityFactor, o_opacity_source); - // ------- Normal ------- float2 normalUv = IN.m_uv[MaterialSrg::m_normalMapUvIndex]; @@ -154,14 +114,10 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // ------- Base Color ------- + float2 baseColorUv = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; float3 sampledColor = GetBaseColorInput(MaterialSrg::m_baseColorMap, MaterialSrg::m_sampler, baseColorUv, MaterialSrg::m_baseColor.rgb, o_baseColor_useTexture); float3 baseColor = BlendBaseColor(sampledColor, MaterialSrg::m_baseColor.rgb, MaterialSrg::m_baseColorFactor, o_baseColorTextureBlendMode, o_baseColor_useTexture); - if(o_parallax_highlightClipping && displacementIsClipped) - { - ApplyParallaxClippingHighlight(baseColor); - } - // ------- Metallic ------- float2 metallicUv = IN.m_uv[MaterialSrg::m_metallicMapUvIndex]; @@ -183,7 +139,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // ------- Lighting Data ------- - LightingData lightingData; + LightingData lightingData = (LightingData)0; // Light iterator lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); @@ -191,51 +147,11 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // Directional light shadow coordinates lightingData.shadowCoords = IN.m_shadowCoords; - - // ------- Emissive ------- - - float2 emissiveUv = IN.m_uv[MaterialSrg::m_emissiveMapUvIndex]; - lightingData.emissiveLighting = GetEmissiveInput(MaterialSrg::m_emissiveMap, MaterialSrg::m_sampler, emissiveUv, MaterialSrg::m_emissiveIntensity, MaterialSrg::m_emissiveColor.rgb, o_emissiveEnabled, o_emissive_useTexture); - - // ------- Occlusion ------- - - lightingData.diffuseAmbientOcclusion = GetOcclusionInput(MaterialSrg::m_diffuseOcclusionMap, MaterialSrg::m_sampler, IN.m_uv[MaterialSrg::m_diffuseOcclusionMapUvIndex], MaterialSrg::m_diffuseOcclusionFactor, o_diffuseOcclusion_useTexture); - lightingData.specularOcclusion = GetOcclusionInput(MaterialSrg::m_specularOcclusionMap, MaterialSrg::m_sampler, IN.m_uv[MaterialSrg::m_specularOcclusionMapUvIndex], MaterialSrg::m_specularOcclusionFactor, o_specularOcclusion_useTexture); - - // ------- Clearcoat ------- - - // [GFX TODO][ATOM-14603]: Clean up the double uses of these clear coat flags - if(o_clearCoat_feature_enabled) - { - if(o_clearCoat_enabled) - { - float3x3 uvMatrix = MaterialSrg::m_clearCoatNormalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); - GetClearCoatInputs(MaterialSrg::m_clearCoatInfluenceMap, IN.m_uv[MaterialSrg::m_clearCoatInfluenceMapUvIndex], MaterialSrg::m_clearCoatFactor, o_clearCoat_factor_useTexture, - MaterialSrg::m_clearCoatRoughnessMap, IN.m_uv[MaterialSrg::m_clearCoatRoughnessMapUvIndex], MaterialSrg::m_clearCoatRoughness, o_clearCoat_roughness_useTexture, - MaterialSrg::m_clearCoatNormalMap, IN.m_uv[MaterialSrg::m_clearCoatNormalMapUvIndex], IN.m_normal, o_clearCoat_normal_useTexture, MaterialSrg::m_clearCoatNormalStrength, - uvMatrix, tangents[MaterialSrg::m_clearCoatNormalMapUvIndex], bitangents[MaterialSrg::m_clearCoatNormalMapUvIndex], - MaterialSrg::m_sampler, isFrontFace, - surface.clearCoat.factor, surface.clearCoat.roughness, surface.clearCoat.normal); - } - - // manipulate base layer f0 if clear coat is enabled - // modify base layer's normal incidence reflectance - // for the derivation of the following equation please refer to: - // https://google.github.io/filament/Filament.md.html#materialsystem/clearcoatmodel/baselayermodification - float3 f0 = (1.0 - 5.0 * sqrt(surface.specularF0)) / (5.0 - sqrt(surface.specularF0)); - surface.specularF0 = lerp(surface.specularF0, f0 * f0, surface.clearCoat.factor); - } // Diffuse and Specular response (used in IBL calculations) lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear); lightingData.diffuseResponse = 1.0 - lightingData.specularResponse; - if(o_clearCoat_feature_enabled) - { - // Clear coat layer has fixed IOR = 1.5 and transparent => F0 = (1.5 - 1)^2 / (1.5 + 1)^2 = 0.04 - lightingData.diffuseResponse *= 1.0 - (FresnelSchlickWithRoughness(lightingData.NdotV, float3(0.04, 0.04, 0.04), surface.clearCoat.roughness) * surface.clearCoat.factor); - } - // ------- Multiscatter ------- lightingData.CalculateMultiscatterCompensation(surface.specularF0, o_specularF0_enableMultiScatterCompensation); @@ -254,99 +170,21 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // Finalize Lighting lightingData.FinalizeLighting(); + float alpha = 1.0f; PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); - // ------- Opacity ------- - - if (o_opacity_mode == OpacityMode::Blended || o_opacity_mode == OpacityMode::TintedTransparent) - { - // Increase opacity at grazing angles for surfaces with a low m_opacityAffectsSpecularFactor. - // For m_opacityAffectsSpecularFactor values close to 0, that indicates a transparent surface - // like glass, so it becomes less transparent at grazing angles. For m_opacityAffectsSpecularFactor - // values close to 1.0, that indicates the absence of a surface entirely, so this effect should - // not apply. - float fresnelAlpha = FresnelSchlickWithRoughness(lightingData.NdotV, alpha, surface.roughnessLinear).x; - alpha = lerp(fresnelAlpha, alpha, MaterialSrg::m_opacityAffectsSpecularFactor); - } - - if (o_opacity_mode == OpacityMode::Blended) - { - // [GFX_TODO ATOM-13187] PbrLighting shouldn't be writing directly to render targets. It's confusing when - // specular is being added to diffuse just because we're calling render target 0 "diffuse". - - // For blended mode, we do (dest * alpha) + (source * 1.0). This allows the specular - // to be added on top of the diffuse, but then the diffuse must be pre-multiplied. - // It's done this way because surface transparency doesn't really change specular response (eg, glass). - - lightingOutput.m_diffuseColor.rgb *= lightingOutput.m_diffuseColor.w; // pre-multiply diffuse - - // Add specular. m_opacityAffectsSpecularFactor controls how much the alpha masks out specular contribution. - float3 specular = lightingOutput.m_specularColor.rgb; - specular = lerp(specular, specular * lightingOutput.m_diffuseColor.w, MaterialSrg::m_opacityAffectsSpecularFactor); - lightingOutput.m_diffuseColor.rgb += specular; - - lightingOutput.m_diffuseColor.w = alpha; - } - else if (o_opacity_mode == OpacityMode::TintedTransparent) - { - // See OpacityMode::Blended above for the basic method. TintedTransparent adds onto the above concept by supporting - // colored alpha. This is currently a very basic calculation that uses the baseColor as a multiplier with strength - // determined by the alpha. We'll modify this later to be more physically accurate and allow surface depth, - // absorption, and interior color to be specified. - // - // The technique uses dual source blending to allow two separate sources to be part of the blending equation - // even though ultimately only a single render target is being written to. m_diffuseColor is render target 0 and - // m_specularColor render target 1, and the blend mode is (dest * source1color) + (source * 1.0). - // - // This means that m_specularColor.rgb (source 1) is multiplied against the destination, then - // m_diffuseColor.rgb (source) is added to that, and the final result is stored in render target 0. - - lightingOutput.m_diffuseColor.rgb *= lightingOutput.m_diffuseColor.w; // pre-multiply diffuse - - // Add specular. m_opacityAffectsSpecularFactor controls how much the alpha masks out specular contribution. - float3 specular = lightingOutput.m_specularColor.rgb; - specular = lerp(specular, specular * lightingOutput.m_diffuseColor.w, MaterialSrg::m_opacityAffectsSpecularFactor); - lightingOutput.m_diffuseColor.rgb += specular; - - lightingOutput.m_specularColor.rgb = baseColor * (1.0 - alpha); - } - else - { - lightingOutput.m_diffuseColor.w = -1; // Disable subsurface scattering - } + lightingOutput.m_diffuseColor.w = -1; // Disable subsurface scattering return lightingOutput; } -ForwardPassOutputWithDepth StandardPbr_ForwardPassPS(VSOutput IN, bool isFrontFace : SV_IsFrontFace) -{ - ForwardPassOutputWithDepth OUT; - float depth; - - PbrLightingOutput lightingOutput = ForwardPassPS_Common(IN, isFrontFace, depth); - -#ifdef UNIFIED_FORWARD_OUTPUT - OUT.m_color.rgb = lightingOutput.m_diffuseColor.rgb + lightingOutput.m_specularColor.rgb; - OUT.m_color.a = lightingOutput.m_diffuseColor.a; - OUT.m_depth = depth; -#else - OUT.m_diffuseColor = lightingOutput.m_diffuseColor; - OUT.m_specularColor = lightingOutput.m_specularColor; - OUT.m_specularF0 = lightingOutput.m_specularF0; - OUT.m_albedo = lightingOutput.m_albedo; - OUT.m_normal = lightingOutput.m_normal; - OUT.m_depth = depth; -#endif - return OUT; -} [earlydepthstencil] -ForwardPassOutput StandardPbr_ForwardPassPS_EDS(VSOutput IN, bool isFrontFace : SV_IsFrontFace) +ForwardPassOutput BasePbr_ForwardPassPS_EDS(VSOutput IN, bool isFrontFace : SV_IsFrontFace) { ForwardPassOutput OUT; - float depth; - - PbrLightingOutput lightingOutput = ForwardPassPS_Common(IN, isFrontFace, depth); + PbrLightingOutput lightingOutput = (PbrLightingOutput)0; + lightingOutput = ForwardPassPS_Common(IN, isFrontFace); #ifdef UNIFIED_FORWARD_OUTPUT OUT.m_color.rgb = lightingOutput.m_diffuseColor.rgb + lightingOutput.m_specularColor.rgb; diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader index d8df49f4b0..377c0eae95 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shader @@ -1,5 +1,5 @@ { - "Source" : "./StandardPBR_ForwardPass.azsl", + "Source" : "./BasePBR_ForwardPass.azsl", "DepthStencilState" : { @@ -30,7 +30,6 @@ } }, - "CompilerHints" : { "DisableOptimizations" : false }, @@ -40,11 +39,11 @@ "EntryPoints": [ { - "name": "StandardPbr_ForwardPassVS", + "name": "BasePbr_ForwardPassVS", "type": "Vertex" }, { - "name": "StandardPbr_ForwardPassPS", + "name": "BasePbr_ForwardPassPS_EDS", "type": "Fragment" } ] diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist index 39f101aca9..c817c793bd 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.shadervariantlist @@ -1,5 +1,5 @@ { - "Shader" : "StandardPBR_ForwardPass.shader", + "Shader" : "BasePBR_ForwardPass.shader", "Variants": [ { "StableId": 1, diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl index 02e9e93ba2..d380045d88 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.azsl @@ -10,4 +10,4 @@ #define QUALITY_LOW_END 1 -#include "StandardPBR_ForwardPass.azsl" +#include "BasePBR_ForwardPass.azsl" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader index 44139608ca..005b001063 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_LowEndForward.shader @@ -5,7 +5,7 @@ // DrawListTag. If your pipeline doesn't have a "lowEndForward" DrawListTag, no draw items // for this shader will be created. - "Source" : "./StandardPBR_LowEndForward.azsl", + "Source" : "./BasePBR_LowEndForward.azsl", "DepthStencilState" : { @@ -45,11 +45,11 @@ "EntryPoints": [ { - "name": "StandardPbr_ForwardPassVS", + "name": "BasePbr_ForwardPassVS", "type": "Vertex" }, { - "name": "StandardPbr_ForwardPassPS", + "name": "BasePbr_ForwardPassPS_EDS", "type": "Fragment" } ] diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua index 7e19641c6b..4a5fba58e8 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua @@ -9,15 +9,6 @@ -- ---------------------------------------------------------------------------------------------------- -function GetMaterialPropertyDependencies() - return {"opacity.mode", "parallax.textureMap", "parallax.useTexture", "parallax.pdo"} -end - -OpacityMode_Opaque = 0 -OpacityMode_Cutout = 1 -OpacityMode_Blended = 2 -OpacityMode_TintedTransparent = 3 - function TryGetShaderByTag(context, shaderTag) if context:HasShaderWithTag(shaderTag) then return context:GetShaderByTag(shaderTag) @@ -33,50 +24,17 @@ function TrySetShaderEnabled(shader, enabled) end function Process(context) - local opacityMode = context:GetMaterialPropertyValue_enum("opacity.mode") - local displacementMap = context:GetMaterialPropertyValue_Image("parallax.textureMap") - local useDisplacementMap = context:GetMaterialPropertyValue_bool("parallax.useTexture") - local parallaxEnabled = displacementMap ~= nil and useDisplacementMap - local parallaxPdoEnabled = context:GetMaterialPropertyValue_bool("parallax.pdo") local depthPass = context:GetShaderByTag("DepthPass") local shadowMap = context:GetShaderByTag("Shadowmap") local forwardPassEDS = context:GetShaderByTag("ForwardPass_EDS") - local depthPassWithPS = context:GetShaderByTag("DepthPass_WithPS") - local shadowMapWithPS = context:GetShaderByTag("Shadowmap_WithPS") - local forwardPass = context:GetShaderByTag("ForwardPass") - - -- Use TryGetShaderByTag because these shaders only exist in StandardPBR but this script is also used for EnhancedPBR + -- Use TryGetShaderByTag because these shaders only exist in BasePBR but this script is also used for EnhancedPBR local lowEndForwardEDS = TryGetShaderByTag(context, "LowEndForward_EDS") - local lowEndForward = TryGetShaderByTag(context, "LowEndForward") - - if parallaxEnabled and parallaxPdoEnabled then - depthPass:SetEnabled(false) - shadowMap:SetEnabled(false) - forwardPassEDS:SetEnabled(false) - - depthPassWithPS:SetEnabled(true) - shadowMapWithPS:SetEnabled(true) - forwardPass:SetEnabled(true) - TrySetShaderEnabled(lowEndForwardEDS, false) - TrySetShaderEnabled(lowEndForward, true) - else - depthPass:SetEnabled(opacityMode == OpacityMode_Opaque) - shadowMap:SetEnabled(opacityMode == OpacityMode_Opaque) - forwardPassEDS:SetEnabled((opacityMode == OpacityMode_Opaque) or (opacityMode == OpacityMode_Blended) or (opacityMode == OpacityMode_TintedTransparent)) - - depthPassWithPS:SetEnabled(opacityMode == OpacityMode_Cutout) - shadowMapWithPS:SetEnabled(opacityMode == OpacityMode_Cutout) - forwardPass:SetEnabled(opacityMode == OpacityMode_Cutout) + depthPass:SetEnabled(true); + shadowMap:SetEnabled(true); + forwardPassEDS:SetEnabled(true); - -- Only enable lowEndForwardEDS in Opaque mode, Transparent mode will be handled by forwardPassEDS. The transparent pass uses the "transparent" draw tag - -- for both standard and low end pipelines, so this keeps both shaders from rendering to the transparent draw list. - TrySetShaderEnabled(lowEndForwardEDS, opacityMode == OpacityMode_Opaque) - TrySetShaderEnabled(lowEndForward, opacityMode == OpacityMode_Cutout) - end - - context:GetShaderByTag("DepthPassTransparentMin"):SetEnabled((opacityMode == OpacityMode_Blended) or (opacityMode == OpacityMode_TintedTransparent)) - context:GetShaderByTag("DepthPassTransparentMax"):SetEnabled((opacityMode == OpacityMode_Blended) or (opacityMode == OpacityMode_TintedTransparent)) + TrySetShaderEnabled(lowEndForwardEDS, true) end diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/LightCulling/NVLC.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/LightCulling/NVLC.azsli index 60d5bf38f2..e9558b39ff 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/LightCulling/NVLC.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/LightCulling/NVLC.azsli @@ -72,7 +72,7 @@ struct TileLightData bool Light_IsInsideBin(uint package, uint bin) { - return (package & (1 << bin)) != 0; + return (package & (1u << bin)) != 0; } uint PackLightIndexWithBinMask(uint ind, uint bins) @@ -127,7 +127,7 @@ uint NVLC_GetBin(const float viewZ, const TileLightData data) const float zFarCoordSystemAdjusted = data.zFar * RH_COORD_SYSTEM_REVERSE; float f = saturate( (abs(viewZCoordSystemAdjusted) - zNearCoordSystemAdjusted) / (zFarCoordSystemAdjusted - zNearCoordSystemAdjusted) ); - float bin = min(f, 0.999999) * float(1 << data.logMaxBins); + float bin = min(f, 0.999999) * float(1u << data.logMaxBins); return uint(bin); } From fbd7b67e1126aeca6a21bd2eb52370a995d9d069 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Tue, 14 Dec 2021 15:57:23 -0800 Subject: [PATCH 3/8] added some explicit use of float3 Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Assets/Materials/Types/BasePBR_ForwardPass.azsl | 2 +- .../Atom/Features/PBR/Lighting/LightingData.azsli | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl index 1a4b386ef1..8c8c9a589d 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl @@ -150,7 +150,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) // Diffuse and Specular response (used in IBL calculations) lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear); - lightingData.diffuseResponse = 1.0 - lightingData.specularResponse; + lightingData.diffuseResponse = float3(1.0, 1.0, 1.0) - lightingData.specularResponse; // ------- Multiscatter ------- diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli index 878bed02d4..dbc348e54a 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli @@ -56,10 +56,10 @@ class LightingData void LightingData::Init(float3 positionWS, float3 normal, float roughnessLinear) { - diffuseLighting = 0; - specularLighting = 0; - translucentBackLighting = 0; - multiScatterCompensation = 1.0f; + diffuseLighting = float3(0.0, 0.0, 0.0); + specularLighting = float3(0.0, 0.0, 0.0); + translucentBackLighting = float3(0.0, 0.0, 0.0); + multiScatterCompensation = float3(1.0f, 1.0f, 1.0f); emissiveLighting = float3(0.0f, 0.0f, 0.0f); diffuseAmbientOcclusion = 1.0f; specularOcclusion = 1.0f; From a436ea7f9bccd98083318da91b7f877aed117589 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Wed, 15 Dec 2021 22:30:37 -0800 Subject: [PATCH 4/8] BasePbr working Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Materials/Presets/PBR/metal_gold.material | 4 +- .../Presets/PBR/metal_gold_matte.material | 4 +- .../Presets/PBR/metal_gold_polished.material | 4 +- .../Materials/Types/BasePBR.materialtype | 18 --------- .../Materials/Types/BasePBR_ForwardPass.azsl | 13 +++--- .../Materials/Types/BasePBR_ShaderEnable.lua | 40 ------------------- .../Types/StandardPBR_ForwardPass.shader | 1 - 7 files changed, 13 insertions(+), 71 deletions(-) delete mode 100644 Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material index f0fd265726..04aaccada4 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material +++ b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold.material @@ -1,8 +1,8 @@ { "description": "", - "materialType": "Materials\\Types\\Temp\\BasePBR.materialtype", + "materialType": "Materials\\Types\\BasePBR.materialtype", "parentMaterial": "", - "propertyLayoutVersion": 3, + "propertyLayoutVersion": 0, "properties": { "baseColor": { "color": [ diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material index 53ba190084..80ddede2ec 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material +++ b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_matte.material @@ -1,8 +1,8 @@ { "description": "", - "materialType": "Materials\\Types\\Temp\\BasePBR.materialtype", + "materialType": "Materials\\Types\\BasePBR.materialtype", "parentMaterial": "", - "propertyLayoutVersion": 3, + "propertyLayoutVersion": 0, "properties": { "baseColor": { "color": [ diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material index d200bddbc5..b9f34f4717 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material +++ b/Gems/Atom/Feature/Common/Assets/Materials/Presets/PBR/metal_gold_polished.material @@ -1,8 +1,8 @@ { "description": "", - "materialType": "Materials/Types/Temp/BasePBR.materialtype", + "materialType": "Materials/Types/BasePBR.materialtype", "parentMaterial": "", - "propertyLayoutVersion": 3, + "propertyLayoutVersion": 0, "properties": { "baseColor": { "color": [ diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype index d4c79a05ef..5765537120 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype @@ -596,24 +596,6 @@ "args": { "file": "StandardPBR_Metallic.lua" } - }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_HandleOpacityDoubleSided.lua" - } - }, - { - "type": "Lua", - "args": { - "file": "StandardPBR_HandleOpacityMode.lua" - } - }, - { - "type": "Lua", - "args": { - "file": "BasePBR_ShaderEnable.lua" - } } ], "uvNameMap": { diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl index 8c8c9a589d..30a8666183 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl @@ -69,7 +69,7 @@ struct VSOutput VSOutput BasePbr_ForwardPassVS(VSInput IN) { - VSOutput OUT = (VSOutput)0; + VSOutput OUT; float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1.0)).xyz; @@ -101,7 +101,8 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents); } - Surface surface = (Surface)0; + Surface surface; + surface.clearCoat.InitializeToZero(); surface.position = IN.m_worldPosition.xyz; // ------- Normal ------- @@ -139,7 +140,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) // ------- Lighting Data ------- - LightingData lightingData = (LightingData)0; + LightingData lightingData; // Light iterator lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); @@ -173,7 +174,8 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) float alpha = 1.0f; PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); - lightingOutput.m_diffuseColor.w = -1; // Disable subsurface scattering + // Disable subsurface scattering + lightingOutput.m_diffuseColor.w = -1; return lightingOutput; } @@ -183,8 +185,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) ForwardPassOutput BasePbr_ForwardPassPS_EDS(VSOutput IN, bool isFrontFace : SV_IsFrontFace) { ForwardPassOutput OUT; - PbrLightingOutput lightingOutput = (PbrLightingOutput)0; - lightingOutput = ForwardPassPS_Common(IN, isFrontFace); + PbrLightingOutput lightingOutput = ForwardPassPS_Common(IN, isFrontFace); #ifdef UNIFIED_FORWARD_OUTPUT OUT.m_color.rgb = lightingOutput.m_diffuseColor.rgb + lightingOutput.m_specularColor.rgb; diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua deleted file mode 100644 index 4a5fba58e8..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ShaderEnable.lua +++ /dev/null @@ -1,40 +0,0 @@ --------------------------------------------------------------------------------------- --- --- Copyright (c) Contributors to the Open 3D Engine Project. --- For complete copyright and license terms please see the LICENSE at the root of this distribution. --- --- SPDX-License-Identifier: Apache-2.0 OR MIT --- --- --- ----------------------------------------------------------------------------------------------------- - -function TryGetShaderByTag(context, shaderTag) - if context:HasShaderWithTag(shaderTag) then - return context:GetShaderByTag(shaderTag) - else - return nil - end -end - -function TrySetShaderEnabled(shader, enabled) - if shader then - shader:SetEnabled(enabled) - end -end - -function Process(context) - - local depthPass = context:GetShaderByTag("DepthPass") - local shadowMap = context:GetShaderByTag("Shadowmap") - local forwardPassEDS = context:GetShaderByTag("ForwardPass_EDS") - - -- Use TryGetShaderByTag because these shaders only exist in BasePBR but this script is also used for EnhancedPBR - local lowEndForwardEDS = TryGetShaderByTag(context, "LowEndForward_EDS") - - depthPass:SetEnabled(true); - shadowMap:SetEnabled(true); - forwardPassEDS:SetEnabled(true); - - TrySetShaderEnabled(lowEndForwardEDS, true) -end diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.shader index d8df49f4b0..7c7a19efc9 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.shader +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.shader @@ -30,7 +30,6 @@ } }, - "CompilerHints" : { "DisableOptimizations" : false }, From a839a8f761869cac43faba90e42e89628ac1e34d Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Thu, 16 Dec 2021 01:13:12 -0800 Subject: [PATCH 5/8] added defines in the shaders to turn off clear coat, transmission and area light types. Allows for thiner surface data and more control over features when authoring bespoke material shaders Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Materials/Types/BasePBR_ForwardPass.azsl | 3 +- .../StandardMultilayerPBR_ForwardPass.azsl | 3 +- .../Atom/Features/PBR/BackLighting.azsli | 7 +- .../Features/PBR/Lighting/BaseLighting.azsli | 83 +++++++++++++++++++ .../Features/PBR/Lighting/LightingData.azsli | 2 + .../PBR/Lighting/StandardLighting.azsli | 2 + .../Atom/Features/PBR/LightingOptions.azsli | 54 +++++++++++- .../Features/PBR/Lights/CapsuleLight.azsli | 7 ++ .../PBR/Lights/DirectionalLight.azsli | 4 + .../Atom/Features/PBR/Lights/DiskLight.azsli | 8 ++ .../Atom/Features/PBR/Lights/Ibl.azsli | 2 + .../PBR/Lights/LightTypesCommon.azsli | 3 - .../Atom/Features/PBR/Lights/Ltc.azsli | 4 + .../Atom/Features/PBR/Lights/PointLight.azsli | 8 ++ .../Features/PBR/Lights/PolygonLight.azsli | 2 + .../Atom/Features/PBR/Lights/QuadLight.azsli | 8 +- .../PBR/Surfaces/ClearCoatSurfaceData.azsli | 4 + .../PBR/Surfaces/StandardSurface.azsli | 7 +- .../Surfaces/TransmissionSurfaceData.azsli | 4 + .../Atom/Features/ShaderQualityOptions.azsli | 17 +++- .../Types/AutoBrick_ForwardPass.azsl | 5 +- .../Types/MinimalPBR_ForwardPass.azsl | 5 +- 22 files changed, 222 insertions(+), 20 deletions(-) create mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/BaseLighting.azsli diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl index 30a8666183..be0fcd7250 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl @@ -21,7 +21,7 @@ #include // Custom Surface & Lighting -#include +#include // Decals #include @@ -102,7 +102,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) } Surface surface; - surface.clearCoat.InitializeToZero(); surface.position = IN.m_worldPosition.xyz; // ------- Normal ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl index 8f58c6dd33..bef07f0a00 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl @@ -428,7 +428,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float Surface surface; surface.position = IN.m_worldPosition; - surface.transmission.InitializeToZero(); // ------- Combine Normals --------- @@ -523,7 +522,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float ApplyIBL(surface, lightingData); // Finalize Lighting - lightingData.FinalizeLighting(0); + lightingData.FinalizeLighting(); const float alpha = 1.0; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli index dfd5522f5c..d33780641d 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli @@ -36,6 +36,9 @@ float ThinObjectFalloff(const float3 surfaceNormal, const float3 dirToLight) float3 GetBackLighting(Surface surface, LightingData lightingData, float3 lightIntensity, float3 dirToLight, float shadowRatio) { float3 result = float3(0.0, 0.0, 0.0); + +#if ENABLE_TRANSMISSION + float thickness = 0.0; float4 transmissionParams = surface.transmission.transmissionParams; @@ -71,7 +74,9 @@ float3 GetBackLighting(Surface surface, LightingData lightingData, float3 lightI break; } - + +#endif + return result; } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/BaseLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/BaseLighting.azsli new file mode 100644 index 0000000000..8bd645498c --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/BaseLighting.azsli @@ -0,0 +1,83 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#pragma once + +#define ENABLE_CLEAR_COAT 0 +#define ENABLE_TRANSMISSION 0 +#define ENABLE_AREA_LIGHT_VALIDATION 0 + +// Include options first +#include + +// Then include custom surface and lighting data types +#include +#include + +#include +#include + +// Then define the Diffuse and Specular lighting functions +float3 GetDiffuseLighting(Surface surface, LightingData lightingData, float3 lightIntensity, float3 dirToLight) +{ + float3 diffuse = DiffuseLambertian(surface.albedo, surface.normal, dirToLight, lightingData.diffuseResponse); + diffuse *= lightIntensity; + return diffuse; +} + +float3 GetSpecularLighting(Surface surface, LightingData lightingData, const float3 lightIntensity, const float3 dirToLight) +{ + float3 specular = SpecularGGX(lightingData.dirToCamera, dirToLight, surface.normal, surface.specularF0, lightingData.NdotV, surface.roughnessA2, lightingData.multiScatterCompensation); + specular *= lightIntensity; + return specular; +} + + +// Then include everything else +#include +#include + + +struct PbrLightingOutput +{ + float4 m_diffuseColor; + float4 m_specularColor; + float4 m_albedo; + float4 m_specularF0; + float4 m_normal; +}; + + +PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingData, float alpha) +{ + PbrLightingOutput lightingOutput; + + lightingOutput.m_diffuseColor = float4(lightingData.diffuseLighting, alpha); + lightingOutput.m_specularColor = float4(lightingData.specularLighting, 1.0); + + // albedo, specularF0, roughness, and normals for later passes (specular IBL, Diffuse GI, SSR, AO, etc) + lightingOutput.m_specularF0 = float4(surface.specularF0, surface.roughnessLinear); + lightingOutput.m_albedo.rgb = surface.albedo * lightingData.diffuseResponse * lightingData.diffuseAmbientOcclusion; + lightingOutput.m_albedo.a = lightingData.specularOcclusion; + lightingOutput.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal); + lightingOutput.m_normal.a = o_specularF0_enableMultiScatterCompensation ? 1.0f : 0.0f; + + return lightingOutput; +} + +PbrLightingOutput DebugOutput(float3 color) +{ + PbrLightingOutput output = (PbrLightingOutput)0; + + float3 defaultNormal = float3(0.0f, 0.0f, 1.0f); + + output.m_diffuseColor = float4(color.rgb, 1.0f); + output.m_normal.rgb = EncodeNormalSignedOctahedron(defaultNormal); + + return output; +} diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli index dbc348e54a..721c9e13cc 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli @@ -88,8 +88,10 @@ void LightingData::FinalizeLighting(float3 transmissionTint) FinalizeLighting(); // Transmitted light +#if ENABLE_TRANSMISSION if(o_transmission_mode != TransmissionMode::None) { diffuseLighting += translucentBackLighting * transmissionTint; } +#endif } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli index 773c86ff0f..ad3c9715d4 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli @@ -8,6 +8,8 @@ #pragma once +#define ENABLE_TRANSMISSION 0 + // Include options first #include diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli index f807acc374..35d9bced0d 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli @@ -8,6 +8,50 @@ #pragma once +// --- Light Defines --- + +#ifndef ENABLE_AREA_LIGHT_VALIDATION +#define ENABLE_AREA_LIGHT_VALIDATION 1 +#endif + +#ifndef ENABLE_AREA_LIGHTS +#define ENABLE_AREA_LIGHTS 1 +#endif + +#ifndef ENABLE_SPHERE_LIGHTS +#define ENABLE_SPHERE_LIGHTS ENABLE_AREA_LIGHTS +#endif + +#ifndef ENABLE_DISK_LIGHTS +#define ENABLE_DISK_LIGHTS ENABLE_AREA_LIGHTS +#endif + +#ifndef ENABLE_CAPSULE_LIGHTS +#define ENABLE_CAPSULE_LIGHTS ENABLE_AREA_LIGHTS +#endif + +#ifndef ENABLE_QUAD_LIGHTS +#define ENABLE_QUAD_LIGHTS ENABLE_AREA_LIGHTS +#endif + +#ifndef ENABLE_POLYGON_LTC_LIGHTS +#define ENABLE_POLYGON_LTC_LIGHTS ENABLE_AREA_LIGHTS +#endif + + +// --- Material defines --- + +#ifndef ENABLE_CLEAR_COAT +#define ENABLE_CLEAR_COAT 1 +#endif + +#ifndef ENABLE_TRANSMISSION +#define ENABLE_TRANSMISSION 1 +#endif + + +// --- Shader Options --- + option bool o_specularF0_enableMultiScatterCompensation = true; option bool o_enableShadows = true; option bool o_enableDirectionalLights = true; @@ -15,8 +59,14 @@ option bool o_enablePunctualLights = true; option bool o_enableAreaLights = true; option bool o_enableIBL = true; option bool o_enableSubsurfaceScattering = false; -option bool o_clearCoat_feature_enabled = false; -option enum class TransmissionMode {None, ThickObject, ThinObject} o_transmission_mode; option bool o_meshUseForwardPassIBLSpecular = false; option bool o_materialUseForwardPassIBLSpecular = false; +option bool o_area_light_validation = false; + +#if ENABLE_CLEAR_COAT +option bool o_clearCoat_feature_enabled = false; +#endif +#if ENABLE_TRANSMISSION +option enum class TransmissionMode {None, ThickObject, ThinObject} o_transmission_mode; +#endif diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli index e6b18df9b5..733ea2dbea 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli @@ -224,14 +224,21 @@ void ApplyCapsuleLights(Surface surface, inout LightingData lightingData) uint currLightIndex = lightingData.tileIterator.GetValue(); lightingData.tileIterator.LoadAdvance(); +#if ENABLE_CAPSULE_LIGHTS + ViewSrg::CapsuleLight light = ViewSrg::m_capsuleLights[currLightIndex]; + + #if ENABLE_AREA_LIGHT_VALIDATION if (o_area_light_validation) { ValidateCapsuleLight(light, surface, lightingData); } else + #endif { ApplyCapsuleLight(light, surface, lightingData); } + +#endif } } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli index 1eee53a24f..7cf10f13a3 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli @@ -27,10 +27,12 @@ void ApplyDirectionalLights(Surface surface, inout LightingData lightingData) surface.vertexNormal, debugInfo); +#if ENABLE_TRANSMISSION if (o_transmission_mode == TransmissionMode::ThickObject) { backShadowRatio = DirectionalLightShadow::GetThickness(shadowIndex, lightingData.shadowCoords); } +#endif } // Add the lighting contribution for each directional light @@ -56,10 +58,12 @@ void ApplyDirectionalLights(Surface surface, inout LightingData lightingData) currentLitRatio = (index == shadowIndex) ? litRatio : 1.; currentBackShadowRatio = 1.0 - currentLitRatio; +#if ENABLE_TRANSMISSION if (o_transmission_mode == TransmissionMode::ThickObject) { currentBackShadowRatio = (index == shadowIndex) ? backShadowRatio : 0.; } +#endif } lightingData.diffuseLighting += GetDiffuseLighting(surface, lightingData, light.m_rgbIntensityLux, dirToLight) * currentLitRatio; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli index 63f671f021..79b377c568 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli @@ -90,12 +90,14 @@ void ApplyDiskLight(ViewSrg::DiskLight light, Surface surface, inout LightingDat // Use backShadowRatio to carry thickness from shadow map for thick mode backShadowRatio = 1.0 - litRatio; +#if ENABLE_TRANSMISSION if (o_transmission_mode == TransmissionMode::ThickObject) { backShadowRatio = ProjectedShadow::GetThickness( light.m_shadowIndex, surface.position); } +#endif } if (useConeAngle && dotWithDirection < light.m_cosInnerConeAngle) // in penumbra @@ -209,15 +211,21 @@ void ApplyDiskLights(Surface surface, inout LightingData lightingData) uint currLightIndex = lightingData.tileIterator.GetValue(); lightingData.tileIterator.LoadAdvance(); +#if ENABLE_DISK_LIGHTS + ViewSrg::DiskLight light = ViewSrg::m_diskLights[currLightIndex]; + #if ENABLE_AREA_LIGHT_VALIDATION if (o_area_light_validation) { ValidateDiskLight(light, surface, lightingData); } else + #endif { ApplyDiskLight(light, surface, lightingData); } + +#endif } } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ibl.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ibl.azsli index abc2d3d3bd..e813993794 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ibl.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ibl.azsli @@ -98,6 +98,7 @@ void ApplyIBL(Surface surface, inout LightingData lightingData) float3 iblSpecular = GetIblSpecular(surface.position, surface.normal, surface.specularF0, surface.roughnessLinear, lightingData.dirToCamera, lightingData.brdf); iblSpecular *= lightingData.multiScatterCompensation; +#if ENABLE_CLEAR_COAT if (o_clearCoat_feature_enabled && surface.clearCoat.factor > 0.0f) { float clearCoatNdotV = saturate(dot(surface.clearCoat.normal, lightingData.dirToCamera)); @@ -115,6 +116,7 @@ void ApplyIBL(Surface surface, inout LightingData lightingData) float3 clearCoatResponse = FresnelSchlickWithRoughness(clearCoatNdotV, clearCoatSpecularF0, surface.clearCoat.roughness) * surface.clearCoat.factor; iblSpecular = iblSpecular * (1.0 - clearCoatResponse) * (1.0 - clearCoatResponse) + clearCoatIblSpecular; } +#endif float exposure = ObjectSrg::m_reflectionProbeData.m_useReflectionProbe ? pow(2.0, ObjectSrg::m_reflectionProbeData.m_exposure) : globalIblExposure; lightingData.specularLighting += (iblSpecular * exposure); diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli index f0169e29b8..16adbba280 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli @@ -13,9 +13,6 @@ #include #include -option bool o_area_light_validation = false; - - //! Adjust the intensity of specular light based on the radius of the light source and roughness of the surface to approximate energy conservation. float GetIntensityAdjustedByRadiusAndRoughness(float roughnessA, float radius, float distance2) { diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ltc.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ltc.azsli index 531eb6e885..0f542870a8 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ltc.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ltc.azsli @@ -403,6 +403,7 @@ void LtcQuadEvaluate( float2 schlick = ltcAmpMatrix.Sample(PassSrg::LinearSampler, ltcCoords).xy; float3 specularRgb = specular * (schlick.x * surface.specularF0 + (1.0 - surface.specularF0) * schlick.y); +#if ENABLE_CLEAR_COAT if(o_clearCoat_feature_enabled) { int vertexCountCc = LtcQuadTransformAndClip(surface.clearCoat.normal, lightingData.dirToCamera, p, polygon); @@ -422,6 +423,7 @@ void LtcQuadEvaluate( specularRgb = (specularRgb * (1.0 - F)) + (clearCoatSpecular * F); } } +#endif diffuseOut = diffuse; specularOut = specularRgb; @@ -620,6 +622,7 @@ void LtcPolygonEvaluate( float2 schlick = ltcAmpMatrix.Sample(PassSrg::LinearSampler, ltcCoords).xy; float3 specularRgb = specular * ((schlick.x * surface.specularF0) + (1.0 - surface.specularF0) * schlick.y); +#if ENABLE_CLEAR_COAT if(o_clearCoat_feature_enabled) { // Rotate ltc matrix @@ -660,6 +663,7 @@ void LtcPolygonEvaluate( specularRgb = (specularRgb * (1.0 - F)) + (specularCc * F); } } +#endif diffuseOut = diffuse; specularRgbOut = specularRgb; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli index 92f4065931..883d86af48 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli @@ -99,12 +99,14 @@ void ApplyPointLight(ViewSrg::PointLight light, Surface surface, inout LightingD // Use backShadowRatio to carry thickness from shadow map for thick mode backShadowRatio = 1.0 - litRatio; +#if ENABLE_TRANSMISSION if (o_transmission_mode == TransmissionMode::ThickObject) { backShadowRatio = ProjectedShadow::GetThickness( shadowIndex, surface.position); } +#endif } // Diffuse contribution @@ -177,15 +179,21 @@ void ApplyPointLights(Surface surface, inout LightingData lightingData) uint currLightIndex = lightingData.tileIterator.GetValue(); lightingData.tileIterator.LoadAdvance(); +#if ENABLE_SPHERE_LIGHTS + ViewSrg::PointLight light = ViewSrg::m_pointLights[currLightIndex]; + #if ENABLE_AREA_LIGHT_VALIDATION if (o_area_light_validation) { ValidatePointLight(light, surface, lightingData); } else + #endif { ApplyPointLight(light, surface, lightingData); } + +#endif } } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PolygonLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PolygonLight.azsli index 07fe6d4f00..e4e25e351b 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PolygonLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PolygonLight.azsli @@ -68,10 +68,12 @@ void ApplyPoylgonLight(ViewSrg::PolygonLight light, Surface surface, inout Light void ApplyPolygonLights(Surface surface, inout LightingData lightingData) { +#if ENABLE_POLYGON_LTC_LIGHTS for (uint currLightIndex = 0; currLightIndex < ViewSrg::m_polygonLightCount; ++currLightIndex) { ViewSrg::PolygonLight light = ViewSrg::m_polygonLights[currLightIndex]; ApplyPoylgonLight(light, surface, lightingData); } +#endif } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli index 63515339d8..a705e663c2 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli @@ -245,16 +245,22 @@ void ApplyQuadLights(Surface surface, inout LightingData lightingData) { uint currLightIndex = lightingData.tileIterator.GetValue(); lightingData.tileIterator.LoadAdvance(); - + +#if ENABLE_QUAD_LIGHTS + ViewSrg::QuadLight light = ViewSrg::m_quadLights[currLightIndex]; + #if ENABLE_AREA_LIGHT_VALIDATION if (o_area_light_validation) { ValidateQuadLight(light, surface, lightingData); } else + #endif { ApplyQuadLight(light, surface, lightingData); } + +#endif } } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli index ff8d4c0a25..6e30f55af4 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli @@ -8,6 +8,8 @@ #pragma once +#if ENABLE_CLEAR_COAT + class ClearCoatSurfaceData { float factor; //!< clear coat strength factor @@ -23,3 +25,5 @@ void ClearCoatSurfaceData::InitializeToZero() roughness = 0.0f; normal = float3(0.0f, 0.0f, 0.0f); } + +#endif diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli index 084943bf38..ab43717919 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli @@ -15,8 +15,14 @@ class Surface { + +#if ENABLE_CLEAR_COAT ClearCoatSurfaceData clearCoat; +#endif + +#if ENABLE_TRANSMISSION TransmissionSurfaceData transmission; // This is not actually used for Standard PBR, but must be present for common lighting code to compile +#endif // ------- BasePbrSurfaceData ------- @@ -37,7 +43,6 @@ class Surface //! Sets albedo and specularF0 using metallic workflow void SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic); - }; // Specular Anti-Aliasing technique from this paper: diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli index 9b575de3ec..dda62d85e5 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli @@ -8,6 +8,8 @@ #pragma once +#if ENABLE_TRANSMISSION + class TransmissionSurfaceData { float3 tint; @@ -23,3 +25,5 @@ void TransmissionSurfaceData::InitializeToZero() thickness = 0.0f; transmissionParams = float4(0.0f, 0.0f, 0.0f, 0.0f); } + +#endif diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ShaderQualityOptions.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ShaderQualityOptions.azsli index 32cd30b97e..430e095bf4 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ShaderQualityOptions.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ShaderQualityOptions.azsli @@ -13,10 +13,23 @@ #ifdef QUALITY_LOW_END // Unifies the forward output into a single lighting buffer instead of splitting it into a GBuffer + #ifndef UNIFIED_FORWARD_OUTPUT #define UNIFIED_FORWARD_OUTPUT 1 - + #endif + // Forces IBL lighting to be executed in the forward pass instead of subsequent refleciton passes + #ifndef FORCE_IBL_IN_FORWARD_PASS #define FORCE_IBL_IN_FORWARD_PASS 1 + #endif -#endif + // Forces removal of area light validation code + #ifndef ENABLE_AREA_LIGHT_VALIDATION + #define ENABLE_AREA_LIGHT_VALIDATION 0 + #endif + // Uncomment to disable all area light calcuation + // #ifndef ENABLE_AREA_LIGHTS + // #define ENABLE_AREA_LIGHTS 0 + // #endif + +#endif diff --git a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl index 2dbba46d8b..585c6283c2 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl @@ -179,9 +179,8 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) const float specularF0Factor = 0.5f; surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic); - // Clear Coat, Transmission + // Clear Coat surface.clearCoat.InitializeToZero(); - surface.transmission.InitializeToZero(); // ------- LightingData ------- @@ -213,7 +212,7 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) ApplyIBL(surface, lightingData); // Finalize Lighting - lightingData.FinalizeLighting(surface.transmission.tint); + lightingData.FinalizeLighting(); PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); diff --git a/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl index 2f6f038e4b..b544a26366 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl @@ -71,9 +71,8 @@ ForwardPassOutput MinimalPBR_MainPassPS(VSOutput IN) const float specularF0Factor = 0.5f; surface.SetAlbedoAndSpecularF0(MinimalPBRSrg::m_baseColor, specularF0Factor, MinimalPBRSrg::m_metallic); - // Clear Coat, Transmission + // Clear Coat surface.clearCoat.InitializeToZero(); - surface.transmission.InitializeToZero(); // ------- LightingData ------- @@ -104,7 +103,7 @@ ForwardPassOutput MinimalPBR_MainPassPS(VSOutput IN) ApplyIBL(surface, lightingData); // Finalize Lighting - lightingData.FinalizeLighting(surface.transmission.tint); + lightingData.FinalizeLighting(); PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); From 31714810cc8cc48a4afe370e9390736aa7a8c1d5 Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Thu, 16 Dec 2021 09:06:09 -0800 Subject: [PATCH 6/8] updating asset cmake file Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Feature/Common/Assets/atom_feature_common_asset_files.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake index f595202218..2849cf9415 100644 --- a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake +++ b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake @@ -16,7 +16,6 @@ set(FILES Materials/Types/BasePBR_ForwardPass.shader Materials/Types/BasePBR_LowEndForward.azsl Materials/Types/BasePBR_LowEndForward.shader - Materials/Types/BasePBR_ShaderEnable.lua Materials/Types/EnhancedPBR.materialtype Materials/Types/EnhancedPBR_Common.azsli Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl @@ -264,6 +263,7 @@ set(FILES ShaderLib/Atom/Features/PBR/Hammersley.azsli ShaderLib/Atom/Features/PBR/LightingOptions.azsli ShaderLib/Atom/Features/PBR/LightingUtils.azsli + ShaderLib/Atom/Features/PBR/Lighting/BaseLighting.azsli ShaderLib/Atom/Features/PBR/Lighting/DualSpecularLighting.azsli ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli From 42a812bb04ca0de1fde664b1a052ed64da5007cd Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Sun, 30 Jan 2022 02:13:38 -0800 Subject: [PATCH 7/8] Removing transmission from terrain PBR shader Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Assets/Shaders/Terrain/TerrainPBR_ForwardPass.azsl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Gems/Terrain/Assets/Shaders/Terrain/TerrainPBR_ForwardPass.azsl b/Gems/Terrain/Assets/Shaders/Terrain/TerrainPBR_ForwardPass.azsl index c9c3e0ab00..119a81e49c 100644 --- a/Gems/Terrain/Assets/Shaders/Terrain/TerrainPBR_ForwardPass.azsl +++ b/Gems/Terrain/Assets/Shaders/Terrain/TerrainPBR_ForwardPass.azsl @@ -177,9 +177,8 @@ ForwardPassOutput TerrainPBR_MainPassPS(VSOutput IN) surface.CalculateRoughnessA(); } - // Clear Coat, Transmission (Not used for terrain) + // Clear Coat surface.clearCoat.InitializeToZero(); - surface.transmission.InitializeToZero(); // ------- LightingData ------- @@ -211,7 +210,7 @@ ForwardPassOutput TerrainPBR_MainPassPS(VSOutput IN) ApplyIBL(surface, lightingData); // Finalize Lighting - lightingData.FinalizeLighting(surface.transmission.tint); + lightingData.FinalizeLighting(); PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); From 5b9bc3b479fe248bd1aa8713814b408e917d11ed Mon Sep 17 00:00:00 2001 From: antonmic <56370189+antonmic@users.noreply.github.com> Date: Tue, 1 Feb 2022 16:08:10 -0800 Subject: [PATCH 8/8] address PR feedback Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com> --- .../Assets/Materials/Types/BasePBR_ForwardPass.azsl | 1 - .../ShaderLib/Atom/Features/PBR/LightingOptions.azsli | 8 ++++++++ .../Atom/Features/PBR/Surfaces/StandardSurface.azsli | 4 ---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl index be0fcd7250..96318f2284 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_ForwardPass.azsl @@ -180,7 +180,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace) } -[earlydepthstencil] ForwardPassOutput BasePbr_ForwardPassPS_EDS(VSOutput IN, bool isFrontFace : SV_IsFrontFace) { ForwardPassOutput OUT; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli index 35d9bced0d..9febc6a9f7 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingOptions.azsli @@ -8,6 +8,14 @@ #pragma once +// --- Note: About this file --- +// This file uses #defines to completely strip out certain lighting features from shaders +// This enables us to avoid code duplication and write an uber-esque shader code and then +// be able to adjust the code for different use cases (for example basic materials can strip +// away transimission related code used for foliage). These are different from shader options +// in that shader options allow more user flexibility to adjust materials at runtime, whereas +// these #define options are for customizing and optimizing material types (like BasePBR) + // --- Light Defines --- #ifndef ENABLE_AREA_LIGHT_VALIDATION diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli index 34d05ecb05..cf4edba923 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli @@ -20,10 +20,6 @@ class Surface ClearCoatSurfaceData clearCoat; #endif -#if ENABLE_TRANSMISSION - TransmissionSurfaceData transmission; // This is not actually used for Standard PBR, but must be present for common lighting code to compile -#endif - // ------- BasePbrSurfaceData ------- precise float3 position; //!< Position in world-space