mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 07:34:45 +00:00
Updates and fixes to probe and lighting logic.
This commit is contained in:
parent
b19a4b22c8
commit
f31445751f
23 changed files with 568 additions and 1466 deletions
|
|
@ -54,6 +54,24 @@ new ShaderData( AL_DeferredShader )
|
|||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
new GFXStateBlockData( AL_DeferredCaptureState : PFX_DefaultStateBlock )
|
||||
{
|
||||
blendEnable = false;
|
||||
|
||||
separateAlphaBlendDefined = true;
|
||||
separateAlphaBlendEnable = true;
|
||||
separateAlphaBlendSrc = GFXBlendSrcAlpha;
|
||||
separateAlphaBlendDest = GFXBlendDestAlpha;
|
||||
separateAlphaBlendOp = GFXBlendOpMin;
|
||||
|
||||
samplersDefined = true;
|
||||
samplerStates[0] = SamplerWrapLinear;
|
||||
samplerStates[1] = SamplerWrapLinear;
|
||||
samplerStates[2] = SamplerWrapLinear;
|
||||
samplerStates[3] = SamplerWrapLinear;
|
||||
samplerStates[4] = SamplerWrapLinear;
|
||||
};
|
||||
|
||||
new ShaderData( AL_ProbeShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
|
|
@ -76,7 +94,7 @@ singleton PostEffect( AL_PreCapture )
|
|||
renderTime = "PFXBeforeBin";
|
||||
renderBin = "ProbeBin";
|
||||
shader = AL_ProbeShader;
|
||||
stateBlock = AL_DeferredShadingState;
|
||||
stateBlock = AL_DeferredCaptureState;
|
||||
texture[0] = "#color";
|
||||
texture[1] = "#diffuseLighting";
|
||||
texture[2] = "#matinfo";
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ new GFXStateBlockData( AL_VectorLightState )
|
|||
{
|
||||
blendDefined = true;
|
||||
blendEnable = true;
|
||||
blendSrc = GFXBlendOne;
|
||||
blendSrc = GFXBlendSrcAlpha;
|
||||
blendDest = GFXBlendOne;
|
||||
blendOp = GFXBlendOpAdd;
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ new GFXStateBlockData( AL_ConvexLightState )
|
|||
{
|
||||
blendDefined = true;
|
||||
blendEnable = true;
|
||||
blendSrc = GFXBlendOne;
|
||||
blendSrc = GFXBlendSrcAlpha;
|
||||
blendDest = GFXBlendOne;
|
||||
blendOp = GFXBlendOpAdd;
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ new GFXStateBlockData( AL_ProbeState )
|
|||
{
|
||||
blendDefined = true;
|
||||
blendEnable = true;
|
||||
blendSrc = GFXBlendOne;
|
||||
blendSrc = GFXBlendSrcAlpha;
|
||||
blendDest = GFXBlendOne;
|
||||
blendOp = GFXBlendOpAdd;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,26 +42,29 @@ void main()
|
|||
return;
|
||||
}
|
||||
|
||||
vec3 colorBuffer = texture( colorBufferTex, uv0 ).rgb; //albedo
|
||||
vec3 albedo = texture( colorBufferTex, uv0 ).rgb; //albedo
|
||||
vec4 matInfo = texture( matInfoTex, uv0 ); //flags|smoothness|ao|metallic
|
||||
|
||||
bool emissive = getFlag(matInfo.r, 0);
|
||||
if (emissive)
|
||||
{
|
||||
OUT_col = float4(colorBuffer, 1.0);
|
||||
OUT_col = float4(albedo, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
vec4 diffuseLighting = texture( diffuseLightingBuffer, uv0 ); //shadowmap*specular
|
||||
|
||||
vec3 specularLighting = texture( specularLightingBuffer, uv0 ).rgb; //environment mapping*lightmaps
|
||||
vec4 diffuse = texture( diffuseLightingBuffer, uv0 ); //shadowmap*specular
|
||||
vec4 specular = texture( specularLightingBuffer, uv0 ); //environment mapping*lightmaps
|
||||
|
||||
float metalness = matInfo.a;
|
||||
|
||||
float frez = diffuseLighting.a;
|
||||
|
||||
vec3 diffuseColor = colorBuffer - (colorBuffer * metalness);
|
||||
vec3 reflectColor = specularLighting*colorBuffer;
|
||||
colorBuffer = diffuseColor+lerp(reflectColor,specularLighting,frez);
|
||||
colorBuffer *= max(diffuseLighting.rgb,vec3(0,0,0));
|
||||
vec3 diffuseColor = albedo - (albedo * metalness);
|
||||
vec3 specularColor = lerp(float3(0.04,0.04,0.04), albedo, metalness);
|
||||
|
||||
vec3 light = (diffuseColor * diffuse.rgb) + (specularColor * specular.rgb);
|
||||
|
||||
//albedo = diffuseColor+lerp(reflectColor,indiffuseLighting,frez);
|
||||
//albedo *= max(diffuseLighting.rgb,vec3(0,0,0));
|
||||
|
||||
OUT_col = hdrEncode(vec4(colorBuffer,1.0));
|
||||
//OUT_col = hdrEncode(vec4(colorBuffer,1.0));
|
||||
OUT_col = hdrEncode(vec4(light, 1.0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,34 +33,6 @@ float attenuate( vec4 lightColor, vec2 attParams, float dist )
|
|||
#endif
|
||||
}
|
||||
|
||||
// Calculate the specular coefficent
|
||||
//
|
||||
// pxlToLight - Normalized vector representing direction from the pixel being lit, to the light source, in world space
|
||||
// normal - Normalized surface normal
|
||||
// pxlToEye - Normalized vector representing direction from pixel being lit, to the camera, in world space
|
||||
// specPwr - Specular exponent
|
||||
// specularScale - A scalar on the specular output used in RGB accumulation.
|
||||
//
|
||||
float calcSpecular( vec3 pxlToLight, vec3 normal, vec3 pxlToEye, float specPwr, float specularScale )
|
||||
{
|
||||
#ifdef PHONG_SPECULAR
|
||||
// (R.V)^c
|
||||
float specVal = dot( normalize( -reflect( pxlToLight, normal ) ), pxlToEye );
|
||||
#else
|
||||
// (N.H)^c [Blinn-Phong, TGEA style, default]
|
||||
float specVal = dot( normal, normalize( pxlToLight + pxlToEye ) );
|
||||
#endif
|
||||
|
||||
#ifdef ACCUMULATE_LUV
|
||||
return pow( max( specVal, 0.00001f ), specPwr );
|
||||
#else
|
||||
// If this is RGB accumulation, than there is no facility for the luminance
|
||||
// of the light to play in to the specular intensity. In LUV, the luminance
|
||||
// of the light color gets rolled into N.L * Attenuation
|
||||
return specularScale * pow( max( specVal, 0.00001f ), specPwr );
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 getDistanceVectorToPlane( vec3 origin, vec3 direction, vec4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
|
|
|
|||
|
|
@ -156,7 +156,6 @@ PS_OUTPUT main(ConvexConnectP IN)
|
|||
bool emissive = getFlag(matInfo.r, 0);
|
||||
if (emissive)
|
||||
{
|
||||
//return float4(0.0, 0.0, 0.0, 0.0);
|
||||
return Output;
|
||||
}
|
||||
|
||||
|
|
@ -274,16 +273,16 @@ PS_OUTPUT main(ConvexConnectP IN)
|
|||
|
||||
//diffuse
|
||||
float disDiff = Fr_DisneyDiffuse(dotNVa, dotNLa, dotLHa, roughness);
|
||||
float3 diffuse = float3(disDiff, disDiff, disDiff) / M_PI_F;// alternative: (lightColor * dotNL) / Pi;
|
||||
//specular
|
||||
float3 diffuse = float3(disDiff, disDiff, disDiff) / M_PI_F;
|
||||
//specular
|
||||
float3 specular = directSpecular(normal, v, l, roughness, 1.0) * lightColor.rgb;
|
||||
|
||||
|
||||
if (nDotL<0) shadowed = 0;
|
||||
float Sat_NL_Att = saturate( nDotL * shadowed ) * lightBrightness;
|
||||
//output
|
||||
Output.diffuse = float4(diffuse * lightBrightness*shadowed, Sat_NL_Att);
|
||||
Output.spec = float4(specular * lightBrightness*shadowed, Sat_NL_Att);
|
||||
Output.diffuse = float4(diffuse * lightBrightness, Sat_NL_Att*shadowed);
|
||||
Output.spec = float4(specular * lightBrightness, Sat_NL_Att*shadowed);
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,13 +86,13 @@ float3 ImportanceSampleGGX(float2 Xi, float3 N)
|
|||
return normalize(sampleVec);
|
||||
}
|
||||
|
||||
float3 prefilterEnvMap(float3 R)
|
||||
float4 prefilterEnvMap(float3 R)
|
||||
{
|
||||
int sampleCount = resolution*2;
|
||||
float3 N = R;
|
||||
float3 V = R;
|
||||
float totalWeight = 0.0;
|
||||
float3 prefilteredColor = float3(0.0, 0.0, 0.0);
|
||||
float4 prefilteredColor = float4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
for (int i = 0; i < sampleCount; ++i)
|
||||
{
|
||||
|
|
@ -114,7 +114,7 @@ float3 prefilterEnvMap(float3 R)
|
|||
|
||||
float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
||||
|
||||
prefilteredColor += TORQUE_TEXCUBELOD(environmentMap, float4(L, mipLevel)).rgb * NdotL;
|
||||
prefilteredColor += TORQUE_TEXCUBELOD(environmentMap, float4(L, mipLevel)) * NdotL;
|
||||
|
||||
totalWeight += NdotL;
|
||||
}
|
||||
|
|
@ -126,5 +126,5 @@ float3 prefilterEnvMap(float3 R)
|
|||
float4 main(ConnectData IN) : TORQUE_TARGET0
|
||||
{
|
||||
float3 N = getCubeDir(face, IN.uv);
|
||||
return float4(prefilterEnvMap(N), 1.0);
|
||||
return prefilterEnvMap(N);
|
||||
}
|
||||
|
|
@ -30,12 +30,14 @@ TORQUE_UNIFORM_SAMPLER2D(matInfoTex,2);
|
|||
TORQUE_UNIFORM_SAMPLER2D(specularLightingBuffer,3);
|
||||
TORQUE_UNIFORM_SAMPLER2D(deferredTex,4);
|
||||
|
||||
uniform float radius;
|
||||
uniform float2 targetSize;
|
||||
uniform int captureRez;
|
||||
float4 main( PFXVertToPix IN) : TORQUE_TARGET0
|
||||
{
|
||||
float depth = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).w;
|
||||
if (depth>0.9999)
|
||||
return float4(0,0,0,0);
|
||||
|
||||
clip(-1);
|
||||
float3 colorBuffer = TORQUE_TEX2D( colorBufferTex, IN.uv0 ).rgb; //albedo
|
||||
float4 matInfo = TORQUE_TEX2D(matInfoTex, IN.uv0); //flags|smoothness|ao|metallic
|
||||
|
||||
|
|
@ -47,6 +49,12 @@ float4 main( PFXVertToPix IN) : TORQUE_TARGET0
|
|||
|
||||
float4 diffuseLighting = TORQUE_TEX2D( diffuseLightingBuffer, IN.uv0 ); //shadowmap*specular
|
||||
colorBuffer *= diffuseLighting.rgb;
|
||||
float2 relUV = IN.uv0*targetSize/captureRez;
|
||||
|
||||
return hdrEncode( float4(colorBuffer.rgb, 1.0) );
|
||||
//we use a 1k depth range in the capture frustum.
|
||||
//reduce that a bit to get something resembling depth fidelity out of 8 bits
|
||||
depth*=2000/radius;
|
||||
|
||||
float rLen = length(float3(relUV,depth)-float3(0.5,0.5,0));
|
||||
return hdrEncode( float4(colorBuffer,rLen));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 1);
|
|||
TORQUE_UNIFORM_SAMPLERCUBE(cubeMap, 2);
|
||||
TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemap, 3);
|
||||
TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 4);
|
||||
uniform float cubeMips;
|
||||
|
||||
uniform float4 rtParams0;
|
||||
|
||||
|
|
@ -36,32 +37,19 @@ uniform float3 bbMax;
|
|||
|
||||
uniform float useSphereMode;
|
||||
|
||||
float3 iblSpecular(float3 v, float3 n, float roughness)
|
||||
{
|
||||
float3 R = reflect(v, n);
|
||||
const float MAX_REFLECTION_LOD = 6.0;
|
||||
float3 prefilteredColor = TORQUE_TEXCUBELOD(cubeMap, float4(R, roughness * MAX_REFLECTION_LOD)).rgb;
|
||||
float2 envBRDF = TORQUE_TEX2D(BRDFTexture, float2(max(dot(n, v), 0.0), roughness)).rg;
|
||||
//return prefilteredColor * (envBRDF.x + envBRDF.y);
|
||||
return prefilteredColor;
|
||||
}
|
||||
|
||||
// Box Projected IBL Lighting
|
||||
// Based on: http://www.gamedev.net/topic/568829-box-projected-cubemap-environment-mapping/
|
||||
|
||||
// and https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
|
||||
float3 boxProject(float3 wsPosition, float3 reflectDir, float3 boxWSPos, float3 boxMin, float3 boxMax)
|
||||
{
|
||||
float3 nrdir = normalize(reflectDir);
|
||||
float3 rbmax = (boxMax - wsPosition) / nrdir;
|
||||
float3 rbmin = (boxMin - wsPosition) / nrdir;
|
||||
|
||||
float3 rbminmax;
|
||||
rbminmax.x = (nrdir.x > 0.0) ? rbmax.x : rbmin.x;
|
||||
rbminmax.y = (nrdir.y > 0.0) ? rbmax.y : rbmin.y;
|
||||
rbminmax.z = (nrdir.z > 0.0) ? rbmax.z : rbmin.z;
|
||||
|
||||
float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);
|
||||
float3 posonbox = wsPosition + nrdir * fa;
|
||||
float3 nrdir = reflectDir;
|
||||
float3 offset = wsPosition;
|
||||
float3 plane1vec = (boxMax - offset) / nrdir;
|
||||
float3 plane2vec = (boxMin - offset) / nrdir;
|
||||
|
||||
float3 furthestPlane = max(plane1vec, plane2vec);
|
||||
float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
|
||||
float3 posonbox = offset + nrdir * dist;
|
||||
|
||||
return posonbox - boxWSPos;
|
||||
}
|
||||
|
|
@ -83,23 +71,22 @@ float3 iblBoxDiffuse(float3 normal,
|
|||
float3 iblBoxSpecular(float3 normal,
|
||||
float3 wsPos,
|
||||
float roughness,
|
||||
float3 viewDir,
|
||||
float3 surfToEye,
|
||||
TORQUE_SAMPLER2D(brdfTexture),
|
||||
TORQUE_SAMPLERCUBE(radianceCube),
|
||||
float3 boxPos,
|
||||
float3 boxMin,
|
||||
float3 boxMax)
|
||||
{
|
||||
float3 v = viewDir;
|
||||
float3 n = normalize(normal);
|
||||
float ndotv = clamp(dot(n, v), 0.0, 1.0);
|
||||
float ndotv = clamp(dot(normal, surfToEye), 0.0, 1.0);
|
||||
|
||||
// BRDF
|
||||
float2 brdf = TORQUE_TEX2D(brdfTexture, float2(roughness, ndotv)).xy;
|
||||
|
||||
// Radiance (Specular)
|
||||
float lod = roughness * 6.0;
|
||||
float3 r = 2.0 * ndotv * n - v; // reflect(v, n);
|
||||
float maxmip = pow(cubeMips+1,2);
|
||||
float lod = roughness*maxmip;
|
||||
float3 r = reflect(surfToEye, normal);
|
||||
float3 cubeR = normalize(r);
|
||||
cubeR = boxProject(wsPos, cubeR, boxPos, boxMin, boxMax);
|
||||
|
||||
|
|
@ -114,6 +101,57 @@ struct PS_OUTPUT
|
|||
float4 spec: TORQUE_TARGET1;
|
||||
};
|
||||
|
||||
float defineSphereSpaceInfluence(float3 centroidPosVS, float rad, float2 atten, float3 surfPosVS, float3 norm)
|
||||
{
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
float3 lightVec = centroidPosVS - surfPosVS;
|
||||
float lenLightV = length( lightVec );
|
||||
if (( rad - lenLightV )<0)
|
||||
return -1;
|
||||
|
||||
// Get the attenuated falloff.
|
||||
float attn = attenuate( float4(1,1,1,1), atten, lenLightV );
|
||||
if ((attn - 1e-6)<0)
|
||||
return -1;
|
||||
|
||||
// Normalize lightVec
|
||||
lightVec = lightVec /= lenLightV;
|
||||
|
||||
// If we can do dynamic branching then avoid wasting
|
||||
// fillrate on pixels that are backfacing to the light.
|
||||
float nDotL = abs(dot( lightVec, norm ));
|
||||
|
||||
return saturate( nDotL * attn );
|
||||
}
|
||||
|
||||
float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float rad, float2 atten) //atten currently unused
|
||||
{
|
||||
float3 boxMin = probePos-(float3(0.5,0.5,0.5)*rad);
|
||||
float3 boxMax = probePos+(float3(0.5,0.5,0.5)*rad);
|
||||
//Try to clip anything that falls outside our box as well
|
||||
//TODO: Make it support rotated boxes as well
|
||||
if(surfPosWS.x > boxMax.x || surfPosWS.y > boxMax.y || surfPosWS.z > boxMax.z ||
|
||||
surfPosWS.x < boxMin.x || surfPosWS.y < boxMin.y || surfPosWS.z < boxMin.z)
|
||||
return -1;
|
||||
|
||||
float blendVal = 1;
|
||||
//float3 atten = min(boxMax-surfPosWS,surfPosWS-boxMin);
|
||||
//blendVal = min(min(atten.x,atten.y),atten.z);
|
||||
return blendVal;
|
||||
}
|
||||
|
||||
float defineDepthInfluence(float3 probePosWS, float3 surfPosWS, TORQUE_SAMPLERCUBE(radianceCube))
|
||||
{
|
||||
//TODO properly: filter out pixels projected uppon by probes behind walls by looking up the depth stored in the probes cubemap alpha
|
||||
//and comparing legths
|
||||
float3 probeToSurf = probePosWS-surfPosWS;
|
||||
|
||||
float depthRef = TORQUE_TEXCUBELOD(cubeMap, float4(-probeToSurf,0)).a*radius;
|
||||
float dist = length( probeToSurf );
|
||||
|
||||
return depthRef-dist;
|
||||
}
|
||||
|
||||
PS_OUTPUT main( ConvexConnectP IN )
|
||||
{
|
||||
PS_OUTPUT Output = (PS_OUTPUT)0;
|
||||
|
|
@ -121,7 +159,6 @@ PS_OUTPUT main( ConvexConnectP IN )
|
|||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
|
||||
//float4 hardCodedRTParams0 = float4(0,0.0277777780,1,0.972222209);
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
||||
// Matinfo flags
|
||||
|
|
@ -137,10 +174,6 @@ PS_OUTPUT main( ConvexConnectP IN )
|
|||
// Need world-space normal.
|
||||
float3 wsNormal = mul(float4(normal, 1), invViewMat).rgb;
|
||||
|
||||
float4 color = float4(1, 1, 1, 1);
|
||||
float4 ref = float4(0,0,0,0);
|
||||
float alpha = 1;
|
||||
|
||||
float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 viewSpacePos = eyeRay * depth;
|
||||
|
||||
|
|
@ -148,70 +181,28 @@ PS_OUTPUT main( ConvexConnectP IN )
|
|||
|
||||
// Use eye ray to get ws pos
|
||||
float3 worldPos = float3(eyePosWorld + wsEyeRay * depth);
|
||||
float smoothness = min((1.0 - matInfo.b)*11.0 + 1.0, 8.0);//bump up to 8 for finalization
|
||||
|
||||
if(useSphereMode)
|
||||
|
||||
float blendVal = 1.0;
|
||||
|
||||
//clip bounds and (TODO properly: set falloff)
|
||||
if(useSphereMode)
|
||||
{
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
float3 lightVec = probeLSPos - viewSpacePos;
|
||||
float lenLightV = length( lightVec );
|
||||
clip( radius - lenLightV );
|
||||
|
||||
// Get the attenuated falloff.
|
||||
float atten = attenuate( float4(1,1,1,1), attenuation, lenLightV );
|
||||
clip( atten - 1e-6 );
|
||||
|
||||
// Normalize lightVec
|
||||
lightVec = normalize(lightVec);
|
||||
|
||||
// If we can do dynamic branching then avoid wasting
|
||||
// fillrate on pixels that are backfacing to the light.
|
||||
float nDotL = abs(dot( lightVec, normal ));
|
||||
|
||||
float Sat_NL_Att = saturate( nDotL * atten );
|
||||
|
||||
float3 reflectionVec = reflect(IN.wsEyeDir, float4(wsNormal,nDotL)).xyz;
|
||||
|
||||
float3 nrdir = normalize(reflectionVec);
|
||||
float3 rbmax = (bbMax - worldPos.xyz) / nrdir;
|
||||
float3 rbmin = (bbMin - worldPos.xyz) / nrdir;
|
||||
|
||||
float3 rbminmax = (nrdir > 0.0) ? rbmax : rbmin;
|
||||
float fa = min(min(rbminmax.x,rbminmax.y),rbminmax.z);
|
||||
if (dot( lightVec, normal )<0.0f)
|
||||
clip(fa);
|
||||
|
||||
float3 posOnBox = worldPos.xyz + nrdir * fa;
|
||||
reflectionVec = posOnBox - probeWSPos;
|
||||
|
||||
reflectionVec = mul(probeWSPos,reflectionVec);
|
||||
|
||||
ref = float4(reflectionVec, smoothness);
|
||||
|
||||
alpha = Sat_NL_Att;
|
||||
float roughness = 1 - matInfo.b;
|
||||
|
||||
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, ref).rgb;
|
||||
|
||||
float3 specular = TORQUE_TEXCUBELOD(cubeMap, ref).rgb;// iblSpecular(wsEyeRay, wsNormal, roughness);
|
||||
|
||||
Output.diffuse = float4(irradiance.rgb, alpha);
|
||||
Output.spec = float4(specular.rgb, alpha);
|
||||
|
||||
return Output;
|
||||
blendVal = defineSphereSpaceInfluence(probeLSPos, radius, attenuation, viewSpacePos, normal);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Try to clip anything that falls outside our box as well
|
||||
//TODO: Make it support rotated boxes as well
|
||||
if(worldPos.x > bbMax.x || worldPos.y > bbMax.y || worldPos.z > bbMax.z ||
|
||||
worldPos.x < bbMin.x || worldPos.y < bbMin.y || worldPos.z < bbMin.z)
|
||||
clip(-1);
|
||||
|
||||
float blendVal = 1.0;
|
||||
float3 pixDir = normalize(eyePosWorld.xyz - worldPos.xyz);
|
||||
Output.diffuse = float4(iblBoxDiffuse(wsNormal, worldPos, TORQUE_SAMPLERCUBE_MAKEARG(irradianceCubemap), probeWSPos, bbMin, bbMax), blendVal);
|
||||
Output.spec = float4(iblBoxSpecular(wsNormal, worldPos, 1.0 - matInfo.b, pixDir, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax), blendVal);
|
||||
return Output;
|
||||
blendVal = defineBoxSpaceInfluence(worldPos, probeWSPos, radius*2, attenuation);
|
||||
}
|
||||
clip(blendVal);
|
||||
|
||||
//flip me on to have probes filter by depth
|
||||
//clip(defineDepthInfluence(probeWSPos, worldPos, TORQUE_SAMPLERCUBE_MAKEARG(cubeMap)));
|
||||
|
||||
|
||||
//render into the bound space defined above
|
||||
float3 surfToEye = normalize(worldPos.xyz-eyePosWorld.xyz);
|
||||
Output.diffuse = float4(iblBoxDiffuse(wsNormal, worldPos, TORQUE_SAMPLERCUBE_MAKEARG(irradianceCubemap), probeWSPos, bbMin, bbMax), blendVal);
|
||||
Output.spec = float4(iblBoxSpecular(wsNormal, worldPos, 1.0 - matInfo.b, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax), blendVal);
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,8 +73,15 @@ uniform float4x4 dynamicViewToLightProj;
|
|||
uniform float2 lightAttenuation;
|
||||
uniform float shadowSoftness;
|
||||
|
||||
float4 main( ConvexConnectP IN ) : TORQUE_TARGET0
|
||||
struct PS_OUTPUT
|
||||
{
|
||||
float4 diffuse: TORQUE_TARGET0;
|
||||
float4 spec: TORQUE_TARGET1;
|
||||
};
|
||||
|
||||
PS_OUTPUT main( ConvexConnectP IN ) : TORQUE_TARGET0
|
||||
{
|
||||
PS_OUTPUT Output = (PS_OUTPUT)0;
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
|
@ -85,7 +92,7 @@ float4 main( ConvexConnectP IN ) : TORQUE_TARGET0
|
|||
bool emissive = getFlag(matInfo.r, 0);
|
||||
if (emissive)
|
||||
{
|
||||
return float4(0.0, 0.0, 0.0, 0.0);
|
||||
return Output;
|
||||
}
|
||||
|
||||
float4 colorSample = TORQUE_TEX2D( colorBuffer, uvScene );
|
||||
|
|
@ -181,36 +188,31 @@ float4 main( ConvexConnectP IN ) : TORQUE_TARGET0
|
|||
// NOTE: Do not clip on fully shadowed pixels as it would
|
||||
// cause the hardware occlusion query to disable the shadow.
|
||||
|
||||
// Specular term
|
||||
float specular = 0;
|
||||
float3 l = normalize(-lightDirection);
|
||||
float3 v = eyeRay;// normalize(eyePosWorld - worldPos.xyz);
|
||||
|
||||
float3 h = normalize(v + l);
|
||||
float dotNLa = clamp(dot(normal, l), 0.0, 1.0);
|
||||
float dotNVa = clamp(dot(normal, v), 0.0, 1.0);
|
||||
float dotNHa = clamp(dot(normal, h), 0.0, 1.0);
|
||||
float dotHVa = clamp(dot(normal, v), 0.0, 1.0);
|
||||
float dotLHa = clamp(dot(l, h), 0.0, 1.0);
|
||||
|
||||
float roughness = matInfo.g;
|
||||
float metalness = matInfo.b;
|
||||
|
||||
//diffuse
|
||||
float disDiff = Fr_DisneyDiffuse(dotNVa, dotNLa, dotLHa, roughness);
|
||||
float3 diffuse = float3(disDiff, disDiff, disDiff) / M_PI_F;
|
||||
//specular
|
||||
float3 specular = directSpecular(normal, v, l, roughness, 1.0) * lightColor.rgb;
|
||||
|
||||
float3 lightVec = lightPosition - viewSpacePos;
|
||||
float4 real_specular = EvalBDRF( float3( 1.0, 1.0, 1.0 ),
|
||||
lightcol,
|
||||
lightVec,
|
||||
viewSpacePos,
|
||||
normal,
|
||||
1.0-matInfo.b,
|
||||
matInfo.a );
|
||||
float3 lightColorOut = real_specular.rgb * lightBrightness * shadowed* atten;
|
||||
|
||||
float Sat_NL_Att = saturate( nDotL * atten * shadowed ) * lightBrightness;
|
||||
float4 addToResult = 0.0;
|
||||
if (nDotL<0) shadowed = 0;
|
||||
float Sat_NL_Att = saturate( nDotL * shadowed ) * lightBrightness;
|
||||
//output
|
||||
Output.diffuse = float4(diffuse * lightBrightness, Sat_NL_Att*shadowed);
|
||||
Output.spec = float4(specular * lightBrightness, Sat_NL_Att*shadowed);
|
||||
|
||||
// TODO: This needs to be removed when lightmapping is disabled
|
||||
// as its extra work per-pixel on dynamic lit scenes.
|
||||
//
|
||||
// Special lightmapping pass.
|
||||
if ( lightMapParams.a < 0.0 )
|
||||
{
|
||||
// This disables shadows on the backsides of objects.
|
||||
shadowed = nDotL < 0.0f ? 1.0f : shadowed;
|
||||
|
||||
Sat_NL_Att = 1.0f;
|
||||
shadowed = lerp( 1.0f, shadowed, atten );
|
||||
lightColorOut = shadowed;
|
||||
specular *= lightBrightness;
|
||||
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
|
||||
}
|
||||
return float4((lightColorOut*Sat_NL_Att+subsurface*(1.0-Sat_NL_Att)+addToResult.rgb),real_specular.a);
|
||||
return Output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,8 +314,8 @@ PS_OUTPUT main(FarFrustumQuadConnectP IN)
|
|||
float finalShadowed = shadowed;
|
||||
|
||||
//output
|
||||
Output.diffuse = float4(diffuse * (lightBrightness*shadowed), dotNLa);
|
||||
Output.spec = float4(specular * (lightBrightness*shadowed), dotNLa);
|
||||
Output.diffuse = float4(diffuse * (lightBrightness), dotNLa*shadowed);
|
||||
Output.spec = float4(specular * (lightBrightness), dotNLa*shadowed);
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue