mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 00:05:40 +00:00
adds wetness
cliffsnotes: $Core::WetnessTexture = "core/rendering/images/wetMap.png"; //for the influence degree map probes/skylight have a new canDamp boolean, set to off for probes, on for skylight by default. :levelinfo has a dampness multiplier (0-1) kicked up numTextures from 8 to 16 for shaderdata and postfx since that hit the 8 texture-in prior limit, and we've already adopted apis that can handle the higher count
This commit is contained in:
parent
e16351605b
commit
d23ee397e6
31 changed files with 352 additions and 100 deletions
|
|
@ -302,7 +302,8 @@ singleton ShaderData( PFX_ReflectionProbeArray )
|
|||
samplerNames[3] = "$BRDFTexture";
|
||||
samplerNames[4] = "$specularCubemapAR";
|
||||
samplerNames[5] = "$irradianceCubemapAR";
|
||||
samplerNames[6] = "$ssaoMask";
|
||||
samplerNames[6] = "$WetnessTexture";
|
||||
samplerNames[7] = "$ssaoMask";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
|
@ -331,5 +332,6 @@ singleton GFXStateBlockData( PFX_ReflectionProbeArrayStateBlock )
|
|||
samplerStates[3] = SamplerClampPoint;
|
||||
samplerStates[4] = SamplerClampLinear;
|
||||
samplerStates[5] = SamplerClampLinear;
|
||||
samplerStates[6] = SamplerClampPoint;
|
||||
samplerStates[6] = SamplerWrapPoint;
|
||||
samplerStates[7] = SamplerClampPoint;
|
||||
};
|
||||
|
|
@ -15,6 +15,5 @@ singleton PostEffect( reflectionProbeArrayPostFX )
|
|||
texture[0] = "#deferred";
|
||||
texture[1] = "#color";
|
||||
texture[2] = "#matinfo";
|
||||
|
||||
allowReflectPass = true;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ function Core_Rendering::onCreate(%this)
|
|||
$Core::UnAvailableTexturePath = "core/rendering/images/unavailable";
|
||||
$Core::WarningTexturePath = "core/rendering/images/warnMat";
|
||||
$Core::CommonShaderPath = "core/rendering/shaders";
|
||||
$Core::BRDFTexture = "core/rendering/images/brdfTexture.dds";
|
||||
$Core::BRDFTexture = "core/rendering/images/brdfTexture.dds";
|
||||
$Core::WetnessTexture = "core/rendering/images/wetMap.png";
|
||||
|
||||
$Core::NoImageAssetFallback = "Core_Rendering:missingTexture_image";
|
||||
$Core::NoMaterialAssetFallback = "Core_Rendering:noMaterial";
|
||||
|
|
|
|||
BIN
Templates/BaseGame/game/core/rendering/images/wetMap.png
Normal file
BIN
Templates/BaseGame/game/core/rendering/images/wetMap.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 484 KiB |
|
|
@ -0,0 +1,8 @@
|
|||
<ImageAsset
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetName="wetMap_image"
|
||||
imageFile="@assetFile=wetMap.png"
|
||||
UseMips="true"
|
||||
isHDRImage="false"
|
||||
imageType="Albedo" />
|
||||
|
|
@ -367,14 +367,36 @@ vec3 boxProject(vec3 wsPosition, vec3 wsReflectVec, mat4 worldToObj, vec3 refSca
|
|||
return posonbox - refPosition.xyz;
|
||||
}
|
||||
|
||||
void dampen(inout Surface surface, sampler2D WetnessTexture, float accumTime, float degree)
|
||||
{
|
||||
if (degree<=0.0) return;
|
||||
vec3 n = abs(surface.N);
|
||||
|
||||
float grav = 2.0-pow(dot(float3(0,0,-1),surface.N),3);
|
||||
if (grav<0) grav*=-1.0;
|
||||
|
||||
float speed = accumTime*(1.0-surface.roughness)*grav;
|
||||
vec2 wetoffset = vec2(speed,speed/2)*0.1;
|
||||
|
||||
float wetness = texture(WetnessTexture, vec2(surface.P.xy*0.2+wetoffset)).b;
|
||||
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zx*0.2+wetoffset)).b,n.y);
|
||||
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zy*0.2+wetoffset)).b,n.x);
|
||||
wetness = pow(wetness,3)*degree;
|
||||
|
||||
surface.roughness = lerp(surface.roughness,(1.0-pow(wetness,2))*surface.roughness*0.92f+0.04f,degree);
|
||||
surface.baseColor.rgb = lerp(surface.baseColor.rgb,surface.baseColor.rgb*(2.0-wetness)/2,degree);
|
||||
updateSurface(surface);
|
||||
}
|
||||
|
||||
vec4 computeForwardProbes(Surface surface,
|
||||
float cubeMips, int numProbes, mat4x4 inWorldToObjArray[MAX_FORWARD_PROBES], vec4 inProbeConfigData[MAX_FORWARD_PROBES],
|
||||
vec4 inProbePosArray[MAX_FORWARD_PROBES], vec4 inRefScaleArray[MAX_FORWARD_PROBES], vec4 inRefPosArray[MAX_FORWARD_PROBES],
|
||||
vec3 wsEyePos, float skylightCubemapIdx, sampler2D BRDFTexture,
|
||||
vec3 wsEyePos, float skylightCubemapIdx, int SkylightDamp, sampler2D BRDFTexture, sampler2D WetnessTexture, float accumTime, float dampness,
|
||||
samplerCubeArray irradianceCubemapAR, samplerCubeArray specularCubemapAR)
|
||||
{
|
||||
int i = 0;
|
||||
float alpha = 1;
|
||||
float wetAmmout = 0;
|
||||
float blendFactor[MAX_FORWARD_PROBES];
|
||||
float blendSum = 0;
|
||||
float blendFacSum = 0;
|
||||
|
|
@ -383,7 +405,7 @@ vec4 computeForwardProbes(Surface surface,
|
|||
//Set up our struct data
|
||||
float contribution[MAX_FORWARD_PROBES];
|
||||
float blendCap = 0;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribution[i] = 0;
|
||||
float atten = 1.0-(length(wsEyePos-inProbePosArray[i].xyz)/maxProbeDrawDistance);
|
||||
|
|
@ -401,9 +423,15 @@ vec4 computeForwardProbes(Surface surface,
|
|||
else
|
||||
contribution[i] = 0.0;
|
||||
|
||||
if (inRefScaleArray[i].w>0)
|
||||
wetAmmout += contribution[i];
|
||||
else
|
||||
wetAmmout -= contribution[i];
|
||||
|
||||
blendSum += contribution[i];
|
||||
blendCap = max(contribution[i],blendCap);
|
||||
}
|
||||
if (wetAmmout<0) wetAmmout =0;
|
||||
|
||||
if (probehits > 0.0)
|
||||
{
|
||||
|
|
@ -415,7 +443,7 @@ vec4 computeForwardProbes(Surface surface,
|
|||
blendFacSum += blendFactor[i]; //running tally of results
|
||||
}
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
//normalize, but in the range of the highest value applied
|
||||
//to preserve blend vs skylight
|
||||
|
|
@ -425,7 +453,7 @@ vec4 computeForwardProbes(Surface surface,
|
|||
|
||||
#if (DEBUGVIZ_ATTENUATION == 1)
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribAlpha -= contribution[i];
|
||||
}
|
||||
|
|
@ -442,7 +470,7 @@ vec4 computeForwardProbes(Surface surface,
|
|||
|
||||
vec3 finalContribColor = vec3(0, 0, 0);
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
finalContribColor += contribution[i] *probeContribColors[i].rgb;
|
||||
contribAlpha -= contribution[i];
|
||||
|
|
@ -458,10 +486,22 @@ vec4 computeForwardProbes(Surface surface,
|
|||
vec3 irradiance = vec3(0, 0, 0);
|
||||
vec3 specular = vec3(0, 0, 0);
|
||||
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
{
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
if (SkylightDamp>0)
|
||||
wetAmmout += alpha;
|
||||
dampen(surface, WetnessTexture, accumTime, wetAmmout*dampness);
|
||||
|
||||
// Radiance (Specular)
|
||||
float lod = roughnessToMipLevel(surface.roughness, cubeMips);
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
|
|
@ -471,16 +511,15 @@ vec4 computeForwardProbes(Surface surface,
|
|||
|
||||
irradiance += textureLod(irradianceCubemapAR, vec4(dir, cubemapIdx), 0).xyz * contrib;
|
||||
specular += textureLod(specularCubemapAR, vec4(dir, cubemapIdx), lod).xyz * contrib;
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(skylightCubemapIdx != -1 && alpha >= 0.001)
|
||||
{
|
||||
irradiance = mix(irradiance,textureLod(irradianceCubemapAR, vec4(surface.R, skylightCubemapIdx), 0).xyz, alpha);
|
||||
specular = mix(specular,textureLod(specularCubemapAR, vec4(surface.R, skylightCubemapIdx), lod).xyz, alpha);
|
||||
}
|
||||
|
||||
|
||||
//energy conservation
|
||||
vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
||||
vec3 kD = 1.0f - F;
|
||||
|
|
@ -521,7 +560,7 @@ vec4 debugVizForwardProbes(Surface surface,
|
|||
float probehits = 0;
|
||||
//Set up our struct data
|
||||
float contribution[MAX_FORWARD_PROBES];
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribution[i] = 0;
|
||||
|
||||
|
|
@ -561,7 +600,7 @@ vec4 debugVizForwardProbes(Surface surface,
|
|||
}
|
||||
|
||||
float invBlendSumWeighted = 1.0f / blendFacSum;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
blendFactor[i] *= invBlendSumWeighted;
|
||||
contribution[i] *= blendFactor[i];
|
||||
|
|
@ -571,7 +610,7 @@ vec4 debugVizForwardProbes(Surface surface,
|
|||
if(showAtten == 1)
|
||||
{
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribAlpha -= contribution[i];
|
||||
}
|
||||
|
|
@ -589,7 +628,7 @@ vec4 debugVizForwardProbes(Surface surface,
|
|||
|
||||
vec3 finalContribColor = vec3(0, 0, 0);
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
finalContribColor += contribution[i] *probeContribColors[i].rgb;
|
||||
contribAlpha -= contribution[i];
|
||||
|
|
@ -613,7 +652,7 @@ vec4 debugVizForwardProbes(Surface surface,
|
|||
lod = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
|
|
|
|||
|
|
@ -371,14 +371,36 @@ float3 boxProject(float3 wsPosition, float3 wsReflectVec, float4x4 worldToObj, f
|
|||
return posonbox-refPosition;
|
||||
}
|
||||
|
||||
void dampen(inout Surface surface, TORQUE_SAMPLER2D(WetnessTexture), float accumTime, float degree)
|
||||
{
|
||||
if (degree<=0.0) return;
|
||||
float3 n = abs(surface.N);
|
||||
|
||||
float grav = 2.0-pow(dot(float3(0,0,-1),surface.N),3);
|
||||
if (grav<0) grav*=-1.0;
|
||||
|
||||
float speed = accumTime*(1.0-surface.roughness)*grav;
|
||||
float2 wetoffset = float2(speed,speed/2)*0.1;
|
||||
|
||||
float wetness = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.2+wetoffset)).b;
|
||||
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zx*0.2+wetoffset)).b,n.y);
|
||||
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.2+wetoffset)).b,n.x);
|
||||
wetness = pow(wetness,3)*degree;
|
||||
|
||||
surface.roughness = lerp(surface.roughness,(1.0-pow(wetness,2))*surface.roughness*0.92f+0.04f,degree);
|
||||
surface.baseColor.rgb = lerp(surface.baseColor.rgb,surface.baseColor.rgb*(2.0-wetness)/2,degree);
|
||||
surface.Update();
|
||||
}
|
||||
|
||||
float4 computeForwardProbes(Surface surface,
|
||||
float cubeMips, int numProbes, float4x4 inWorldToObjArray[MAX_FORWARD_PROBES], float4 inProbeConfigData[MAX_FORWARD_PROBES],
|
||||
float4 inProbePosArray[MAX_FORWARD_PROBES], float4 inRefScaleArray[MAX_FORWARD_PROBES], float4 inRefPosArray[MAX_FORWARD_PROBES],
|
||||
float3 wsEyePos, float skylightCubemapIdx, TORQUE_SAMPLER2D(BRDFTexture),
|
||||
float3 wsEyePos, float skylightCubemapIdx, int SkylightDamp, TORQUE_SAMPLER2D(BRDFTexture), TORQUE_SAMPLER2D(WetnessTexture), float accumTime, float dampness,
|
||||
TORQUE_SAMPLERCUBEARRAY(irradianceCubemapAR), TORQUE_SAMPLERCUBEARRAY(specularCubemapAR))
|
||||
{
|
||||
int i = 0;
|
||||
float alpha = 1;
|
||||
float wetAmmout = 0;
|
||||
float blendFactor[MAX_FORWARD_PROBES];
|
||||
float blendSum = 0;
|
||||
float blendFacSum = 0;
|
||||
|
|
@ -389,7 +411,7 @@ float4 computeForwardProbes(Surface surface,
|
|||
|
||||
float blendCap = 0;
|
||||
//Process prooooobes
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribution[i] = 0.0;
|
||||
float atten = 1.0-(length(wsEyePos-inProbePosArray[i].xyz)/maxProbeDrawDistance);
|
||||
|
|
@ -407,10 +429,16 @@ float4 computeForwardProbes(Surface surface,
|
|||
else
|
||||
contribution[i] = 0.0;
|
||||
|
||||
if (inRefScaleArray[i].w>0)
|
||||
wetAmmout += contribution[i];
|
||||
else
|
||||
wetAmmout -= contribution[i];
|
||||
|
||||
blendSum += contribution[i];
|
||||
blendCap = max(contribution[i],blendCap);
|
||||
}
|
||||
|
||||
if (wetAmmout<0) wetAmmout =0;
|
||||
|
||||
if (probehits > 0.0)
|
||||
{
|
||||
invBlendSum = (probehits - blendSum)/probehits; //grab the remainder
|
||||
|
|
@ -421,7 +449,7 @@ float4 computeForwardProbes(Surface surface,
|
|||
blendFacSum += blendFactor[i]; //running tally of results
|
||||
}
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
//normalize, but in the range of the highest value applied
|
||||
//to preserve blend vs skylight
|
||||
|
|
@ -431,7 +459,7 @@ float4 computeForwardProbes(Surface surface,
|
|||
|
||||
#if DEBUGVIZ_ATTENUATION == 1
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribAlpha -= contribution[i];
|
||||
}
|
||||
|
|
@ -448,7 +476,7 @@ float4 computeForwardProbes(Surface surface,
|
|||
|
||||
float3 finalContribColor = float3(0, 0, 0);
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
finalContribColor += contribution[i] *probeContribColors[i].rgb;
|
||||
contribAlpha -= contribution[i];
|
||||
|
|
@ -464,10 +492,22 @@ float4 computeForwardProbes(Surface surface,
|
|||
float3 irradiance = float3(0, 0, 0);
|
||||
float3 specular = float3(0, 0, 0);
|
||||
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
{
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
if (SkylightDamp>0)
|
||||
wetAmmout += alpha;
|
||||
dampen(surface, TORQUE_SAMPLER2D_MAKEARG(WetnessTexture), accumTime, wetAmmout*dampness);
|
||||
|
||||
// Radiance (Specular)
|
||||
float lod = roughnessToMipLevel(surface.roughness, cubeMips);
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
|
|
@ -477,9 +517,9 @@ float4 computeForwardProbes(Surface surface,
|
|||
|
||||
irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib;
|
||||
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(skylightCubemapIdx != -1 && alpha >= 0.001)
|
||||
{
|
||||
|
|
@ -527,7 +567,7 @@ float4 debugVizForwardProbes(Surface surface,
|
|||
float probehits = 0;
|
||||
//Set up our struct data
|
||||
float contribution[MAX_FORWARD_PROBES];
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribution[i] = 0;
|
||||
|
||||
|
|
@ -567,7 +607,7 @@ float4 debugVizForwardProbes(Surface surface,
|
|||
}
|
||||
|
||||
float invBlendSumWeighted = 1.0f / blendFacSum;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
blendFactor[i] *= invBlendSumWeighted;
|
||||
contribution[i] *= blendFactor[i];
|
||||
|
|
@ -577,7 +617,7 @@ float4 debugVizForwardProbes(Surface surface,
|
|||
if(showAtten == 1)
|
||||
{
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribAlpha -= contribution[i];
|
||||
}
|
||||
|
|
@ -595,7 +635,7 @@ float4 debugVizForwardProbes(Surface surface,
|
|||
|
||||
float3 finalContribColor = float3(0, 0, 0);
|
||||
float contribAlpha = 1;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
finalContribColor += contribution[i] *probeContribColors[i].rgb;
|
||||
contribAlpha -= contribution[i];
|
||||
|
|
@ -619,7 +659,7 @@ float4 debugVizForwardProbes(Surface surface,
|
|||
lod = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@ uniform int numProbes;
|
|||
|
||||
uniform samplerCubeArray specularCubemapAR;
|
||||
uniform samplerCubeArray irradianceCubemapAR;
|
||||
|
||||
uniform sampler2D WetnessTexture;
|
||||
#ifdef USE_SSAO_MASK
|
||||
uniform sampler2D ssaoMask;
|
||||
uniform vec4 rtParams6;
|
||||
uniform vec4 rtParams7;
|
||||
#endif
|
||||
uniform float accumTime;
|
||||
uniform float dampness;
|
||||
|
||||
uniform vec4 probePosArray[MAX_PROBES];
|
||||
uniform vec4 refPosArray[MAX_PROBES];
|
||||
|
|
@ -42,6 +44,7 @@ uniform vec4 probeContribColors[MAX_PROBES];
|
|||
#endif
|
||||
|
||||
uniform int skylightCubemapIdx;
|
||||
uniform int SkylightDamp;
|
||||
|
||||
out vec4 OUT_col;
|
||||
|
||||
|
|
@ -67,6 +70,7 @@ void main()
|
|||
|
||||
|
||||
float alpha = 1;
|
||||
float wetAmmout = 0;
|
||||
|
||||
#if SKYLIGHT_ONLY == 0
|
||||
int i = 0;
|
||||
|
|
@ -82,7 +86,7 @@ void main()
|
|||
if (alpha > 0)
|
||||
{
|
||||
//Process prooooobes
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribution[i] = 0;
|
||||
|
||||
|
|
@ -96,14 +100,20 @@ void main()
|
|||
contribution[i] = defineSphereSpaceInfluence(surface.P, probePosArray[i].xyz, probeConfigData[i].g)*atten;
|
||||
}
|
||||
|
||||
if (contribution[i]>0.0)
|
||||
probehits++;
|
||||
if (contribution[i]>0.0)
|
||||
probehits++;
|
||||
else
|
||||
contribution[i] = 0;
|
||||
|
||||
if (refScaleArray[i].w>0)
|
||||
wetAmmout += contribution[i];
|
||||
else
|
||||
wetAmmout -= contribution[i];
|
||||
|
||||
blendSum += contribution[i];
|
||||
blendCap = max(contribution[i],blendCap);
|
||||
}
|
||||
if (wetAmmout<0) wetAmmout =0;
|
||||
|
||||
if (probehits > 0.0)
|
||||
{
|
||||
|
|
@ -115,7 +125,7 @@ void main()
|
|||
blendFacSum += blendFactor[i]; //running tally of results
|
||||
}
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
//normalize, but in the range of the highest value applied
|
||||
//to preserve blend vs skylight
|
||||
|
|
@ -125,7 +135,7 @@ void main()
|
|||
|
||||
#if DEBUGVIZ_ATTENUATION == 1
|
||||
float contribAlpha = 0;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribAlpha += contribution[i];
|
||||
}
|
||||
|
|
@ -136,7 +146,7 @@ void main()
|
|||
|
||||
#if DEBUGVIZ_CONTRIB == 1
|
||||
vec3 finalContribColor = vec3(0, 0, 0);
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
finalContribColor += contribution[i] * vec3(fmod(i+1,2),fmod(i+1,3),fmod(i+1,4));
|
||||
}
|
||||
|
|
@ -144,11 +154,23 @@ void main()
|
|||
return;
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
{
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 irradiance = vec3(0, 0, 0);
|
||||
vec3 specular = vec3(0, 0, 0);
|
||||
|
||||
if (SkylightDamp>0)
|
||||
wetAmmout += alpha;
|
||||
dampen(surface, WetnessTexture, accumTime, wetAmmout*dampness);
|
||||
|
||||
// Radiance (Specular)
|
||||
#if DEBUGVIZ_SPECCUBEMAP == 0
|
||||
float lod = roughnessToMipLevel(surface.roughness, cubeMips);
|
||||
|
|
@ -157,7 +179,7 @@ void main()
|
|||
#endif
|
||||
|
||||
#if SKYLIGHT_ONLY == 0
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
|
|
@ -167,17 +189,16 @@ void main()
|
|||
|
||||
irradiance += textureLod(irradianceCubemapAR, vec4(dir, cubemapIdx), 0).xyz * contrib;
|
||||
specular += textureLod(specularCubemapAR, vec4(dir, cubemapIdx), lod).xyz * contrib;
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (skylightCubemapIdx != -1 && alpha >= 0.001)
|
||||
{
|
||||
irradiance = lerp(irradiance,textureLod(irradianceCubemapAR, vec4(surface.R, skylightCubemapIdx), 0).xyz,alpha);
|
||||
specular = lerp(specular,textureLod(specularCubemapAR, vec4(surface.R, skylightCubemapIdx), lod).xyz,alpha);
|
||||
}
|
||||
|
||||
|
||||
#if DEBUGVIZ_SPECCUBEMAP == 1 && DEBUGVIZ_DIFFCUBEMAP == 0
|
||||
OUT_col = vec4(specular, 1);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -20,11 +20,14 @@ uniform int numProbes;
|
|||
|
||||
TORQUE_UNIFORM_SAMPLERCUBEARRAY(specularCubemapAR, 4);
|
||||
TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
|
||||
TORQUE_UNIFORM_SAMPLER2D(WetnessTexture, 6);
|
||||
|
||||
#ifdef USE_SSAO_MASK
|
||||
TORQUE_UNIFORM_SAMPLER2D(ssaoMask, 6);
|
||||
uniform float4 rtParams6;
|
||||
TORQUE_UNIFORM_SAMPLER2D(ssaoMask, 7);
|
||||
uniform float4 rtParams7;
|
||||
#endif
|
||||
uniform float accumTime;
|
||||
uniform float dampness;
|
||||
|
||||
uniform float4 probePosArray[MAX_PROBES];
|
||||
uniform float4 refPosArray[MAX_PROBES];
|
||||
|
|
@ -37,6 +40,7 @@ uniform float4 probeContribColors[MAX_PROBES];
|
|||
#endif
|
||||
|
||||
uniform int skylightCubemapIdx;
|
||||
uniform int SkylightDamp;
|
||||
|
||||
float4 main(PFXVertToPix IN) : SV_TARGET
|
||||
{
|
||||
|
|
@ -59,7 +63,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
#endif
|
||||
|
||||
float alpha = 1;
|
||||
|
||||
float wetAmmout = 0;
|
||||
#if SKYLIGHT_ONLY == 0
|
||||
int i = 0;
|
||||
float blendFactor[MAX_PROBES];
|
||||
|
|
@ -74,7 +78,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
if (alpha > 0)
|
||||
{
|
||||
//Process prooooobes
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribution[i] = 0.0;
|
||||
|
||||
|
|
@ -93,9 +97,15 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
else
|
||||
contribution[i] = 0.0;
|
||||
|
||||
if (refScaleArray[i].w>0)
|
||||
wetAmmout += contribution[i];
|
||||
else
|
||||
wetAmmout -= contribution[i];
|
||||
|
||||
blendSum += contribution[i];
|
||||
blendCap = max(contribution[i],blendCap);
|
||||
}
|
||||
if (wetAmmout<0) wetAmmout =0;
|
||||
if (probehits > 0.0)
|
||||
{
|
||||
invBlendSum = (probehits - blendSum)/probehits; //grab the remainder
|
||||
|
|
@ -106,7 +116,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
blendFacSum += blendFactor[i]; //running tally of results
|
||||
}
|
||||
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
//normalize, but in the range of the highest value applied
|
||||
//to preserve blend vs skylight
|
||||
|
|
@ -116,7 +126,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
|
||||
#if DEBUGVIZ_ATTENUATION == 1
|
||||
float contribAlpha = 0;
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
contribAlpha += contribution[i];
|
||||
}
|
||||
|
|
@ -126,18 +136,30 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
|
||||
#if DEBUGVIZ_CONTRIB == 1
|
||||
float3 finalContribColor = float3(0, 0, 0);
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
finalContribColor += contribution[i] * float3(fmod(i+1,2),fmod(i+1,3),fmod(i+1,4));
|
||||
}
|
||||
return float4(finalContribColor, 1);
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
{
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
float3 irradiance = float3(0, 0, 0);
|
||||
float3 specular = float3(0, 0, 0);
|
||||
|
||||
if (SkylightDamp>0)
|
||||
wetAmmout += alpha;
|
||||
dampen(surface, TORQUE_SAMPLER2D_MAKEARG(WetnessTexture), accumTime, wetAmmout*dampness);
|
||||
|
||||
// Radiance (Specular)
|
||||
#if DEBUGVIZ_SPECCUBEMAP == 0
|
||||
float lod = roughnessToMipLevel(surface.roughness, cubeMips);
|
||||
|
|
@ -146,7 +168,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
#endif
|
||||
|
||||
#if SKYLIGHT_ONLY == 0
|
||||
for (i = 0; i < numProbes; ++i)
|
||||
for (i = 0; i < numProbes; i++)
|
||||
{
|
||||
float contrib = contribution[i];
|
||||
if (contrib > 0.0f)
|
||||
|
|
@ -156,11 +178,9 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
|
||||
irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, cubemapIdx, 0).xyz * contrib;
|
||||
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;
|
||||
alpha -= contrib;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(skylightCubemapIdx != -1 && alpha >= 0.001)
|
||||
{
|
||||
irradiance = lerp(irradiance,TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz,alpha);
|
||||
|
|
@ -172,7 +192,6 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|||
#elif DEBUGVIZ_DIFFCUBEMAP == 1
|
||||
return float4(irradiance, 1);
|
||||
#endif
|
||||
|
||||
//energy conservation
|
||||
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
||||
float3 kD = 1.0f - F;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue