shader refactor

This commit is contained in:
Turanszki Janos
2020-12-04 21:01:05 +01:00
parent 9b503b3b40
commit 4a8ddf98ac
4 changed files with 15 additions and 44 deletions
+11 -34
View File
@@ -214,59 +214,36 @@ float microfacetDistribution(in Surface surface, in SurfaceToLight surfaceToLigh
// Aniso functions source: https://github.com/google/filament/blob/main/shaders/src/brdf.fs
float D_GGX_Anisotropic(float at, float ab, float ToH, float BoH, float NoH) {
float D_GGX_Anisotropic(in Surface surface, in SurfaceToLight surfaceToLight)
{
// Burley 2012, "Physically-Based Shading at Disney"
// The values at and ab are perceptualRoughness^2, a2 is therefore perceptualRoughness^4
// The dot product below computes perceptualRoughness^8. We cannot fit in fp16 without clamping
// the roughness to too high values so we perform the dot product and the division in fp32
float a2 = at * ab;
float3 d = float3(ab * ToH, at * BoH, a2 * NoH);
float a2 = surface.at * surface.ab;
float3 d = float3(surface.ab * surfaceToLight.TdotH, surface.at * surfaceToLight.BdotH, a2 * surfaceToLight.NdotH);
float d2 = dot(d, d);
float b2 = a2 / d2;
return a2 * b2 * b2 * (1.0 / PI);
return a2 * b2 * b2 / PI;
}
float V_SmithGGXCorrelated_Anisotropic(float at, float ab, float ToV, float BoV,
float ToL, float BoL, float NoV, float NoL) {
float V_SmithGGXCorrelated_Anisotropic(in Surface surface, in SurfaceToLight surfaceToLight)
{
// Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs"
// TODO: lambdaV can be pre-computed for all the lights, it should be moved out of this function
float lambdaV = NoL * length(float3(at * ToV, ab * BoV, NoV));
float lambdaL = NoV * length(float3(at * ToL, ab * BoL, NoL));
float lambdaV = surfaceToLight.NdotL * length(float3(surface.at * surface.TdotV, surface.ab * surface.BdotV, surface.NdotV));
float lambdaL = surface.NdotV * length(float3(surface.at * surfaceToLight.TdotL, surface.ab * surfaceToLight.BdotL, surfaceToLight.NdotL));
float v = 0.5 / (lambdaV + lambdaL);
return saturate(v);
}
float distributionAnisotropic(float at, float ab, float ToH, float BoH, float NoH) {
return D_GGX_Anisotropic(at, ab, ToH, BoH, NoH);
}
float visibilityAnisotropic(float at, float ab,
float ToV, float BoV, float ToL, float BoL, float NoV, float NoL) {
return V_SmithGGXCorrelated_Anisotropic(at, ab, ToV, BoV, ToL, BoL, NoV, NoL);
}
// These are the functions that will be used by shaders:
float3 BRDF_GetSpecular(in Surface surface, in SurfaceToLight surfaceToLight)
{
#ifdef BRDF_ANISOTROPIC
float Vis = visibilityAnisotropic(
surface.at,
surface.ab,
surface.TdotV,
surface.BdotV,
surfaceToLight.TdotL,
surfaceToLight.BdotL,
surface.NdotV,
surfaceToLight.NdotL
);
float D = distributionAnisotropic(
surface.at,
surface.ab,
surfaceToLight.TdotH,
surfaceToLight.BdotH,
surfaceToLight.NdotH
);
float Vis = V_SmithGGXCorrelated_Anisotropic(surface, surfaceToLight);
float D = D_GGX_Anisotropic(surface, surfaceToLight);
#else
float Vis = visibilityOcclusion(surface, surfaceToLight);
float D = microfacetDistribution(surface, surfaceToLight);
+1 -1
View File
@@ -11,7 +11,7 @@ float4 main(PixelInputType input) : SV_Target0
if (g_xMaterial.uvset_normalMap >= 0)
{
float3 bumpColor;
NormalMapping(input.uvsets, P, N, TBN, bumpColor);
NormalMapping(input.uvsets, N, TBN, bumpColor);
}
return float4(N * 0.5f + 0.5f, 1);
+2 -8
View File
@@ -89,18 +89,12 @@ struct GBUFFEROutputType
{
float4 g0 : SV_Target0; // texture_gbuffer0
float4 g1 : SV_Target1; // texture_gbuffer1
//float4 diffuse : SV_Target2;
//float4 specular : SV_Target3;
};
inline GBUFFEROutputType CreateGbuffer(in float4 color, in Surface surface, in float2 velocity, in Lighting lighting)
{
//LightingPart combined_lighting = CombineLighting(surface, lighting);
GBUFFEROutputType Out;
Out.g0 = float4(color.rgb, surface.roughness); /*FORMAT_R16G16B16A16_FLOAT*/
Out.g1 = float4(encodeNormal(surface.N), velocity); /*FORMAT_R16G16B16A16_FLOAT*/
//Out.diffuse = float4(combined_lighting.diffuse, 1); /*FORMAT_R11G11B10_FLOAT*/
//Out.specular = float4(combined_lighting.specular, 1); /*FORMAT_R11G11B10_FLOAT*/
return Out;
}
@@ -127,7 +121,7 @@ inline void LightMapping(in float2 ATLAS, inout Lighting lighting)
}
}
inline void NormalMapping(inout float4 uvsets, in float3 V, inout float3 N, in float3x3 TBN, out float3 bumpColor)
inline void NormalMapping(inout float4 uvsets, inout float3 N, in float3x3 TBN, out float3 bumpColor)
{
[branch]
if (g_xMaterial.normalMapStrength > 0 && g_xMaterial.uvset_normalMap >= 0)
@@ -785,7 +779,7 @@ GBUFFEROutputType main(PIXELINPUT input)
const float2 ReprojectedScreenCoord = ScreenCoord + velocity;
#ifndef WATER
NormalMapping(input.uvsets, surface.P, surface.N, TBN, bumpColor);
NormalMapping(input.uvsets, surface.N, TBN, bumpColor);
#endif // WATER
#endif // ENVMAPRENDERING
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates, breaking API changes
const int minor = 50;
// minor bug fixes, alterations, refactors, updates
const int revision = 11;
const int revision = 12;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);