Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fresnel refactor, f0 tint and specularity factor. Added support for KHR_materials_specular, which provides a specular tint (same as specularMap) as well as a specularity factor. The specularity factor isn't a substitute for metalness however, but simply a specular reflection intensity, which is applied to both fresnel and general specularity. Decoupled the fresnel component from the specularity. This is because fresnel is dependent on each light, and in the case of reflections dependent on the surface normal. Therefore, we should calculate the fresnel factor once per each light source. Currently though, the fresnel factor only applies to reflections, but that's the same behaviour from before, and this should be addressed in a separate ticket. Metalness modulation (linear interpolation between f0 and albedo) is done in the backend as a separate shader chunk, and metalness is passed to the backend with dMetalness. Since the specular color, f0, is dependent on the fresnel effect, and the fresnel effect is dependent on a per-light basis, the specular color can't just be applied on top of everything when combining the light together. Instead, the f0 color has to be an argument to each specularity calculation for it to be accurate. We can also remove the dSpecularityNoFres from the area light calculation as the fresnel function is no longer combined with the f0 color. * Reverted the GLTF parsing of sheen and ior, as that's supposed to be another PR. * Fixed specularity factor not being applied. * Fixed compilation issue with clear coat. * Revert ior wip code. * Fixed typo in types. * Removed the use of useSpecularityFactor boolean * Update src/graphics/program-lib/chunks/standard/frag/specular.js Co-authored-by: Will Eastcott <will@playcanvas.com> * Update src/scene/materials/standard-material.js Co-authored-by: Will Eastcott <will@playcanvas.com> * Minor fixes Replaced the manual gamma correction with the one from gamma2_2.js. Removed the f0Tint from the material, this can be deduced from the parameters. Updated the material documentation to be more descriptive of F0 and specularity factor. * Set specularity factor to default to 1.0. * Specularity factor wasn't correctly disabled. * Calculate fresnel for directional lights This is necessary to not get too much light when using directional lights. Calculating the half vector is done outside of getLightSpecular, and then passed to the function to prevent multiple evaluations. Fresnel is calculated using the half vector for lights, and can be enabled by setting the calcFresnel flag to true. * Forgot to update clustered lights with half dir calculation. * Fix lint. * Revert to using the old method for fresnel strength. * Replaced fresnel balancing function with more correct version. * Fresnel refactor, f0 tint and specularity factor. Added support for KHR_materials_specular, which provides a specular tint (same as specularMap) as well as a specularity factor. The specularity factor isn't a substitute for metalness however, but simply a specular reflection intensity, which is applied to both fresnel and general specularity. Decoupled the fresnel component from the specularity. This is because fresnel is dependent on each light, and in the case of reflections dependent on the surface normal. Therefore, we should calculate the fresnel factor once per each light source. Currently though, the fresnel factor only applies to reflections, but that's the same behaviour from before, and this should be addressed in a separate ticket. Metalness modulation (linear interpolation between f0 and albedo) is done in the backend as a separate shader chunk, and metalness is passed to the backend with dMetalness. Since the specular color, f0, is dependent on the fresnel effect, and the fresnel effect is dependent on a per-light basis, the specular color can't just be applied on top of everything when combining the light together. Instead, the f0 color has to be an argument to each specularity calculation for it to be accurate. We can also remove the dSpecularityNoFres from the area light calculation as the fresnel function is no longer combined with the f0 color. * Reverted the GLTF parsing of sheen and ior, as that's supposed to be another PR. * Fixed specularity factor not being applied. * Fixed compilation issue with clear coat. * Revert ior wip code. * Fixed typo in types. * Removed the use of useSpecularityFactor boolean * Update src/graphics/program-lib/chunks/standard/frag/specular.js Co-authored-by: Will Eastcott <will@playcanvas.com> * Update src/scene/materials/standard-material.js Co-authored-by: Will Eastcott <will@playcanvas.com> * Minor fixes Replaced the manual gamma correction with the one from gamma2_2.js. Removed the f0Tint from the material, this can be deduced from the parameters. Updated the material documentation to be more descriptive of F0 and specularity factor. * Set specularity factor to default to 1.0. * Specularity factor wasn't correctly disabled. * Calculate fresnel for directional lights This is necessary to not get too much light when using directional lights. Calculating the half vector is done outside of getLightSpecular, and then passed to the function to prevent multiple evaluations. Fresnel is calculated using the half vector for lights, and can be enabled by setting the calcFresnel flag to true. * Forgot to update clustered lights with half dir calculation. * Fix lint. * Revert to using the old method for fresnel strength. * Replaced fresnel balancing function with more correct version. * Fix typo * Removed the 'energy balancing' combine function. * Removing redundant normalizations for half vector calculation. * Removed unnecessary parentheses. * Missed specularity should be summed together now when we separate the terms. * Should be no need to have a conserve combine if we calculate the specular and diffuse correctly to begin with. * Calculate fresnel for clustered lights as well. If no fresnel is used, simply multiply by specular color. * Fixed clearcoat having specular weight multiplied in twice. Also fall back to multiplying specular light with the specularity factor as a cheaper fresnel fallback. * Revert a bunch of commits that was accidentally included with rebase. * Fix revert. * Revert "Fix revert." This reverts commit fd7d602. * Rearranged specularity factor and half dir. Half dir calculation works for multiple directional lights. SpecularityFactor is applied on all specularity at the end, removing the need to multiply it on a per-light basis. * Removed the metalness modulate since we multiply the specularity factor on top at the end. * Repurpose specular map and tint to avoid adding a new texture and tint for metalness specular color. Replaced the f0 chunk with specularColor, which essentially does the same thing. Specular now just calls getSpecularColor. Metalness calls getSpecularColor instead of getF0. Cleared the f0 related arguments from the standard material. * Fix shader compilation issue if not using fresnel. * Set defaults in GLB loader. * Specular should default to 1, surely, since white specular means no color tint is applied. * Fix unit test for specular. * No need to use two switches for specular tint when we can remove the metalness switch. * Revert defaults. * Revert the default change, as that actually breaks shading now with metalness. * Fixed bug with clustered lights and clearcoat. * Again simplified specular color evaluation. The metalness and the specular used to do the same thing when getting specular color, so that's been extracted to a separate call in the shader and the specularColor file has been made redundant. * Fix dSpecularity getting multiplied in twice. * Revert specular default but set specular to 1 if using metalness. * Add specularity factor vertex support. * Cleanup f0 stuff and add arguments for specularity map tiling * Fix test * Removed superfluous condition. * Cleaned up the f0 stuff in the types mixup. * Added documentation for the specularity factor map stuff. * Moved comment about not using environment reflections to where it's relevant. Also realised the reflection alpha is used as an intensity, so we shouldn't multiply it with the specularity factor. Co-authored-by: Will Eastcott <will@playcanvas.com>
- Loading branch information