Merge branch 'Preview4_0' of https://github.com/Azaezel/Torque3D into Preview4_0

This commit is contained in:
Areloch 2019-11-01 01:24:57 -05:00
commit a85bc7bae0
10 changed files with 107 additions and 85 deletions

View file

@ -447,10 +447,6 @@ AdvancedLightBinManager::LightMaterialInfo* AdvancedLightBinManager::_getLightMa
if ( smPSSMDebugRender )
shadowMacros.push_back( GFXShaderMacro( "PSSM_DEBUG_RENDER" ) );
// If its a vector light see if we can enable SSAO.
if ( lightType == LightInfo::Vector && smUseSSAOMask )
shadowMacros.push_back( GFXShaderMacro( "USE_SSAO_MASK" ) );
// Now create the material info object.
info = new LightMaterialInfo( lightMatName, smLightMatVertex[ lightType ], shadowMacros );
}

View file

@ -30,7 +30,7 @@
#include "renderInstance/renderDeferredMgr.h"
#include "math/mPolyhedron.impl.h"
#include "gfx/gfxTransformSaver.h"
#include "lighting/advanced/advancedLightBinManager.h" //for ssao
#include "gfx/gfxDebugEvent.h"
#include "shaderGen/shaderGenVars.h"
#include "materials/shaderData.h"
@ -752,6 +752,24 @@ void RenderProbeMgr::render( SceneRenderState *state )
mProbeArrayEffect->setShaderMacro("SKYLIGHT_ONLY", "1");
else
mProbeArrayEffect->setShaderMacro("SKYLIGHT_ONLY", "0");
//ssao mask
if (AdvancedLightBinManager::smUseSSAOMask)
{
//find ssaoMask
NamedTexTargetRef ssaoTarget = NamedTexTarget::find("ssaoMask");
GFXTextureObject* pTexObj = ssaoTarget->getTexture();
if (pTexObj)
{
mProbeArrayEffect->setShaderMacro("USE_SSAO_MASK");
mProbeArrayEffect->setTexture(6, pTexObj);
}
}
else
{
mProbeArrayEffect->setTexture(6, NULL);
}
mProbeArrayEffect->setTexture(3, mBRDFTexture);
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);

View file

@ -48,9 +48,7 @@ singleton GFXStateBlockData( AL_VectorLightState )
mSamplerNames[1] = "shadowMap";
samplerStates[2] = SamplerClampPoint; // Shadow Map (Do not change this to linear, as all cards can not filter equally.)
mSamplerNames[2] = "dynamicShadowMap";
samplerStates[3] = SamplerClampLinear; // SSAO Mask
mSamplerNames[3] = "ssaoMask";
samplerStates[4] = SamplerWrapPoint; // Random Direction Map
samplerStates[3] = SamplerWrapPoint; // Random Direction Map
cullDefined = true;
cullMode = GFXCullNone;
@ -72,11 +70,10 @@ singleton shaderData( AL_VectorLightShader )
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$shadowMap";
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$ssaoMask";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
samplerNames[3] = "$gTapRotationTex";
samplerNames[4] = "$lightBuffer";
samplerNames[5] = "$colorBuffer";
samplerNames[6] = "$matInfoBuffer";
pixVersion = 3.0;
};
@ -89,7 +86,6 @@ new CustomMaterial( AL_VectorLightMaterial )
sampler["deferredBuffer"] = "#deferred";
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["ssaoMask"] = "#ssaoMask";
sampler["lightBuffer"] = "#specularLighting";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
@ -322,6 +318,7 @@ singleton ShaderData( PFX_ReflectionProbeArray )
samplerNames[3] = "$BRDFTexture";
samplerNames[4] = "$specularCubemapAR";
samplerNames[5] = "$irradianceCubemapAR";
samplerNames[6] = "$ssaoMask";
pixVersion = 2.0;
};
@ -350,4 +347,5 @@ singleton GFXStateBlockData( PFX_ReflectionProbeArrayStateBlock )
samplerStates[3] = SamplerClampPoint;
samplerStates[4] = SamplerClampLinear;
samplerStates[5] = SamplerClampLinear;
samplerStates[6] = SamplerClampPoint;
};

View file

@ -81,6 +81,7 @@ struct Surface
float NdotV; // cos(angle between normal and view vector)
vec3 f0; // fresnel value (rgb)
float f90;
vec3 albedo; // diffuse light absorbtion value (rgb)
vec3 R; // reflection vector
vec3 F; // fresnel term computed from f0, N and V
@ -93,8 +94,8 @@ void updateSurface(inout Surface surface)
surface.albedo = surface.baseColor.rgb * (1.0 - surface.metalness);
surface.f0 = lerp(vec3(0.04f), surface.baseColor.rgb, surface.metalness);
surface.R = -reflect(surface.V, surface.N);
float f90 = saturate(50.0 * dot(surface.f0, vec3(0.33,0.33,0.33)));
surface.F = F_Schlick(surface.f0, f90, surface.NdotV);
surface.f90 = saturate(50.0 * dot(surface.f0, vec3(0.33,0.33,0.33)));
surface.F = F_Schlick(surface.f0, surface.f90, surface.NdotV);
}
Surface createSurface(vec4 normDepth, sampler2D colorBuffer, sampler2D matInfoBuffer, in vec2 uv, in vec3 wsEyePos, in vec3 wsEyeRay, in mat4 invView)
@ -229,6 +230,11 @@ vec3 getPunctualLight(in Surface surface, in SurfaceToLight surfaceToLight, vec3
return final;
}
float computeSpecOcclusion( float NdotV , float AO , float roughness )
{
return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO );
}
vec4 compute4Lights( Surface surface,
vec4 shadowMask,
vec4 inLightPos[4],
@ -421,20 +427,18 @@ vec4 computeForwardProbes(Surface surface,
specular = mix(specular,textureLod(specularCubemapAR, vec4(surface.R, skylightCubemapIdx), lod).xyz, alpha);
}
vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
//energy conservation
vec3 kD = vec3(1.0,1.0,1.0) - F;
kD *= 1.0 - surface.metalness;
vec3 kD = 1.0f - surface.F;
kD *= 1.0f - surface.metalness;
//apply brdf
//Do it once to save on texture samples
vec2 brdf = textureLod(BRDFTexture, vec2(surface.roughness, 1.0-surface.NdotV),0).xy;
specular *= brdf.x * F + brdf.y;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg;
specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;
//final diffuse color
vec3 diffuse = kD * irradiance * surface.baseColor.rgb;
vec4 finalColor = vec4(diffuse + specular * surface.ao, 1.0);
//AO
irradiance *= surface.ao;
specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness);
return finalColor;
return vec4(irradiance + specular, 0);//alpha writes disabled
}

View file

@ -85,6 +85,7 @@ struct Surface
float3 albedo; // diffuse light absorbtion value (rgb)
float3 R; // reflection vector
float3 F; // fresnel term computed from f0, N and V
float f90;
inline void Update()
{
@ -94,7 +95,7 @@ struct Surface
f0 = lerp(0.04.xxx, baseColor.rgb, metalness);
R = -reflect(V, N);
float f90 = saturate(50.0 * dot(f0, 0.33));
f90 = saturate(50.0 * dot(f0, 0.33));
F = F_Schlick(f0, f90, NdotV);
}
};
@ -235,6 +236,11 @@ inline float3 getPunctualLight(in Surface surface, in SurfaceToLight surfaceToLi
return final;
}
float computeSpecOcclusion( float NdotV , float AO , float roughness )
{
return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO );
}
float4 compute4Lights( Surface surface,
float4 shadowMask,
float4 inLightPos[4],
@ -462,19 +468,18 @@ float4 computeForwardProbes(Surface surface,
specular = lerp(specular,TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, surface.R, skylightCubemapIdx, lod).xyz,alpha);
}
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
float3 kD = 1.0f - surface.F;
kD *= 1.0f - surface.metalness;
//apply brdf
//Do it once to save on texture samples
float2 brdf = TORQUE_TEX2DLOD(BRDFTexture,float4(surface.roughness, 1.0-surface.NdotV, 0.0, 0.0)).xy;
specular *= brdf.x * F + brdf.y;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg;
specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
float4 finalColor = float4(diffuse* surface.ao + specular * surface.ao, 1.0);
return finalColor;
//AO
irradiance *= surface.ao;
specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness);
return float4(irradiance + specular, 0);//alpha writes disabled
}

View file

@ -24,6 +24,11 @@ uniform int numProbes;
uniform samplerCubeArray specularCubemapAR;
uniform samplerCubeArray irradianceCubemapAR;
#ifdef USE_SSAO_MASK
uniform sampler2D ssaoMask;
uniform vec4 rtParams6;
#endif
uniform vec4 inProbePosArray[MAX_PROBES];
uniform vec4 inRefPosArray[MAX_PROBES];
uniform mat4 worldToObjArray[MAX_PROBES];
@ -52,6 +57,12 @@ void main()
{
discard;
}
#ifdef USE_SSAO_MASK
float ssao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams6 ) ).r;
surface.ao = min(surface.ao, ssao);
#endif
float alpha = 1;
@ -190,20 +201,19 @@ void main()
return;
#endif
vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
//energy conservation
vec3 kD = vec3(1,1,1) - F;
kD *= 1.0 - surface.metalness;
vec3 kD = 1.0f - surface.F;
kD *= 1.0f - surface.metalness;
//apply brdf
//Do it once to save on texture samples
vec2 brdf = textureLod(BRDFTexture, vec2(surface.roughness, surface.NdotV),0).xy;
specular *= brdf.x * F + brdf.y;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg;
specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;
//final diffuse color
vec3 diffuse = kD * irradiance * surface.baseColor.rgb;
vec4 finalColor = vec4(diffuse + specular * surface.ao, 1.0);
//AO
irradiance *= surface.ao;
specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness);
OUT_col = finalColor;
OUT_col = vec4(irradiance + specular, 0);//alpha writes disabled
}

View file

@ -37,11 +37,6 @@ uniform sampler2D deferredBuffer;
uniform sampler2D shadowMap;
uniform sampler2D dynamicShadowMap;
#ifdef USE_SSAO_MASK
uniform sampler2D ssaoMask ;
uniform vec4 rtParams3;
#endif
uniform sampler2D colorBuffer;
uniform sampler2D matInfoBuffer;
uniform float lightBrightness;
@ -245,10 +240,6 @@ void main()
#endif
#endif //NO_SHADOW
// Sample the AO texture.
#ifdef USE_SSAO_MASK
surface.ao *= 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams3 ) ).r;
#endif
//get directional light contribution
vec3 lighting = getDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);

View file

@ -21,6 +21,11 @@ uniform int numProbes;
TORQUE_UNIFORM_SAMPLERCUBEARRAY(specularCubemapAR, 4);
TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
#ifdef USE_SSAO_MASK
TORQUE_UNIFORM_SAMPLER2D(ssaoMask, 6);
uniform float4 rtParams6;
#endif
uniform float4 inProbePosArray[MAX_PROBES];
uniform float4 inRefPosArray[MAX_PROBES];
uniform float4x4 worldToObjArray[MAX_PROBES];
@ -49,6 +54,11 @@ float4 main(PFXVertToPix IN) : SV_TARGET
return TORQUE_TEX2D(colorBuffer, IN.uv0.xy);
}
#ifdef USE_SSAO_MASK
float ssao = 1.0 - TORQUE_TEX2D( ssaoMask, viewportCoordToRenderTarget( IN.uv0.xy, rtParams6 ) ).r;
surface.ao = min(surface.ao, ssao);
#endif
float alpha = 1;
#if SKYLIGHT_ONLY == 0
@ -182,19 +192,18 @@ float4 main(PFXVertToPix IN) : SV_TARGET
return float4(irradiance, 1);
#endif
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
float3 kD = 1.0f - surface.F;
kD *= 1.0f - surface.metalness;
//apply brdf
//Do it once to save on texture samples
float2 brdf = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.roughness, 1.0-surface.NdotV, 0.0, 0.0)).xy;
specular *= brdf.x * F + brdf.y;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg;
specular *= surface.F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
float4 finalColor = float4(diffuse* surface.ao + specular * surface.ao, 1.0);
return finalColor;
//AO
irradiance *= surface.ao;
specular *= computeSpecOcclusion(surface.NdotV, surface.ao, surface.roughness);
return float4(irradiance + specular, 0);//alpha writes disabled
}

View file

@ -70,7 +70,7 @@ static float2 sNonUniformTaps[NUM_PRE_TAPS] =
/// The texture used to do per-pixel pseudorandom
/// rotations of the filter taps.
TORQUE_UNIFORM_SAMPLER2D(gTapRotationTex, 4);
TORQUE_UNIFORM_SAMPLER2D(gTapRotationTex, 3);
float softShadow_sampleTaps( TORQUE_SAMPLER2D(shadowMap1),
float2 sinCos,

View file

@ -33,13 +33,8 @@ TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1);
TORQUE_UNIFORM_SAMPLER2D(dynamicShadowMap, 2);
#ifdef USE_SSAO_MASK
TORQUE_UNIFORM_SAMPLER2D(ssaoMask, 3);
uniform float4 rtParams3;
#endif
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 6);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 7);
TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 5);
TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 6);
uniform float lightBrightness;
uniform float3 lightDirection;
@ -234,10 +229,6 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET
#endif
#endif //NO_SHADOW
// Sample the AO texture.
#ifdef USE_SSAO_MASK
surface.ao *= 1.0 - TORQUE_TEX2D( ssaoMask, viewportCoordToRenderTarget( IN.uv0.xy, rtParams3 ) ).r;
#endif
//get directional light contribution
float3 lighting = getDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);